bool LoadPositions(UInt64 addr) { string filename = FIndResourceFile(addr); if (filename.Length <= 0) { return(false); } string fullname = Application.dataPath + PathGeoMetry + filename; byte[] data = File.ReadAllBytes(fullname); MyRes_CreateBuffer vert = new MyRes_CreateBuffer(); int headerSize = Marshal.SizeOf(vert); Utils.Deserialize(ref vert, data, headerSize); int stride = (int)Info.vb[0].strides[0]; uint vertCount = vert.desc.ByteWidth / (uint)stride; int startIdx = headerSize; for (int i = 0; i < vertCount; ++i) { Vector3 pos = new Vector3(); pos.x = BitConverter.ToSingle(data, startIdx); pos.y = BitConverter.ToSingle(data, startIdx + 4); pos.z = BitConverter.ToSingle(data, startIdx + 8); Positions.Add(pos); startIdx += stride; } return(true); }
bool LoadNormals(UInt64 addr) { string filename = FIndResourceFile(addr); if (filename.Length <= 0) { return(false); } string fullname = Application.dataPath + PathGeoMetry + filename; byte[] data = File.ReadAllBytes(fullname); MyRes_CreateBuffer vert = new MyRes_CreateBuffer(); int headerSize = Marshal.SizeOf(vert); Utils.Deserialize(ref vert, data, headerSize); int stride = (int)Info.vb[0].strides[0]; uint vertCount = vert.desc.ByteWidth / (uint)stride; int startIdx = headerSize + 0xc; for (int i = 0; i < vertCount; ++i) { Vector3 nor = new Vector3(); nor.x = (data[startIdx + 0] / 128.0f) - 1.0f; nor.y = (data[startIdx + 4] / 128.0f) - 1.0f; nor.z = (data[startIdx + 8] / 128.0f) - 1.0f; Normals.Add(nor); startIdx += stride; } return(true); }
bool LoadTriangles(UInt64 addr) { string filename = FIndResourceFile(addr); if (filename.Length <= 0) { return(false); } string fullname = Application.dataPath + PathGeoMetry + filename; byte[] data = File.ReadAllBytes(fullname); MyRes_CreateBuffer vert = new MyRes_CreateBuffer(); int headerSize = Marshal.SizeOf(vert); Utils.Deserialize(ref vert, data, headerSize); int startIdx = headerSize; for (int i = 0; i < Info.draw_IndexCount; ++i) { UInt16 index = BitConverter.ToUInt16(data, startIdx); Triangles.Add(index); startIdx += 2; } return(true); }
bool LoadWeights(UInt64 addr) { string filename = FIndResourceFile(addr); if (filename.Length <= 0) { return(false); } string fullname = Application.dataPath + PathGeoMetry + filename; byte[] data = File.ReadAllBytes(fullname); MyRes_CreateBuffer vert = new MyRes_CreateBuffer(); int headerSize = Marshal.SizeOf(vert); Utils.Deserialize(ref vert, data, headerSize); int stride = (int)Info.vb[0].strides[0]; uint vertCount = vert.desc.ByteWidth / (uint)stride; int startIdxOfIdx = headerSize + 0x20; int startIdxOfWeight = headerSize + 0x24; for (int i = 0; i < vertCount; ++i) { BoneWeight info = new BoneWeight(); info.boneIndex0 = data[startIdxOfIdx + 0]; //BitConverter.ToSingle(vert.data, startIdxOfIdx); info.boneIndex1 = data[startIdxOfIdx + 1]; //BitConverter.ToSingle(vert.data, startIdxOfIdx + 4); info.boneIndex2 = data[startIdxOfIdx + 2]; //BitConverter.ToSingle(vert.data, startIdxOfIdx + 8); info.boneIndex3 = data[startIdxOfIdx + 3]; //BitConverter.ToSingle(vert.data, startIdxOfIdx + 8); info.weight0 = BitConverter.ToSingle(data, startIdxOfWeight); info.weight1 = BitConverter.ToSingle(data, startIdxOfWeight + 4); info.weight2 = BitConverter.ToSingle(data, startIdxOfWeight + 8); info.weight3 = 1.0f - (info.weight0 + info.weight1 + info.weight2); info.weight3 = info.weight3 < 0 ? 0 : info.weight3; info.weight3 = info.weight3 > 1 ? 1 : info.weight3; Weights.Add(info); startIdxOfIdx += stride; startIdxOfWeight += stride; } return(true); }