Skip to content

Commit

Permalink
gltf-export: Set the material group of overwritten models
Browse files Browse the repository at this point in the history
Without this, any RenderAtoms would have material IDs corresponding to
the created-but-not-installed-to-model MaterialGroup's materials, rather
than those already in the model.

This could be seen with players, where their head would disappear since
it became the 'mtl_hair' material instead of 'mtl_head'.
  • Loading branch information
ZNixian committed Jul 15, 2022
1 parent 26233bf commit 0119697
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions PD2ModelParser/Importers/GltfImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ void OverwriteModel(GLTF.Mesh gmesh, DM.Model model)

var matGroup = new DM.MaterialGroup(mats);
data.AddSection(matGroup);
model.MaterialGroup = matGroup;

var ms = new MeshSections();
ms.matg = matGroup;
ms.topoip = model.TopologyIP;
ms.passgp = model.PassthroughGP;
ms.geom = ms.passgp.Geometry;
Expand Down Expand Up @@ -286,7 +286,6 @@ DM.Model CreateNewModel(GLTF.Mesh gmesh, string name)
data.AddSection(matGroup);

var ms = new MeshSections();
ms.matg = matGroup;

ms.geom = new DM.Geometry();
data.AddSection(ms.geom);
Expand All @@ -306,7 +305,7 @@ DM.Model CreateNewModel(GLTF.Mesh gmesh, string name)
ms.PopulateFromMeshData(md);
ms.Scale(this.scaleFactor);

var model = new DM.Model(name, (uint)ms.geom.verts.Count, (uint)ms.topo.facelist.Count, ms.passgp, ms.topoip, ms.matg, null);
var model = new DM.Model(name, (uint)ms.geom.verts.Count, (uint)ms.topo.facelist.Count, ms.passgp, ms.topoip, matGroup, null);
model.RenderAtoms = md.renderAtoms;

return model;
Expand Down Expand Up @@ -484,7 +483,6 @@ public class MeshSections
public DM.Topology topo;
public DM.TopologyIP topoip;
public DM.PassthroughGP passgp;
public DM.MaterialGroup matg;
public List<DM.RenderAtom> atoms = new List<DM.RenderAtom>();

public void PopulateFromMeshData(MeshData md)
Expand Down

0 comments on commit 0119697

Please sign in to comment.