animation system update

beta.r3js.org
-=yb4f310 2018-02-18 18:48:14 +01:00
parent b0cb6db4a8
commit 4fbd3424c6
5 changed files with 493 additions and 444 deletions

View File

@ -95,8 +95,8 @@ GameLib.Event.GET_REMOTE_API_URL = 0x4d;
GameLib.Event.COMPONENT_TYPES_UPDATE = 0x4e; GameLib.Event.COMPONENT_TYPES_UPDATE = 0x4e;
GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f; GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f;
GameLib.Event.CAST_SOURCE_CHANGED = 0x50; GameLib.Event.CAST_SOURCE_CHANGED = 0x50;
GameLib.Event.ANIMATION_MESH_ADDED = 0x51; // GameLib.Event.ANIMATION_MESH_ADDED = 0x51;
GameLib.Event.ANIMATION_MESH_REMOVED = 0x52; // GameLib.Event.ANIMATION_MESH_REMOVED = 0x52;
GameLib.Event.CANVAS_CHANGE = 0x53; GameLib.Event.CANVAS_CHANGE = 0x53;
GameLib.Event.AFTER_WINDOW_RESIZE = 0x54; GameLib.Event.AFTER_WINDOW_RESIZE = 0x54;
GameLib.Event.LOAD_FONT = 0x55; GameLib.Event.LOAD_FONT = 0x55;
@ -222,8 +222,8 @@ GameLib.Event.GetEventName = function(number) {
case 0x4e : return 'component_types_update'; case 0x4e : return 'component_types_update';
case 0x4f : return 'delayed_instance_encountered'; case 0x4f : return 'delayed_instance_encountered';
case 0x50 : return 'cast_source_changed'; case 0x50 : return 'cast_source_changed';
case 0x51 : return 'animation_mesh_added'; case 0x51 : return 'unused';//'animation_mesh_added';
case 0x52 : return 'animation_mesh_removed'; case 0x52 : return 'unused';//'animation_mesh_removed';
case 0x53 : return 'dom_element_change'; case 0x53 : return 'dom_element_change';
case 0x54 : return 'after_window_resize'; case 0x54 : return 'after_window_resize';
case 0x55 : return 'load_font'; case 0x55 : return 'load_font';

View File

@ -163,13 +163,13 @@ GameLib.D3.Animation.prototype.updateInstance = function(property, item) {
} }
if (property === 'meshes') { if (property === 'meshes') {
GameLib.Event.Emit( // GameLib.Event.Emit(
GameLib.Event.ANIMATION_MESH_ADDED, // GameLib.Event.ANIMATION_MESH_ADDED,
{ // {
animation : this, // animation : this,
mesh : item // mesh : item
} // }
) // )
} }
GameLib.Component.prototype.updateInstance.call(this, property); GameLib.Component.prototype.updateInstance.call(this, property);
@ -203,19 +203,6 @@ GameLib.D3.Animation.prototype.toApiObject = function() {
}; };
/**
* Converts from an Object Animation to a GameLib.D3.Animation
* @param objectAnimation Object
* @returns {GameLib.D3.Animation}
* @constructor
*/
GameLib.D3.Animation.FromObject = function(objectAnimation) {
var apiAnimation = GameLib.D3.API.Animation.FromObject(objectAnimation);
return new GameLib.D3.Animation(
apiAnimation
);
};
GameLib.D3.Animation.prototype.launchEditor = function(){ GameLib.D3.Animation.prototype.launchEditor = function(){
GameLib.Event.Emit( GameLib.Event.Emit(
@ -272,32 +259,32 @@ GameLib.D3.Animation.prototype.closeEditor = function(){
dom.parentElement.removeChild(dom); dom.parentElement.removeChild(dom);
}; };
GameLib.D3.Animation.prototype.addMesh = function(mesh) { // GameLib.D3.Animation.prototype.addMesh = function(mesh) {
//
GameLib.Utils.PushUnique(this.meshes, mesh); // GameLib.Utils.PushUnique(this.meshes, mesh);
//
GameLib.Event.Emit( // GameLib.Event.Emit(
GameLib.Event.ANIMATION_MESH_ADDED, // GameLib.Event.ANIMATION_MESH_ADDED,
{ // {
animation : this, // animation : this,
mesh : mesh // mesh : mesh
} // }
) // )
//
}; // };
//
GameLib.D3.Animation.prototype.removeMesh = function(mesh) { // GameLib.D3.Animation.prototype.removeMesh = function(mesh) {
//
var index = this.meshes.indexOf(mesh); // var index = this.meshes.indexOf(mesh);
//
this.meshes.splice(index, 1); // this.meshes.splice(index, 1);
//
GameLib.Event.Emit( // GameLib.Event.Emit(
GameLib.Event.ANIMATION_MESH_REMOVED, // GameLib.Event.ANIMATION_MESH_REMOVED,
{ // {
animation : this, // animation : this,
mesh : mesh // mesh : mesh
} // }
) // )
//
}; // };

View File

@ -353,6 +353,70 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
} }
if (property === 'parentMesh') { if (property === 'parentMesh') {
/**
* Check if we already have a parent mesh
*/
if (GameLib.Utils.UndefinedOrNull(this.parentMesh)) {
/**
* We are detaching this instance from the parent
*/
if (this.instance.parent && this.parentScene.instance) {
/**
* Update the parent matrix world
*/
this.instance.parent.updateMatrixWorld();
/**
* Copy the child world position into a temporary vector
* @type {THREE.Vector3}
*/
var vector = new THREE.Vector3();
vector.setFromMatrixPosition(this.instance.matrixWorld);
/**
* Detach child from parent within this scene
*/
THREE.SceneUtils.detach(
this.instance,
this.instance.parent,
this.parentScene.instance
);
/**
* We store the world position back to the child
*/
this.position.x = vector.x;
this.position.y = vector.y;
this.position.z = vector.z;
/**
* Update the instance position
*/
this.updateInstance('position');
/**
* Don't touch this instance parent - since it is now probably a scene object
*/
/**
* TODO: do we apply rotation somehow?
*/
} else {
throw new Error('Not enough information to detach')
}
} else {
/**
* Add this as a child to the parent
*/
this.parentMesh.instance.add(this.instance);
}
if (this.parentMesh && this.parentMesh.instance) { if (this.parentMesh && this.parentMesh.instance) {
if (this.instance.parent !== this.parentMesh.instance) { if (this.instance.parent !== this.parentMesh.instance) {
this.instance.parent = this.parentMesh.instance; this.instance.parent = this.parentMesh.instance;
@ -508,125 +572,125 @@ GameLib.D3.Mesh.prototype.applyBones = function(geometry) {
* @param childInstance * @param childInstance
* @param child * @param child
*/ */
GameLib.D3.Mesh.prototype.addChild = function(childInstance, child) { // GameLib.D3.Mesh.prototype.addChild = function(childInstance, child) {
//
if (!this.instance) { // if (!this.instance) {
throw new Error('mesh instance not loaded yet : ' + this.name); // throw new Error('mesh instance not loaded yet : ' + this.name);
} // }
//
if (GameLib.Utils.UndefinedOrNull(childInstance)) { // if (GameLib.Utils.UndefinedOrNull(childInstance)) {
throw new Error('no child mesh instance'); // throw new Error('no child mesh instance');
} // }
//
if (GameLib.Utils.UndefinedOrNull(child)) { // if (GameLib.Utils.UndefinedOrNull(child)) {
throw new Error('no child mesh'); // throw new Error('no child mesh');
} // }
//
this.instance.add(childInstance); // this.instance.add(childInstance);
//
childInstance.parent = this.instance; // childInstance.parent = this.instance;
//
child.parentMesh = this; // child.parentMesh = this;
}; // };
/** /**
* Sets a parent for this mesh * Sets a parent for this mesh
* @param parentMesh * @param parentMesh
*/ */
GameLib.D3.Mesh.prototype.setParentMesh = function(parentMesh) { // GameLib.D3.Mesh.prototype.setParentMesh = function(parentMesh) {
//
// /**
// * Are we removing this child from the parent?
// */
// if (GameLib.Utils.UndefinedOrNull(parentMesh)) {
//
// if (this.instance && this.instance.parent && this.parentScene.instance) {
//
// /**
// * Update the parent matrix world
// */
// this.instance.parent.updateMatrixWorld();
//
// /**
// * Copy the child world position into a temporary vector
// * @type {THREE.Vector3}
// */
// var vector = new THREE.Vector3();
// vector.setFromMatrixPosition(this.instance.matrixWorld);
//
// /**
// * Detach child from parent within this scene
// */
// THREE.SceneUtils.detach(
// this.instance,
// this.instance.parent,
// this.parentScene.instance
// );
//
// /**
// * We remember from now on that we have no parent mesh
// * @type {null}
// */
// this.parentMesh = null;
//
// /**
// * We store the world position back to the child
// */
// this.position.x = vector.x;
// this.position.y = vector.y;
// this.position.z = vector.z;
//
// /**
// * Update the instance position
// */
// this.updateInstancePosition();
//
// /**
// * Don't touch this instance parent - since it is now probably a scene object
// */
//
// /**
// * TODO: do we apply rotation somehow?
// */
//
// } else {
// throw new Error('Not enough information to detach')
// }
//
// } else {
//
// if (!this.instance) {
// throw new Error('No valid instance at time of adding to parent for mesh ' + this.name);
// }
//
// if (!(parentMesh instanceof GameLib.D3.Mesh)) {
// throw new Error('Not a valid parent mesh');
// }
//
// this.parentMesh = parentMesh;
//
// /**
// * Add this as a child to the parent
// */
// this.parentMesh.addChild(this.instance, this);
// }
//
// };
/** // GameLib.D3.Mesh.prototype.getBoundingBox = function() {
* Are we removing this child from the parent? //
*/ // this.instance.geometry.computeBoundingBox();
if (GameLib.Utils.UndefinedOrNull(parentMesh)) { //
// return new GameLib.Vector3(
if (this.instance && this.instance.parent && this.parentScene.instance) { // this.graphics,
// new GameLib.API.Vector3(
/** // this.instance.geometry.boundingBox.max.x - this.instance.geometry.boundingBox.min.x,
* Update the parent matrix world // this.instance.geometry.boundingBox.max.y - this.instance.geometry.boundingBox.min.y,
*/ // this.instance.geometry.boundingBox.max.z - this.instance.geometry.boundingBox.min.z
this.instance.parent.updateMatrixWorld(); // )
// );
/** //
* Copy the child world position into a temporary vector // };
* @type {THREE.Vector3}
*/
var vector = new THREE.Vector3();
vector.setFromMatrixPosition(this.instance.matrixWorld);
/**
* Detach child from parent within this scene
*/
THREE.SceneUtils.detach(
this.instance,
this.instance.parent,
this.parentScene.instance
);
/**
* We remember from now on that we have no parent mesh
* @type {null}
*/
this.parentMesh = null;
/**
* We store the world position back to the child
*/
this.position.x = vector.x;
this.position.y = vector.y;
this.position.z = vector.z;
/**
* Update the instance position
*/
this.updateInstancePosition();
/**
* Don't touch this instance parent - since it is now probably a scene object
*/
/**
* TODO: do we apply rotation somehow?
*/
} else {
throw new Error('Not enough information to detach')
}
} else {
if (!this.instance) {
throw new Error('No valid instance at time of adding to parent for mesh ' + this.name);
}
if (!(parentMesh instanceof GameLib.D3.Mesh)) {
throw new Error('Not a valid parent mesh');
}
this.parentMesh = parentMesh;
/**
* Add this as a child to the parent
*/
this.parentMesh.addChild(this.instance, this);
}
};
GameLib.D3.Mesh.prototype.getBoundingBox = function() {
this.instance.geometry.computeBoundingBox();
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
)
);
};
/** /**
* Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh * Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh
@ -1039,17 +1103,17 @@ GameLib.D3.Mesh.prototype.createHelper = function() {
}; };
GameLib.D3.Mesh.prototype.addMaterial = function(material) { // GameLib.D3.Mesh.prototype.addMaterial = function(material) {
if (this.materials.length === 1) { // if (this.materials.length === 1) {
this.instance.material = material.instance; // this.instance.material = material.instance;
} else { // } else {
this.instance.material = this.materials.map( // this.instance.material = this.materials.map(
function(material) { // function(material) {
return material.instance; // return material.instance;
} // }
); // );
} // }
}; // };
/** /**
* Convenience function for removing a helper for this Mesh - should be called from Systems only * Convenience function for removing a helper for this Mesh - should be called from Systems only

View File

@ -11,13 +11,16 @@ GameLib.System.Animation = function(
apiSystem apiSystem
); );
this.animations = {}; this.animations = [];
this.latest = {}; // this.textures = [];
// this.textureIds = [];
// this.latest = {};
this.textures = {}; this.textures = {};
this.textureIds = []; this.textureIds = [];
this.animationMeshAddedSubscription = null; // this.animationMeshAddedSubscription = null;
this.animationMeshRemovedSubscription = null; // this.animationMeshRemovedSubscription = null;
this.instanceCreatedSubscription = null; this.instanceCreatedSubscription = null;
this.removeComponentSubscription = null; this.removeComponentSubscription = null;
this.textureAnimatedSubscription = null; this.textureAnimatedSubscription = null;
@ -40,30 +43,31 @@ GameLib.System.Animation.prototype.start = function() {
this.beforeRender.bind(this) this.beforeRender.bind(this)
); );
var animations = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.ANIMATION); this.animations = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.ANIMATION);
animations.map(function(animation){ //
animation.meshes.map( // animations.map(function(animation){
function(mesh) { // animation.meshes.map(
this.attachAnimation(animation, mesh); // function(mesh) {
}.bind(this) // this.attachAnimation(animation, mesh);
); // }.bind(this)
this.animations[animation.id] = animation; // );
}.bind(this)); // this.animations[animation.id] = animation;
// }.bind(this));
this.animationMeshAddedSubscription = GameLib.Event.Subscribe( // this.animationMeshAddedSubscription = GameLib.Event.Subscribe(
GameLib.Event.ANIMATION_MESH_ADDED, // GameLib.Event.ANIMATION_MESH_ADDED,
function(data) { // function(data) {
this.attachAnimation(data.animation, data.mesh); // this.attachAnimation(data.animation, data.mesh);
}.bind(this) // }.bind(this)
); // );
//
this.animationMeshRemovedSubscription = GameLib.Event.Subscribe( // this.animationMeshRemovedSubscription = GameLib.Event.Subscribe(
GameLib.Event.ANIMATION_MESH_REMOVED, // GameLib.Event.ANIMATION_MESH_REMOVED,
function(data) { // function(data) {
this.detachAnimation(data.mesh); // this.detachAnimation(data.mesh);
}.bind(this) // }.bind(this)
); // );
this.instanceCreatedSubscription = GameLib.Event.Subscribe( this.instanceCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED, GameLib.Event.INSTANCE_CREATED,
@ -87,6 +91,7 @@ GameLib.System.Animation.prototype.start = function() {
}; };
GameLib.System.Animation.prototype.instanceCreated = function(data) { GameLib.System.Animation.prototype.instanceCreated = function(data) {
if ( if (
data.component instanceof GameLib.D3.Texture && data.component instanceof GameLib.D3.Texture &&
data.component.animated data.component.animated
@ -109,16 +114,20 @@ GameLib.System.Animation.prototype.instanceCreated = function(data) {
} }
if (data.component instanceof GameLib.D3.Animation) { if (data.component instanceof GameLib.D3.Animation) {
this.animations[data.component.id] = data.component;
data.component.meshes.map( GameLib.Utils.PushUnique(this.animations, data.component);
function(mesh){ //
this.attachAnimation(data.component, mesh) // this.animations[data.component.id] = data.component;
}.bind(this) // data.component.meshes.map(
); // function(mesh){
// this.attachAnimation(data.component, mesh)
// }.bind(this)
// );
} }
}; };
GameLib.System.Animation.prototype.removeComponent = function(data) { GameLib.System.Animation.prototype.removeComponent = function(data) {
if ( if (
data.component instanceof GameLib.D3.Texture && data.component instanceof GameLib.D3.Texture &&
data.component.animated data.component.animated
@ -133,13 +142,27 @@ GameLib.System.Animation.prototype.removeComponent = function(data) {
if (data.component instanceof GameLib.D3.Animation) { if (data.component instanceof GameLib.D3.Animation) {
data.component.meshes.map( var index = this.animations.indexOf(data.component);
function(mesh){
this.detachAnimation(mesh)
}.bind(this)
);
delete this.animations[data.component.id]; if (index === -1) {
console.warn('animation index out of sync');
} else {
this.animations.splice(index, 1);
}
}
if (data.component instanceof GameLib.D3.Mesh) {
this.animations.map(
function(animation) {
var index = animation.meshes.indexOf(data.component);
if (index !== -1) {
animation.meshes.splice(index, 1);
animation.updateInstance('meshes');
}
}
)
} }
}; };
@ -199,97 +222,83 @@ GameLib.System.Animation.prototype.animateTextureInstance = function(data) {
this.textureIds = Object.keys(this.textures); this.textureIds = Object.keys(this.textures);
}; };
/**
* Performs a slight change on object[property][subProperty] from instance towards object
* @param object
* @param property
* @param subProperty
* @param increment
* @returns {boolean}
*/
GameLib.System.Animation.prototype.slightChange = function(object, property, subProperty, increment) {
var current = object.instance[property][subProperty];
var target = object[property][subProperty];
if (Math.abs(target - current) < increment) {
object.instance[property][subProperty] = object[property][subProperty];
return false;
} else if (current > target) {
object.instance[property][subProperty] -= increment;
} else {
object.instance[property][subProperty] += increment;
}
return true;
};
GameLib.System.Animation.prototype.beforeRender = function(data) { GameLib.System.Animation.prototype.beforeRender = function(data) {
if (this.paused) { if (this.paused) {
return; return;
} }
var increment = 0;
var delta = data.delta; this.animations.map(
function(animation) {
animation.meshes.map(
function(mesh) {
for (var property in this.animations) { if (animation.rotationSpeed) {
if (this.animations.hasOwnProperty(property)) { /**
* Apply slight rotation to mesh
var processing = []; */
increment = animation.rotationSpeed * data.delta;
if (this.animations[property].length > 0) {
this.slightChange(mesh, 'rotation', 'x', increment);
var rotationDone = false; this.slightChange(mesh, 'rotation', 'y', increment);
var positionDone = false; this.slightChange(mesh, 'rotation', 'z', increment);
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 (animation.translationSpeed) {
/**
* Apply slight translation to mesh
*/
increment = animation.translationSpeed * data.delta;
if (this.animations[property][i].type === 'position' && !positionDone) { this.slightChange(mesh, 'position', 'x', increment);
this.slightChange(mesh, 'position', 'y', increment);
// if (this.animations[property][i].animation.blocking.position) { this.slightChange(mesh, 'position', 'z', increment);
// positionDone = true;
// }
processing.push(this.animations[property][i]);
} }
if (animation.scaleSpeed) {
/**
* Apply slight scale to mesh
*/
increment = animation.scaleSpeed * data.delta;
if (this.animations[property][i].type === 'scale' && !scaleDone) { this.slightChange(mesh, 'scale', 'x', increment);
//scaleDone = true; this.slightChange(mesh, 'scale', 'y', increment);
processing.push(this.animations[property][i]); this.slightChange(mesh, 'scale', 'z', increment);
} }
}.bind(this)
if (scaleDone && positionDone && rotationDone) { )
break; }.bind(this)
} );
}
}
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)
);
}
}
this.textureIds.map( this.textureIds.map(
function(textureId) { function(textureId) {
var texture = this.textures[textureId]; var texture = this.textures[textureId];
@ -359,6 +368,33 @@ GameLib.System.Animation.prototype.beforeRender = function(data) {
) )
}; };
/**
* Stop Animation System
*/
GameLib.System.Animation.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.beforeRenderSubscription.remove();
// this.animationMeshAddedSubscription.remove();
//
// this.animationMeshRemovedSubscription.remove();
//
this.animations = [];
this.instanceCreatedSubscription.remove();
this.removeComponentSubscription.remove();
this.textureAnimatedSubscription.remove();
this.animateTextureInstanceSubscription.remove();
};
/*
GameLib.System.Animation.prototype.detachAnimation = function(mesh) { GameLib.System.Animation.prototype.detachAnimation = function(mesh) {
var detached = false; var detached = false;
@ -546,7 +582,6 @@ GameLib.System.Animation.prototype.detachAnimation = function(mesh) {
if (this.animations[mesh.id]) { if (this.animations[mesh.id]) {
delete this.animations[mesh.id]; delete this.animations[mesh.id];
detached = true; detached = true;
} }
@ -557,13 +592,14 @@ GameLib.System.Animation.prototype.detachAnimation = function(mesh) {
} }
}; };
*/
GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) { //GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) {
/** /**
* Initialize the property with the original mesh z value * Initialize the property with the original mesh z value
*/ */
this.latest[mesh.id] = { /* this.latest[mesh.id] = {
rotation : { rotation : {
x : mesh.rotation.x, x : mesh.rotation.x,
y : mesh.rotation.y, y : mesh.rotation.y,
@ -739,7 +775,7 @@ 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 function() {
@ -1017,150 +1053,110 @@ GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) {
// this.latest[mesh.id].quaternion.axis.z = value; // this.latest[mesh.id].quaternion.axis.z = value;
// }.bind(this); // }.bind(this);
// }; // };
//
// GameLib.System.Animation.prototype.getSubProperty = function(mesh, axis, property, subProperty) {
// return function() {
// return this.latest[mesh.id][property][subProperty][axis];
// }.bind(this);
// };
GameLib.System.Animation.prototype.getSubProperty = function(mesh, axis, property, subProperty) { // GameLib.System.Animation.prototype.setSubProperty = function(mesh, animation, axis, property, subProperty) {
return function() { // return function(value) {
return this.latest[mesh.id][property][subProperty][axis]; //
}.bind(this); // var from = Number(this.latest[mesh.id][property][subProperty][axis]);
}; //
// this.latest[mesh.id][property][subProperty][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,
// axis : axis,
// from : from,
// to : value,
// animation : animation,
// mesh : mesh
// }
// );
//
// }.bind(this)
// };
GameLib.System.Animation.prototype.setSubProperty = function(mesh, animation, axis, property, subProperty) { // GameLib.System.Animation.prototype.getProperty = function(mesh, axis, property) {
return function(value) { // return function() {
// return this.latest[mesh.id][property][axis];
var from = Number(this.latest[mesh.id][property][subProperty][axis]); // }.bind(this);
// };
this.latest[mesh.id][property][subProperty][axis] = value; //
// GameLib.System.Animation.prototype.setProperty = function(mesh, animation, axis, property) {
if (property === 'position') { // return function(value) {
/** //
* Look for other position animations // var from = Number(this.latest[mesh.id][property][axis]);
* TODO:check when not super exausted //
*/ // this.latest[mesh.id][property][axis] = value;
// var positionAnimationObject = this.animations[mesh.id].reduce( //
// function(result, animationObject) { // if (property === 'position') {
// // /**
// if (animationObject.type === 'position') { // * Look for other position animations
// result = animationObject; // * TODO:check when not super exausted
// } // */
// // // var positionAnimationObject = this.animations[mesh.id].reduce(
// return result; // // function(result, animationObject) {
// }, // //
// null // // if (animationObject.type === 'position') {
// ); // // result = animationObject;
// // }
/** // //
* We found another position animation - just update the 'to' property // // return result;
*/ // // },
// if (positionAnimationObject) { // // null
// positionAnimationObject.to = value; // // );
// return; //
// } // /**
} // * We found another position animation - just update the 'to' property
// */
this.animations[mesh.id].push( // // if (positionAnimationObject) {
{ // // positionAnimationObject.to = value;
type : property, // // return;
axis : axis, // // }
from : from, // }
to : value, //
animation : animation, // this.animations[mesh.id].push(
mesh : mesh // {
} // type : property,
); // axis : axis,
// from : from,
}.bind(this) // to : value,
}; // animation : animation,
// mesh : mesh
GameLib.System.Animation.prototype.getProperty = function(mesh, axis, property) { // }
return function() { // );
return this.latest[mesh.id][property][axis]; //
}.bind(this); // }.bind(this)
}; // };
GameLib.System.Animation.prototype.setProperty = function(mesh, animation, axis, property) {
return function(value) {
var from = Number(this.latest[mesh.id][property][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,
axis : axis,
from : from,
to : value,
animation : animation,
mesh : mesh
}
);
}.bind(this)
};
/**
* Stop Animation System
*/
GameLib.System.Animation.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
this.beforeRenderSubscription.remove();
this.animationMeshAddedSubscription.remove();
this.animationMeshRemovedSubscription.remove();
Object.keys(this.animations).map(
function(animationId) {
if (
this.animations[animationId] &&
this.animations[animationId].meshes
) {
this.animations[animationId].meshes.map(
function (mesh) {
this.detachAnimation(mesh);
}.bind(this)
)
}
}.bind(this)
);
this.animations = {};
this.instanceCreatedSubscription.remove();
this.removeComponentSubscription.remove();
this.textureAnimatedSubscription.remove();
this.animateTextureInstanceSubscription.remove();
};

View File

@ -554,11 +554,13 @@ GameLib.System.Linking.prototype.arrayItemAdded = function(data) {
data.component.addRigidBody(data.item); data.component.addRigidBody(data.item);
} }
if (data.component instanceof GameLib.D3.Mesh && console.warn('todo: check if this is still necessary to add material to mesh');
data.item instanceof GameLib.D3.Material
) { // if (data.component instanceof GameLib.D3.Mesh &&
data.component.addMaterial(data.item); // data.item instanceof GameLib.D3.Material
} // ) {
// data.component.updateInstance('materials');
// }
}; };
GameLib.System.Linking.prototype.instanceCloned = function(data) { GameLib.System.Linking.prototype.instanceCloned = function(data) {