animation system, camera offsets
parent
3a422a5acf
commit
02e1718efa
|
@ -96,7 +96,9 @@ GameLib.Event.GET_GRAPHICS_IMPLEMENTATION = 0x4e;
|
|||
GameLib.Event.GET_PHYSICS_IMPLEMENTATION = 0x4f;
|
||||
GameLib.Event.GET_CODER_IMPLEMENTATION = 0x50;
|
||||
GameLib.Event.ANIMATION_MESH_ADDED = 0x51;
|
||||
|
||||
GameLib.Event.ANIMATION_MESH_REMOVED = 0x52;
|
||||
GameLib.Event.GET_SCENE = 0x53;
|
||||
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54;
|
||||
|
||||
/**
|
||||
* Returns string name of event ID
|
||||
|
@ -188,6 +190,9 @@ GameLib.Event.GetEventName = function(number) {
|
|||
case 0x4f : return 'get_physics_implementation';
|
||||
case 0x50 : return 'get_coder_implementation';
|
||||
case 0x51 : return 'animation_mesh_added';
|
||||
case 0x52 : return 'animation_mesh_removed';
|
||||
case 0x53 : return 'get_scene';
|
||||
case 0x54 : return 'custom_code_window_resize';
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,11 @@ GameLib.D3.API.Animation = function (
|
|||
this.scaleFn = scaleFn;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(blocking)) {
|
||||
blocking = true;
|
||||
blocking = {
|
||||
position : false, //positions can be blocked from accumulating and executing at once
|
||||
rotation : true, //rotations need to execute in order
|
||||
scale : false //scale can accumulate
|
||||
};
|
||||
}
|
||||
this.blocking = blocking;
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
* @param maxY
|
||||
* @param minZ
|
||||
* @param maxZ
|
||||
* @param offsetX
|
||||
* @param offsetY
|
||||
* @param quaternion GameLib.Quaternion
|
||||
* @param parentEntity
|
||||
* @param eyeSeparation
|
||||
|
@ -37,6 +39,8 @@ GameLib.D3.API.Camera = function(
|
|||
maxY,
|
||||
minZ,
|
||||
maxZ,
|
||||
offsetX,
|
||||
offsetY,
|
||||
quaternion,
|
||||
parentEntity,
|
||||
eyeSeparation,
|
||||
|
@ -131,6 +135,16 @@ GameLib.D3.API.Camera = function(
|
|||
}
|
||||
this.maxZ = maxZ;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(offsetX)) {
|
||||
offsetX = 0;
|
||||
}
|
||||
this.offsetX = offsetX;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(offsetY)) {
|
||||
offsetY = 0;
|
||||
}
|
||||
this.offsetY = offsetY;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(eyeSeparation)) {
|
||||
eyeSeparation = 30;
|
||||
}
|
||||
|
@ -173,6 +187,8 @@ GameLib.D3.API.Camera.FromObject = function(objectCamera) {
|
|||
objectCamera.maxY,
|
||||
objectCamera.minZ,
|
||||
objectCamera.maxZ,
|
||||
objectCamera.offsetX,
|
||||
objectCamera.offsetY,
|
||||
GameLib.API.Quaternion.FromObject(objectCamera.quaternion),
|
||||
objectCamera.parentEntity,
|
||||
objectCamera.eyeSeparation,
|
||||
|
|
|
@ -243,7 +243,9 @@ GameLib.D3.Animation.prototype.closeEditor = function(){
|
|||
};
|
||||
|
||||
GameLib.D3.Animation.prototype.addMesh = function(mesh) {
|
||||
this.meshes.push(mesh);
|
||||
|
||||
GameLib.Utils.PushUnique(this.meshes, mesh);
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.ANIMATION_MESH_ADDED,
|
||||
{
|
||||
|
@ -253,3 +255,19 @@ GameLib.D3.Animation.prototype.addMesh = function(mesh) {
|
|||
)
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Animation.prototype.removeMesh = function(mesh) {
|
||||
|
||||
var index = this.meshes.indexOf(mesh);
|
||||
|
||||
this.meshes.splice(index, 1);
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.ANIMATION_MESH_REMOVED,
|
||||
{
|
||||
animation : this,
|
||||
mesh : mesh
|
||||
}
|
||||
)
|
||||
|
||||
};
|
|
@ -37,6 +37,8 @@ GameLib.D3.Camera = function(
|
|||
apiCamera.maxY,
|
||||
apiCamera.minZ,
|
||||
apiCamera.maxZ,
|
||||
apiCamera.offsetX,
|
||||
apiCamera.offsetY,
|
||||
apiCamera.quaternion,
|
||||
apiCamera.parentEntity,
|
||||
apiCamera.eyeSeparation,
|
||||
|
@ -108,8 +110,8 @@ GameLib.D3.Camera.prototype.createInstance = function() {
|
|||
);
|
||||
} else if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
|
||||
instance = new THREE.OrthographicCamera(
|
||||
this.minX,
|
||||
this.maxX,
|
||||
this.minX + this.offsetX,
|
||||
this.maxX + this.offsetX,
|
||||
this.maxY,
|
||||
this.minY,
|
||||
this.minZ,
|
||||
|
@ -162,10 +164,16 @@ GameLib.D3.Camera.prototype.updateInstance = function() {
|
|||
}
|
||||
|
||||
if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
|
||||
this.instance.left = this.minX;
|
||||
this.instance.right = this.maxX;
|
||||
this.instance.bottom = this.minY;
|
||||
this.instance.top = this.maxY;
|
||||
|
||||
this.minX = this.aspect * this.minY;
|
||||
this.maxX = this.aspect * this.maxY;
|
||||
|
||||
this.instance.left = this.minX + this.offsetX;
|
||||
this.instance.right = this.maxX + this.offsetX;
|
||||
|
||||
this.instance.bottom = this.minY + this.offsetY;
|
||||
this.instance.top = this.maxY + this.offsetY;
|
||||
|
||||
this.instance.near = this.minZ;
|
||||
this.instance.far = this.maxZ;
|
||||
}
|
||||
|
@ -232,6 +240,8 @@ GameLib.D3.Camera.prototype.toApiObject = function() {
|
|||
this.maxY,
|
||||
this.minZ,
|
||||
this.maxZ,
|
||||
this.offsetX,
|
||||
this.offsetY,
|
||||
this.quaternion.toApiObject(),
|
||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||
this.eyeSeparation,
|
||||
|
|
|
@ -26,6 +26,8 @@ GameLib.System = function(
|
|||
|
||||
this.started = false;
|
||||
|
||||
this.paused = false;
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPONENT_SYSTEM
|
||||
|
|
|
@ -24,228 +24,501 @@ GameLib.System.Animation.prototype.start = function() {
|
|||
|
||||
this.beforeRenderSubscription = GameLib.Event.Subscribe(
|
||||
GameLib.Event.BEFORE_RENDER,
|
||||
function(data) {
|
||||
|
||||
var delta = data.delta;
|
||||
|
||||
for (var property in this.animations) {
|
||||
if (this.animations.hasOwnProperty(property)) {
|
||||
|
||||
|
||||
if (this.animations[property].length > 0) {
|
||||
|
||||
var done = false;
|
||||
|
||||
var animationObject = this.animations[property][0];
|
||||
|
||||
if (animationObject.type === 'rotation') {
|
||||
|
||||
var increment = animationObject.animation.rotationSpeed * delta;
|
||||
|
||||
animationObject.from += increment;
|
||||
|
||||
if (Math.abs(animationObject.from - animationObject.to) < increment) {
|
||||
animationObject.mesh.instance.rotation[animationObject.axis] = animationObject.to;
|
||||
done = true;
|
||||
} else {
|
||||
animationObject.mesh.instance.rotation[animationObject.axis] = animationObject.from;
|
||||
}
|
||||
}
|
||||
|
||||
if (done) {
|
||||
this.animations[property].splice(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
this.beforeRender.bind(this)
|
||||
);
|
||||
|
||||
var animations = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Animation);
|
||||
|
||||
animations.map(function(animation){
|
||||
animation.meshes.map(
|
||||
function(mesh) {
|
||||
this.attachAnimation(animation, mesh);
|
||||
}.bind(this)
|
||||
)
|
||||
}.bind(this));
|
||||
|
||||
this.animationMeshAddedSubscription = GameLib.Event.Subscribe(
|
||||
GameLib.Event.ANIMATION_MESH_ADDED,
|
||||
function(data) {
|
||||
|
||||
var animation = data.animation;
|
||||
var mesh = data.mesh;
|
||||
|
||||
/**
|
||||
* Initialize the property with the original mesh z value
|
||||
*/
|
||||
this.latest[mesh.id] = {
|
||||
rotation : {
|
||||
x : mesh.rotation.x,
|
||||
y : mesh.rotation.y,
|
||||
z : mesh.rotation.z
|
||||
},
|
||||
position : {
|
||||
x : mesh.position.x,
|
||||
y : mesh.position.y,
|
||||
z : mesh.position.z
|
||||
},
|
||||
scale : {
|
||||
x : mesh.scale.x,
|
||||
y : mesh.scale.y,
|
||||
z : mesh.scale.z
|
||||
},
|
||||
quaternion : {
|
||||
axis : {
|
||||
x : mesh.quaternion.axis.x,
|
||||
y : mesh.quaternion.axis.y,
|
||||
z : mesh.quaternion.axis.z
|
||||
},
|
||||
angle : mesh.quaternion.angle
|
||||
}
|
||||
};
|
||||
|
||||
this.animations[mesh.id] = [];
|
||||
|
||||
mesh.backupQuaternionAngleDescriptor = Object.getOwnPropertyDescriptor(mesh.quaternion, 'angle');
|
||||
mesh.backupQuaternionAxisXDescriptor = Object.getOwnPropertyDescriptor(mesh.quaternion.axis, 'x');
|
||||
mesh.backupQuaternionAxisYDescriptor = Object.getOwnPropertyDescriptor(mesh.quaternion.axis, 'y');
|
||||
mesh.backupQuaternionAxisZDescriptor = Object.getOwnPropertyDescriptor(mesh.quaternion.axis, 'z');
|
||||
mesh.backupRotationXDescriptor = Object.getOwnPropertyDescriptor(mesh.rotation, 'x');
|
||||
mesh.backupRotationYDescriptor = Object.getOwnPropertyDescriptor(mesh.rotation, 'y');
|
||||
mesh.backupRotationZDescriptor = Object.getOwnPropertyDescriptor(mesh.rotation, 'z');
|
||||
mesh.backupPositionXDescriptor = Object.getOwnPropertyDescriptor(mesh.position, 'x');
|
||||
mesh.backupPositionYDescriptor = Object.getOwnPropertyDescriptor(mesh.position, 'y');
|
||||
mesh.backupPositionZDescriptor = Object.getOwnPropertyDescriptor(mesh.position, 'z');
|
||||
mesh.backupScaleXDescriptor = Object.getOwnPropertyDescriptor(mesh.scale, 'x');
|
||||
mesh.backupScaleYDescriptor = Object.getOwnPropertyDescriptor(mesh.scale, 'y');
|
||||
mesh.backupScaleZDescriptor = Object.getOwnPropertyDescriptor(mesh.scale, 'z');
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.quaternion,
|
||||
'angle',
|
||||
{
|
||||
'get': this.getQuaternionAngle(mesh, animation),
|
||||
'set': this.setQuaternionAngle(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'x',
|
||||
{
|
||||
'get': this.getQuaternionAxisX(mesh, animation),
|
||||
'set': this.setQuaternionAxisX(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'y',
|
||||
{
|
||||
'get': this.getQuaternionAxisY(mesh, animation),
|
||||
'set': this.setQuaternionAxisY(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'z',
|
||||
{
|
||||
'get': this.getQuaternionAxisZ(mesh, animation),
|
||||
'set': this.setQuaternionAxisZ(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'x',
|
||||
{
|
||||
'get': this.getRotation(mesh, 'x'),
|
||||
'set': this.setRotation(mesh, animation, 'x'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'y',
|
||||
{
|
||||
'get': this.getRotation(mesh, 'y'),
|
||||
'set': this.setRotation(mesh, animation, 'y'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'z',
|
||||
{
|
||||
'get': this.getRotation(mesh, 'z'),
|
||||
'set': this.setRotation(mesh, animation, 'z'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'x',
|
||||
{
|
||||
'get': this.getScaleX(mesh, animation),
|
||||
'set': this.setScaleX(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'y',
|
||||
{
|
||||
'get': this.getScaleY(mesh, animation),
|
||||
'set': this.setScaleY(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'z',
|
||||
{
|
||||
'get': this.getScaleZ(mesh, animation),
|
||||
'set': this.setScaleZ(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'x',
|
||||
{
|
||||
'get': this.getPositionX(mesh, animation),
|
||||
'set': this.setPositionX(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'y',
|
||||
{
|
||||
'get': this.getPositionY(mesh, animation),
|
||||
'set': this.setPositionY(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'z',
|
||||
{
|
||||
'get': this.getPositionZ(mesh, animation),
|
||||
'set': this.setPositionZ(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
this.attachAnimation(data.animation, data.mesh);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.animationMeshRemovedSubscription = GameLib.Event.Subscribe(
|
||||
GameLib.Event.ANIMATION_MESH_REMOVED,
|
||||
function(data) {
|
||||
this.detachAnimation(data.mesh);
|
||||
}.bind(this)
|
||||
)
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.beforeRender = function(data) {
|
||||
|
||||
if (this.paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
var delta = data.delta;
|
||||
|
||||
for (var property in this.animations) {
|
||||
if (this.animations.hasOwnProperty(property)) {
|
||||
|
||||
var processing = [];
|
||||
|
||||
if (this.animations[property].length > 0) {
|
||||
|
||||
var rotationDone = false;
|
||||
var positionDone = false;
|
||||
var scaleDone = false;
|
||||
|
||||
for (var i = 0; i < this.animations[property].length; i++) {
|
||||
if (this.animations[property][i].type === 'rotation' && !rotationDone) {
|
||||
rotationDone = true;
|
||||
processing.push(this.animations[property][i]);
|
||||
}
|
||||
|
||||
if (this.animations[property][i].type === 'position' && !positionDone) {
|
||||
|
||||
// if (this.animations[property][i].animation.blocking.position) {
|
||||
// positionDone = true;
|
||||
// }
|
||||
|
||||
processing.push(this.animations[property][i]);
|
||||
}
|
||||
|
||||
if (this.animations[property][i].type === 'scale' && !scaleDone) {
|
||||
//scaleDone = true;
|
||||
processing.push(this.animations[property][i]);
|
||||
}
|
||||
|
||||
if (scaleDone && positionDone && rotationDone) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processing.map(
|
||||
function(__property) {
|
||||
return function(animationObject) {
|
||||
|
||||
var done = false;
|
||||
|
||||
var increment = 0;
|
||||
|
||||
if (animationObject.type === 'rotation') {
|
||||
increment = animationObject.animation.rotationSpeed * delta;
|
||||
}
|
||||
|
||||
if (animationObject.type === 'position') {
|
||||
increment = animationObject.animation.translationSpeed * delta;
|
||||
}
|
||||
|
||||
if (animationObject.type === 'scale') {
|
||||
increment = animationObject.animation.scaleSpeed * delta;
|
||||
}
|
||||
|
||||
if (animationObject.from < animationObject.to) {
|
||||
animationObject.from += increment;
|
||||
} else {
|
||||
animationObject.from -= increment;
|
||||
}
|
||||
|
||||
if (Math.abs(animationObject.from - animationObject.to) < increment) {
|
||||
animationObject.mesh.instance[animationObject.type][animationObject.axis] = animationObject.to;
|
||||
done = true;
|
||||
} else {
|
||||
animationObject.mesh.instance[animationObject.type][animationObject.axis] = animationObject.from;
|
||||
}
|
||||
|
||||
if (done) {
|
||||
var index = this.animations[__property].indexOf(animationObject);
|
||||
this.animations[__property].splice(index, 1);
|
||||
}
|
||||
|
||||
}.bind(this);
|
||||
}.bind(this)(property)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.detachAnimation = function(mesh) {
|
||||
|
||||
var detached = false;
|
||||
|
||||
if (mesh.backupQuaternionAngleDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.quaternion,
|
||||
'angle',
|
||||
mesh.backupQuaternionAngleDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupQuaternionAngleDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupQuaternionAxisXDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'x',
|
||||
mesh.backupQuaternionAxisXDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupQuaternionAxisXDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupQuaternionAxisYDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'y',
|
||||
mesh.backupQuaternionAxisYDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupQuaternionAxisYDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupQuaternionAxisZDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'z',
|
||||
mesh.backupQuaternionAxisZDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupQuaternionAxisXDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupRotationXDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'x',
|
||||
mesh.backupRotationXDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupRotationXDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupRotationYDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'y',
|
||||
mesh.backupRotationYDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupRotationYDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupRotationZDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'z',
|
||||
mesh.backupRotationZDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupRotationZDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupPositionXDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'x',
|
||||
mesh.backupPositionXDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupPositionXDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupPositionYDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'y',
|
||||
mesh.backupPositionYDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupPositionYDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupPositionZDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'z',
|
||||
mesh.backupPositionZDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupPositionZDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupScaleXDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'x',
|
||||
mesh.backupScaleXDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupScaleXDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupScaleYDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'y',
|
||||
mesh.backupScaleYDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupScaleYDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (mesh.backupScaleZDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'z',
|
||||
mesh.backupScaleZDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupScaleZDescriptor;
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (this.latest[mesh.id]) {
|
||||
|
||||
mesh.rotation.x = this.latest[mesh.id].rotation.x;
|
||||
mesh.rotation.y = this.latest[mesh.id].rotation.y;
|
||||
mesh.rotation.z = this.latest[mesh.id].rotation.z;
|
||||
|
||||
mesh.position.x = this.latest[mesh.id].position.x;
|
||||
mesh.position.y = this.latest[mesh.id].position.y;
|
||||
mesh.position.z = this.latest[mesh.id].position.z;
|
||||
|
||||
mesh.scale.x = this.latest[mesh.id].scale.x;
|
||||
mesh.scale.y = this.latest[mesh.id].scale.y;
|
||||
mesh.scale.z = this.latest[mesh.id].scale.z;
|
||||
|
||||
mesh.quaternion.axis.x = this.latest[mesh.id].quaternion.axis.x;
|
||||
mesh.quaternion.axis.y = this.latest[mesh.id].quaternion.axis.y;
|
||||
mesh.quaternion.axis.z = this.latest[mesh.id].quaternion.axis.z;
|
||||
|
||||
mesh.quaternion.angle = this.latest[mesh.id].quaternion.angle;
|
||||
|
||||
delete this.latest[mesh.id];
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (this.animations[mesh.id]) {
|
||||
delete this.animations[mesh.id];
|
||||
|
||||
detached = true;
|
||||
}
|
||||
|
||||
if (detached) {
|
||||
mesh.updateInstance();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) {
|
||||
|
||||
/**
|
||||
* Initialize the property with the original mesh z value
|
||||
*/
|
||||
this.latest[mesh.id] = {
|
||||
rotation : {
|
||||
x : mesh.rotation.x,
|
||||
y : mesh.rotation.y,
|
||||
z : mesh.rotation.z
|
||||
},
|
||||
position : {
|
||||
x : mesh.position.x,
|
||||
y : mesh.position.y,
|
||||
z : mesh.position.z
|
||||
},
|
||||
scale : {
|
||||
x : mesh.scale.x,
|
||||
y : mesh.scale.y,
|
||||
z : mesh.scale.z
|
||||
},
|
||||
quaternion : {
|
||||
axis : {
|
||||
x : mesh.quaternion.axis.x,
|
||||
y : mesh.quaternion.axis.y,
|
||||
z : mesh.quaternion.axis.z
|
||||
},
|
||||
angle : mesh.quaternion.angle
|
||||
}
|
||||
};
|
||||
|
||||
this.animations[mesh.id] = [];
|
||||
|
||||
if (mesh.backupRotationXDescriptor) {
|
||||
throw new Error('already a backed up x descriptor');
|
||||
}
|
||||
|
||||
mesh.backupQuaternionAngleDescriptor = Object.getOwnPropertyDescriptor(mesh.quaternion, 'angle');
|
||||
mesh.backupQuaternionAxisXDescriptor = Object.getOwnPropertyDescriptor(mesh.quaternion.axis, 'x');
|
||||
mesh.backupQuaternionAxisYDescriptor = Object.getOwnPropertyDescriptor(mesh.quaternion.axis, 'y');
|
||||
mesh.backupQuaternionAxisZDescriptor = Object.getOwnPropertyDescriptor(mesh.quaternion.axis, 'z');
|
||||
mesh.backupRotationXDescriptor = Object.getOwnPropertyDescriptor(mesh.rotation, 'x');
|
||||
mesh.backupRotationYDescriptor = Object.getOwnPropertyDescriptor(mesh.rotation, 'y');
|
||||
mesh.backupRotationZDescriptor = Object.getOwnPropertyDescriptor(mesh.rotation, 'z');
|
||||
mesh.backupPositionXDescriptor = Object.getOwnPropertyDescriptor(mesh.position, 'x');
|
||||
mesh.backupPositionYDescriptor = Object.getOwnPropertyDescriptor(mesh.position, 'y');
|
||||
mesh.backupPositionZDescriptor = Object.getOwnPropertyDescriptor(mesh.position, 'z');
|
||||
mesh.backupScaleXDescriptor = Object.getOwnPropertyDescriptor(mesh.scale, 'x');
|
||||
mesh.backupScaleYDescriptor = Object.getOwnPropertyDescriptor(mesh.scale, 'y');
|
||||
mesh.backupScaleZDescriptor = Object.getOwnPropertyDescriptor(mesh.scale, 'z');
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.quaternion,
|
||||
'angle',
|
||||
{
|
||||
'get': this.getQuaternionAngle(mesh, animation),
|
||||
'set': this.setQuaternionAngle(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'x',
|
||||
{
|
||||
'get': this.getQuaternionAxisX(mesh, animation),
|
||||
'set': this.setQuaternionAxisX(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'y',
|
||||
{
|
||||
'get': this.getQuaternionAxisY(mesh, animation),
|
||||
'set': this.setQuaternionAxisY(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'z',
|
||||
{
|
||||
'get': this.getQuaternionAxisZ(mesh, animation),
|
||||
'set': this.setQuaternionAxisZ(mesh, animation),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'x',
|
||||
{
|
||||
'get': this.getProperty(mesh, 'x', 'rotation'),
|
||||
'set': this.setProperty(mesh, animation, 'x', 'rotation'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'y',
|
||||
{
|
||||
'get': this.getProperty(mesh, 'y', 'rotation'),
|
||||
'set': this.setProperty(mesh, animation, 'y', 'rotation'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'z',
|
||||
{
|
||||
'get': this.getProperty(mesh, 'z', 'rotation'),
|
||||
'set': this.setProperty(mesh, animation, 'z', 'rotation'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'x',
|
||||
{
|
||||
'get': this.getProperty(mesh, 'x', 'scale'),
|
||||
'set': this.setProperty(mesh, animation, 'x', 'scale'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'y',
|
||||
{
|
||||
'get': this.getProperty(mesh, 'y', 'scale'),
|
||||
'set': this.setProperty(mesh, animation, 'y', 'scale'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'z',
|
||||
{
|
||||
'get': this.getProperty(mesh, 'z', 'scale'),
|
||||
'set': this.setProperty(mesh, animation, 'z', 'scale'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'x',
|
||||
{
|
||||
'get': this.getProperty(mesh, 'x', 'position'),
|
||||
'set': this.setProperty(mesh, animation, 'x', 'position'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'y',
|
||||
{
|
||||
'get': this.getProperty(mesh, 'y', 'position'),
|
||||
'set': this.setProperty(mesh, animation, 'y', 'position'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'z',
|
||||
{
|
||||
'get': this.getProperty(mesh, 'z', 'position'),
|
||||
'set': this.setProperty(mesh, animation, 'z', 'position'),
|
||||
'configurable': true
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.getQuaternionAngle = function(mesh, animation) {
|
||||
|
@ -539,6 +812,32 @@ GameLib.System.Animation.prototype.setProperty = function(mesh, animation, axis,
|
|||
|
||||
this.latest[mesh.id][property][axis] = value;
|
||||
|
||||
if (property === 'position') {
|
||||
/**
|
||||
* Look for other position animations
|
||||
* TODO:check when not super exausted
|
||||
*/
|
||||
// var positionAnimationObject = this.animations[mesh.id].reduce(
|
||||
// function(result, animationObject) {
|
||||
//
|
||||
// if (animationObject.type === 'position') {
|
||||
// result = animationObject;
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
// },
|
||||
// null
|
||||
// );
|
||||
|
||||
/**
|
||||
* We found another position animation - just update the 'to' property
|
||||
*/
|
||||
// if (positionAnimationObject) {
|
||||
// positionAnimationObject.to = value;
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
this.animations[mesh.id].push(
|
||||
{
|
||||
type : property,
|
||||
|
@ -553,78 +852,6 @@ GameLib.System.Animation.prototype.setProperty = function(mesh, animation, axis,
|
|||
}.bind(this)
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.getPositionX = function(mesh, axis) {
|
||||
return function() {
|
||||
return this.latest[mesh.id].position[axis];
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.setPositionX = function(mesh, animation) {
|
||||
return function(value) {
|
||||
this.latest[mesh.id].position.x = value;
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.getPositionY = function(mesh, animation) {
|
||||
return function() {
|
||||
return this.latest[mesh.id].position.y;
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.setPositionY = function(mesh, animation) {
|
||||
return function(value) {
|
||||
this.latest[mesh.id].position.y = value;
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.getPositionZ = function(mesh, animation) {
|
||||
return function() {
|
||||
return this.latest[mesh.id].position.z;
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.setPositionZ = function(mesh, animation) {
|
||||
return function(value) {
|
||||
this.latest[mesh.id].position.z = value;
|
||||
}.bind(this)
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.getScaleX = function(mesh, animation) {
|
||||
return function() {
|
||||
return this.latest[mesh.id].scale.x;
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.setScaleX = function(mesh, animation) {
|
||||
return function(value) {
|
||||
this.latest[mesh.id].scale.x = value;
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.getScaleY = function(mesh, animation) {
|
||||
return function() {
|
||||
return this.latest[mesh.id].scale.y;
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.setScaleY = function(mesh, animation) {
|
||||
return function(value) {
|
||||
this.latest[mesh.id].scale.y = value;
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.getScaleZ = function(mesh, animation) {
|
||||
return function() {
|
||||
return this.latest[mesh.id].scale.z;
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype.setScaleZ = function(mesh, animation) {
|
||||
return function(value) {
|
||||
this.latest[mesh.id].scale.z = value;
|
||||
}.bind(this)
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop Animation System
|
||||
*/
|
||||
|
@ -636,140 +863,24 @@ GameLib.System.Animation.prototype.stop = function() {
|
|||
|
||||
this.animationMeshAddedSubscription.remove();
|
||||
|
||||
this.animationMeshRemovedSubscription.remove();
|
||||
|
||||
this.animations = {};
|
||||
|
||||
var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh);
|
||||
|
||||
meshes.map(
|
||||
function(mesh) {
|
||||
if (mesh.backupQuaternionAngleDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.quaternion,
|
||||
'angle',
|
||||
mesh.backupQuaternionAngleDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupQuaternionAngleDescriptor;
|
||||
for (var property in this.latest) {
|
||||
if (
|
||||
this.latest.hasOwnProperty(property) &&
|
||||
property === mesh.id
|
||||
) {
|
||||
this.detachAnimation(mesh);
|
||||
}
|
||||
}
|
||||
|
||||
if (mesh.backupQuaternionAxisXDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'x',
|
||||
mesh.backupQuaternionAxisXDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupQuaternionAxisXDescriptor;
|
||||
}
|
||||
|
||||
if (mesh.backupQuaternionAxisYDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'y',
|
||||
mesh.backupQuaternionAxisYDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupQuaternionAxisYDescriptor;
|
||||
}
|
||||
|
||||
if (mesh.backupQuaternionAxisZDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.quaternion.axis,
|
||||
'z',
|
||||
mesh.backupQuaternionAxisZDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupQuaternionAxisXDescriptor;
|
||||
}
|
||||
|
||||
if (mesh.backupRotationXDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'x',
|
||||
mesh.backupRotationXDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupRotationXDescriptor;
|
||||
}
|
||||
|
||||
if (mesh.backupRotationYDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'y',
|
||||
mesh.backupRotationYDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupRotationYDescriptor;
|
||||
}
|
||||
|
||||
if (mesh.backupRotationZDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.rotation,
|
||||
'z',
|
||||
mesh.backupRotationZDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupRotationZDescriptor;
|
||||
}
|
||||
|
||||
if (mesh.backupPositionXDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'x',
|
||||
mesh.backupPositionXDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupPositionXDescriptor;
|
||||
}
|
||||
|
||||
if (mesh.backupPositionYDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'y',
|
||||
mesh.backupPositionYDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupPositionYDescriptor;
|
||||
}
|
||||
|
||||
if (mesh.backupPositionZDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.position,
|
||||
'z',
|
||||
mesh.backupPositionZDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupPositionZDescriptor;
|
||||
}
|
||||
|
||||
if (mesh.backupScaleXDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'x',
|
||||
mesh.backupScaleXDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupScaleXDescriptor;
|
||||
}
|
||||
|
||||
if (mesh.backupScaleYDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'y',
|
||||
mesh.backupScaleYDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupScaleYDescriptor;
|
||||
}
|
||||
|
||||
if (mesh.backupScaleZDescriptor) {
|
||||
Object.defineProperty(
|
||||
mesh.scale,
|
||||
'z',
|
||||
mesh.backupScaleZDescriptor
|
||||
);
|
||||
|
||||
delete mesh.backupScaleZDescriptor;
|
||||
}
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -1098,9 +1098,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
|||
property === 'minZ' ||
|
||||
property === 'maxX' ||
|
||||
property === 'maxY' ||
|
||||
property === 'maxZ'
|
||||
property === 'maxZ' ||
|
||||
property === 'offsetX'
|
||||
) {
|
||||
controllers.push(folder.add(object, property, -100, 100, 1));
|
||||
controllers.push(folder.add(object, property, -100, 100, 0.01));
|
||||
} else if (
|
||||
property === 'widthSegments' ||
|
||||
property === 'radiusSegments' ||
|
||||
|
|
Loading…
Reference in New Issue