Rescaling the shape/body at runtime using WASM/javascript #1154
-
Hello all, I've read the docs on recommendations of how to scale a shape in JOLT however the advice doesn't seem possible to follow when in WASM due to the lack of the ability to access to the ScaledShape from the body. As referenced by this line " const ScaledShape *scaled_shape = static_cast<const ScaledShape *>(body.GetShape()); Javascript does have the capability to cast the shape to a scaled shape. Is there another way? I had tried ScaleShape() but that isn't useful as it is cumulative and so the shape gets larger each time. Many thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
So I've managed to get it to work now with this. By instead retaining the reference to the original shape and passing that to the scale function (so I don't need to get it from the "ScaledShape->GetInnerShape()").
But I'm not sure about destroying the ScaledShape? it crashes if I try and remove the previous one? whats the option here so that I'm not leaking memory? |
Beta Was this translation helpful? Give feedback.
I'm assuming you meant to say 'doesn't have the capability'. Use
Jolt.castObject(shape, Jolt.ScaledShape)
to cast it.As described here, shapes are reference counted. When you assign a shape to a body it gets a ref count of 1. If you then assign another shape to the same body, the first shape is released, its ref count reaches 0 and the shape gets deleted.