# HG changeset patch # User Sam # Date 1695142384 -25200 # Node ID 6f61e0bb89b7e59bef9c14d506f65dc618dc9d4a # Parent b75760e1a77b9e587eccad11631bf3d0bd8cead2 did: mini-API QoL improvment diff -r b75760e1a77b -r 6f61e0bb89b7 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 b75760e1a77b -r 6f61e0bb89b7 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):