annotate examples/alotof_triangles.nim @ 21:316923e9247c

add: clean examples, update build configs
author Sam <sam@basx.dev>
date Tue, 10 Jan 2023 00:24:37 +0700
parents
children b45a5d338cd0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
1 import std/random
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
2
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
3 import zamikongine/engine
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
4 import zamikongine/math/vector
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
5 import zamikongine/math/matrix
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
6 import zamikongine/vertex
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
7 import zamikongine/mesh
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
8 import zamikongine/thing
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
9 import zamikongine/shader
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
10
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
11 type
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
12 VertexDataA = object
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
13 position11: VertexAttribute[Vec2[float32]]
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
14 color22: VertexAttribute[Vec3[float32]]
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
15
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
16 when isMainModule:
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
17 randomize()
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
18 var myengine = igniteEngine()
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
19 const baseTriangle = [
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
20 Vec3([-0.3'f32, -0.3'f32, 1'f32]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
21 Vec3([ 0.3'f32, 0.3'f32, 1'f32]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
22 Vec3([-0.3'f32, 0.3'f32, 1'f32]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
23 ]
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
24
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
25 var scene = new Thing
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
26
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
27 for i in 1 .. 300:
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
28 var randommesh = new Mesh[VertexDataA]
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
29 # TODO: create randomized position11 from baseTriangle with random transformation matrix
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
30 var transform = (Mat33[float32]().randomized() * 2'f32) - 1'f32
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
31 randommesh.vertexData = VertexDataA(
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
32 position11: VertexAttribute[Vec2[float32]](
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
33 data: @[
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
34 Vec2[float32](transform * baseTriangle[0]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
35 Vec2[float32](transform * baseTriangle[1]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
36 Vec2[float32](transform * baseTriangle[2]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
37 ]
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
38 ),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
39 color22: VertexAttribute[Vec3[float32]](
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
40 data: @[
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
41 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
42 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
43 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
44 ]
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
45 )
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
46 )
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
47
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
48 var randomindexedmesh = new IndexedMesh[VertexDataA, uint16]
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
49 randomindexedmesh.vertexData = VertexDataA(
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
50 position11: VertexAttribute[Vec2[float32]](
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
51 data: @[
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
52 Vec2[float32](transform * baseTriangle[0]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
53 Vec2[float32](transform * baseTriangle[1]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
54 Vec2[float32](transform * baseTriangle[2]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
55 ]
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
56 ),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
57 color22: VertexAttribute[Vec3[float32]](
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
58 data: @[
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
59 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
60 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
61 Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
62 ]
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
63 )
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
64 )
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
65 randomindexedmesh.indices = @[[0'u16, 1'u16, 2'u16], [0'u16, 2'u16, 1'u16]]
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
66 var childthing = new Thing
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
67 childthing.parts.add randommesh
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
68 childthing.parts.add randomindexedmesh
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
69 scene.children.add childthing
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
70
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
71 setupPipeline[VertexDataA, uint16](
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
72 myengine,
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
73 scene,
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
74 generateVertexShaderCode[VertexDataA]("main", "position11", "color22"),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
75 generateFragmentShaderCode[VertexDataA]("main"),
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
76 )
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
77 myengine.fullThrottle()
316923e9247c add: clean examples, update build configs
Sam <sam@basx.dev>
parents:
diff changeset
78 myengine.trash()