comparison 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
comparison
equal deleted inserted replaced
1250:9ceb509af5ea 1251:3f98ad20a9d3
1 type 1 type
2 GltfNode* = object 2 GltfNode* = object
3 children: seq[int] 3 children*: seq[int]
4 mesh: int 4 mesh*: int = -1
5 transform: Mat4 5 transform*: Mat4 = Unit4
6 GltfMesh*[TMesh, TMaterial] = object 6 GltfData*[TMesh, TMaterial] = object
7 scenes*: seq[seq[int]] # each scene has a seq of node indices 7 scenes*: seq[seq[int]] # each scene has a seq of node indices
8 nodes*: seq[GltfNode] # each node has a seq of mesh indices 8 nodes*: seq[GltfNode] # each node has a seq of mesh indices
9 meshes*: seq[seq[(TMesh, VkPrimitiveTopology)]] 9 meshes*: seq[seq[(TMesh, VkPrimitiveTopology)]]
10 materials*: seq[TMaterial] 10 materials*: seq[TMaterial]
11 textures*: seq[Image[BGRA]] 11 textures*: seq[Image[BGRA]]
222 let accessor = primitive["attributes"][gltfAttributeIndexed].getInt() 222 let accessor = primitive["attributes"][gltfAttributeIndexed].getInt()
223 resultValue.data = getAccessorData[elementType(resultValue.data)](root, root["accessors"][accessor], mainBuffer) 223 resultValue.data = getAccessorData[elementType(resultValue.data)](root, root["accessors"][accessor], mainBuffer)
224 inc i 224 inc i
225 225
226 proc loadNode(node: JsonNode): GltfNode = 226 proc loadNode(node: JsonNode): GltfNode =
227 result.transform = Unit4 227 result = GltfNode()
228 if "mesh" in node: 228 if "mesh" in node:
229 result.mesh = node["mesh"].getInt() 229 result.mesh = node["mesh"].getInt()
230 if "children" in node: 230 if "children" in node:
231 for child in items(node["children"]): 231 for child in items(node["children"]):
232 result.children.add child.getInt() 232 result.children.add child.getInt()
261 261
262 proc ReadglTF*[TMesh, TMaterial]( 262 proc ReadglTF*[TMesh, TMaterial](
263 stream: Stream, 263 stream: Stream,
264 meshAttributesMapping: static MeshAttributeNames, 264 meshAttributesMapping: static MeshAttributeNames,
265 materialAttributesMapping: static MaterialAttributeNames, 265 materialAttributesMapping: static MaterialAttributeNames,
266 ): GltfMesh[TMesh, TMaterial] = 266 ): GltfData[TMesh, TMaterial] =
267 var 267 var
268 header: glTFHeader 268 header: glTFHeader
269 data: glTFData 269 data: glTFData
270 270
271 for name, value in fieldPairs(header): 271 for name, value in fieldPairs(header):
322 proc LoadMeshes*[TMesh, TMaterial]( 322 proc LoadMeshes*[TMesh, TMaterial](
323 path: string, 323 path: string,
324 meshAttributesMapping: static MeshAttributeNames, 324 meshAttributesMapping: static MeshAttributeNames,
325 materialAttributesMapping: static MaterialAttributeNames, 325 materialAttributesMapping: static MaterialAttributeNames,
326 package = DEFAULT_PACKAGE 326 package = DEFAULT_PACKAGE
327 ): GltfMesh[TMesh, TMaterial] = 327 ): GltfData[TMesh, TMaterial] =
328 ReadglTF[TMesh, TMaterial]( 328 ReadglTF[TMesh, TMaterial](
329 stream = loadResource_intern(path, package = package), 329 stream = loadResource_intern(path, package = package),
330 meshAttributesMapping = meshAttributesMapping, 330 meshAttributesMapping = meshAttributesMapping,
331 materialAttributesMapping = materialAttributesMapping, 331 materialAttributesMapping = materialAttributesMapping,
332 ) 332 )