# HG changeset patch # User Sam # Date 1687801896 -25200 # Node ID 44ecc0a01a9fe4c28d0646e8ea17f44f669b6904 # Parent 0c6e73fcc61f4ff7a9cc1bdff6ad25a49bc5fc62 fix: some issues with new scene/api/component api diff -r 0c6e73fcc61f -r 44ecc0a01a9f src/semicongine/resources/mesh.nim --- 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("") diff -r 0c6e73fcc61f -r 44ecc0a01a9f src/semicongine/scene.nim --- 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 =