diff semiconginev2/gltf.nim @ 1251:3f98ad20a9d3

add: render by-node instead of by-mesh
author sam <sam@basx.dev>
date Fri, 26 Jul 2024 20:34:02 +0700
parents 9ceb509af5ea
children 01e9f41d35b1
line wrap: on
line diff
--- a/semiconginev2/gltf.nim	Thu Jul 25 23:15:05 2024 +0700
+++ b/semiconginev2/gltf.nim	Fri Jul 26 20:34:02 2024 +0700
@@ -1,9 +1,9 @@
 type
   GltfNode* = object
-    children: seq[int]
-    mesh: int
-    transform: Mat4
-  GltfMesh*[TMesh, TMaterial] = object
+    children*: seq[int]
+    mesh*: int = -1
+    transform*: Mat4 = Unit4
+  GltfData*[TMesh, TMaterial] = object
     scenes*: seq[seq[int]] # each scene has a seq of node indices
     nodes*: seq[GltfNode]  # each node has a seq of mesh indices
     meshes*: seq[seq[(TMesh, VkPrimitiveTopology)]]
@@ -224,7 +224,7 @@
           inc i
 
 proc loadNode(node: JsonNode): GltfNode =
-  result.transform = Unit4
+  result = GltfNode()
   if "mesh" in node:
     result.mesh = node["mesh"].getInt()
   if "children" in node:
@@ -263,7 +263,7 @@
   stream: Stream,
   meshAttributesMapping: static MeshAttributeNames,
   materialAttributesMapping: static MaterialAttributeNames,
-): GltfMesh[TMesh, TMaterial] =
+): GltfData[TMesh, TMaterial] =
   var
     header: glTFHeader
     data: glTFData
@@ -324,7 +324,7 @@
   meshAttributesMapping: static MeshAttributeNames,
   materialAttributesMapping: static MaterialAttributeNames,
   package = DEFAULT_PACKAGE
-): GltfMesh[TMesh, TMaterial] =
+): GltfData[TMesh, TMaterial] =
   ReadglTF[TMesh, TMaterial](
     stream = loadResource_intern(path, package = package),
     meshAttributesMapping = meshAttributesMapping,