private void ParseSkinSet(BinaryParser parser, AnimSkin skin) { var name = parser.ConsumeUInt32(); var numVerts = parser.ConsumeUInt32(); var numBones = parser.ConsumeByte(); parser.Expect(1); var boneIds = parser.ConsumeByteArray(numBones); var vertIds = parser.ConsumeUInt16Array((int)numVerts); var preMultipliedPositions = parser.ConsumeVector3Array((int)numVerts * numBones); var weights = parser.ConsumeFloatArray((int)numVerts * numBones); for (int index = 0; index < vertIds.Length; index++) { var id = vertIds[index]; skin.Weights.EnsureAt(id); var vertexWeights = new VertexWeights { }; if (numBones > 0) { vertexWeights.Bone0 = new VertexWeight { BoneIndex = boneIds[0], Weight = weights[0 + index * numBones] }; } if (numBones > 1) { vertexWeights.Bone1 = new VertexWeight { BoneIndex = boneIds[1], Weight = weights[1 + index * numBones] }; } if (numBones > 2) { vertexWeights.Bone2 = new VertexWeight { BoneIndex = boneIds[2], Weight = weights[2 + index * numBones] }; } if (numBones > 3) { vertexWeights.Bone3 = new VertexWeight { BoneIndex = boneIds[3], Weight = weights[3 + index * numBones] }; } skin.Weights[id] = vertexWeights; } }
private static void ParseAnimSkinSet(TextParser parser, AnimSkin mesh) { List<int> bones = new List<int>(4); parser.Consume("{"); for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "useBones") { parser.Consume(); parser.Consume("{"); for (;;) { attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } bones.Add(mesh.EnsureBone(parser.ConsumeString())); parser.Skip(","); } continue; } if (attribute == "numVerts") { parser.Consume(); parser.ConsumeInt(); continue; } if (attribute == "vertWeights") { parser.Consume(); ParseVertWeights(parser, bones, mesh); continue; } parser.UnknownLexemError(); } }
private static void ParseVertWeights(TextParser parser, List<int> bones, AnimSkin mesh) { parser.Consume("{"); var bone = parser.ConsumeInt(); mesh.Weights.EnsureAt(bone); parser.Skip(","); VertexWeights w = VertexWeights.Empty; if (bones.Count > 0) { w.Bone0 = new VertexWeight { BoneIndex = bones[0], Weight = parser.ConsumeFloat() }; parser.Skip(","); if (bones.Count > 1) { w.Bone1 = new VertexWeight { BoneIndex = bones[1], Weight = parser.ConsumeFloat() }; parser.Skip(","); if (bones.Count > 2) { w.Bone2 = new VertexWeight { BoneIndex = bones[2], Weight = parser.ConsumeFloat() }; parser.Skip(","); if (bones.Count > 3) { w.Bone3 = new VertexWeight { BoneIndex = bones[3], Weight = parser.ConsumeFloat() }; parser.Skip(","); if (bones.Count > 4) { throw new TextParserException("max 4 bones supported"); } } } } } parser.Consume("}"); }