本文整理汇总了C++中FileStream::ReadUShort方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStream::ReadUShort方法的具体用法?C++ FileStream::ReadUShort怎么用?C++ FileStream::ReadUShort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStream
的用法示例。
在下文中一共展示了FileStream::ReadUShort方法的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());
}
示例2: ImportAnm
//.........这里部分代码省略.........
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());
//
// Offset section.
//
// Note: Unlike versions 0-3, data in this version is
// Frame 1:
// Bone 1:
// Bone 2:
// ...
// Frame 2:
// Bone 1:
// ...
//
//Dictionary<UInt32, ANMBone> boneMap = new Dictionary<UInt32, ANMBone>();
for (uint32_t i = 0; i < numBones; ++i)
{
// The first frame is a special case since we are allocating bones
// as we read them in.
// Read in the offset data.
uint32_t boneID = file.ReadUInt();
uint16_t positionID = file.ReadUShort();
uint16_t unknownIndex = file.ReadUShort(); // Unknown.
uint16_t orientationID = file.ReadUShort();
unknownIndex = file.ReadUShort(); // Unknown. Seems to always be zero.
// Allocate the bone.
//ANMBone bone = new ANMBone();
//bone.id = boneID;
//// Allocate all the frames for the bone.
//for (int j = 0; j < numBones; ++j)
//{
// bone.frames.Add(new ANMFrame());
//}
//// Retrieve the data for the first frame.
//ANMFrame frame = bone.frames[0];
//frame.position = LookUpVector(positionID, positions);
//frame.orientation = LookUpQuaternion(orientationID, orientations);
//// Store the bone in the dictionary by bone ID.
//boneMap[boneID] = bone;
}
}
}
示例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
//.........这里部分代码省略.........