friction materials

beta.r3js.org
-=yb4f310 2017-09-01 13:14:14 +02:00
parent 3b09906efe
commit 048470521d
10 changed files with 259 additions and 46 deletions

View File

@ -145,7 +145,7 @@ GameLib.Component.COMPONENT_SHAPE_PLANE = 0x2f;
GameLib.Component.COMPONENT_CONTROLS = 0x30;
GameLib.Component.COMPONENT_CONTROLS_EDITOR = 0x31;
GameLib.Component.COMPONENT_CONTROLS_FLY = 0x32;
// GameLib.Component.COMPONENT_FACE = 0x33;
GameLib.Component.COMPONENT_FRICTION_MATERIAL = 0x33;
/**
* Returns string name for component number
@ -205,7 +205,7 @@ GameLib.Component.GetComponentName = function(number) {
case 0x30 : return 'GameLib.D3.Controls';
case 0x31 : return 'GameLib.D3.Controls.Editor';
case 0x32 : return 'GameLib.D3.Controls.Fly';
// case 0x33 : return 'GameLib.D3.Face';
case 0x33 : return 'GameLib.D3.FrictionMaterial';
break;
}

View File

@ -0,0 +1,61 @@
/**
* Raw FrictionMaterial API object - should always correspond with the FrictionMaterial Schema
* @param id
* @param name
* @param friction
* @param restitution
* @param parentEntity
* @constructor
*/
GameLib.D3.API.FrictionMaterial = function(
id,
name,
friction,
restitution,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Friction Material (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(friction)) {
friction = -1;
}
this.friction = friction;
if (GameLib.Utils.UndefinedOrNull(restitution)) {
restitution = -1;
}
this.restitution = restitution;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.FrictionMaterial.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.FrictionMaterial.prototype.constructor = GameLib.D3.API.FrictionMaterial;
/**
* Creates an API FrictionMaterial from an Object FrictionMaterial
* @param objectFrictionMaterial
* @constructor
*/
GameLib.D3.API.FrictionMaterial.FromObject = function(objectFrictionMaterial) {
return new GameLib.D3.API.FrictionMaterial(
objectFrictionMaterial.id,
objectFrictionMaterial.name,
objectFrictionMaterial.friction,
objectFrictionMaterial.restitution,
objectFrictionMaterial.parentEntity
);
};

View File

@ -0,0 +1,97 @@
/**
* FrictionMaterial Runtime
* @param physics GameLib.D3.Graphics
* @param apiFrictionMaterial GameLib.D3.API.FrictionMaterial
* @constructor
*/
GameLib.D3.FrictionMaterial = function (
physics,
apiFrictionMaterial
) {
this.physics = physics;
this.physics.isNotCannonThrow();
if (GameLib.Utils.UndefinedOrNull(apiFrictionMaterial)) {
apiFrictionMaterial = {};
}
if (apiFrictionMaterial instanceof GameLib.D3.FrictionMaterial) {
return apiFrictionMaterial;
}
GameLib.D3.API.FrictionMaterial.call(
this,
apiFrictionMaterial.id,
apiFrictionMaterial.name,
apiFrictionMaterial.friction,
apiFrictionMaterial.restitution,
apiFrictionMaterial.parentEntity
);
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_FRICTION_MATERIAL
);
};
GameLib.D3.FrictionMaterial.prototype = Object.create(GameLib.D3.API.FrictionMaterial.prototype);
GameLib.D3.FrictionMaterial.prototype.constructor = GameLib.D3.FrictionMaterial;
/**
*
* @returns {*}
*/
GameLib.D3.FrictionMaterial.prototype.createInstance = function() {
var instance = new CANNON.Material(this.name);
instance.friction = this.friction;
instance.restitution = this.restitution;
return instance;
};
/**
*
*/
GameLib.D3.FrictionMaterial.prototype.updateInstance = function() {
this.instance.friction = this.friction;
this.instance.restitution = this.restitution;
this.instance.name = this.name;
};
/**
* GameLib.D3.FrictionMaterial to GameLib.D3.API.FrictionMaterial
* @returns {GameLib.D3.API.FrictionMaterial}
*/
GameLib.D3.FrictionMaterial.prototype.toApiObject = function() {
var apiFrictionMaterial = new GameLib.D3.API.FrictionMaterial(
this.id,
this.name,
this.friction,
this.restitution,
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiFrictionMaterial;
};
/**
* GameLib.D3.FrictionMaterial from Object FrictionMaterial
* @param physics
* @param objectComponent
* @returns {GameLib.D3.FrictionMaterial}
* @constructor
*/
GameLib.D3.FrictionMaterial.FromObject = function(physics, objectComponent) {
var apiFrictionMaterial = GameLib.D3.API.FrictionMaterial.FromObject(objectComponent);
return new GameLib.D3.FrictionMaterial(
physics,
apiFrictionMaterial
);
};

View File

@ -720,7 +720,7 @@ GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance = function() {
*/
GameLib.D3.Material.prototype.createInstance = function() {
console.log('material create instance');
// console.log('material create instance');
var instance = null;
@ -758,7 +758,7 @@ GameLib.D3.Material.prototype.createInstance = function() {
*/
GameLib.D3.Material.prototype.updateInstance = function() {
console.log('material update instance');
// console.log('material update instance');
if (!this.instance) {
console.warn('Attempt to update a non-existent instance');

View File

@ -416,7 +416,7 @@ GameLib.D3.Mesh.prototype.createInstanceGeometry = function(instanceGeometry) {
*/
GameLib.D3.Mesh.prototype.createInstance = function() {
console.log('mesh create instance');
// console.log('mesh create instance');
var geometry = this.createInstanceGeometry();
@ -457,7 +457,7 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
*/
GameLib.D3.Mesh.prototype.updateInstance = function() {
console.log('mesh update instance');
// console.log('mesh update instance');
if (( this.isBufferMesh && !(this.instance.geometry instanceof THREE.BufferGeometry)) ||
( !this.isBufferMesh && (this.instance.geometry instanceof THREE.BufferGeometry)))

View File

@ -43,11 +43,35 @@ GameLib.D3.RigidBody = function (
apiRigidBody.parentEntity
);
this.position = new GameLib.Vector3(
this.physics,
this.position,
this
);
this.quaternion = new GameLib.Quaternion(
this.physics,
this.quaternion,
this
);
this.velocity = new GameLib.Vector3(
this.physics,
this.velocity,
this
);
this.angularVelocity = new GameLib.Vector3(
this.physics,
this.angularVelocity,
this
);
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_RIGID_BODY,
{
'shapes' : [GameLib.D3.Shape, GameLib.D3.Shape.Box]
'shapes' : [GameLib.D3.Shape.Box]
}
);
};
@ -61,29 +85,14 @@ GameLib.D3.RigidBody.prototype.constructor = GameLib.D3.RigidBody;
*/
GameLib.D3.RigidBody.prototype.createInstance = function() {
//TODO: create instance
var instance = new CANNON.Body(
{
mass : this.mass,
friction : this.friction,
position : new CANNON.Vec3(
this.position.x,
this.position.y,
this.position.z
),
quaternion : new CANNON.Quaternion(
this.quaternion.x,
this.quaternion.y,
this.quaternion.z,
this.quaternion.w
),
velocity : new CANNON.Vec3(
this.velocity.x,
this.velocity.y,
this.velocity.z
),
angularVelocity : this.angularVelocity,
position : this.position.instance,
quaternion : this.quaternion.instance,
velocity : this.velocity.instance,
angularVelocity : this.angularVelocity.instance,
linearDamping : this.linearDamping,
angularDamping : this.angularDamping,
allowSleep : this.allowSleep,
@ -154,10 +163,10 @@ GameLib.D3.RigidBody.prototype.toApiObject = function() {
this.name,
this.mass,
this.friction,
this.position,
this.quaternion,
this.velocity,
this.angularVelocity,
this.position.toApiObject(),
this.quaternion.toApiObject(),
this.velocity.toApiObject(),
this.angularVelocity.toApiObject(),
this.linearDamping,
this.angularDamping,
this.allowSleep,

View File

@ -155,7 +155,7 @@ GameLib.D3.Texture.TEXTURE_TYPE_CUBE = 0x2;
*/
GameLib.D3.Texture.prototype.createInstance = function() {
console.log('texture create instance');
// console.log('texture create instance');
var instance = null;
@ -220,7 +220,7 @@ GameLib.D3.Texture.prototype.createInstance = function() {
*/
GameLib.D3.Texture.prototype.updateInstance = function() {
console.log('texture update instance');
// console.log('texture update instance');
var imageChanged = false;

View File

@ -1,19 +1,30 @@
/**
* Runtime quaternion for updating instance objects
* @param graphics GameLib.D3.Graphics
* @param implementation
* @param parentObject GameLib.D3.*
* @param apiQuaternion GameLib.API.Quaternion
* @param grain Number
* @constructor
*/
GameLib.Quaternion = function (
graphics,
implementation,
apiQuaternion,
parentObject,
grain
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
this.implementation = implementation;
if (implementation instanceof GameLib.D3.Graphics) {
this.physics = null;
this.graphics = implementation;
this.graphics.isNotThreeThrow();
} else if (implementation instanceof GameLib.D3.Physics) {
this.graphics = null;
this.physics = implementation;
this.physics.isNotCannonThrow();
} else {
throw new Error('Unhandled implementation : ' + implementation);
}
if (GameLib.Utils.UndefinedOrNull(apiQuaternion)) {
apiQuaternion = {};
@ -39,7 +50,7 @@ GameLib.Quaternion = function (
this.parentObject = parentObject;
this.axis = new GameLib.Vector3(
this.graphics,
this.implementation,
this.axis,
this,
this.grain
@ -72,12 +83,23 @@ GameLib.Quaternion.prototype.createInstance = function(update) {
instance.z = this.z;
instance.w = this.w;
} else {
instance = new THREE.Quaternion(
this.x,
this.y,
this.z,
this.w
);
if (this.graphics) {
instance = new THREE.Quaternion(
this.x,
this.y,
this.z,
this.w
);
}
if (this.physics) {
instance = new CANNON.Quaternion(
this.x,
this.y,
this.z,
this.w
);
}
}
return instance;

View File

@ -1158,7 +1158,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) {
* Check if we have components to build a GUI for
*/
if (GameLib.Utils.UndefinedOrNull(this.components.length) || this.components.length < 1) {
console.log('no components selected');
// console.log('no components selected');
return;
}

View File

@ -503,6 +503,28 @@ GameLib.System.Linking.prototype.shapeInstanceCreated = function(data) {
}
);
/**
* We need to now, find the rigid bodies to which the shape belongs, and add it - also the reverse ?
*
* this is not ok - because we are not dealing with links to parent objects - these are dependencies which need
* to be resolved - an array of dependencies... eeek...
*/
// var rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RigidBody);
// rigidBodies.map(function(rigidBody){
//
// rigidBody.shapes = rigidBody.shapes.reduce(
// function(result, shape) {
// if (shape === data.shape.id) {
// result.push(data.shape);
// }
// return result;
// },
// []
// );
//
// });
};
GameLib.System.Linking.prototype.lightInstanceCreated = function(data) {
@ -657,11 +679,13 @@ GameLib.System.Linking.prototype.onParentSceneChange = function(data) {
*/
GameLib.System.Linking.prototype.onParentEntityChange = function(data) {
if (data.originalEntity) {
if (data.originalEntity instanceof GameLib.Entity) {
data.originalEntity.removeComponent(data.object);
}
data.newEntity.addComponent(data.object);
if (data.newEntity instanceof GameLib.Entity) {
data.newEntity.addComponent(data.object);
}
GameLib.Event.Emit(
GameLib.Event.PARENT_ENTITY_CHANGED,