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

View File

@ -163,13 +163,13 @@ GameLib.D3.Animation.prototype.updateInstance = function(property, item) {
}
if (property === 'meshes') {
GameLib.Event.Emit(
GameLib.Event.ANIMATION_MESH_ADDED,
{
animation : this,
mesh : item
}
)
// GameLib.Event.Emit(
// GameLib.Event.ANIMATION_MESH_ADDED,
// {
// animation : this,
// mesh : item
// }
// )
}
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.Event.Emit(
@ -272,32 +259,32 @@ GameLib.D3.Animation.prototype.closeEditor = function(){
dom.parentElement.removeChild(dom);
};
GameLib.D3.Animation.prototype.addMesh = function(mesh) {
GameLib.Utils.PushUnique(this.meshes, mesh);
GameLib.Event.Emit(
GameLib.Event.ANIMATION_MESH_ADDED,
{
animation : this,
mesh : 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
}
)
};
// GameLib.D3.Animation.prototype.addMesh = function(mesh) {
//
// GameLib.Utils.PushUnique(this.meshes, mesh);
//
// GameLib.Event.Emit(
// GameLib.Event.ANIMATION_MESH_ADDED,
// {
// animation : this,
// mesh : 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
// }
// )
//
// };

View File

@ -353,6 +353,70 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
}
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.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 child
*/
GameLib.D3.Mesh.prototype.addChild = function(childInstance, child) {
if (!this.instance) {
throw new Error('mesh instance not loaded yet : ' + this.name);
}
if (GameLib.Utils.UndefinedOrNull(childInstance)) {
throw new Error('no child mesh instance');
}
if (GameLib.Utils.UndefinedOrNull(child)) {
throw new Error('no child mesh');
}
this.instance.add(childInstance);
childInstance.parent = this.instance;
child.parentMesh = this;
};
// GameLib.D3.Mesh.prototype.addChild = function(childInstance, child) {
//
// if (!this.instance) {
// throw new Error('mesh instance not loaded yet : ' + this.name);
// }
//
// if (GameLib.Utils.UndefinedOrNull(childInstance)) {
// throw new Error('no child mesh instance');
// }
//
// if (GameLib.Utils.UndefinedOrNull(child)) {
// throw new Error('no child mesh');
// }
//
// this.instance.add(childInstance);
//
// childInstance.parent = this.instance;
//
// child.parentMesh = this;
// };
/**
* Sets a parent for this mesh
* @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);
// }
//
// };
/**
* 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() {
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
)
);
};
// 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
@ -1039,17 +1103,17 @@ GameLib.D3.Mesh.prototype.createHelper = function() {
};
GameLib.D3.Mesh.prototype.addMaterial = function(material) {
if (this.materials.length === 1) {
this.instance.material = material.instance;
} else {
this.instance.material = this.materials.map(
function(material) {
return material.instance;
}
);
}
};
// GameLib.D3.Mesh.prototype.addMaterial = function(material) {
// if (this.materials.length === 1) {
// this.instance.material = material.instance;
// } else {
// this.instance.material = this.materials.map(
// function(material) {
// return material.instance;
// }
// );
// }
// };
/**
* 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
);
this.animations = {};
this.latest = {};
this.animations = [];
// this.textures = [];
// this.textureIds = [];
// this.latest = {};
this.textures = {};
this.textureIds = [];
this.animationMeshAddedSubscription = null;
this.animationMeshRemovedSubscription = null;
// this.animationMeshAddedSubscription = null;
// this.animationMeshRemovedSubscription = null;
this.instanceCreatedSubscription = null;
this.removeComponentSubscription = null;
this.textureAnimatedSubscription = null;
@ -40,30 +43,31 @@ GameLib.System.Animation.prototype.start = function() {
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(
function(mesh) {
this.attachAnimation(animation, mesh);
}.bind(this)
);
this.animations[animation.id] = animation;
}.bind(this));
//
// animations.map(function(animation){
// animation.meshes.map(
// function(mesh) {
// this.attachAnimation(animation, mesh);
// }.bind(this)
// );
// this.animations[animation.id] = animation;
// }.bind(this));
this.animationMeshAddedSubscription = GameLib.Event.Subscribe(
GameLib.Event.ANIMATION_MESH_ADDED,
function(data) {
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)
);
// this.animationMeshAddedSubscription = GameLib.Event.Subscribe(
// GameLib.Event.ANIMATION_MESH_ADDED,
// function(data) {
// 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)
// );
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED,
@ -87,6 +91,7 @@ GameLib.System.Animation.prototype.start = function() {
};
GameLib.System.Animation.prototype.instanceCreated = function(data) {
if (
data.component instanceof GameLib.D3.Texture &&
data.component.animated
@ -109,16 +114,20 @@ GameLib.System.Animation.prototype.instanceCreated = function(data) {
}
if (data.component instanceof GameLib.D3.Animation) {
this.animations[data.component.id] = data.component;
data.component.meshes.map(
function(mesh){
this.attachAnimation(data.component, mesh)
}.bind(this)
);
GameLib.Utils.PushUnique(this.animations, data.component);
//
// this.animations[data.component.id] = data.component;
// data.component.meshes.map(
// function(mesh){
// this.attachAnimation(data.component, mesh)
// }.bind(this)
// );
}
};
GameLib.System.Animation.prototype.removeComponent = function(data) {
if (
data.component instanceof GameLib.D3.Texture &&
data.component.animated
@ -133,13 +142,27 @@ GameLib.System.Animation.prototype.removeComponent = function(data) {
if (data.component instanceof GameLib.D3.Animation) {
data.component.meshes.map(
function(mesh){
this.detachAnimation(mesh)
}.bind(this)
);
var index = this.animations.indexOf(data.component);
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);
};
/**
* 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) {
if (this.paused) {
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 (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 (animation.rotationSpeed) {
/**
* Apply slight rotation to mesh
*/
increment = animation.rotationSpeed * data.delta;
this.slightChange(mesh, 'rotation', 'x', increment);
this.slightChange(mesh, 'rotation', 'y', increment);
this.slightChange(mesh, 'rotation', 'z', increment);
}
if (animation.translationSpeed) {
/**
* Apply slight translation to mesh
*/
increment = animation.translationSpeed * data.delta;
if (this.animations[property][i].type === 'position' && !positionDone) {
// if (this.animations[property][i].animation.blocking.position) {
// positionDone = true;
// }
processing.push(this.animations[property][i]);
this.slightChange(mesh, 'position', 'x', increment);
this.slightChange(mesh, 'position', 'y', increment);
this.slightChange(mesh, 'position', 'z', increment);
}
if (animation.scaleSpeed) {
/**
* Apply slight scale to mesh
*/
increment = animation.scaleSpeed * data.delta;
if (this.animations[property][i].type === 'scale' && !scaleDone) {
//scaleDone = true;
processing.push(this.animations[property][i]);
this.slightChange(mesh, 'scale', 'x', increment);
this.slightChange(mesh, 'scale', 'y', increment);
this.slightChange(mesh, 'scale', 'z', increment);
}
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)
);
}
}
}.bind(this)
)
}.bind(this)
);
this.textureIds.map(
function(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) {
var detached = false;
@ -546,7 +582,6 @@ GameLib.System.Animation.prototype.detachAnimation = function(mesh) {
if (this.animations[mesh.id]) {
delete this.animations[mesh.id];
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
*/
this.latest[mesh.id] = {
/* this.latest[mesh.id] = {
rotation : {
x : mesh.rotation.x,
y : mesh.rotation.y,
@ -739,7 +775,7 @@ GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) {
}
);
};
*/
// GameLib.System.Animation.prototype.getQuaternionAngle = function(mesh, animation) {
//
// return function() {
@ -1017,150 +1053,110 @@ GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) {
// this.latest[mesh.id].quaternion.axis.z = value;
// }.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) {
return function() {
return this.latest[mesh.id][property][subProperty][axis];
}.bind(this);
};
// GameLib.System.Animation.prototype.setSubProperty = function(mesh, animation, axis, property, subProperty) {
// return function(value) {
//
// 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) {
return function(value) {
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.getProperty = function(mesh, axis, property) {
return function() {
return this.latest[mesh.id][property][axis];
}.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();
};
// GameLib.System.Animation.prototype.getProperty = function(mesh, axis, property) {
// return function() {
// return this.latest[mesh.id][property][axis];
// }.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)
// };

View File

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