60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
/**
|
|
* Physics
|
|
* @param id
|
|
* @param name
|
|
* @param physicsType
|
|
* @constructor
|
|
*/
|
|
R3.PhysicsRuntime = function(
|
|
id,
|
|
name,
|
|
physicsType
|
|
) {
|
|
if (R3.Utils.UndefinedOrNull(id)) {
|
|
id = R3.Utils.RandomId();
|
|
}
|
|
this.id = id;
|
|
|
|
if (R3.Utils.UndefinedOrNull(name)) {
|
|
name = 'Physics (' + id + ')';
|
|
}
|
|
this.name = name;
|
|
|
|
if (R3.Utils.UndefinedOrNull(physicsType)) {
|
|
physicsType = R3.PhysicsRuntime.TYPE_CANNON_JS;
|
|
}
|
|
this.physicsType = physicsType;
|
|
|
|
this.createInstance();
|
|
};
|
|
|
|
/**
|
|
* R3.PhysicsRuntime Types
|
|
* @type {number}
|
|
*/
|
|
R3.PhysicsRuntime.TYPE_CANNON_JS = 0x1;
|
|
|
|
R3.PhysicsRuntime.prototype.createInstance = function() {
|
|
if (this.physicsType === R3.PhysicsRuntime.TYPE_CANNON_JS) {
|
|
this.instance = CANNON;
|
|
} else {
|
|
this.instance = null;
|
|
}
|
|
};
|
|
|
|
R3.PhysicsRuntime.prototype.updateInstance = function(property) {
|
|
if (property === 'physicsType') {
|
|
this.createInstance();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Logs a warning and throws an error if not cannon
|
|
*/
|
|
R3.PhysicsRuntime.prototype.isNotCannonThrow = function() {
|
|
if (this.instance !== CANNON) {
|
|
console.error('Only CANNON supported');
|
|
throw new Error('Only CANNON supported');
|
|
}
|
|
};
|