private ModelVertex BuildVertex(mesh_vertex_t v0, mstudio_model_t mdl, int textureId) { var tex = this.textures[textureId]; var boneID = mdl.Weights[v0.v]; var bone = modelBones[boneID]; var pos = mdl.Vertices[v0.v]; pos = bone.Transform(pos); return new ModelVertex() { Position = pos, Normal = mdl.Normals[v0.n], UV0 = new Vector2((float)v0.s / (float)tex.width, (float)v0.t / (float)tex.height), Bones = new ModelBoneWeight[] { new ModelBoneWeight() { Weight = 1.0f, Bone = bone } } }; }
private void ReadTrianglesStrip(BinaryReader source, mstudio_mesh_t mesh, mstudio_model_t mdl, int numVertices) { mesh_vertex_t v0 = new mesh_vertex_t(); v0.Read(source); mesh_vertex_t v1 = new mesh_vertex_t(); v1.Read(source); for (int i = 2; i < numVertices; ++i) { mesh_vertex_t v2 = new mesh_vertex_t(); v2.Read(source); BuildTriangle(v0, v1, v2, mesh, mdl); //v0 = v1; //v1 = v2; if (0 == (i & 1)) v0 = v2; else v1 = v2; } }
private void BuildTriangle(mesh_vertex_t v0, mesh_vertex_t v1, mesh_vertex_t v2, mstudio_mesh_t mesh, mstudio_model_t mdl) { var textureId = mesh.skinref; if ((v0.v == v1.v) || (v0.v == v2.v) || (v1.v == v2.v)) return; mesh.Faces.Add(new ModelFace() { Texture = modelTextures[textureId], Vertex0 = BuildVertex(v0, mdl, textureId), Vertex1 = BuildVertex(v1, mdl, textureId), Vertex2 = BuildVertex(v2, mdl, textureId) }); }