createBody method
Makes a body of shape; 0 when it cannot be made (a shape that is
not Shape3D.isValid, a mesh or a height field on a body that is not
static, a layer outside 0–15, a full world).
Implementation
@override
int createBody(Shape3D shape, BodySettings3D settings) {
if (_gone) return 0;
final pointer = shapes.acquire(shape);
if (pointer == null) return 0;
final s = _bodySettings.ref;
s.position[0] = settings.position.x;
s.position[1] = settings.position.y;
s.position[2] = settings.position.z;
s.rotation[0] = settings.rotation.x;
s.rotation[1] = settings.rotation.y;
s.rotation[2] = settings.rotation.z;
s.rotation[3] = settings.rotation.w;
s.linearVelocity[0] = settings.linearVelocity.x;
s.linearVelocity[1] = settings.linearVelocity.y;
s.linearVelocity[2] = settings.linearVelocity.z;
s.angularVelocity[0] = settings.angularVelocity.x;
s.angularVelocity[1] = settings.angularVelocity.y;
s.angularVelocity[2] = settings.angularVelocity.z;
s
..motionType = settings.type.index
..motionQuality = settings.motionQuality.index
..layer = settings.layer
// Translation X, Y and Z only (Jolt's EAllowedDOFs); 0 is all six.
..allowedDofs = settings.lockRotation ? 7 : 0
..friction = settings.friction
..restitution = settings.restitution
..linearDamping = settings.linearDamping
..angularDamping = settings.angularDamping
..gravityFactor = settings.gravityFactor
..mass = settings.mass
..isSensor = settings.isSensor
..allowSleeping = settings.allowSleeping
..enhancedInternalEdgeRemoval = false
..userData = settings.userData;
final body = jj_body_create(handle, pointer, _bodySettings);
if (body == 0) {
shapes.release(shape);
return 0;
}
_bodyShapes[body] = shape;
_bodyTypes[body] = settings.type;
return body;
}