当前位置: 首页>>代码示例>>C++>>正文


C++ FileStream::ReadUInt方法代码示例

本文整理汇总了C++中FileStream::ReadUInt方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStream::ReadUInt方法的具体用法?C++ FileStream::ReadUInt怎么用?C++ FileStream::ReadUInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileStream的用法示例。


在下文中一共展示了FileStream::ReadUInt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ImportSkn

void LOLExporter::ImportSkn( const String& sknFilename )
{
	FileStream file;
	if (!file.Open(sknFilename))
	{
		printf("ERROR: could not open %s\n", sknFilename.c_str());
		exit(1);
	}

	uint32_t magic = file.ReadInt();

	uint16_t version = file.ReadUShort();
	uint16_t numObjects = file.ReadUShort();

	mLOLSkinMesh.Version = version;
	if (version == 1 || version == 2)
	{
		// Contains material headers.
		uint32_t numParts = file.ReadUInt();

		char nameBuffer[64];

		mLOLSkinMesh.MeshParts.resize(numParts);
		for (uint32_t i = 0; i < numParts; ++i)
		{
			// Read in the headers.
			LOLSkinMesh::MeshPart& meshPart = mLOLSkinMesh.MeshParts[i];

			file.Read(nameBuffer, sizeof(nameBuffer));
			meshPart.Material = nameBuffer;

			meshPart.StartVertex = file.ReadInt();
			meshPart.VertexCount = file.ReadUInt();
			meshPart.StartIndex = file.ReadInt();
			meshPart.IndexCount = file.ReadUInt();
		}

		uint32_t numIndices = file.ReadUInt();
		uint32_t numVertices = file.ReadUInt();

		mLOLSkinMesh.Indices.resize(numIndices);
		file.Read(&mLOLSkinMesh.Indices[0], numIndices * sizeof(uint16_t));

		mLOLSkinMesh.Verteces.resize(numVertices);
		for (LOLSkinMesh::Vertex& vertex : mLOLSkinMesh.Verteces)
		{
			file.Read(&vertex.Position, sizeof(float3));
			file.Read(&vertex.BoneIndices, sizeof(uint8_t)*4);
			file.Read(&vertex.BoneWeights, sizeof(float)*4);
			file.Read(&vertex.Normal, sizeof(float3));
			file.Read(&vertex.Texcoords, sizeof(float2));

			// Check SkinModelVertex
			/*float totalWeight = 0.0f;
			for (int i = 0; i < 4; ++i) 
			{
				if (vertex.BoneIndices[i] >= mBones.size())
					printf("Bone Index Out of Range!");

				totalWeight += vertex.weights[i];
			}

			if ( fabsf(totalWeight - 1.0f) > 0.001)
				printf("Unnormalized Bone Weights!");

			if ( vertex.texcoords[0] < 0.0f || vertex.texcoords[0] > 1.0f ||
				vertex.texcoords[1] < 0.0f || vertex.texcoords[1] > 1.0f )
				printf("Texcoords Index Out of Range!");*/
		}

		for ( size_t i = 0; i < mLOLSkinMesh.MeshParts.size(); ++i )
		{
			LOLSkinMesh::MeshPart& lolMeshPart = mLOLSkinMesh.MeshParts[i];

			const int32_t StartIndex = lolMeshPart.StartIndex;
			const int32_t EndIndex = lolMeshPart.StartIndex + lolMeshPart.IndexCount;
			for (int32_t j = StartIndex; j < EndIndex; ++j)
			{
				uint16_t index = mLOLSkinMesh.Indices[j];
				const LOLSkinMesh::Vertex& vertex = mLOLSkinMesh.Verteces[index];
				lolMeshPart.Bound.Merge(vertex.Position);
			}

			mLOLSkinMesh.Bound.Merge(lolMeshPart.Bound);
		}
	}
	else
	{
		printf("Unsupported Skn format!\n");
		exit(1);
	}

	printf("SkinnedMesh %s\n", sknFilename.c_str());
	printf("Version: %d\n", mLOLSkinMesh.Version);
	printf("Number of Objects: %d\n", numObjects);
	printf("Number of Material Headers: %d\n", mLOLSkinMesh.MeshParts.size());
	printf("Number of Vertices: %d\n", mLOLSkinMesh.Verteces.size());
	printf("Number of Indices: %d\n", mLOLSkinMesh.Indices.size());
}
开发者ID:hustruan,项目名称:RcEngine,代码行数:99,代码来源:LOLExporter.cpp

示例2: ImportAnm

void LOLExporter::ImportAnm( const String& anmFilename )
{
	FileStream file;
	if (!file.Open(anmFilename))
	{
		printf("ERROR: could not open %s\n", anmFilename.c_str());
		exit(1);
	}

	char id[8];
	file.Read(id, sizeof(id));
	
	uint32_t version = file.ReadUInt();
	mLOLAnimation.Version = version;

	// Version 0, 1, 2, 3 Code
	if (version == 0 || version == 1 || version == 2 || version == 3)
	{
		uint32_t magic = file.ReadUInt();
		uint32_t numBones = file.ReadUInt();
		uint32_t numFrames = file.ReadUInt();
		uint32_t playbackFPS = file.ReadUInt();

		char nameBuffer[32];

		// Read in all the bones
		mLOLAnimation.Clip.AnimationTracks.resize(numBones);
		for (uint32_t i = 0; i < numBones; ++i)
		{
			LOLAnimation::AnimationClip::AnimationTrack& animTrack = mLOLAnimation.Clip.AnimationTracks[i];

			file.Read(nameBuffer, sizeof(nameBuffer));
			animTrack.BoneName = nameBuffer;
			
			// Unknown
			uint32_t boneType = file.ReadUInt();

			// For each bone, read in its value at each frame in the animation.
			animTrack.KeyFrames.resize(numFrames);
			for (LOLAnimation::AnimationClip::KeyFrame& frame : animTrack.KeyFrames)
			{
				// Read in the frame's quaternion.
				frame.Orientation[3] = file.ReadFloat(); // x
				frame.Orientation[1] = file.ReadFloat(); // y
				frame.Orientation[2] = file.ReadFloat(); // z
				frame.Orientation[0] = file.ReadFloat(); // w

				// Read in the frame's position.
				file.Read(&frame.Position, sizeof(float3));
			}
		}
	}
	else if (version == 4)
	{
		uint32_t magic = file.ReadUInt();

		// Not sure what any of these mean.
		float unknown = file.ReadFloat();
		unknown = file.ReadFloat();
		unknown = file.ReadFloat();

		uint32_t numBones = file.ReadUInt();
		uint32_t numFrames = file.ReadUInt();
		uint32_t playbackFPS = (uint32_t)(1.0f / file.ReadFloat() + 0.5f);

		// These are offsets to specific data sections in the file.
		uint32_t unknownOffset = file.ReadUInt();
		unknownOffset = file.ReadUInt();
		unknownOffset = file.ReadUInt();

		uint32_t positionOffset = file.ReadUInt();
		uint32_t orientationOffset = file.ReadUInt();
		uint32_t indexOffset = file.ReadUInt();

		// These last three values are confusing.
		// They aren't a vector and they throw off the offset values
		// by 12 bytes. Just ignore them and keep reading.
		unknownOffset = file.ReadUInt();
		unknownOffset = file.ReadUInt();
		unknownOffset = file.ReadUInt();

		//
		// Vector section.
		//

		std::vector<float> positions;
		uint32_t numPositions = (orientationOffset - positionOffset) / sizeof(float);
		for (uint32_t i = 0; i < numPositions; ++i)
			positions.push_back(file.ReadFloat());

		//
		// Quaternion section.
		//

		std::vector<float> orientations;
		uint32_t numOrientations = (indexOffset - orientationOffset) / sizeof(float);
		for (uint32_t i = 0; i < numOrientations; ++i)
			orientations.push_back(file.ReadFloat());

		//
//.........这里部分代码省略.........
开发者ID:hustruan,项目名称:RcEngine,代码行数:101,代码来源:LOLExporter.cpp

示例3: ImportSkl

void LOLExporter::ImportSkl( const String& sklFilename )
{
	FileStream stream;
	if (!stream.Open(sklFilename))
	{
		printf("ERROR: could not open %s\n", sklFilename.c_str());
		exit(1);
	}

	char id[8];
	stream.Read(id, 8);
	mLOLSkeleton.Version = stream.ReadUInt();

	if (mLOLSkeleton.Version == 1 || mLOLSkeleton.Version == 2)
	{
		uint32_t designerID = stream.ReadUInt();

		char nameBuffer[32];
		float matrix[12];

		// Read in the bones.
		uint32_t numBones = stream.ReadUInt();
		mLOLSkeleton.Bones.resize(numBones);
		for (uint32_t i = 0; i < numBones; ++i)
		{
			LOLBone& bone = mLOLSkeleton.Bones[i];

			stream.Read(nameBuffer, 32);
			bone.Name = nameBuffer;

			bone.Index = i;
			bone.ParentIndex = stream.ReadInt();
			bone.Scale = stream.ReadFloat();

			// Read in transform matrix.
			stream.Read(matrix, sizeof(matrix));

			float4x4 rotation(
				matrix[0], matrix[4], matrix[8],  0.0f,
				matrix[1], matrix[5], matrix[9],  0.0f,
				matrix[2], matrix[6], matrix[10], 0.0f,
				0.0f,	   0.0f,	  0.0f,		  1.0f);

			bone.Orientation = QuaternionFromRotationMatrix(rotation);
			bone.Position = float3(matrix[3], matrix[7], matrix[11]);
		}

		// Version two contains bone IDs.
		if (mLOLSkeleton.Version == 2)
		{
			uint32_t numBoneIDs = stream.ReadUInt();
			for (uint32_t i = 0; i < numBoneIDs; ++i)
				mLOLSkeleton.BoneIDs.push_back(stream.ReadUInt());
		}
	}
	else if (mLOLSkeleton.Version == 0)
	{
		uint16_t zero = stream.ReadUShort();
		uint16_t numBones = stream.ReadUShort();
		uint32_t numBoneIDs = stream.ReadUInt();
		uint16_t offsetToVertexData = stream.ReadUShort(); // Should be 64.

		int unknown = stream.ReadShort(); // ?

		int offset1 = stream.ReadInt();
		int offsetToAnimationIndices = stream.ReadInt();
		int offset2 = stream.ReadInt();
		int offset3 = stream.ReadInt();
		int offsetToStrings = stream.ReadInt();

		// Not sure what this data represents.
		// I think it's padding incase more header data is required later.
		//stream.Seek(stream.GetPosition() + 20);

		mLOLSkeleton.Bones.resize(numBones);
		stream.Seek(offsetToVertexData);	
		for (int i = 0; i < numBones; ++i)
		{
			LOLBone& bone = mLOLSkeleton.Bones[i];

			// The old scale was always 0.1. For now, just go with it.
			bone.Scale = 0.1f;

			zero = stream.ReadShort(); // ?
			bone.Index = stream.ReadShort();
			bone.ParentIndex = stream.ReadShort();
			unknown = stream.ReadShort(); // ?

			int namehash = stream.ReadInt();
			float twoPointOne = stream.ReadFloat();

			stream.Read(&bone.Position, sizeof(float3));

			float one = stream.ReadFloat(); // ? Maybe scales for X, Y, and Z
			one = stream.ReadFloat();
			one = stream.ReadFloat();

			stream.Read(&bone.Orientation, sizeof(Quaternionf));

			float ctx = stream.ReadFloat(); // ctx
//.........这里部分代码省略.........
开发者ID:hustruan,项目名称:RcEngine,代码行数:101,代码来源:LOLExporter.cpp


注:本文中的FileStream::ReadUInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。