Esempio n. 1
0
void Bvh::ParseFrame(const char* frameStr, char* p, BONE_ID parentFrameId)
{
	while(p) {
		std::string name;
		char* child = _searchChildTag(p, frameStr, &name);
		if (child) {
			if (name == "Site") {
				name = std::string("End of ") + m_frames[parentFrameId].name;
			}
			BONE_ID frameId = _getFrameIdByName(name.c_str());
			BvhFrame& frame = m_frames[frameId];

			_getToken(child);	// "OFFSET"
			frame.offset.x = _getF(child);
			frame.offset.y = _getF(child);
			frame.offset.z = -_getF(child);
			frame.offsetCombined = Vec3();

			if (parentFrameId >= 0) {
				_linkFrame(parentFrameId, frameId);
			}

			CalcBoneOffsetMatrix(frameId);

			if ("CHANNELS" == _getToken(child)) {
				int nChannels = _getI(child);
				for (int i = 0; i < nChannels; i++) {
					std::string t = _getToken(child);
					if (t == "Xposition") {
						frame.posIndices.x = channels++;
					} else if (t == "Yposition") {
						frame.posIndices.y = channels++;
					} else if (t == "Zposition") {
						frame.posIndices.z = channels++;
					} else if (t == "Xrotation") {
						frame.rotIndices.x = channels++;
					} else if (t == "Yrotation") {
						frame.rotIndices.y = channels++;
					} else if (t == "Zrotation") {
						frame.rotIndices.z = channels++;
					}
				}
			}

			ParseFrame("JOINT", child, frameId);
			ParseFrame("End", child, frameId);
		}
		p = _leaveBrace(child);
	}
}
static bool ParseFramesFromSpriteArray(const TArray<TSharedPtr<FJsonValue>>& ArrayBlock, TArray<FSpriteFrame>& OutSpriteFrames, TSet<FName>& FrameNames)
{
	GWarn->BeginSlowTask(NSLOCTEXT("Paper2D", "PaperJsonImporterFactory_ParsingSprites", "Parsing Sprite Frame"), true, true);
	bool bLoadedSuccessfully = true;

	// Parse all of the frames
	for (int32 FrameCount = 0; FrameCount < ArrayBlock.Num(); ++FrameCount)
	{
		GWarn->StatusUpdate(FrameCount, ArrayBlock.Num(), NSLOCTEXT("Paper2D", "PaperJsonImporterFactory_ParsingSprites", "Parsing Sprite Frames"));
		bool bReadFrameSuccessfully = true;
		FSpriteFrame Frame;

		const TSharedPtr<FJsonValue>& FrameDataAsValue = ArrayBlock[FrameCount];
		if (FrameDataAsValue->Type == EJson::Object)
		{
			TSharedPtr<FJsonObject> FrameData;
			FrameData = FrameDataAsValue->AsObject();

			FString FrameFilename = FPaperJSONHelpers::ReadString(FrameData, TEXT("filename"), TEXT(""));
			if (!FrameFilename.IsEmpty())
			{
				Frame.FrameName = FName(*FrameFilename); // case insensitive
				if (FrameNames.Contains(Frame.FrameName))
				{
					bReadFrameSuccessfully = false;
				}
				else
				{
					FrameNames.Add(Frame.FrameName);
				}

				bReadFrameSuccessfully = bReadFrameSuccessfully && ParseFrame(FrameData, /*out*/Frame);
			}
			else
			{
				bReadFrameSuccessfully = false;
			}
		}
		else
		{
			bReadFrameSuccessfully = false;
		}

		if (bReadFrameSuccessfully)
		{
			OutSpriteFrames.Add(Frame);
		}
		else
		{
			UE_LOG(LogPaperSpriteSheetImporter, Warning, TEXT("Frame %s is in an unexpected format"), *Frame.FrameName.ToString());
			bLoadedSuccessfully = false;
		}
	}

	GWarn->EndSlowTask();
	return bLoadedSuccessfully;
}
static bool ParseFramesFromSpriteHash(TSharedPtr<FJsonObject> ObjectBlock, TArray<FSpriteFrame>& OutSpriteFrames, TSet<FName>& FrameNames)
{
	GWarn->BeginSlowTask(NSLOCTEXT("Paper2D", "PaperJsonImporterFactory_ParsingSprites", "Parsing Sprite Frame"), true, true);
	bool bLoadedSuccessfully = true;

	// Parse all of the frames
	int32 FrameCount = 0;
	for (auto FrameIt = ObjectBlock->Values.CreateIterator(); FrameIt; ++FrameIt)
	{
		GWarn->StatusUpdate(FrameCount, ObjectBlock->Values.Num(), NSLOCTEXT("Paper2D", "PaperJsonImporterFactory_ParsingSprites", "Parsing Sprite Frames"));

		bool bReadFrameSuccessfully = true;

		FSpriteFrame Frame;
		Frame.FrameName = *FrameIt.Key();

		if (FrameNames.Contains(Frame.FrameName))
		{
			bReadFrameSuccessfully = false;
		}
		else
		{
			FrameNames.Add(Frame.FrameName);
		}

		TSharedPtr<FJsonValue> FrameDataAsValue = FrameIt.Value();
		TSharedPtr<FJsonObject> FrameData;
		if (FrameDataAsValue->Type == EJson::Object)
		{
			FrameData = FrameDataAsValue->AsObject();
			bReadFrameSuccessfully = bReadFrameSuccessfully && ParseFrame(FrameData, /*out*/Frame);
		}
		else
		{
			bReadFrameSuccessfully = false;
		}

		if (bReadFrameSuccessfully)
		{
			OutSpriteFrames.Add(Frame);
		}
		else
		{
			UE_LOG(LogPaperSpriteSheetImporter, Warning, TEXT("Frame %s is in an unexpected format"), *Frame.FrameName.ToString());
			bLoadedSuccessfully = false;
		}

		FrameCount++;
	}

	GWarn->EndSlowTask();
	return bLoadedSuccessfully;
}
Esempio n. 4
0
bool Transceiver::Parse()
{
  static IMFrame rxFrame;

  if(GetFrame(rxFrame))
      {
        if (!ParseFrame(rxFrame))
        {
   //       DBGINFO(" rxGET ");
        } else{
          return true;
        }
   }
   return false;
}
Esempio n. 5
0
void Bvh::LoadSub(const char *fileName)
{
	void *img = LoadFile(fileName);
	if (!img) {
		return;
	}

	char* body = (char*)img;

	channels = 0;
	ParseFrame("ROOT", body, -1);
	ParseMotion(body);
	PreCalculateMotion();
	free(img);

	printf("===============DumpFrames begin\n");
	DumpFrames(0, 0);
	printf("===============DumpFrames end\n");

}
Esempio n. 6
0
bool
KRT2Device::DataReceived(const void *_data, size_t length,
                         struct NMEAInfo &info)
{
  assert(length > 0);

  const char *data = static_cast<const char *>(_data);
  const char *end = data + length;
  bool result = false;

  unsigned expected_size = 0;
  do {
    if (!input_buffer.empty()) {
      input_buffer.append(*data);
      if (!expected_size)
        expected_size = FrameSize(input_buffer[1]);

      if (input_buffer.size() == expected_size) {
        // frame complete
        result |= ParseFrame(info);
        input_buffer.clear();
      } else if (input_buffer.full()) {
        // too much data (will never happen when buffer >= max(expected_size))
        input_buffer.clear();
      }
    } else if (*data == SYNC) {
      // reply to SYNC from radio
      port.Write(SYNC_ACK);
    } else if (*data == STX) {
      // found start of new frame
      input_buffer.append(*data);
      expected_size = 0;
    } else if (*data == ACK) {
      // previous command accepted
    } else if (*data == NAK) {
      // previous command rejected
    }
  } while (++data != end);

  return result;
}
Esempio n. 7
0
static ParseStatus ParseVP8X(WebPDemuxer* const dmux) {
  MemBuffer* const mem = &dmux->mem_;
  int loop_chunks = 0;
  uint32_t vp8x_size;
  ParseStatus status = PARSE_OK;

  if (MemDataSize(mem) < CHUNK_HEADER_SIZE) return PARSE_NEED_MORE_DATA;

  dmux->is_ext_format_ = 1;
  Skip(mem, TAG_SIZE);  // VP8X
  vp8x_size = GetLE32(mem);
  if (vp8x_size > MAX_CHUNK_PAYLOAD) return PARSE_ERROR;
  if (vp8x_size < VP8X_CHUNK_SIZE) return PARSE_ERROR;
  vp8x_size += vp8x_size & 1;
  if (SizeIsInvalid(mem, vp8x_size)) return PARSE_ERROR;
  if (MemDataSize(mem) < vp8x_size) return PARSE_NEED_MORE_DATA;

  dmux->feature_flags_ = GetByte(mem);
  Skip(mem, 3);  // Reserved.
  dmux->canvas_width_  = 1 + GetLE24s(mem);
  dmux->canvas_height_ = 1 + GetLE24s(mem);
  if (dmux->canvas_width_ * (uint64_t)dmux->canvas_height_ >= MAX_IMAGE_AREA) {
    return PARSE_ERROR;  // image final dimension is too large
  }
  Skip(mem, vp8x_size - VP8X_CHUNK_SIZE);  // skip any trailing data.
  dmux->state_ = WEBP_DEMUX_PARSED_HEADER;

  if (SizeIsInvalid(mem, CHUNK_HEADER_SIZE)) return PARSE_ERROR;
  if (MemDataSize(mem) < CHUNK_HEADER_SIZE) return PARSE_NEED_MORE_DATA;

  do {
    int store_chunk = 1;
    const size_t chunk_start_offset = mem->start_;
    const uint32_t fourcc = GetLE32(mem);
    const uint32_t chunk_size = GetLE32(mem);
    const uint32_t chunk_size_padded = chunk_size + (chunk_size & 1);

    if (chunk_size > MAX_CHUNK_PAYLOAD) return PARSE_ERROR;
    if (SizeIsInvalid(mem, chunk_size_padded)) return PARSE_ERROR;

    switch (fourcc) {
      case MKFOURCC('V', 'P', '8', 'X'): {
        return PARSE_ERROR;
      }
      case MKFOURCC('A', 'L', 'P', 'H'):
      case MKFOURCC('V', 'P', '8', ' '):
      case MKFOURCC('V', 'P', '8', 'L'): {
        Rewind(mem, CHUNK_HEADER_SIZE);
        status = ParseSingleImage(dmux);
        break;
      }
      case MKFOURCC('L', 'O', 'O', 'P'): {
        if (chunk_size_padded < LOOP_CHUNK_SIZE) return PARSE_ERROR;

        if (MemDataSize(mem) < chunk_size_padded) {
          status = PARSE_NEED_MORE_DATA;
        } else if (loop_chunks == 0) {
          ++loop_chunks;
          dmux->loop_count_ = GetLE16s(mem);
          Skip(mem, chunk_size_padded - LOOP_CHUNK_SIZE);
        } else {
          store_chunk = 0;
          goto Skip;
        }
        break;
      }
      case MKFOURCC('F', 'R', 'M', ' '): {
        status = ParseFrame(dmux, chunk_size_padded);
        break;
      }
      case MKFOURCC('T', 'I', 'L', 'E'): {
        if (dmux->num_frames_ == 0) dmux->num_frames_ = 1;
        status = ParseTile(dmux, chunk_size_padded);
        break;
      }
      case MKFOURCC('I', 'C', 'C', 'P'): {
        store_chunk = !!(dmux->feature_flags_ & ICCP_FLAG);
        goto Skip;
      }
      case MKFOURCC('M', 'E', 'T', 'A'): {
        store_chunk = !!(dmux->feature_flags_ & META_FLAG);
        goto Skip;
      }
 Skip:
      default: {
        if (chunk_size_padded <= MemDataSize(mem)) {
          if (store_chunk) {
            // Store only the chunk header and unpadded size as only the payload
            // will be returned to the user.
            if (!StoreChunk(dmux, chunk_start_offset,
                            CHUNK_HEADER_SIZE + chunk_size)) {
              return PARSE_ERROR;
            }
          }
          Skip(mem, chunk_size_padded);
        } else {
          status = PARSE_NEED_MORE_DATA;
        }
      }
    }

    if (mem->start_ == mem->riff_end_) {
      break;
    } else if (MemDataSize(mem) < CHUNK_HEADER_SIZE) {
      status = PARSE_NEED_MORE_DATA;
    }
  } while (status == PARSE_OK);

  return status;
}
Esempio n. 8
0
int main(int argc, char* argv[]) {
    FILE* Log1;
    FILE* Log2;
    FILE* Opt;
    unsigned long StartFrame;
    frame CurrentFrame1;
    frame CurrentFrame2;
    unsigned long OldFrameNumber;
    bool HoldLog1;
    bool HoldLog2;
    HoldLog1=HoldLog2=FALSE;
    NoDifferences=TRUE;
    RememberedVars.Count=0;
    if(argc!=5) {
        fprintf(stderr, "Requires 4 arguments\n");
        exit(1);
    }
    StartFrame=strtol(argv[1], NULL, 0);
    Log1=fopen(argv[2], "r");
    if(!Log1) {
        fprintf(stderr, "Could not open file '%s'\n", argv[1]);
        exit(1);
    }
    Log2=fopen(argv[3], "r");
    if(!Log2) {
        fprintf(stderr, "Could not open file '%s'\n", argv[2]);
        exit(1);
    }
    Opt=fopen(argv[4], "r");
    if(!Opt) {
        fprintf(stderr, "Could not open options file '%s'\n", argv[3]);
        exit(1);
    }
    ParseConfig(Opt);
    fclose(Opt);
    if(StartFrame!=0) {
        fprintf(stderr, "Skipping initial frames...\n", StartFrame);
        ForwardToFrame(StartFrame-1, Log1, Log2);
    }
    fprintf(stderr, "Comparing logs at frame %d...\n", StartFrame);
    while(!feof(Log1) && !feof(Log2)) {
        int i;
        if(!HoldLog1) ParseFrame(Log1, &CurrentFrame1);
        else HoldLog1=FALSE;
        if(!HoldLog2) ParseFrame(Log2, &CurrentFrame2);
        else HoldLog2=FALSE;
        if(CurrentFrame1.Number==CurrentFrame2.Number) {
            if(!CompareFrames(&CurrentFrame1, &CurrentFrame2)) {
                int i;
                fprintf(stderr, "At previous frame (%d):\n", OldFrameNumber);
                for(i=0; i<RememberedVars.Count; i++) {
                    fprintf(stderr, "\t%-10s <%s>\n", RememberedVars.Elements[i].Name, RememberedVars.Elements[i].Value);
                }
                exit(0);
            }
        } else {
            if(CurrentFrame1.Number>CurrentFrame2.Number) {
                fprintf(stderr, "Frame number %ld does not appear in log 1\n", CurrentFrame2.Number);
                HoldLog1=TRUE;
            } else {
                fprintf(stderr, "Frame number %ld does not appear in log 2\n", CurrentFrame1.Number);
                HoldLog2=TRUE;
            }
        }
        OldFrameNumber=CurrentFrame1.Number;
        for(i=0; i<RememberedVars.Count; i++) {
            strcpy(RememberedVars.Elements[i].Value, GetVariable(&CurrentFrame1, RememberedVars.Elements[i].Name));
        }
    }
    fprintf(stderr, "Logs match\n");
    exit(0);
}
Esempio n. 9
0
	bool MD5AnimParser::Parse()
	{
		while (Advance(false))
		{
			switch (m_currentLine[0])
			{
				#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
				case 'M': // MD5Version
					if (m_currentLine.GetWord(0) != "MD5Version")
						UnrecognizedLine();
					break;
				#endif

				case 'b': // baseframe/bounds
					if (m_currentLine.StartsWith("baseframe {"))
					{
						if (!ParseBaseframe())
						{
							Error("Failed to parse baseframe");
							return false;
						}
					}
					else if (m_currentLine.StartsWith("bounds {"))
					{
						if (!ParseBounds())
						{
							Error("Failed to parse bounds");
							return false;
						}
					}
					#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
					else
						UnrecognizedLine();
					#endif
					break;

				#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
				case 'c': // commandline
					if (m_currentLine.GetWord(0) != "commandline")
						UnrecognizedLine();
					break;
				#endif

				case 'f':
				{
					unsigned int index;
					if (std::sscanf(&m_currentLine[0], "frame %u {", &index) == 1)
					{
						if (m_frameIndex != index)
						{
							Error("Unexpected frame index (expected " + String::Number(m_frameIndex) + ", got " + String::Number(index) + ')');
							return false;
						}

						if (!ParseFrame())
						{
							Error("Failed to parse frame");
							return false;
						}

						m_frameIndex++;
					}
					else if (std::sscanf(&m_currentLine[0], "frameRate %u", &m_frameRate) != 1)
					{
						#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
						UnrecognizedLine();
						#endif
					}
					break;
				}

				case 'h': // hierarchy
					if (m_currentLine.StartsWith("hierarchy {"))
					{
						if (!ParseHierarchy())
						{
							Error("Failed to parse hierarchy");
							return false;
						}
					}
					#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
					else
						UnrecognizedLine();
					#endif
					break;

				case 'n': // num[Frames/Joints]
				{
					unsigned int count;
					if (std::sscanf(&m_currentLine[0], "numAnimatedComponents %u", &count) == 1)
					{
						#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
						if (!m_animatedComponents.empty())
							Warning("Animated components count is already defined");
						#endif

						m_animatedComponents.resize(count);
					}
					else if (std::sscanf(&m_currentLine[0], "numFrames %u", &count) == 1)
					{
						#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
						if (!m_frames.empty())
							Warning("Frame count is already defined");
						#endif

						m_frames.resize(count);
					}
					else if (std::sscanf(&m_currentLine[0], "numJoints %u", &count) == 1)
					{
						#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
						if (!m_joints.empty())
							Warning("Joint count is already defined");
						#endif

						m_joints.resize(count);
					}
					#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
					else
						UnrecognizedLine();
					#endif
					break;
				}

				default:
					#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
					UnrecognizedLine();
					#endif
					break;
			}
		}

		unsigned int frameCount = m_frames.size();
		if (frameCount == 0)
		{
			NazaraError("Frame count is invalid or missing");
			return false;
		}

		unsigned int jointCount = m_joints.size();
		if (jointCount == 0)
		{
			NazaraError("Joint count is invalid or missing");
			return false;
		}

		if (m_frameIndex != frameCount)
		{
			NazaraError("Missing frame infos: [" + String::Number(m_frameIndex) + ',' + String::Number(frameCount) + ']');
			return false;
		}

		if (m_frameRate == 0)
		{
			NazaraWarning("Framerate is either invalid or missing, assuming a default value of 24");
			m_frameRate = 24;
		}

		return true;
	}
Esempio n. 10
0
bool NzMD5AnimParser::Parse(NzAnimation* animation)
{
	while (Advance(false))
	{
		switch (m_currentLine[0])
		{
			#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
			case 'M': // MD5Version
				if (m_currentLine.GetWord(0) != "MD5Version")
					UnrecognizedLine();
				break;
			#endif

			case 'b': // baseframe/bounds
				if (m_currentLine.StartsWith("baseframe {"))
				{
					if (!ParseBaseframe())
					{
						Error("Failed to parse baseframe");
						return false;
					}
				}
				else if (m_currentLine.StartsWith("bounds {"))
				{
					if (!ParseBounds())
					{
						Error("Failed to parse bounds");
						return false;
					}
				}
				#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
				else
					UnrecognizedLine();
				#endif
				break;

			#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
			case 'c': // commandline
				if (m_currentLine.GetWord(0) != "commandline")
					UnrecognizedLine();
				break;
			#endif

			case 'f':
			{
				unsigned int index;
				if (std::sscanf(&m_currentLine[0], "frame %u {", &index) == 1)
				{
					if (m_frameIndex != index)
					{
						Error("Unexpected frame index (expected " + NzString::Number(m_frameIndex) + ", got " + NzString::Number(index) + ')');
						return false;
					}

					if (!ParseFrame())
					{
						Error("Failed to parse frame");
						return false;
					}

					m_frameIndex++;
				}
				else if (std::sscanf(&m_currentLine[0], "frameRate %u", &m_frameRate) != 1)
				{
					#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
					UnrecognizedLine();
					#endif
				}
				break;
			}

			case 'h': // hierarchy
				if (m_currentLine.StartsWith("hierarchy {"))
				{
					if (!ParseHierarchy())
					{
						Error("Failed to parse hierarchy");
						return false;
					}
				}
				#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
				else
					UnrecognizedLine();
				#endif
				break;

			case 'n': // num[Frames/Joints]
			{
				unsigned int count;
				if (std::sscanf(&m_currentLine[0], "numAnimatedComponents %u", &count) == 1)
				{
					#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
					if (!m_animatedComponents.empty())
						Warning("Animated components count is already defined");
					#endif

					m_animatedComponents.resize(count);
				}
				else if (std::sscanf(&m_currentLine[0], "numFrames %u", &count) == 1)
				{
					#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
					if (!m_frames.empty())
						Warning("Frame count is already defined");
					#endif

					m_frames.resize(count);
				}
				else if (std::sscanf(&m_currentLine[0], "numJoints %u", &count) == 1)
				{
					#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
					if (!m_joints.empty())
						Warning("Joint count is already defined");
					#endif

					m_joints.resize(count);
				}
				#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
				else
					UnrecognizedLine();
				#endif
				break;
			}

			default:
				#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
				UnrecognizedLine();
				#endif
				break;
		}
	}

	unsigned int frameCount = m_frames.size();
	if (frameCount == 0)
	{
		NazaraError("Frame count is invalid or missing");
		return false;
	}

	unsigned int jointCount = m_joints.size();
	if (jointCount == 0)
	{
		NazaraError("Joint count is invalid or missing");
		return false;
	}

	if (m_frameIndex != frameCount)
	{
		NazaraError("Missing frame infos: [" + NzString::Number(m_frameIndex) + ',' + NzString::Number(frameCount) + ']');
		return false;
	}

	if (m_frameRate == 0)
	{
		NazaraWarning("Framerate is either invalid or missing, assuming a default value of 24");
		m_frameRate = 24;
	}

	// À ce stade, nous sommes censés avoir assez d'informations pour créer l'animation
	if (!animation->CreateSkeletal(frameCount, jointCount))
	{
		NazaraError("Failed to create animation");
		return false;
	}

	NzSequence sequence;
	sequence.firstFrame = 0;
	sequence.frameCount = m_frames.size();
	sequence.frameRate = m_frameRate;
	sequence.name = m_stream.GetPath().SubStringFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true);
	if (!animation->AddSequence(sequence))
		NazaraWarning("Failed to add sequence");

	NzSequenceJoint* sequenceJoints = animation->GetSequenceJoints();

	// Pour que le squelette soit correctement aligné, il faut appliquer un quaternion "de correction" aux joints à la base du squelette
	NzQuaternionf rotationQuat = NzEulerAnglesf(-90.f, 90.f, 0.f);
	for (unsigned int i = 0; i < jointCount; ++i)
	{
		int parent = m_joints[i].parent;
		for (unsigned int j = 0; j < frameCount; ++j)
		{
			NzSequenceJoint& sequenceJoint = sequenceJoints[j*jointCount + i];

			if (parent >= 0)
			{
				sequenceJoint.position = m_frames[j].joints[i].pos;
				sequenceJoint.rotation = m_frames[j].joints[i].orient;
			}
			else
			{
				sequenceJoint.position = rotationQuat * m_frames[j].joints[i].pos;
				sequenceJoint.rotation = rotationQuat * m_frames[j].joints[i].orient;
			}

			sequenceJoint.scale = NzVector3f(1.f, 1.f, 1.f);
		}
	}

	return true;
}
Esempio n. 11
0
char *PROJECT::Load(char *filename, DISPLAY *disp)
{
	long error = 0;
	struct IFFHandle *iff;
	struct ContextNode *cn;
	char *err;
	OBJECT *where = NULL;
	int dir = INSERT_HORIZ;

	// there is currently no active camera read
	camera[0] = 0;

	iff = AllocIFF();
	if (!iff)
		return errors[ERR_MEM];

#ifdef __AMIGA__
	iff->iff_Stream = Open(filename, MODE_OLDFILE);
#else
	iff->iff_Stream = Open_(filename, MODE_OLDFILE);
#endif
	if (!(iff->iff_Stream))
	{
		IFFCleanup(iff);
		return errors[ERR_OPEN];
	}

	InitIFFasDOS(iff);
	error = OpenIFF(iff, IFFF_READ);
	if (error)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}

	error = ParseIFF(iff, IFFPARSE_RAWSTEP);
	if (error)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}
	cn = CurrentChunk(iff);
	if(!cn)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}
	if((cn->cn_ID != ID_FORM) || (cn->cn_Type != ID_RSCN))
	{
		IFFCleanup(iff);
		return errors[ERR_NORSCNFILE];
	}

	while(!error || error == IFFERR_EOC)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error != IFFERR_EOC)
		{
			// Get a pointer to the context node describing the current context
			cn = CurrentChunk(iff);
			if (cn)
			{
				switch (cn->cn_ID)
				{
					case ID_VERS:
						if(!ReadULONG(iff,&rscn_version,1))
						{
							IFFCleanup(iff);
							return errors[ERR_RSCNFILE];
						}
						if(rscn_version > VERSION)
						{
							IFFCleanup(iff);
							return errors[ERR_WRONGVERS];
						}
						break;
					case ID_FORM:
						switch(cn->cn_Type)
						{
							case ID_GNRL:
								err = ParseGeneral(iff,disp);
								if(err)
								{
									IFFCleanup(iff);
									return err;
								}
								break;
							case ID_FRAM:
								err = ParseFrame(iff);
								if(err)
								{
									IFFCleanup(iff);
									return err;
								}
								break;
							case ID_SRFS:
								err = ParseSurfaces(iff);
								if(err)
								{
									IFFCleanup(iff);
									return err;
								}
								break;
							case ID_CAMR:
								where = ParseCamera(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_SPHR:
								where = ParseSphere(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_PLAN:
								where = ParsePlane(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_PLGT:
							case ID_SLGT:
							case ID_DLGT:
								where = ParseLight(iff, where, dir, cn->cn_Type);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_MESH:
								where = ParseMesh(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_EXTN:
								where = ParseExternal(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_BOX:
								where = ParseBox(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_CYLR:
								where = ParseCylinder(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_CONE:
								where = ParseCone(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_CSG:
								where = ParseCSG(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_SOR:
								where = ParseSOR(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_HIER:
								dir = INSERT_VERT;
								break;
						}
						break;
				}
			}
		}
		else
		{
			cn = CurrentChunk(iff);
			if (cn)
			{
				if((cn->cn_ID == ID_FORM) && (cn->cn_Type == ID_HIER))
				{
					if(dir == INSERT_HORIZ)
					{
						while(where->GetPrev())
							where = (OBJECT*)where->GetPrev();
						if(where->GoUp())
							where = (OBJECT*)where->GoUp();
					}
					else
						dir = INSERT_HORIZ;
				}
			}
		}
	}
	if (error != IFFERR_EOF)
	{
		return errors[ERR_IFFPARSE];
	}

	IFFCleanup(iff);

	// we have to set the active camera
	disp->camera = (CAMERA*)GetObjectByName(camera);
	if(!disp->camera)
		err = errors[ERR_NOCAMERA];
	else
		err = NULL;

	// and translate track names to track objects
	// and the surface names to surface pointers
	TranslateNames();

	return err;
}
Esempio n. 12
0
void LoadTextXFile(const char *pText)
{
	const char *pTok = GetNextToken(pText, &pText);

	while(pTok)
	{
		if(!MFString_Compare(pTok, "Header"))
		{
			SkipToken(pText, "{");

			int maj = GetInt(pText, &pText);
			int min = GetInt(pText, &pText);
			int flag = GetInt(pText, &pText);

//			printf("XFile V%d.%d, 0x%X\n", maj, min, flag);

			pTok = GetNextToken(pText, &pText);
			while(MFString_Compare(pTok, "}"))
			{
				pTok = GetNextToken(pText, &pText);
			}
		}
		else if(!MFString_Compare(pTok, "Frame"))
		{
			pText = ParseFrame(pText, MFMatrix::identity, -1);
		}
		else if(!MFString_Compare(pTok, "Mesh"))
		{
			gMeshChunks.push(XMeshChunk::Create(MFMatrix::identity, pText, ""));
			SkipSection(pText);
		}
		else if(!MFString_Compare(pTok, "AnimationSet"))
		{
			gAnimSets.push(pText);
			SkipSection(pText);
		}
		else if(!MFString_Compare(pTok, "template"))
		{
//			const char *pName = GetNextToken(pText, &pText);
			SkipSection(pText);
		}
		else
		{
			MFDebug_Warn(4, MFStr("Unknown token '%s'\n", pTok));
			SkipSection(pText);
		}

		pTok = GetNextToken(pText, &pText);
	}

	int a;
	for(a=0; a<gMeshChunks.size(); a++)
	{
		ParseMesh(gMeshChunks[a].pMesh, gMeshChunks[a].mat, gMeshChunks[a].frameName);
	}

	for(a=0; a<gAnimSets.size(); a++)
	{
		ParseAnimationSet(gAnimSets[a]);
	}

	gMeshChunks.clear();
}
Esempio n. 13
0
const char *ParseFrame(const char *pText, const MFMatrix &mat, int parentID)
{
	char frameName[64];
	const char *pName = GetNextToken(pText, &pText, frameName);

	MFMatrix worldMatrix = mat;

	F3DBone *pBone = NULL;

	if(!MFString_CaseCmpN(pName, "bn_", 3) || !MFString_CaseCmpN(pName, "z_", 2))
	{
		int boneID = pModel->GetSkeletonChunk()->bones.size();
		pBone = &pModel->GetSkeletonChunk()->bones[boneID];

		F3DBone *pParent = parentID == -1 ? NULL : &pModel->GetSkeletonChunk()->bones[parentID];
		parentID = boneID;

		MFString_Copy(pBone->name, pName);
		MFString_Copy(pBone->parentName, pParent ? pParent->name : "");

		pBone->worldMatrix = mat;
	}

	if(MFString_Compare(pName, "{"))
		SkipToken(pText, "{");

	const char *pTok = GetNextToken(pText, &pText);

	while(MFString_Compare(pTok, "}"))
	{
		if(!MFString_Compare(pTok, "Frame"))
		{
			pText = ParseFrame(pText, worldMatrix, parentID);
		}
		else if(!MFString_Compare(pTok, "FrameTransformMatrix"))
		{
			SkipToken(pText, "{");

			MFMatrix localMatrix;
			GetFloatArray(pText, (float*)&localMatrix, 16, &pText);

			worldMatrix.Multiply(localMatrix, worldMatrix);

			if(pBone)
			{
				pBone->boneMatrix = localMatrix;
				pBone->worldMatrix = worldMatrix;
			}

			SkipToken(pText, ";");
			SkipToken(pText, "}");
		}
		else if(!MFString_Compare(pTok, "Mesh"))
		{
			gMeshChunks.push(XMeshChunk::Create(worldMatrix, pText, pName));
			SkipSection(pText);
		}
		else
		{
			MFDebug_Warn(4, MFStr("Unexpected token '%s'\n", pTok));
			SkipSection(pText);
		}

		pTok = GetNextToken(pText, &pText);
	}

	return pText;
}