start saving physics components
parent
9e038c3247
commit
57902a9750
|
@ -199,6 +199,8 @@ GameLib.Component.GetComponentName = function(number) {
|
||||||
case 0x2f : return 'GameLib.D3.Shape.Plane';
|
case 0x2f : return 'GameLib.D3.Shape.Plane';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new Error('Unknown component type: ' + number );
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* @param collisionFilterGroup
|
* @param collisionFilterGroup
|
||||||
* @param collisionFilterMask
|
* @param collisionFilterMask
|
||||||
* @param fixedRotation
|
* @param fixedRotation
|
||||||
* @param shape
|
* @param shapes
|
||||||
* @param kinematic
|
* @param kinematic
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -38,7 +38,7 @@ GameLib.D3.API.RigidBody = function(
|
||||||
collisionFilterGroup,
|
collisionFilterGroup,
|
||||||
collisionFilterMask,
|
collisionFilterMask,
|
||||||
fixedRotation,
|
fixedRotation,
|
||||||
shape,
|
shapes,
|
||||||
kinematic,
|
kinematic,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
|
@ -123,10 +123,10 @@ GameLib.D3.API.RigidBody = function(
|
||||||
}
|
}
|
||||||
this.fixedRotation = fixedRotation;
|
this.fixedRotation = fixedRotation;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(shape)) {
|
if (GameLib.Utils.UndefinedOrNull(shapes)) {
|
||||||
shape = null;
|
shapes = [];
|
||||||
}
|
}
|
||||||
this.shape = shape;
|
this.shapes = shapes;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(kinematic)) {
|
if (GameLib.Utils.UndefinedOrNull(kinematic)) {
|
||||||
kinematic = false;
|
kinematic = false;
|
||||||
|
@ -165,7 +165,7 @@ GameLib.D3.API.RigidBody.FromObject = function(objectRigidBody) {
|
||||||
objectRigidBody.collisionFilterGroup,
|
objectRigidBody.collisionFilterGroup,
|
||||||
objectRigidBody.collisionFilterMask,
|
objectRigidBody.collisionFilterMask,
|
||||||
objectRigidBody.fixedRotation,
|
objectRigidBody.fixedRotation,
|
||||||
objectRigidBody.shape,
|
objectRigidBody.shapes,
|
||||||
objectRigidBody.kinematic,
|
objectRigidBody.kinematic,
|
||||||
objectRigidBody.parentEntity
|
objectRigidBody.parentEntity
|
||||||
);
|
);
|
||||||
|
|
|
@ -531,14 +531,22 @@ GameLib.D3.Mesh.prototype.updateInstance = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.instance.renderOrder = this.renderOrder;
|
this.instance.renderOrder = this.renderOrder;
|
||||||
//
|
|
||||||
// this.instance.geometry.computeBoundingBox();
|
};
|
||||||
//
|
|
||||||
// if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_NORMAL) {
|
GameLib.D3.Mesh.prototype.getBoundingBox = function() {
|
||||||
// this.width = this.instance.geometry.boundingBox.max.x - this.instance.geometry.boundingBox.min.x;
|
|
||||||
// this.height = this.instance.geometry.boundingBox.max.y - this.instance.geometry.boundingBox.min.y;
|
this.instance.geometry.computeBoundingBox();
|
||||||
// this.depth = this.instance.geometry.boundingBox.max.z - this.instance.geometry.boundingBox.min.z;
|
|
||||||
// }
|
return new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.API.Vector3(
|
||||||
|
this.instance.geometry.boundingBox.max.x - this.instance.geometry.boundingBox.min.x,
|
||||||
|
this.instance.geometry.boundingBox.max.y - this.instance.geometry.boundingBox.min.y,
|
||||||
|
this.instance.geometry.boundingBox.max.z - this.instance.geometry.boundingBox.min.z
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -38,7 +38,7 @@ GameLib.D3.RigidBody = function (
|
||||||
apiRigidBody.collisionFilterGroup,
|
apiRigidBody.collisionFilterGroup,
|
||||||
apiRigidBody.collisionFilterMask,
|
apiRigidBody.collisionFilterMask,
|
||||||
apiRigidBody.fixedRotation,
|
apiRigidBody.fixedRotation,
|
||||||
apiRigidBody.shape,
|
apiRigidBody.shapes,
|
||||||
apiRigidBody.kinematic,
|
apiRigidBody.kinematic,
|
||||||
apiRigidBody.parentEntity
|
apiRigidBody.parentEntity
|
||||||
);
|
);
|
||||||
|
@ -47,7 +47,7 @@ GameLib.D3.RigidBody = function (
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_RIGID_BODY,
|
GameLib.Component.COMPONENT_RIGID_BODY,
|
||||||
{
|
{
|
||||||
'shape' : GameLib.D3.Shape
|
'shapes' : [GameLib.D3.Shape]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -166,7 +166,7 @@ GameLib.D3.RigidBody.prototype.toApiObject = function() {
|
||||||
this.collisionFilterGroup,
|
this.collisionFilterGroup,
|
||||||
this.collisionFilterMask,
|
this.collisionFilterMask,
|
||||||
this.fixedRotation,
|
this.fixedRotation,
|
||||||
GameLib.Utils.IdOrNull(this.shape),
|
this.shapes.map(function(shape){return GameLib.Utils.IdOrNull(shape)}),
|
||||||
this.kinematic,
|
this.kinematic,
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
|
@ -176,17 +176,17 @@ GameLib.D3.RigidBody.prototype.toApiObject = function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GameLib.D3.RigidBody from Object RigidBody
|
* GameLib.D3.RigidBody from Object RigidBody
|
||||||
* @param graphics
|
* @param physics
|
||||||
* @param objectComponent
|
* @param objectComponent
|
||||||
* @returns {GameLib.D3.RigidBody}
|
* @returns {GameLib.D3.RigidBody}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.RigidBody.FromObject = function(graphics, objectComponent) {
|
GameLib.D3.RigidBody.FromObject = function(physics, objectComponent) {
|
||||||
|
|
||||||
var apiRigidBody = GameLib.D3.API.RigidBody.FromObject(objectComponent);
|
var apiRigidBody = GameLib.D3.API.RigidBody.FromObject(objectComponent);
|
||||||
|
|
||||||
return new GameLib.D3.RigidBody(
|
return new GameLib.D3.RigidBody(
|
||||||
graphics,
|
physics,
|
||||||
apiRigidBody
|
apiRigidBody
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -96,16 +96,16 @@ GameLib.D3.Shape.prototype.toApiObject = function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a standard object mesh to a GameLib.D3.Shape
|
* Converts a standard object mesh to a GameLib.D3.Shape
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param physics GameLib.D3.Physics
|
||||||
* @param objectShape {Object}
|
* @param objectShape {Object}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Shape.FromObject = function(graphics, objectShape) {
|
GameLib.D3.Shape.FromObject = function(physics, objectShape) {
|
||||||
|
|
||||||
var apiShape = GameLib.D3.API.Shape.FromObject(objectShape);
|
var apiShape = GameLib.D3.API.Shape.FromObject(objectShape);
|
||||||
|
|
||||||
return new GameLib.D3.Shape(
|
return new GameLib.D3.Shape(
|
||||||
graphics,
|
physics,
|
||||||
apiShape
|
apiShape
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,14 @@
|
||||||
* @param physics
|
* @param physics
|
||||||
* @param apiShape GameLib.D3.API.Shape
|
* @param apiShape GameLib.D3.API.Shape
|
||||||
* @param halfExtents
|
* @param halfExtents
|
||||||
|
* @param activeMesh
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Shape.Box = function (
|
GameLib.D3.Shape.Box = function (
|
||||||
physics,
|
physics,
|
||||||
apiShape,
|
apiShape,
|
||||||
halfExtents
|
halfExtents,
|
||||||
|
activeMesh
|
||||||
) {
|
) {
|
||||||
this.physics = physics;
|
this.physics = physics;
|
||||||
this.physics.isNotCannonThrow();
|
this.physics.isNotCannonThrow();
|
||||||
|
@ -28,6 +30,12 @@ GameLib.D3.Shape.Box = function (
|
||||||
this.physics,
|
this.physics,
|
||||||
apiShape
|
apiShape
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(activeMesh)) {
|
||||||
|
activeMesh = null;
|
||||||
|
}
|
||||||
|
this.activeMesh = activeMesh;
|
||||||
|
this.linkedObjects.activeMesh = GameLib.D3.Mesh;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Shape.Box.prototype = Object.create(GameLib.D3.Shape.prototype);
|
GameLib.D3.Shape.Box.prototype = Object.create(GameLib.D3.Shape.prototype);
|
||||||
|
@ -50,9 +58,48 @@ GameLib.D3.Shape.Box.prototype.updateInstance = function() {
|
||||||
this.instance.halfExtents.x = this.halfExtents.x;
|
this.instance.halfExtents.x = this.halfExtents.x;
|
||||||
this.instance.halfExtents.y = this.halfExtents.y;
|
this.instance.halfExtents.y = this.halfExtents.y;
|
||||||
this.instance.halfExtents.z = this.halfExtents.z;
|
this.instance.halfExtents.z = this.halfExtents.z;
|
||||||
this.instance.updateAABB();
|
|
||||||
this.instance.updateBoundingSphereRadius();
|
this.instance.updateBoundingSphereRadius();
|
||||||
this.instance.updateEdges();
|
this.instance.updateConvexPolyhedronRepresentation();
|
||||||
this.instance.updateNormals();
|
};
|
||||||
this.instance.updateTree();
|
|
||||||
|
GameLib.D3.Shape.Box.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
var apiShape = GameLib.D3.Shape.prototype.toApiObject.call(this);
|
||||||
|
|
||||||
|
apiShape.halfExtents = this.halfExtents.toApiObject();
|
||||||
|
apiShape.activeMesh = GameLib.Utils.IdOrNull(this.activeMesh);
|
||||||
|
|
||||||
|
return apiShape;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Shape.Box.prototype.setFromMesh = function() {
|
||||||
|
|
||||||
|
if (this.activeMesh === null) {
|
||||||
|
console.log('select a mesh first');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var box = this.activeMesh.getBoundingBox();
|
||||||
|
|
||||||
|
this.halfExtents.x = box.x / 2;
|
||||||
|
this.halfExtents.y = box.y / 2;
|
||||||
|
this.halfExtents.z = box.z / 2;
|
||||||
|
|
||||||
|
this.halfExtents.updateInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Shape.Box.FromObject = function(physics, objectShape) {
|
||||||
|
|
||||||
|
var apiShape = GameLib.D3.Shape.FromObject(physics, objectShape);
|
||||||
|
|
||||||
|
apiShape.halfExtents = objectShape.halfExtents;
|
||||||
|
apiShape.activeMesh = objectShape.activeMesh;
|
||||||
|
|
||||||
|
return new GameLib.D3.Shape.Box(
|
||||||
|
graphics,
|
||||||
|
apiShape,
|
||||||
|
apiShape.halfExtents,
|
||||||
|
apiShape.activeMesh
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
|
@ -1,6 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Storage System takes care loading and linking components and dependencies
|
* Storage System takes care loading and linking components and dependencies
|
||||||
* @param graphics
|
* @param graphics
|
||||||
|
* @param physics
|
||||||
* @param apiSystem GameLib.API.System
|
* @param apiSystem GameLib.API.System
|
||||||
* @param apiUrl
|
* @param apiUrl
|
||||||
* @param token
|
* @param token
|
||||||
|
@ -15,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
GameLib.System.Storage = function(
|
GameLib.System.Storage = function(
|
||||||
graphics,
|
graphics,
|
||||||
|
physics,
|
||||||
apiSystem,
|
apiSystem,
|
||||||
apiUrl,
|
apiUrl,
|
||||||
token,
|
token,
|
||||||
|
@ -29,6 +31,9 @@ GameLib.System.Storage = function(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
this.physics = physics;
|
||||||
|
this.physics.isNotCannonThrow();
|
||||||
|
|
||||||
GameLib.System.call(
|
GameLib.System.call(
|
||||||
this,
|
this,
|
||||||
apiSystem
|
apiSystem
|
||||||
|
@ -251,7 +256,24 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
|
||||||
runtimeComponent.parentEntity = parentEntity;
|
runtimeComponent.parentEntity = parentEntity;
|
||||||
parentEntity = runtimeComponent;
|
parentEntity = runtimeComponent;
|
||||||
} else {
|
} else {
|
||||||
runtimeComponent = fn(__system.graphics, component);
|
try {
|
||||||
|
runtimeComponent = fn(__system.graphics, component);
|
||||||
|
} catch (error) {
|
||||||
|
runtimeComponent = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!runtimeComponent) {
|
||||||
|
try {
|
||||||
|
runtimeComponent = fn(__system.physics, component);
|
||||||
|
} catch (error) {
|
||||||
|
runtimeComponent = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!runtimeComponent) {
|
||||||
|
throw new Error('Could not create a runtime component: ', component);
|
||||||
|
}
|
||||||
|
|
||||||
runtimeComponent.parentEntity = parentEntity;
|
runtimeComponent.parentEntity = parentEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue