本文整理汇总了C++中FileStream::ReadInt方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStream::ReadInt方法的具体用法?C++ FileStream::ReadInt怎么用?C++ FileStream::ReadInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStream
的用法示例。
在下文中一共展示了FileStream::ReadInt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例2: 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
//.........这里部分代码省略.........