# HG changeset patch # User Sam # Date 1695227144 -25200 # Node ID 670f598d59e79b86750bb99279159457b03d03b7 # Parent 5341af5b9b2b8abea32d5b85ad1d895731d7f118 add: correct ordering of materials diff -r 5341af5b9b2b -r 670f598d59e7 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