annotate examples/alotof_triangles.nim @ 482:1670f8e70964

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