comparison tests/test_vulkan_wrapper.nim @ 763:a4c757f5d17f

did: change API for ECS
author Sam <sam@basx.dev>
date Tue, 27 Jun 2023 00:17:40 +0700
parents 07c755e65a4a
children 4921ec86dcb4
comparison
equal deleted inserted replaced
762:4f991bc3613a 763:a4c757f5d17f
1 import std/tables 1 import std/tables
2 2
3 import semicongine 3 import semicongine
4 4
5 proc scene_different_mesh_types(): Entity = 5 proc scene_different_mesh_types(): Entity =
6 result = newEntity("root", 6 result = newEntity("root", [],
7 newEntity("triangle1", newMesh( 7 newEntity("triangle1", {"mesh": Component(newMesh(
8 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], 8 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)],
9 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], 9 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)],
10 )), 10 ))}),
11 newEntity("triangle1b", newMesh( 11 newEntity("triangle1b", {"mesh": Component(newMesh(
12 positions=[newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)], 12 positions=[newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)],
13 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], 13 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)],
14 )), 14 ))}),
15 newEntity("triangle2a", newMesh( 15 newEntity("triangle2a", {"mesh": Component(newMesh(
16 positions=[newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)], 16 positions=[newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)],
17 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], 17 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)],
18 indices=[[0'u16, 2'u16, 1'u16]] 18 indices=[[0'u16, 2'u16, 1'u16]]
19 )), 19 ))}),
20 newEntity("triangle2b", newMesh( 20 newEntity("triangle2b", {"mesh": Component(newMesh(
21 positions=[newVec3f(0.0, 0.4), newVec3f(0.4, -0.4), newVec3f(-0.4, -0.4)], 21 positions=[newVec3f(0.0, 0.4), newVec3f(0.4, -0.4), newVec3f(-0.4, -0.4)],
22 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], 22 colors=[newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)],
23 indices=[[0'u16, 2'u16, 1'u16]] 23 indices=[[0'u16, 2'u16, 1'u16]]
24 )), 24 ))}),
25 newEntity("triangle3a", newMesh( 25 newEntity("triangle3a", {"mesh": Component(newMesh(
26 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], 26 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)],
27 colors=[newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1)], 27 colors=[newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1)],
28 indices=[[0'u32, 2'u32, 1'u32]], 28 indices=[[0'u32, 2'u32, 1'u32]],
29 autoResize=false 29 autoResize=false
30 )), 30 ))}),
31 newEntity("triangle3b", newMesh( 31 newEntity("triangle3b", {"mesh": Component(newMesh(
32 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], 32 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)],
33 colors=[newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1)], 33 colors=[newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1)],
34 indices=[[0'u32, 2'u32, 1'u32]], 34 indices=[[0'u32, 2'u32, 1'u32]],
35 autoResize=false 35 autoResize=false
36 )), 36 ))}),
37 ) 37 )
38 for mesh in allComponentsOfType[Mesh](result): 38 for mesh in allComponentsOfType[Mesh](result):
39 mesh.setInstanceData("translate", @[newVec3f()]) 39 mesh.setInstanceData("translate", @[newVec3f()])
40 40
41 proc scene_simple(): Entity = 41 proc scene_simple(): Entity =
61 ) 61 )
62 mymesh1.setInstanceData("translate", @[newVec3f(0.3, 0.0)]) 62 mymesh1.setInstanceData("translate", @[newVec3f(0.3, 0.0)])
63 mymesh2.setInstanceData("translate", @[newVec3f(0.0, 0.3)]) 63 mymesh2.setInstanceData("translate", @[newVec3f(0.0, 0.3)])
64 mymesh3.setInstanceData("translate", @[newVec3f(-0.3, 0.0)]) 64 mymesh3.setInstanceData("translate", @[newVec3f(-0.3, 0.0)])
65 mymesh4.setInstanceData("translate", @[newVec3f(0.0, -0.3), newVec3f(0.0, 0.5)]) 65 mymesh4.setInstanceData("translate", @[newVec3f(0.0, -0.3), newVec3f(0.0, 0.5)])
66 result = newEntity("root", newEntity("triangle", mymesh4, mymesh3, mymesh2, mymesh1)) 66 result = newEntity("root", [], newEntity("triangle", {"mesh1": Component(mymesh4), "mesh2": Component(mymesh3), "mesh3": Component(mymesh2), "mesh4": Component(mymesh1)}))
67 67
68 proc scene_primitives(): Entity = 68 proc scene_primitives(): Entity =
69 var r = rect(color="ff0000") 69 var r = rect(color="ff0000")
70 var t = tri(color="0000ff") 70 var t = tri(color="0000ff")
71 var c = circle(color="00ff00") 71 var c = circle(color="00ff00")
72 72
73 r.setInstanceData("translate", @[newVec3f(0.5, -0.3)]) 73 r.setInstanceData("translate", @[newVec3f(0.5, -0.3)])
74 t.setInstanceData("translate", @[newVec3f(0.3, 0.3)]) 74 t.setInstanceData("translate", @[newVec3f(0.3, 0.3)])
75 c.setInstanceData("translate", @[newVec3f(-0.3, 0.1)]) 75 c.setInstanceData("translate", @[newVec3f(-0.3, 0.1)])
76 result = newEntity("root", t, r, c) 76 result = newEntity("root", {"mesh1": Component(t), "mesh1": Component(r), "mesh1": Component(c)})
77 77
78 proc scene_flag(): Entity = 78 proc scene_flag(): Entity =
79 var r = rect(color="ff0000") 79 var r = rect(color="ff0000")
80 r.updateMeshData("color", @[newVec4f(0, 0), newVec4f(1, 0), newVec4f(1, 1), newVec4f(0, 1)]) 80 r.updateMeshData("color", @[newVec4f(0, 0), newVec4f(1, 0), newVec4f(1, 1), newVec4f(0, 1)])
81 result = newEntity("root", r) 81 result = newEntity("root", {"mesh": Component(r)})
82 82
83 proc main() = 83 proc main() =
84 var engine = initEngine("Test") 84 var engine = initEngine("Test")
85 85
86 # INIT RENDERER: 86 # INIT RENDERER: