Mercurial > games > semicongine
annotate src/semicongine/thing.nim @ 61:0f04ba283558
did: rename and update older demos to work with new APIs
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 24 Jan 2023 10:22:38 +0700 |
parents | c57285d292b6 |
children | 7153eadb07eb |
rev | line source |
---|---|
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
1 import std/strformat |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
2 import std/typetraits |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
3 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
4 import ./vertex |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
5 import ./math/matrix |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
7 type |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
8 Part* = ref object of RootObj |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
9 thing: Thing |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
10 Transform* = ref object of Part |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
11 mat: Mat44 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
12 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
13 Thing* = ref object of RootObj |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
14 name*: string |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
15 parent*: Thing |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
16 children*: seq[Thing] |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
17 parts*: seq[Part] |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
18 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
19 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
20 func `$`*(thing: Thing): string = thing.name |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
21 method `$`*(part: Part): string {.base.} = &"{part.thing} -> Part" |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
22 method `$`*(part: Transform): string = &"{part.thing} -> Transform" |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
23 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
24 func newTransform*(mat: Mat44): Transform = |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
25 result = new Transform |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
26 result.mat = mat |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
27 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
28 proc add*(thing: Thing, child: Thing) = |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
29 child.parent = thing |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
30 thing.children.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
31 proc add*(thing: Thing, part: Part) = |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
32 part.thing = thing |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
33 thing.parts.add part |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
34 proc add*(thing: Thing, children: seq[Thing]) = |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
35 for child in children: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
36 child.parent = thing |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
37 thing.children.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
38 proc add*(thing: Thing, parts: seq[Part]) = |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
39 for part in parts: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
40 part.thing = thing |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
41 thing.parts.add part |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
42 |
61
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
43 func newThing*(name: string = ""): Thing = |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
44 result = new Thing |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
45 result.name = name |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
46 if result.name == "": |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
47 result.name = &"Thing[{$(cast[ByteAddress](result))}]" |
61
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
48 func newThing*(name: string, firstChild: Thing, children: varargs[ |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
49 Thing]): Thing = |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
50 result = new Thing |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
51 result.add firstChild |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
52 for child in children: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
53 result.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
54 result.name = name |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
55 if result.name == "": |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
56 result.name = &"Thing[{$(cast[ByteAddress](result))}]" |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
57 proc newThing*(name: string, firstPart: Part, parts: varargs[Part]): Thing = |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
58 result = new Thing |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
59 result.name = name |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
60 result.add firstPart |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
61 for part in parts: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
62 result.add part |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
63 if result.name == "": |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
64 result.name = &"Thing[{$(cast[ByteAddress](result))}]" |
28 | 65 |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
66 func getModelTransform*(thing: Thing): Mat44 = |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
67 result = Unit44 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
68 var currentThing = thing |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
69 while currentThing != nil: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
70 for part in currentThing.parts: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
71 if part of Transform: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
72 result = Transform(part).mat * result |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
73 currentThing = currentThing.parent |
61
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
74 |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
75 iterator allPartsOfType*[T: Part](root: Thing): T = |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
76 var queue = @[root] |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
77 while queue.len > 0: |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
78 let thing = queue.pop |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
79 for part in thing.parts: |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
80 if part of T: |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
81 yield T(part) |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
82 for child in thing.children: |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
83 queue.insert(child, 0) |
28 | 84 |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
85 func firstWithName*(root: Thing, name: string): Thing = |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
86 var queue = @[root] |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
87 while queue.len > 0: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
88 let next = queue.pop |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
89 for child in next.children: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
90 if child.name == name: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
91 return child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
92 queue.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
93 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
94 func firstPartWithName*[T: Part](root: Thing, name: string): T = |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
95 var queue = @[root] |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
96 while queue.len > 0: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
97 let next = queue.pop |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
98 for child in next.children: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
99 if child.name == name: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
100 for part in child.parts: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
101 if part of T: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
102 return T(part) |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
103 queue.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
104 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
105 func allWithName*(root: Thing, name: string): seq[Thing] = |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
106 var queue = @[root] |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
107 while queue.len > 0: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
108 let next = queue.pop |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
109 for child in next.children: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
110 if child.name == name: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
111 result.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
112 queue.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
113 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
114 func allPartsWithName*[T: Part](root: Thing, name: string): seq[T] = |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
115 var queue = @[root] |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
116 while queue.len > 0: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
117 let next = queue.pop |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
118 for child in next.children: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
119 if child.name == name: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
120 for part in child.parts: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
121 if part of T: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
122 result.add T(part) |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
123 queue.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
124 |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
125 iterator allThings*(root: Thing): Thing = |
28 | 126 var queue = @[root] |
127 while queue.len > 0: | |
128 let next = queue.pop | |
129 for child in next.children: | |
130 queue.add child | |
131 yield next | |
61
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
132 |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
133 method update*(thing: Thing, dt: float32) {.base.} = |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
134 echo "The update" |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
135 let transform = thing.getModelTransform() |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
136 for part in thing.parts: |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
137 echo " The part ", part |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
138 for name, value in part[].fieldPairs: |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
139 echo " attribute ", name |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
140 when typeof(value) is ModelTransformAttribute: |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
141 value.data = @[transform.transposed()] |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
142 echo "updated stuff" |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
143 |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
144 method update*(part: Part, dt: float32) {.base.} = discard |
0f04ba283558
did: rename and update older demos to work with new APIs
Sam <sam@basx.dev>
parents:
60
diff
changeset
|
145 |