private static void ExtractModelDataForObj( MyModel model, Matrix matrix, List<Vector3> vertices, List<TriangleWithMaterial> triangles, List<Vector2> uvs, ref Vector2 offsetUV, Dictionary<string, MyExportModel.Material> materials, ref int currVerticesCount, Vector3 colorMaskHSV) { if (false == model.HasUV) { model.LoadUV = true; model.UnloadData(); model.LoadData(); } MyExportModel renderModel = new MyExportModel(model); int modelVerticesCount = renderModel.GetVerticesCount(); List<HalfVector2> modelUVs = GetUVsForModel(renderModel, modelVerticesCount); Debug.Assert(modelUVs.Count == modelVerticesCount, "wrong UVs for model"); if (modelUVs.Count != modelVerticesCount) { return; } //we need new material for every HSV and texture combination, therefore we need to create new materials for each model List<MyExportModel.Material> newModelMaterials = CreateMaterialsForModel(materials, colorMaskHSV, renderModel); for (int i = 0; i < modelVerticesCount; ++i) { vertices.Add(Vector3.Transform(model.GetVertex(i), matrix)); Vector2 localUV = modelUVs[i].ToVector2()/model.PatternScale + offsetUV; uvs.Add(new Vector2(localUV.X, -localUV.Y)); } for (int i = 0; i < renderModel.GetTrianglesCount(); ++i) { int matID = -1; for (int j = 0; j < newModelMaterials.Count; ++j) { if (i <= newModelMaterials[j].LastTri) { matID = j; break; } } Debug.Assert(matID != -1, "Triangle with no material"); var t = renderModel.GetTriangle(i); string materialName = "EmptyMaterial"; if (matID != -1) { materialName = newModelMaterials[matID].Name; } triangles.Add(new TriangleWithMaterial() { triangle = new MyTriangleVertexIndices(t.I0 + 1 + currVerticesCount, t.I1 + 1 + currVerticesCount, t.I2 + 1 + currVerticesCount), material = materialName, }); } currVerticesCount += modelVerticesCount; }
public MyExportModel(MyModel model) { m_model = model; m_model.LoadData(); ExtractMaterialsFromModel(); }
public void Init(MyModel model, Matrix matrix) { Model = model; InstanceData.LocalMatrix = matrix; model.LoadData(); }