# HG changeset patch # User Sam # Date 1695142384 -25200 # Node ID 27346eb7dd37939cc128e5493cf19bb8c1cd3901 # Parent cc59b7650075d16fcc981d0365d333ec4a3a8fe8 did: mini-API QoL improvment diff -r cc59b7650075 -r 27346eb7dd37 src/semicongine/collision.nim --- 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)) diff -r cc59b7650075 -r 27346eb7dd37 src/semicongine/mesh.nim --- 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):