changeset 305:44ecc0a01a9f

fix: some issues with new scene/api/component api
author Sam <sam@basx.dev>
date Tue, 27 Jun 2023 00:51:36 +0700
parents 0c6e73fcc61f
children 046f7e2b1e13
files src/semicongine/resources/mesh.nim src/semicongine/scene.nim
diffstat 2 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/semicongine/resources/mesh.nim	Tue Jun 27 00:17:55 2023 +0700
+++ b/src/semicongine/resources/mesh.nim	Tue Jun 27 00:51:36 2023 +0700
@@ -237,7 +237,7 @@
 
   # mesh
   if node.hasKey("mesh"):
-    result[name & "_mesh"] = loadMesh(root, root["meshes"][node["mesh"].getInt()], mainBuffer)
+    result["mesh"] = loadMesh(root, root["meshes"][node["mesh"].getInt()], mainBuffer)
 
 proc loadScene(root: JsonNode, scenenode: JsonNode, mainBuffer: var seq[uint8]): Scene =
   var rootEntity = newEntity("<root>")
--- a/src/semicongine/scene.nim	Tue Jun 27 00:17:55 2023 +0700
+++ b/src/semicongine/scene.nim	Tue Jun 27 00:51:36 2023 +0700
@@ -27,9 +27,9 @@
   Entity* = ref object of RootObj
     name*: string
     internal_transform: Mat4 # todo: cache transform + only update VBO when transform changed
-    parent*: Entity
-    children*: seq[Entity]
-    components*: Table[string, Component]
+    parent: Entity
+    children: seq[Entity]
+    components: Table[string, Component]
 
   EntityAnimation* = ref object of Component
     player: AnimationPlayer[Mat4]
@@ -51,6 +51,9 @@
 func update*(animation: var EntityAnimation, dt: float32) =
   animation.player.advance(dt)
 
+func parent(entity: Entity): Entity =
+  entity.parent
+
 func transform*(entity: Entity): Mat4 =
   result = entity.internal_transform
   for component in entity.components.mvalues:
@@ -129,7 +132,7 @@
 proc add*(entity: Entity, child: Entity) =
   child.parent = entity
   entity.children.add child
-proc `[]=`*(entity: Entity, index: int, child: Entity) =
+proc `[]=`*(entity: var Entity, index: int, child: var Entity) =
   child.parent = entity
   entity.children[index] = child
 proc `[]`*(entity: Entity, index: int): Entity =