public static ModelPart CreatePlane(string name, int materialId) { var model = new ModelPart { Faces = new ModelPartFace[1], Name = name, MaterialId = materialId }; model.Faces[0] = ModelPartFace.CreateSquare(model, 0); model.Faces[0].VertexIndices = new[] { 0, 1, 2, 3 }; model.Faces[0].Triangles[0] = new ModelTriangle(0, 1, 2, model.Faces[0], 0, 1, 2); model.Faces[0].Triangles[1] = new ModelTriangle(0, 2, 3, model.Faces[0], 0, 2, 3); model.Vertices = new[] { new Vector3(-0.5f, 0, 0.5f), new Vector3(-0.5f, 0, -0.5f), new Vector3(0.5f, 0, -0.5f), new Vector3(0.5f, 0, 0.5f), }; return(model); }
public static ModelPart CreateCuboid() { var model = new ModelPart(); model.Faces = new ModelPartFace[6]; for (var i = 0; i < 6; i++) { model.Faces[i] = ModelPartFace.CreateSquare(model, i); } const int front = (int)CuboidFaceIndices.Front; model.Faces[front].VertexIndices = new[] { 0, 1, 2, 3 }; model.Faces[front].Triangles[0] = new ModelTriangle(0, 1, 2, model.Faces[front], 0, 1, 2); model.Faces[front].Triangles[1] = new ModelTriangle(0, 2, 3, model.Faces[front], 0, 2, 3); const int back = (int)CuboidFaceIndices.Back; model.Faces[back].VertexIndices = new[] { 7, 6, 5, 4 }; model.Faces[back].Triangles[0] = new ModelTriangle(7, 6, 5, model.Faces[back], 0, 1, 2); model.Faces[back].Triangles[1] = new ModelTriangle(7, 5, 4, model.Faces[back], 0, 2, 3); const int left = (int)CuboidFaceIndices.Left; model.Faces[left].VertexIndices = new[] { 4, 5, 1, 0 }; model.Faces[left].Triangles[0] = new ModelTriangle(4, 5, 1, model.Faces[left], 0, 1, 2); model.Faces[left].Triangles[1] = new ModelTriangle(4, 1, 0, model.Faces[left], 0, 2, 3); const int right = (int)CuboidFaceIndices.Right; model.Faces[right].VertexIndices = new[] { 3, 2, 6, 7 }; model.Faces[right].Triangles[0] = new ModelTriangle(3, 2, 6, model.Faces[right], 0, 1, 2); model.Faces[right].Triangles[1] = new ModelTriangle(3, 6, 7, model.Faces[right], 0, 2, 3); const int top = (int)CuboidFaceIndices.Top; model.Faces[top].VertexIndices = new[] { 1, 5, 6, 2 }; model.Faces[top].Triangles[0] = new ModelTriangle(1, 5, 6, model.Faces[top], 0, 1, 2); model.Faces[top].Triangles[1] = new ModelTriangle(1, 6, 2, model.Faces[top], 0, 2, 3); const int bottom = (int)CuboidFaceIndices.Bottom; model.Faces[bottom].VertexIndices = new[] { 4, 0, 3, 7 }; model.Faces[bottom].Triangles[0] = new ModelTriangle(4, 0, 3, model.Faces[bottom], 0, 1, 2); model.Faces[bottom].Triangles[1] = new ModelTriangle(4, 3, 7, model.Faces[bottom], 0, 2, 3); model.Vertices = new[] { new Vector3(-0.5f, -0.5f, 0.5f), // 0 new Vector3(-0.5f, -0.5f, -0.5f), // 1 new Vector3(0.5f, -0.5f, -0.5f), // 2 new Vector3(0.5f, -0.5f, 0.5f), // 3 new Vector3(-0.5f, 0.5f, 0.5f), // 4 new Vector3(-0.5f, 0.5f, -0.5f), // 5 new Vector3(0.5f, 0.5f, -0.5f), // 6 new Vector3(0.5f, 0.5f, 0.5f), // 7 }; return(model); }
private ModelTriangle ReadModelPartTriangle(ModelPartFace modelPartFace) { var v1VertexIndex = _reader.ReadInt32(); var v1TexCoordIndex = _reader.ReadInt32(); var v2VertexIndex = _reader.ReadInt32(); var v2TexCoordIndex = _reader.ReadInt32(); var v3VertexIndex = _reader.ReadInt32(); var v3TexCoordIndex = _reader.ReadInt32(); return new ModelTriangle( v1VertexIndex, v2VertexIndex, v3VertexIndex, modelPartFace, v1TexCoordIndex, v2TexCoordIndex, v3TexCoordIndex); }
private void ReadModelPartFaceTriangles(ModelPartFace modelPartFace) { var count = _reader.ReadInt32(); modelPartFace.Triangles = new ModelTriangle[count]; for (var i = 0; i < count; i++) { modelPartFace.Triangles[i] = ReadModelPartTriangle(modelPartFace); } }
private ModelPartFace ReadModelPartFace(ModelPart modelPart) { var index = _reader.ReadInt32(); var modelPartFace = new ModelPartFace(index, modelPart) {Colour = _reader.ReadColour()}; var texCoordinateCount = _reader.ReadInt32(); modelPartFace.TextureCoordinates = new Vector2[texCoordinateCount]; for (var i = 0; i < texCoordinateCount; i++) { modelPartFace.TextureCoordinates[i] = _reader.ReadVectorXY(); } var vertexIndexCount = _reader.ReadInt32(); modelPartFace.VertexIndices = new int[vertexIndexCount]; for (var i = 0; i < vertexIndexCount; i++) { modelPartFace.VertexIndices[i] = _reader.ReadInt32(); } ReadModelPartFaceTriangles(modelPartFace); return modelPartFace; }
private static void WriteModelPartFaceTriangles(BinaryWriter writer, ModelPartFace modelPartFace) { writer.Write(modelPartFace.Triangles.Length); foreach (var modelTriangle in modelPartFace.Triangles) { WriteModelPartTriangle(writer, modelTriangle); } }
private static void WriteModelPartFace(BinaryWriter writer, ModelPartFace modelPartFace) { writer.Write(modelPartFace.Index); writer.WriteColour(modelPartFace.Colour); writer.Write(modelPartFace.TextureCoordinates.Length); foreach (var textureCoordinate in modelPartFace.TextureCoordinates) { writer.WriteVectorXY(textureCoordinate); } writer.Write(modelPartFace.VertexIndices.Length); foreach (var vertexIndex in modelPartFace.VertexIndices) { writer.Write(vertexIndex); } WriteModelPartFaceTriangles(writer, modelPartFace); }