comparison tests/test_mesh.nim @ 814:6a09fe5dc99b

add: multi-material for meshes
author Sam <sam@basx.dev>
date Wed, 20 Sep 2023 22:35:04 +0700
parents 7a13941ba204
children f054b8bacab8
comparison
equal deleted inserted replaced
813:fb22fd8142b9 814:6a09fe5dc99b
56 for scene in scenes.mitems: 56 for scene in scenes.mitems:
57 scene.addShaderGlobal("projection", Unit4F32) 57 scene.addShaderGlobal("projection", Unit4F32)
58 scene.addShaderGlobal("view", Unit4F32) 58 scene.addShaderGlobal("view", Unit4F32)
59 var materials: Table[uint16, Material] 59 var materials: Table[uint16, Material]
60 for mesh in scene.meshes: 60 for mesh in scene.meshes:
61 if not materials.contains(mesh.material.index): 61 for material in mesh.materials:
62 materials[mesh.material.index] = mesh.material 62 if not materials.contains(material.index):
63 materials[material.index] = material
63 let baseColors = sortedByIt(values(materials).toSeq, it.index).mapIt(getValue[Vec4f](it.constants["baseColorFactor"], 0)) 64 let baseColors = sortedByIt(values(materials).toSeq, it.index).mapIt(getValue[Vec4f](it.constants["baseColorFactor"], 0))
64 let baseTextures = sortedByIt(values(materials).toSeq, it.index).mapIt(it.textures["baseColorTexture"]) 65 let baseTextures = sortedByIt(values(materials).toSeq, it.index).mapIt(it.textures["baseColorTexture"])
65 for t in baseTextures:
66 echo "- ", t
67 scene.addShaderGlobalArray("baseColorFactor", baseColors) 66 scene.addShaderGlobalArray("baseColorFactor", baseColors)
68 scene.addShaderGlobalArray("baseColorTexture", baseTextures) 67 scene.addShaderGlobalArray("baseColorTexture", baseTextures)
69 engine.addScene(scene) 68 engine.addScene(scene)
70 69
71 var 70 var