r3-legacy/src/r3-d3-raycast-wheel.js

170 lines
5.1 KiB
JavaScript

/**
* RaycastWheel Runtime
* @param physics R3.Runtime.Graphics
* @param apiRaycastWheel R3.D3.API.RaycastWheel
* @constructor
*/
R3.D3.RaycastWheel = function(
physics,
apiRaycastWheel
) {
this.physics = physics;
this.physics.isNotCannonThrow();
if (R3.Utils.UndefinedOrNull(apiRaycastWheel)) {
apiRaycastWheel = {};
}
R3.D3.API.RaycastWheel.call(
this,
apiRaycastWheel.id,
apiRaycastWheel.name,
apiRaycastWheel.radius,
apiRaycastWheel.directionLocal,
apiRaycastWheel.suspensionStiffness,
apiRaycastWheel.suspensionRestLength,
apiRaycastWheel.frictionSlip,
apiRaycastWheel.dampingRelaxation,
apiRaycastWheel.dampingCompression,
apiRaycastWheel.maxSuspensionForce,
apiRaycastWheel.rollInfluence,
apiRaycastWheel.axleLocal,
apiRaycastWheel.chassisConnectionPointLocal,
apiRaycastWheel.maxSuspensionTravel,
apiRaycastWheel.customSlidingRotationalSpeed,
apiRaycastWheel.useCustomSlidingRotationalSpeed,
apiRaycastWheel.parentMesh,
apiRaycastWheel.parent
);
this.directionLocal = new R3.Vector3(
this.physics,
this.directionLocal,
this
);
this.axleLocal = new R3.Vector3(
this.physics,
this.axleLocal,
this
);
this.chassisConnectionPointLocal = new R3.Vector3(
this.physics,
this.chassisConnectionPointLocal,
this
);
R3.Component.call(
this,
{
'parentMesh' : R3.D3.Mesh
}
);
};
R3.D3.RaycastWheel.prototype = Object.create(R3.Component.prototype);
R3.D3.RaycastWheel.prototype.constructor = R3.D3.RaycastWheel;
/**
*
* @returns {*}
*/
R3.D3.RaycastWheel.prototype.createInstance = function() {
this.instance = {
radius: this.radius,
directionLocal: this.directionLocal.instance,
suspensionStiffness: this.suspensionStiffness,
suspensionRestLength: this.suspensionRestLength,
frictionSlip: this.frictionSlip,
dampingRelaxation: this.dampingRelaxation,
dampingCompression: this.dampingCompression,
maxSuspensionForce: this.maxSuspensionForce,
rollInfluence: this.rollInfluence,
axleLocal: this.axleLocal.instance,
chassisConnectionPointLocal: this.chassisConnectionPointLocal.instance,
maxSuspensionTravel: this.maxSuspensionTravel,
customSlidingRotationalSpeed: this.customSlidingRotationalSpeed,
useCustomSlidingRotationalSpeed: this.useCustomSlidingRotationalSpeed
};
R3.Component.prototype.createInstance.call(this);
};
R3.D3.RaycastWheel.prototype.updateInstance = function() {
this.instance.radius = this.radius;
this.instance.directionLocal = this.directionLocal.instance;
this.instance.suspensionStiffness = this.suspensionStiffness;
this.instance.suspensionRestLength = this.suspensionRestLength;
this.instance.frictionSlip = this.frictionSlip;
this.instance.dampingRelaxation = this.dampingRelaxation;
this.instance.dampingCompression = this.dampingCompression;
this.instance.maxSuspensionForce = this.maxSuspensionForce;
this.instance.rollInfluence = this.rollInfluence;
this.instance.axleLocal = this.axleLocal.instance;
this.instance.chassisConnectionPointLocal = this.chassisConnectionPointLocal.instance;
this.instance.maxSuspensionTravel = this.maxSuspensionTravel;
this.instance.customSlidingRotationalSpeed = this.customSlidingRotationalSpeed;
this.instance.useCustomSlidingRotationalSpeed = this.useCustomSlidingRotationalSpeed;
};
/**
* R3.D3.RaycastWheel to R3.D3.API.RaycastWheel
* @returns {R3.D3.API.RaycastWheel}
*/
R3.D3.RaycastWheel.prototype.toApiObject = function() {
var apiRaycastWheel = new R3.D3.API.RaycastWheel(
this.id,
this.name,
this.radius,
this.directionLocal.toApiObject(),
this.suspensionStiffness,
this.suspensionRestLength,
this.frictionSlip,
this.dampingRelaxation,
this.dampingCompression,
this.maxSuspensionForce,
this.rollInfluence,
this.axleLocal.toApiObject(),
this.chassisConnectionPointLocal.toApiObject(),
this.maxSuspensionTravel,
this.customSlidingRotationalSpeed,
this.useCustomSlidingRotationalSpeed,
R3.Utils.IdOrNull(this.parentMesh),
R3.Utils.IdOrNull(this.parent)
);
return apiRaycastWheel;
};
/**
* R3.D3.RaycastWheel from Object RaycastWheel
* @param physics
* @param objectComponent
* @returns {R3.D3.RaycastWheel}
* @constructor
*/
R3.D3.RaycastWheel.FromObject = function(physics, objectComponent) {
var apiRaycastWheel = R3.D3.API.RaycastWheel.FromObject(objectComponent);
return new R3.D3.RaycastWheel(
physics,
apiRaycastWheel
);
};
R3.D3.RaycastWheel.prototype.setChassisLocalConnectionPoint = function() {
if (!this.parentMesh) {
console.log('you need to set the parent mesh first');
}
this.chassisConnectionPointLocal.x = this.parentMesh.position.x;
this.chassisConnectionPointLocal.y = this.parentMesh.position.y;
this.chassisConnectionPointLocal.z = this.parentMesh.position.z;
};