diff examples/alotof_triangles.nim @ 521:a25325bec7f2

did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
author Sam <sam@basx.dev>
date Sun, 22 Jan 2023 22:46:53 +0700
parents cd73e429fc99
children
line wrap: on
line diff
--- a/examples/alotof_triangles.nim	Fri Jan 20 16:53:37 2023 +0700
+++ b/examples/alotof_triangles.nim	Sun Jan 22 22:46:53 2023 +0700
@@ -2,7 +2,6 @@
 import std/strutils
 import std/math
 import std/random
-import std/enumerate
 
 import semicongine
 
@@ -19,7 +18,8 @@
 proc randomtransform(): Mat33 =
   let randomscale = scale2d(float32(rand(1.0) + 0.5), float32(rand(1.0) + 0.5))
   let randomrotate = rotate2d(float32(rand(2 * PI)))
-  let randomtranslate = translate2d(float32(rand(1.6) - 0.8), float32(rand(1.6) - 0.8))
+  let randomtranslate = translate2d(float32(rand(1.6) - 0.8), float32(rand(
+      1.6) - 0.8))
   result = randomtranslate * randomrotate * randomscale
 
 when isMainModule:
@@ -27,11 +27,11 @@
   var myengine = igniteEngine("A lot of triangles")
   const baseTriangle = [
     Vec3([-0.1'f32, -0.1'f32, 1'f32]),
-    Vec3([ 0.1'f32,  0.1'f32, 1'f32]),
-    Vec3([-0.1'f32,  0.1'f32, 1'f32]),
+    Vec3([0.1'f32, 0.1'f32, 1'f32]),
+    Vec3([-0.1'f32, 0.1'f32, 1'f32]),
   ]
 
-  var scene = new Thing
+  var scene = newThing("scene")
 
   for i in 1 .. 300:
     var randommesh = new Mesh[VertexDataA]
@@ -43,8 +43,8 @@
           Vec2(transform1 * baseTriangle[0]),
           Vec2(transform1 * baseTriangle[1]),
           Vec2(transform1 * baseTriangle[2]),
-        ]
-      ),
+      ]
+    ),
       color22: ColorAttribute[Vec3](
         data: @[randomcolor1, randomcolor1, randomcolor1]
       )
@@ -59,17 +59,14 @@
           Vec2(transform2 * baseTriangle[0]),
           Vec2(transform2 * baseTriangle[1]),
           Vec2(transform2 * baseTriangle[2]),
-        ]
-      ),
+      ]
+    ),
       color22: ColorAttribute[Vec3](
         data: @[randomcolor2, randomcolor2, randomcolor2]
       )
     )
     randomindexedmesh.indices = @[[0'u16, 1'u16, 2'u16]]
-    var childthing = new Thing
-    childthing.parts.add randommesh
-    childthing.parts.add randomindexedmesh
-    scene.children.add childthing
+    scene.add newThing("randommesh", randommesh, randomindexedmesh)
 
   const vertexShader = generateVertexShaderCode[VertexDataA, Uniforms]()
   const fragmentShader = generateFragmentShaderCode[VertexDataA]()