# HG changeset patch # User Sam # Date 1695227144 -25200 # Node ID 26b29ca448fcbae7e4836cc99459cc39925cec61 # Parent b87dd3eaa9bd521369e7b4a97ed8a3e4fad50462 add: correct ordering of materials diff -r b87dd3eaa9bd -r 26b29ca448fc src/semicongine/resources/mesh.nim --- a/src/semicongine/resources/mesh.nim Wed Sep 20 22:52:46 2023 +0700 +++ b/src/semicongine/resources/mesh.nim Wed Sep 20 23:25:44 2023 +0700 @@ -227,9 +227,11 @@ # but or current mesh/rendering implementation is only designed for a single material # currently this is usually handled by adding the values as shader globals # TODO: this is bad - mesh[].materials.add material + if not mesh[].materials.contains(material): + mesh[].materials.add material else: - mesh[].materials.add DEFAULT_MATERIAL + if not mesh[].materials.contains(DEFAULT_MATERIAL): + mesh[].materials.add DEFAULT_MATERIAL if primitiveNode.hasKey("indices"): assert mesh[].indexType != None @@ -285,6 +287,14 @@ for primitive in meshNode["primitives"]: result.addPrimitive(root, primitive, mainBuffer) + var maxMaterialIndex = 0 + for material in result[].materials: + maxMaterialIndex = max(int(material.index), maxMaterialIndex) + var materials = result[].materials + result[].materials = newSeqWith(maxMaterialIndex + 1, DEFAULT_MATERIAL) + for material in materials: + result[].materials[material.index] = material + proc loadNode(root: JsonNode, node: JsonNode, mainBuffer: var seq[uint8]): MeshTree = result = MeshTree() # mesh