get sub property

beta.r3js.org
-=yb4f310 2017-10-05 21:50:40 +02:00
parent 02e1718efa
commit b6c019a00a
1 changed files with 317 additions and 264 deletions

View File

@ -394,8 +394,8 @@ GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) {
mesh.quaternion,
'angle',
{
'get': this.getQuaternionAngle(mesh, animation),
'set': this.setQuaternionAngle(mesh, animation),
'get': this.getProperty(mesh, 'angle', 'quaternion'),
'set': this.setProperty(mesh, animation, 'angle', 'quaternion'),
'configurable': true
}
);
@ -404,8 +404,8 @@ GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) {
mesh.quaternion.axis,
'x',
{
'get': this.getQuaternionAxisX(mesh, animation),
'set': this.setQuaternionAxisX(mesh, animation),
'get': this.getSubProperty(mesh, 'x', 'quaternion', 'axis'),
'set': this.setSubProperty(mesh, animation, 'x', 'quaternion', 'axis'),
'configurable': true
}
);
@ -414,8 +414,8 @@ GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) {
mesh.quaternion.axis,
'y',
{
'get': this.getQuaternionAxisY(mesh, animation),
'set': this.setQuaternionAxisY(mesh, animation),
'get': this.getSubProperty(mesh, 'y', 'quaternion', 'axis'),
'set': this.setSubProperty(mesh, animation, 'y', 'quaternion', 'axis'),
'configurable': true
}
);
@ -424,8 +424,8 @@ GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) {
mesh.quaternion.axis,
'z',
{
'get': this.getQuaternionAxisZ(mesh, animation),
'set': this.setQuaternionAxisZ(mesh, animation),
'get': this.getSubProperty(mesh, 'z', 'quaternion', 'axis'),
'set': this.setSubProperty(mesh, animation, 'z', 'quaternion', 'axis'),
'configurable': true
}
);
@ -521,282 +521,335 @@ GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) {
);
};
GameLib.System.Animation.prototype.getQuaternionAngle = function(mesh, animation) {
// GameLib.System.Animation.prototype.getQuaternionAngle = function(mesh, animation) {
//
// return function() {
// return;
// /**
// * TODO: fix this shit..
// * Back up the current property descriptor
// */
// mesh.animationObject = {
// backupAngleDescriptor: Object.getOwnPropertyDescriptor(mesh.quaternion, 'angle'),
// targetAngle: mesh.quaternion.angle,
// angleIncrement: true,
// intermediateAngle: mesh.quaternion.angle,
// subscription: null,
// inProcess: false,
// blocking: animation.blocking//,
// // callbacks : [],
// // storedValues : []
// };
//
// var getIntermediateAngle = function () {
// return mesh.animationObject.intermediateAngle;
// };
//
// var getTargetAngle = function () {
//
// // if (mesh.animationObject.storedValues.length > 0) {
// // return mesh.animationObject.storedValues[mesh.animationObject.storedValues.length - 1];
// // }
//
// return mesh.animationObject.targetAngle;
// };
//
// var animateRotation = function (value) {
//
// mesh.animationObject.intermediateAngle += value;
//
// var done = false;
//
// if (mesh.animationObject.angleIncrement) {
// /**
// * We are rotating upwards
// */
// if (mesh.animationObject.intermediateAngle >= mesh.animationObject.targetAngle) {
// /**
// * We need to stop
// */
// done = true;
// }
// } else {
// /**
// * We are rotating downwards
// */
// if (mesh.animationObject.intermediateAngle <= mesh.animationObject.targetAngle) {
// /**
// * We need to stop
// */
// done = true;
// }
// }
//
// if (done) {
//
// /**
// * We clamp to our target angle
// */
// mesh.animationObject.intermediateAngle = mesh.animationObject.targetAngle;
//
// /**
// * We limit our intermediate angle between values of -pi and pi
// */
// while (mesh.animationObject.intermediateAngle > Math.PI) {
// mesh.animationObject.intermediateAngle -= (Math.PI * 2);
// }
//
// while (mesh.animationObject.intermediateAngle < -(Math.PI)) {
// mesh.animationObject.intermediateAngle += (Math.PI * 2);
// }
//
// /**
// * We apply our new intermediate angle to our target
// */
// mesh.animationObject.targetAngle = mesh.animationObject.intermediateAngle;
// }
//
// /**
// * Apply the actual rotation to the mesh
// */
// mesh.updateInstanceRotationFromAxisAngle(mesh.quaternion.axis, mesh.animationObject.intermediateAngle);
//
// /**
// * Check again if we are done, we need to do some additional work -
// */
// if (done) {
//
// if (!mesh.animationObject.subscription) {
// var message = 'mesh animation object subscription went missing for ';
// message += mesh.name + ': ';
// message += animation.name;
// console.warn(message);
// throw new Error(message);
// }
//
// /**
// * Stop subscribing to before render events
// */
// mesh.animationObject.subscription.remove();
//
// /**
// * @type {null}
// */
// mesh.animationObject.subscription = null;
//
// /**
// * For some meshes, when we are done with the animation, we want to apply
// * the current state of the mesh to the object data itself (i.e. update
// * its vertices etc)
// */
// if (animation.applyToMeshWhenDone) {
// /**
// * Now we say that our intermediate angle is zero, because we will apply our rotation
// * and this will prevent us from re-registering a new 'animationRender' event
// */
// mesh.animationObject.targetAngle = 0;
// mesh.animationObject.intermediateAngle = 0;
//
// /**
// * Apply our position, rotation and scale to the mesh
// */
// mesh.applyPositionRotationScale();
// }
//
// /**
// * Tell our animation component that it is no longer in process...
// * @type {boolean}
// */
// mesh.animationObject.inProcess = false;
//
// // if (mesh.animationObject.callbacks.length > 0) {
// // var callback = mesh.animationObject.callbacks[0];
// // mesh.animationObject.callbacks.splice(0,1);
// // callback();
// // }
//
// // mesh.animationObject.storedValues = [];
// }
// };
// }
// };
//
// GameLib.System.Animation.prototype.setQuaternionAngle = function(mesh, animation) {
//
// return function(value) {
// return;
// /**
// * TODO: update this shit
// */
// /**
// * Check if we have work to do
// */
// if (mesh.animationObject.intermediateAngle === value) {
//
// mesh.animationObject.inProcess = false;
//
// /**
// * Nothing to do
// */
// return;
// }
//
// /**
// * Check if we have another animation in process
// */
// if (mesh.animationObject.inProcess && mesh.animationObject.blocking) {
//
// console.log('another animation is already in process');
//
// // setTargetAngle(value);
//
// // GameLib.Utils.PushUnique(mesh.animationObject.storedValues, value);
// //
// // mesh.animationObject.callbacks.push(
// // function(__value) {
// // return function(){
// // mesh.quaternion.angle = __value;
// // }
// // }(value)
// // );
//
// /**
// * Respond that our angle is actually our target angle (it will be that soon)
// */
// return;
// }
//
// /**
// * We indicate that we now have an animation in process
// * @type {boolean}
// */
// mesh.animationObject.inProcess = true;
//
// /**
// * Ok - all good - lets start the animation
// */
// if (mesh.animationObject.intermediateAngle > value) {
// /**
// * We will rotate towards by decrementing
// */
// mesh.animationObject.angleIncrement = false;
// } else {
// /**
// * We will rotate towards by incrementing
// */
// mesh.animationObject.angleIncrement = true;
// }
//
// /**
// * We say what our target angle is - when we reach our target angle, we want
// * to stop our animation
// */
// mesh.animationObject.targetAngle = value;
//
// /**
// * Now we subscribe to 'before render' events, and slowly increment the value
// * @type {{fn, remove}}
// */
// mesh.animationObject.subscription = GameLib.Event.Subscribe(
// GameLib.Event.BEFORE_RENDER,
// function(data) {
//
// var increment = Math.abs(animation.rotationSpeed);
//
// if (!mesh.animationObject.angleIncrement) {
// increment *= -1;
// }
//
// animateRotation(data.delta * increment);
// }
// );
// }
// };
//
// GameLib.System.Animation.prototype.getQuaternionAxisX = function(mesh, animation) {
// return function() {
// return this.latest[mesh.id].quaternion.axis.x;
// }.bind(this);
// };
//
// GameLib.System.Animation.prototype.setQuaternionAxisX = function(mesh, animation) {
// return function(value) {
// this.latest[mesh.id].quaternion.axis.x = value;
// }.bind(this);
// };
//
// GameLib.System.Animation.prototype.getQuaternionAxisY = function(mesh, animation) {
// return function() {
// return this.latest[mesh.id].quaternion.axis.y;
// }.bind(this);
// };
//
// GameLib.System.Animation.prototype.setQuaternionAxisY = function(mesh, animation) {
// return function(value) {
// this.latest[mesh.id].quaternion.axis.y = value;
// }.bind(this);
// };
//
// GameLib.System.Animation.prototype.getQuaternionAxisZ = function(mesh, animation) {
// return function() {
// return this.latest[mesh.id].quaternion.axis.z;
// }.bind(this);
// };
//
// GameLib.System.Animation.prototype.setQuaternionAxisZ = function(mesh, animation) {
// return function(value) {
// this.latest[mesh.id].quaternion.axis.z = value;
// }.bind(this);
// };
GameLib.System.Animation.prototype.getSubProperty = function(mesh, axis, property, subProperty) {
return function() {
return;
/**
* TODO: fix this shit..
* Back up the current property descriptor
*/
mesh.animationObject = {
backupAngleDescriptor: Object.getOwnPropertyDescriptor(mesh.quaternion, 'angle'),
targetAngle: mesh.quaternion.angle,
angleIncrement: true,
intermediateAngle: mesh.quaternion.angle,
subscription: null,
inProcess: false,
blocking: animation.blocking//,
// callbacks : [],
// storedValues : []
};
var getIntermediateAngle = function () {
return mesh.animationObject.intermediateAngle;
};
var getTargetAngle = function () {
// if (mesh.animationObject.storedValues.length > 0) {
// return mesh.animationObject.storedValues[mesh.animationObject.storedValues.length - 1];
// }
return mesh.animationObject.targetAngle;
};
var animateRotation = function (value) {
mesh.animationObject.intermediateAngle += value;
var done = false;
if (mesh.animationObject.angleIncrement) {
/**
* We are rotating upwards
*/
if (mesh.animationObject.intermediateAngle >= mesh.animationObject.targetAngle) {
/**
* We need to stop
*/
done = true;
}
} else {
/**
* We are rotating downwards
*/
if (mesh.animationObject.intermediateAngle <= mesh.animationObject.targetAngle) {
/**
* We need to stop
*/
done = true;
}
}
if (done) {
/**
* We clamp to our target angle
*/
mesh.animationObject.intermediateAngle = mesh.animationObject.targetAngle;
/**
* We limit our intermediate angle between values of -pi and pi
*/
while (mesh.animationObject.intermediateAngle > Math.PI) {
mesh.animationObject.intermediateAngle -= (Math.PI * 2);
}
while (mesh.animationObject.intermediateAngle < -(Math.PI)) {
mesh.animationObject.intermediateAngle += (Math.PI * 2);
}
/**
* We apply our new intermediate angle to our target
*/
mesh.animationObject.targetAngle = mesh.animationObject.intermediateAngle;
}
/**
* Apply the actual rotation to the mesh
*/
mesh.updateInstanceRotationFromAxisAngle(mesh.quaternion.axis, mesh.animationObject.intermediateAngle);
/**
* Check again if we are done, we need to do some additional work -
*/
if (done) {
if (!mesh.animationObject.subscription) {
var message = 'mesh animation object subscription went missing for ';
message += mesh.name + ': ';
message += animation.name;
console.warn(message);
throw new Error(message);
}
/**
* Stop subscribing to before render events
*/
mesh.animationObject.subscription.remove();
/**
* @type {null}
*/
mesh.animationObject.subscription = null;
/**
* For some meshes, when we are done with the animation, we want to apply
* the current state of the mesh to the object data itself (i.e. update
* its vertices etc)
*/
if (animation.applyToMeshWhenDone) {
/**
* Now we say that our intermediate angle is zero, because we will apply our rotation
* and this will prevent us from re-registering a new 'animationRender' event
*/
mesh.animationObject.targetAngle = 0;
mesh.animationObject.intermediateAngle = 0;
/**
* Apply our position, rotation and scale to the mesh
*/
mesh.applyPositionRotationScale();
}
/**
* Tell our animation component that it is no longer in process...
* @type {boolean}
*/
mesh.animationObject.inProcess = false;
// if (mesh.animationObject.callbacks.length > 0) {
// var callback = mesh.animationObject.callbacks[0];
// mesh.animationObject.callbacks.splice(0,1);
// callback();
// }
// mesh.animationObject.storedValues = [];
}
};
}
return this.latest[mesh.id][property][subProperty][axis];
}.bind(this);
};
GameLib.System.Animation.prototype.setQuaternionAngle = function(mesh, animation) {
GameLib.System.Animation.prototype.setSubProperty = function(mesh, animation, axis, property, subProperty) {
return function(value) {
return;
/**
* TODO: update this shit
*/
/**
* Check if we have work to do
*/
if (mesh.animationObject.intermediateAngle === value) {
mesh.animationObject.inProcess = false;
var from = Number(this.latest[mesh.id][property][subProperty][axis]);
this.latest[mesh.id][property][subProperty][axis] = value;
if (property === 'position') {
/**
* Nothing to do
* Look for other position animations
* TODO:check when not super exausted
*/
return;
}
/**
* Check if we have another animation in process
*/
if (mesh.animationObject.inProcess && mesh.animationObject.blocking) {
console.log('another animation is already in process');
// setTargetAngle(value);
// GameLib.Utils.PushUnique(mesh.animationObject.storedValues, value);
// var positionAnimationObject = this.animations[mesh.id].reduce(
// function(result, animationObject) {
//
// mesh.animationObject.callbacks.push(
// function(__value) {
// return function(){
// mesh.quaternion.angle = __value;
// if (animationObject.type === 'position') {
// result = animationObject;
// }
// }(value)
//
// return result;
// },
// null
// );
/**
* Respond that our angle is actually our target angle (it will be that soon)
* We found another position animation - just update the 'to' property
*/
return;
// if (positionAnimationObject) {
// positionAnimationObject.to = value;
// return;
// }
}
/**
* We indicate that we now have an animation in process
* @type {boolean}
*/
mesh.animationObject.inProcess = true;
/**
* Ok - all good - lets start the animation
*/
if (mesh.animationObject.intermediateAngle > value) {
/**
* We will rotate towards by decrementing
*/
mesh.animationObject.angleIncrement = false;
} else {
/**
* We will rotate towards by incrementing
*/
mesh.animationObject.angleIncrement = true;
}
/**
* We say what our target angle is - when we reach our target angle, we want
* to stop our animation
*/
mesh.animationObject.targetAngle = value;
/**
* Now we subscribe to 'before render' events, and slowly increment the value
* @type {{fn, remove}}
*/
mesh.animationObject.subscription = GameLib.Event.Subscribe(
GameLib.Event.BEFORE_RENDER,
function(data) {
var increment = Math.abs(animation.rotationSpeed);
if (!mesh.animationObject.angleIncrement) {
increment *= -1;
}
animateRotation(data.delta * increment);
this.animations[mesh.id].push(
{
type : property,
axis : axis,
from : from,
to : value,
animation : animation,
mesh : mesh
}
);
}
};
GameLib.System.Animation.prototype.getQuaternionAxisX = function(mesh, animation) {
return function() {
return this.latest[mesh.id].quaternion.axis.x;
}.bind(this);
};
GameLib.System.Animation.prototype.setQuaternionAxisX = function(mesh, animation) {
return function(value) {
this.latest[mesh.id].quaternion.axis.x = value;
}.bind(this);
};
GameLib.System.Animation.prototype.getQuaternionAxisY = function(mesh, animation) {
return function() {
return this.latest[mesh.id].quaternion.axis.y;
}.bind(this);
};
GameLib.System.Animation.prototype.setQuaternionAxisY = function(mesh, animation) {
return function(value) {
this.latest[mesh.id].quaternion.axis.y = value;
}.bind(this);
};
GameLib.System.Animation.prototype.getQuaternionAxisZ = function(mesh, animation) {
return function() {
return this.latest[mesh.id].quaternion.axis.z;
}.bind(this);
};
GameLib.System.Animation.prototype.setQuaternionAxisZ = function(mesh, animation) {
return function(value) {
this.latest[mesh.id].quaternion.axis.z = value;
}.bind(this);
}.bind(this)
};
GameLib.System.Animation.prototype.getProperty = function(mesh, axis, property) {