Mercurial > games > semicongine
changeset 812:27346eb7dd37
did: mini-API QoL improvment
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 19 Sep 2023 23:53:04 +0700 |
parents | cc59b7650075 |
children | fb22fd8142b9 |
files | src/semicongine/collision.nim src/semicongine/mesh.nim |
diffstat | 2 files changed, 14 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/semicongine/collision.nim Tue Sep 19 21:27:25 2023 +0700 +++ b/src/semicongine/collision.nim Tue Sep 19 23:53:04 2023 +0700 @@ -370,7 +370,7 @@ direction[0] = 0.0001 inc n -func calculateCollider*(points: seq[Vec3f], theType: ColliderType): Collider = +func calculateCollider*(points: openArray[Vec3f], theType: ColliderType): Collider = var minX = high(float32) maxX = low(float32) @@ -396,7 +396,7 @@ scaleZ = (maxZ - minZ) if theType == Points: - result = Collider(theType: Points, points: points) + result = Collider(theType: Points, points: @points) else: result = Collider(theType: theType, transform: translate(minX, minY, minZ) * scale(scaleX, scaleY, scaleZ))
--- a/src/semicongine/mesh.nim Tue Sep 19 21:27:25 2023 +0700 +++ b/src/semicongine/mesh.nim Tue Sep 19 23:53:04 2023 +0700 @@ -237,10 +237,22 @@ else: raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") +proc getAttribute[T: GPUType|int|uint|float](mesh: MeshObject, attribute: string, i: int): T = + if mesh.vertexData.contains(attribute): + getValue[T](mesh.vertexData[attribute], i) + elif mesh.instanceData.contains(attribute): + getValue[T](mesh.instanceData[attribute], i) + else: + raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") + template `[]`*(mesh: MeshObject, attribute: string, t: typedesc): ref seq[t] = getAttribute[t](mesh, attribute) template `[]`*(mesh: Mesh, attribute: string, t: typedesc): ref seq[t] = getAttribute[t](mesh[], attribute) +template `[]`*(mesh: MeshObject, attribute: string, i: int, t: typedesc): untyped = + getAttribute[t](mesh, attribute, i) +template `[]`*(mesh: Mesh, attribute: string, i: int, t: typedesc): untyped = + getAttribute[t](mesh[], attribute, i) proc updateAttributeData[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, data: seq[T]) = if mesh.vertexData.contains(attribute):