raycast vehicles, wheels - need to do the linking
parent
42de37c1dc
commit
66cd4c7ba1
|
@ -147,7 +147,8 @@ GameLib.Component.COMPONENT_CONTROLS_EDITOR = 0x31;
|
|||
GameLib.Component.COMPONENT_CONTROLS_FLY = 0x32;
|
||||
GameLib.Component.COMPONENT_FRICTION_MATERIAL = 0x33;
|
||||
GameLib.Component.COMPONENT_FRICTION_CONTACT_MATERIAL = 0x34;
|
||||
|
||||
GameLib.Component.COMPONENT_RAYCAST_VEHICLE = 0x35;
|
||||
GameLib.Component.COMPONENT_RAYCAST_WHEEL = 0x36;
|
||||
|
||||
/**
|
||||
* Returns string name for component number
|
||||
|
@ -209,6 +210,8 @@ GameLib.Component.GetComponentName = function(number) {
|
|||
case 0x32 : return 'GameLib.D3.Controls.Fly';
|
||||
case 0x33 : return 'GameLib.D3.FrictionMaterial';
|
||||
case 0x34 : return 'GameLib.D3.FrictionContactMaterial';
|
||||
case 0x35 : return 'GameLib.D3.RaycastVehicle';
|
||||
case 0x36 : return 'GameLib.D3.RaycastWheel';
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* Raw RaycastVehicle API object - should always correspond with the RaycastVehicle Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param chassis
|
||||
* @param wheels
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.RaycastVehicle = function(
|
||||
id,
|
||||
name,
|
||||
chassis,
|
||||
wheels,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'RaycastVehicle (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(chassis)) {
|
||||
chassis = null;
|
||||
}
|
||||
this.chassis = chassis;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(wheels)) {
|
||||
wheels = [];
|
||||
}
|
||||
this.wheels = wheels;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
};
|
||||
|
||||
GameLib.D3.API.RaycastVehicle.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.D3.API.RaycastVehicle.prototype.constructor = GameLib.D3.API.RaycastVehicle;
|
||||
|
||||
/**
|
||||
* Creates an API RaycastVehicle from an Object RaycastVehicle
|
||||
* @param objectRaycastVehicle
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.RaycastVehicle.FromObject = function(objectRaycastVehicle) {
|
||||
return new GameLib.D3.API.RaycastVehicle(
|
||||
objectRaycastVehicle.id,
|
||||
objectRaycastVehicle.name,
|
||||
objectRaycastVehicle.chassis,
|
||||
objectRaycastVehicle.wheels,
|
||||
objectRaycastVehicle.parentEntity
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
/**
|
||||
* Raw RaycastWheel API object - should always correspond with the RaycastWheel Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param radius
|
||||
* @param directionLocal
|
||||
* @param suspensionStiffness
|
||||
* @param suspensionRestLength
|
||||
* @param frictionSlip
|
||||
* @param dampingRelaxation
|
||||
* @param dampingCompression
|
||||
* @param maxSuspensionForce
|
||||
* @param rollInfluence
|
||||
* @param axleLocal
|
||||
* @param chassisConnectionPointLocal
|
||||
* @param maxSuspensionTravel
|
||||
* @param customSlidingRotationalSpeed
|
||||
* @param useCustomSlidingRotationalSpeed
|
||||
* @param parentEntity
|
||||
* @param parentMesh
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.RaycastWheel = function(
|
||||
id,
|
||||
name,
|
||||
radius,
|
||||
directionLocal,
|
||||
suspensionStiffness,
|
||||
suspensionRestLength,
|
||||
frictionSlip,
|
||||
dampingRelaxation,
|
||||
dampingCompression,
|
||||
maxSuspensionForce,
|
||||
rollInfluence,
|
||||
axleLocal,
|
||||
chassisConnectionPointLocal,
|
||||
maxSuspensionTravel,
|
||||
customSlidingRotationalSpeed,
|
||||
useCustomSlidingRotationalSpeed,
|
||||
parentEntity,
|
||||
parentMesh
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'RaycastWheel (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(radius)) {
|
||||
radius = 0.5;
|
||||
}
|
||||
this.radius = radius;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(directionLocal)) {
|
||||
directionLocal = new GameLib.API.Vector3(0, 0, -1);
|
||||
}
|
||||
this.directionLocal = directionLocal;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(suspensionStiffness)) {
|
||||
suspensionStiffness = 30;
|
||||
}
|
||||
this.suspensionStiffness = suspensionStiffness;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(suspensionRestLength)) {
|
||||
suspensionRestLength = 0.3;
|
||||
}
|
||||
this.suspensionRestLength = suspensionRestLength;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(frictionSlip)) {
|
||||
frictionSlip = 5;
|
||||
}
|
||||
this.frictionSlip = frictionSlip;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(dampingRelaxation)) {
|
||||
dampingRelaxation = 2.3;
|
||||
}
|
||||
this.dampingRelaxation = dampingRelaxation;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(dampingCompression)) {
|
||||
dampingCompression = 4.4;
|
||||
}
|
||||
this.dampingCompression = dampingCompression;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(maxSuspensionForce)) {
|
||||
maxSuspensionForce = 100000;
|
||||
}
|
||||
this.maxSuspensionForce = maxSuspensionForce;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rollInfluence)) {
|
||||
rollInfluence = 0.01;
|
||||
}
|
||||
this.rollInfluence = rollInfluence;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(axleLocal)) {
|
||||
axleLocal = new GameLib.API.Vector3(0, 1, 0);
|
||||
}
|
||||
this.axleLocal = axleLocal;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(chassisConnectionPointLocal)) {
|
||||
chassisConnectionPointLocal = new GameLib.API.Vector3(1, 1, 0);
|
||||
}
|
||||
this.chassisConnectionPointLocal = chassisConnectionPointLocal;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(maxSuspensionTravel)) {
|
||||
maxSuspensionTravel = 0.3;
|
||||
}
|
||||
this.maxSuspensionTravel = maxSuspensionTravel;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(customSlidingRotationalSpeed)) {
|
||||
customSlidingRotationalSpeed = -30;
|
||||
}
|
||||
this.customSlidingRotationalSpeed = customSlidingRotationalSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(useCustomSlidingRotationalSpeed)) {
|
||||
useCustomSlidingRotationalSpeed = true;
|
||||
}
|
||||
this.useCustomSlidingRotationalSpeed = useCustomSlidingRotationalSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentMesh)) {
|
||||
parentMesh = null;
|
||||
}
|
||||
this.parentMesh = parentMesh;
|
||||
};
|
||||
|
||||
GameLib.D3.API.RaycastWheel.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.D3.API.RaycastWheel.prototype.constructor = GameLib.D3.API.RaycastWheel;
|
||||
|
||||
/**
|
||||
* Creates an API RaycastWheel from an Object RaycastWheel
|
||||
* @param objectRaycastWheel
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.RaycastWheel.FromObject = function(objectRaycastWheel) {
|
||||
return new GameLib.D3.API.RaycastWheel(
|
||||
objectRaycastWheel.id,
|
||||
objectRaycastWheel.name,
|
||||
objectRaycastWheel.radius,
|
||||
objectRaycastWheel.directionLocal,
|
||||
objectRaycastWheel.suspensionStiffness,
|
||||
objectRaycastWheel.suspensionRestLength,
|
||||
objectRaycastWheel.frictionSlip,
|
||||
objectRaycastWheel.dampingRelaxation,
|
||||
objectRaycastWheel.dampingCompression,
|
||||
objectRaycastWheel.maxSuspensionForce,
|
||||
objectRaycastWheel.rollInfluence,
|
||||
objectRaycastWheel.axleLocal,
|
||||
objectRaycastWheel.chassisConnectionPointLocal,
|
||||
objectRaycastWheel.maxSuspensionTravel,
|
||||
objectRaycastWheel.customSlidingRotationalSpeed,
|
||||
objectRaycastWheel.useCustomSlidingRotationalSpeed,
|
||||
objectRaycastWheel.parentEntity,
|
||||
objectRaycastWheel.parentMesh
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
/**
|
||||
* RaycastVehicle Runtime
|
||||
* @param physics GameLib.D3.Graphics
|
||||
* @param apiRaycastVehicle GameLib.D3.API.RaycastVehicle
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.RaycastVehicle = function (
|
||||
physics,
|
||||
apiRaycastVehicle
|
||||
) {
|
||||
|
||||
this.physics = physics;
|
||||
this.physics.isNotCannonThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiRaycastVehicle)) {
|
||||
apiRaycastVehicle = {};
|
||||
}
|
||||
|
||||
if (apiRaycastVehicle instanceof GameLib.D3.RaycastVehicle) {
|
||||
return apiRaycastVehicle;
|
||||
}
|
||||
|
||||
GameLib.D3.API.RaycastVehicle.call(
|
||||
this,
|
||||
apiRaycastVehicle.id,
|
||||
apiRaycastVehicle.name,
|
||||
apiRaycastVehicle.chassis,
|
||||
apiRaycastVehicle.wheels,
|
||||
apiRaycastVehicle.parentEntity
|
||||
);
|
||||
|
||||
if (this.chassis instanceof GameLib.D3.API.RaycastVehicle) {
|
||||
this.chassis = new GameLib.D3.RaycastVehicle(
|
||||
this.physics,
|
||||
this.chassis
|
||||
)
|
||||
}
|
||||
|
||||
this.wheels = this.wheels.map(function(wheel){
|
||||
if (wheel instanceof GameLib.D3.API.RaycastWheel) {
|
||||
return new GameLib.D3.RaycastWheel(
|
||||
this.physics,
|
||||
wheel
|
||||
)
|
||||
} else {
|
||||
return wheel;
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPONENT_RAYCAST_VEHICLE,
|
||||
{
|
||||
'chassis' : GameLib.D3.RigidBody,
|
||||
'wheels' : [GameLib.D3.RaycastWheel]
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.RaycastVehicle.prototype = Object.create(GameLib.D3.API.RaycastVehicle.prototype);
|
||||
GameLib.D3.RaycastVehicle.prototype.constructor = GameLib.D3.RaycastVehicle;
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.RaycastVehicle.prototype.createInstance = function() {
|
||||
|
||||
var instance = new CANNON.RaycastVehicle({
|
||||
chassisBody: this.chassis.instance
|
||||
});
|
||||
|
||||
//TODO: maybe move this into linking system - ALSO - store a reference to the wheel somehow to update the wheel instance?
|
||||
this.wheels.map(
|
||||
function(wheel){
|
||||
instance.addWheel(wheel.instance);
|
||||
}
|
||||
);
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
GameLib.D3.RaycastVehicle.prototype.updateInstance = function() {
|
||||
this.instance.chassisBody = this.chassis.instance;
|
||||
//TODO: add / remove wheels?
|
||||
console.log('TODO: add/remove wheels?');
|
||||
};
|
||||
|
||||
/**
|
||||
* GameLib.D3.RaycastVehicle to GameLib.D3.API.RaycastVehicle
|
||||
* @returns {GameLib.D3.API.RaycastVehicle}
|
||||
*/
|
||||
GameLib.D3.RaycastVehicle.prototype.toApiObject = function() {
|
||||
|
||||
var apiRaycastVehicle = new GameLib.D3.API.RaycastVehicle(
|
||||
this.id,
|
||||
this.name,
|
||||
GameLib.Utils.IdOrNull(this.chassis),
|
||||
this.wheels.map(function(wheel){
|
||||
return GameLib.Utils.IdOrNull(wheel);
|
||||
}),
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
return apiRaycastVehicle;
|
||||
};
|
||||
|
||||
/**
|
||||
* GameLib.D3.RaycastVehicle from Object RaycastVehicle
|
||||
* @param physics
|
||||
* @param objectComponent
|
||||
* @returns {GameLib.D3.RaycastVehicle}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.RaycastVehicle.FromObject = function(physics, objectComponent) {
|
||||
|
||||
var apiRaycastVehicle = GameLib.D3.API.RaycastVehicle.FromObject(objectComponent);
|
||||
|
||||
return new GameLib.D3.RaycastVehicle(
|
||||
physics,
|
||||
apiRaycastVehicle
|
||||
);
|
||||
};
|
|
@ -0,0 +1,163 @@
|
|||
/**
|
||||
* RaycastWheel Runtime
|
||||
* @param physics GameLib.D3.Graphics
|
||||
* @param apiRaycastWheel GameLib.D3.API.RaycastWheel
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.RaycastWheel = function (
|
||||
physics,
|
||||
apiRaycastWheel
|
||||
) {
|
||||
|
||||
this.physics = physics;
|
||||
this.physics.isNotCannonThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiRaycastWheel)) {
|
||||
apiRaycastWheel = {};
|
||||
}
|
||||
|
||||
if (apiRaycastWheel instanceof GameLib.D3.RaycastWheel) {
|
||||
return apiRaycastWheel;
|
||||
}
|
||||
|
||||
GameLib.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.parentEntity,
|
||||
apiRaycastWheel.parentMesh
|
||||
);
|
||||
|
||||
this.directionLocal = new GameLib.Vector3(
|
||||
this.physics,
|
||||
this.directionLocal,
|
||||
this
|
||||
);
|
||||
|
||||
this.axleLocal = new GameLib.Vector3(
|
||||
this.physics,
|
||||
this.axleLocal,
|
||||
this
|
||||
);
|
||||
|
||||
this.chassisConnectionPointLocal = new GameLib.Vector3(
|
||||
this.physics,
|
||||
this.chassisConnectionPointLocal,
|
||||
this
|
||||
);
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPONENT_RAYCAST_WHEEL,
|
||||
{
|
||||
'parentMesh' : GameLib.D3.Mesh
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.RaycastWheel.prototype = Object.create(GameLib.D3.API.RaycastWheel.prototype);
|
||||
GameLib.D3.RaycastWheel.prototype.constructor = GameLib.D3.RaycastWheel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.RaycastWheel.prototype.createInstance = function() {
|
||||
|
||||
var 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
|
||||
};
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
GameLib.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;
|
||||
};
|
||||
|
||||
/**
|
||||
* GameLib.D3.RaycastWheel to GameLib.D3.API.RaycastWheel
|
||||
* @returns {GameLib.D3.API.RaycastWheel}
|
||||
*/
|
||||
GameLib.D3.RaycastWheel.prototype.toApiObject = function() {
|
||||
|
||||
var apiRaycastWheel = new GameLib.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,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||
GameLib.Utils.IdOrNull(this.parentMesh)
|
||||
);
|
||||
|
||||
return apiRaycastWheel;
|
||||
};
|
||||
|
||||
/**
|
||||
* GameLib.D3.RaycastWheel from Object RaycastWheel
|
||||
* @param physics
|
||||
* @param objectComponent
|
||||
* @returns {GameLib.D3.RaycastWheel}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.RaycastWheel.FromObject = function(physics, objectComponent) {
|
||||
|
||||
var apiRaycastWheel = GameLib.D3.API.RaycastWheel.FromObject(objectComponent);
|
||||
|
||||
return new GameLib.D3.RaycastWheel(
|
||||
physics,
|
||||
apiRaycastWheel
|
||||
);
|
||||
};
|
|
@ -975,6 +975,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
|||
property === 'envMapIntensity'
|
||||
) {
|
||||
controllers.push(folder.add(object, property, -10, 100, 0.001));
|
||||
} else if (
|
||||
property === 'chassisConnectionPointLocal'
|
||||
) {
|
||||
controllers.push(folder.add(object, property, -1, 1, 1));
|
||||
} else if (
|
||||
property === 'heightOffset' ||
|
||||
property === 'rotationFactor'
|
||||
|
|
Loading…
Reference in New Issue