| 2140 | } |
| 2141 | |
| 2142 | export class DefaultBodyUpdater |
| 2143 | implements gdjs.Physics3DRuntimeBehavior.BodyUpdater |
| 2144 | { |
| 2145 | behavior: gdjs.Physics3DRuntimeBehavior; |
| 2146 | |
| 2147 | constructor(behavior: gdjs.Physics3DRuntimeBehavior) { |
| 2148 | this.behavior = behavior; |
| 2149 | } |
| 2150 | |
| 2151 | createAndAddBody(): Jolt.Body | null { |
| 2152 | const { behavior } = this; |
| 2153 | const { _sharedData } = behavior; |
| 2154 | |
| 2155 | const shape = behavior.createShape(); |
| 2156 | const bodyCreationSettings = new Jolt.BodyCreationSettings( |
| 2157 | shape, |
| 2158 | behavior._getPhysicsPosition(_sharedData.getRVec3(0, 0, 0)), |
| 2159 | behavior._getPhysicsRotation(_sharedData.getQuat(0, 0, 0, 1)), |
| 2160 | behavior.bodyType === 'Static' |
| 2161 | ? Jolt.EMotionType_Static |
| 2162 | : behavior.bodyType === 'Kinematic' |
| 2163 | ? Jolt.EMotionType_Kinematic |
| 2164 | : Jolt.EMotionType_Dynamic, |
| 2165 | behavior.getBodyLayer() |
| 2166 | ); |
| 2167 | bodyCreationSettings.mMotionQuality = behavior.bullet |
| 2168 | ? Jolt.EMotionQuality_LinearCast |
| 2169 | : Jolt.EMotionQuality_Discrete; |
| 2170 | bodyCreationSettings.mAllowedDOFs = behavior.fixedRotation |
| 2171 | ? Jolt.EAllowedDOFs_TranslationX | |
| 2172 | Jolt.EAllowedDOFs_TranslationY | |
| 2173 | Jolt.EAllowedDOFs_TranslationZ |
| 2174 | : Jolt.EAllowedDOFs_All; |
| 2175 | bodyCreationSettings.mFriction = behavior.friction; |
| 2176 | bodyCreationSettings.mRestitution = behavior.restitution; |
| 2177 | bodyCreationSettings.mLinearDamping = behavior.linearDamping; |
| 2178 | bodyCreationSettings.mAngularDamping = behavior.angularDamping; |
| 2179 | bodyCreationSettings.mGravityFactor = behavior.gravityScale; |
| 2180 | if (behavior.massOverride > 0) { |
| 2181 | bodyCreationSettings.mOverrideMassProperties = |
| 2182 | Jolt.EOverrideMassProperties_CalculateInertia; |
| 2183 | bodyCreationSettings.mMassPropertiesOverride.mMass = |
| 2184 | behavior.massOverride; |
| 2185 | } |
| 2186 | |
| 2187 | const bodyInterface = _sharedData.bodyInterface; |
| 2188 | const body = bodyInterface.CreateBody(bodyCreationSettings); |
| 2189 | Jolt.destroy(bodyCreationSettings); |
| 2190 | |
| 2191 | bodyInterface.AddBody(body.GetID(), Jolt.EActivation_Activate); |
| 2192 | return body; |
| 2193 | } |
| 2194 | |
| 2195 | updateObjectFromBody() { |
| 2196 | const { behavior } = this; |
| 2197 | const { _body } = behavior; |
| 2198 | // Copy transform from body to the GD object. |
| 2199 | // The body is null when the behavior was either deactivated or the object deleted. |
nothing calls this directly
no outgoing calls
no test coverage detected