Mercurial > games > semicongine
comparison src/zamikongine/mesh.nim @ 481:c472abfcee57
add: generate ubermeshes
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 10 Jan 2023 00:23:40 +0700 |
parents | 14e5151f68d1 |
children | 94c38e4b5782 |
comparison
equal
deleted
inserted
replaced
480:14e5151f68d1 | 481:c472abfcee57 |
---|---|
9 Mesh*[T] = object of Part | 9 Mesh*[T] = object of Part |
10 vertexData*: T | 10 vertexData*: T |
11 IndexedMesh*[T: object, U: uint16|uint32] = object of Part | 11 IndexedMesh*[T: object, U: uint16|uint32] = object of Part |
12 vertexData*: T | 12 vertexData*: T |
13 indices*: seq[array[3, U]] | 13 indices*: seq[array[3, U]] |
14 | |
15 func createUberMesh*[T](meshes: openArray[Mesh[T]]): Mesh[T] = | |
16 for mesh in meshes: | |
17 for srcname, srcvalue in mesh.vertexData.fieldPairs: | |
18 when typeof(srcvalue) is VertexAttribute: | |
19 for dstname, dstvalue in result.vertexData.fieldPairs: | |
20 when srcname == dstname: | |
21 dstvalue.data.add srcvalue.data | |
22 | |
23 func createUberMesh*[T: object, U: uint16|uint32](meshes: openArray[IndexedMesh[T, U]]): IndexedMesh[T, U] = | |
24 var indexoffset = U(0) | |
25 for mesh in meshes: | |
26 for srcname, srcvalue in mesh.vertexData.fieldPairs: | |
27 when typeof(srcvalue) is VertexAttribute: | |
28 for dstname, dstvalue in result.vertexData.fieldPairs: | |
29 when srcname == dstname: | |
30 dstvalue.data.add srcvalue.data | |
31 var indexdata: seq[array[3, U]] | |
32 for i in mesh.indices: | |
33 indexdata.add [i[0] + indexoffset, i[1] + indexoffset, i[2] + indexoffset] | |
34 result.indices.add indexdata | |
35 indexoffset += U(mesh.vertexData.VertexCount) | |
14 | 36 |
15 func getVkIndexType[T: object, U: uint16|uint32](m: IndexedMesh[T, U]): VkIndexType = | 37 func getVkIndexType[T: object, U: uint16|uint32](m: IndexedMesh[T, U]): VkIndexType = |
16 when U is uint16: VK_INDEX_TYPE_UINT16 | 38 when U is uint16: VK_INDEX_TYPE_UINT16 |
17 elif U is uint32: VK_INDEX_TYPE_UINT32 | 39 elif U is uint32: VK_INDEX_TYPE_UINT32 |
18 | 40 |