create instance updated
parent
9d82f9830c
commit
f94f74b31e
|
@ -61,66 +61,12 @@ GameLib.Utils.ObjectIdWithNameInArray = function(name, array) {
|
|||
// };
|
||||
|
||||
GameLib.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) {
|
||||
array.map(
|
||||
function(object) {
|
||||
|
||||
if (object instanceof Object) {
|
||||
|
||||
if (object.buildIdToObject) {
|
||||
object.buildIdToObject();
|
||||
var _idToObject = object.idToObject;
|
||||
|
||||
for (var property in _idToObject) {
|
||||
if (_idToObject.hasOwnProperty(property)) {
|
||||
idToObject[property] = _idToObject[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (object.id) {
|
||||
idToObject[object.id] = object;
|
||||
} else {
|
||||
console.warn('Object with no ID passed: ' + object)
|
||||
}
|
||||
|
||||
} else if (typeof object === 'string') {
|
||||
// console.warn('Linked object found:' + object);
|
||||
} else {
|
||||
console.warn('Unhandled type of object: ', object);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return idToObject;
|
||||
};
|
||||
|
||||
GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) {
|
||||
|
||||
if (object instanceof Object) {
|
||||
|
||||
if (object.buildIdToObject) {
|
||||
object.buildIdToObject();
|
||||
var _idToObject = object.idToObject;
|
||||
|
||||
for (var property in _idToObject) {
|
||||
if (_idToObject.hasOwnProperty(property)) {
|
||||
idToObject[property] = _idToObject[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (object.id) {
|
||||
idToObject[object.id] = object;
|
||||
} else {
|
||||
console.warn('Object with no ID passed: ' + object)
|
||||
}
|
||||
} else if (typeof object === 'string') {
|
||||
// console.warn('Linked object found:' + object);
|
||||
} else {
|
||||
console.warn('Unhandled type of object: ', object);
|
||||
}
|
||||
|
||||
return idToObject;
|
||||
};
|
||||
|
||||
GameLib.Utils.InterpolateArray = function(data, fitCount) {
|
||||
|
@ -301,7 +247,7 @@ GameLib.Utils.InvertMeshWindingOrder = function(mesh) {
|
|||
);
|
||||
|
||||
mesh.computeNormals = true;
|
||||
mesh.instance = mesh.createInstance(false);
|
||||
mesh.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,24 +37,27 @@ GameLib.Component = function(
|
|||
}
|
||||
);
|
||||
|
||||
// GameLib.Event.Emit(
|
||||
// GameLib.Event.COMPONENT_CREATED,
|
||||
// {
|
||||
// component : this
|
||||
// }
|
||||
// );
|
||||
|
||||
if (this.dependencies.length === 0) {
|
||||
|
||||
delete this.dependencies;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
/**
|
||||
* Build ID to object should run through all sub components -
|
||||
* if one is found which is not loaded, this component is not loaded fully
|
||||
*/
|
||||
this.buildIdToObject();
|
||||
|
||||
if (this.instance) {
|
||||
this.loaded = true;
|
||||
this.buildIdToObject();
|
||||
GameLib.Event.EmitInstanceEvents(this);
|
||||
/**
|
||||
* Don't try to create an instance of this object until it is fully loaded
|
||||
*/
|
||||
if (this.loaded) {
|
||||
try {
|
||||
this.createInstance();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.REGISTER_DEPENDENCIES,
|
||||
|
@ -72,6 +75,12 @@ GameLib.Component.prototype.constructor = GameLib.Component;
|
|||
|
||||
GameLib.Component.prototype.createInstance = function() {
|
||||
|
||||
console.log('create instance : '+ this.name);
|
||||
|
||||
if (this.instance) {
|
||||
GameLib.Event.EmitInstanceEvents(this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
GameLib.Component.prototype.getDependencies = function() {
|
||||
|
@ -188,6 +197,7 @@ GameLib.Component.COMPONENT_CONTROLS_MOUSE = 0x3a;
|
|||
GameLib.Component.COMPONENT_MESH_TEXT = 0x3b;
|
||||
GameLib.Component.COMPONENT_FONT = 0x3c;
|
||||
GameLib.Component.COMPONENT_CANVAS = 0x3d;
|
||||
GameLib.Component.COMPONENT_BONE = 0x3e;
|
||||
|
||||
/**
|
||||
* Returns string name for component number
|
||||
|
@ -258,6 +268,7 @@ GameLib.Component.GetComponentName = function(number) {
|
|||
case 0x3b : return 'GameLib.D3.Mesh.Text';
|
||||
case 0x3c : return 'GameLib.D3.Font';
|
||||
case 0x3d : return 'GameLib.D3.Canvas';
|
||||
case 0x3e : return 'GameLib.D3.Bone';
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -286,6 +297,8 @@ GameLib.Component.prototype.buildIdToObject = function() {
|
|||
|
||||
this.idToObject = {};
|
||||
|
||||
var loaded = true;
|
||||
|
||||
for (var property in this.linkedObjects) {
|
||||
if (
|
||||
this.linkedObjects.hasOwnProperty(property) &&
|
||||
|
@ -295,16 +308,107 @@ GameLib.Component.prototype.buildIdToObject = function() {
|
|||
property !== 'parentScene' &&
|
||||
property !== 'parentMesh' &&
|
||||
property !== 'parentWorld' &&
|
||||
property !== 'parentEntityManager'
|
||||
property !== 'parentEntityManager' &&
|
||||
loaded
|
||||
) {
|
||||
|
||||
if (this.linkedObjects[property] instanceof Array) {
|
||||
this.idToObject = GameLib.Utils.LoadIdsFromArrayToIdObject(this[property], this.idToObject);
|
||||
|
||||
/**
|
||||
* Remove null objects (can happen)
|
||||
*/
|
||||
this[property] = this[property].filter(
|
||||
function(object) {
|
||||
if (object === null) {
|
||||
console.log('null object found and removed');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
this[property].map(
|
||||
|
||||
function(object) {
|
||||
|
||||
if (object instanceof Object) {
|
||||
|
||||
if (object.buildIdToObject) {
|
||||
|
||||
object.buildIdToObject();
|
||||
|
||||
if (object.loaded === false) {
|
||||
loaded = false;
|
||||
/**
|
||||
* Don't continue processing
|
||||
*/
|
||||
} else {
|
||||
var _idToObject = object.idToObject;
|
||||
|
||||
for (var property in _idToObject) {
|
||||
if (_idToObject.hasOwnProperty(property)) {
|
||||
this.idToObject[property] = _idToObject[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (object.id) {
|
||||
this.idToObject[object.id] = object;
|
||||
} else {
|
||||
console.warn('Object with no ID passed: ' + object)
|
||||
}
|
||||
|
||||
} else if (typeof object === 'string') {
|
||||
loaded = false;
|
||||
} else {
|
||||
console.warn('Unhandled type of object: ', object);
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
} else {
|
||||
this.idToObject = GameLib.Utils.LoadIdsFromObjectToIdObject(this[property], this.idToObject);
|
||||
|
||||
var object = this[property];
|
||||
|
||||
if (object instanceof Object) {
|
||||
|
||||
if (object.buildIdToObject) {
|
||||
|
||||
object.buildIdToObject();
|
||||
|
||||
if (object.loaded === false) {
|
||||
loaded = false;
|
||||
} else {
|
||||
var _idToObject = object.idToObject;
|
||||
|
||||
for (var objectProperty in _idToObject) {
|
||||
if (_idToObject.hasOwnProperty(objectProperty)) {
|
||||
this.idToObject[objectProperty] = _idToObject[objectProperty];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (object.id) {
|
||||
this.idToObject[object.id] = object;
|
||||
} else {
|
||||
console.warn('Object with no ID passed: ' + object)
|
||||
}
|
||||
|
||||
} else if (typeof object === 'string') {
|
||||
|
||||
loaded = false;
|
||||
|
||||
} else {
|
||||
console.warn('Unhandled type of object: ', object);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.loaded = loaded;
|
||||
|
||||
this.idToObject[this.id] = this;
|
||||
|
||||
this.built = false;
|
||||
|
@ -324,6 +428,7 @@ GameLib.Component.prototype.generateNewIds = function() {
|
|||
this.idToObject[property].name = this.idToObject[property].name.replace(oldId,newId);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
GameLib.Component.prototype.clone = function() {
|
||||
|
|
|
@ -43,9 +43,9 @@ GameLib.Clock.prototype.constructor = GameLib.Clock;
|
|||
*/
|
||||
GameLib.Clock.prototype.createInstance = function() {
|
||||
|
||||
var instance = new THREE.Clock();
|
||||
this.instance = new THREE.Clock();
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,7 +42,7 @@ GameLib.Color = function (
|
|||
}
|
||||
this.grain = grain;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.Color.prototype = Object.create(GameLib.API.Color.prototype);
|
||||
|
@ -50,23 +50,14 @@ GameLib.Color.prototype.constructor = GameLib.Color;
|
|||
|
||||
/**
|
||||
* Creates an instance color
|
||||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.Color.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
instance.r = this.r;
|
||||
instance.g = this.g;
|
||||
instance.b = this.b;
|
||||
} else {
|
||||
instance = new THREE.Color(this.r, this.g, this.b);
|
||||
}
|
||||
|
||||
return instance;
|
||||
GameLib.Color.prototype.createInstance = function() {
|
||||
this.instance = new THREE.Color(
|
||||
this.r,
|
||||
this.g,
|
||||
this.b
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -74,7 +65,9 @@ GameLib.Color.prototype.createInstance = function(update) {
|
|||
*/
|
||||
GameLib.Color.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
this.instance.r = this.r;
|
||||
this.instance.g = this.g;
|
||||
this.instance.b = this.b;
|
||||
|
||||
if (this.parentObject &&
|
||||
this.parentObject.updateInstance) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* @param typeId
|
||||
* @param name
|
||||
* @param image
|
||||
* @param images
|
||||
* @param wrapS
|
||||
* @param wrapT
|
||||
* @param repeat
|
||||
|
@ -30,6 +31,7 @@ GameLib.D3.API.Texture = function(
|
|||
typeId,
|
||||
name,
|
||||
image,
|
||||
images,
|
||||
wrapS,
|
||||
wrapT,
|
||||
repeat,
|
||||
|
@ -75,6 +77,11 @@ GameLib.D3.API.Texture = function(
|
|||
}
|
||||
this.image = image;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(images)) {
|
||||
images = [];
|
||||
}
|
||||
this.images = images;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(wrapS)) {
|
||||
wrapS = GameLib.D3.Texture.TYPE_REPEAT_WRAPPING;
|
||||
}
|
||||
|
@ -182,6 +189,7 @@ GameLib.D3.API.Texture.FromObject = function(objectTexture) {
|
|||
objectTexture.typeId,
|
||||
objectTexture.name,
|
||||
objectTexture.image,
|
||||
objectTexture.images,
|
||||
objectTexture.wrapS,
|
||||
objectTexture.wrapT,
|
||||
GameLib.API.Vector2.FromObject(objectTexture.repeat),
|
||||
|
|
|
@ -55,7 +55,10 @@ GameLib.D3.Bone = function (
|
|||
this
|
||||
);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPONENT_BONE
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Bone.prototype = Object.create(GameLib.D3.API.Bone.prototype);
|
||||
|
@ -68,28 +71,28 @@ GameLib.D3.Bone.prototype.constructor = GameLib.D3.Bone;
|
|||
*/
|
||||
GameLib.D3.Bone.prototype.createInstance = function() {
|
||||
|
||||
var instance = new THREE.Bone();
|
||||
this.instance = new THREE.Bone();
|
||||
|
||||
instance.name = this.name;
|
||||
this.instance.name = this.name;
|
||||
|
||||
instance.position.x = this.position.x;
|
||||
instance.position.y = this.position.y;
|
||||
instance.position.z = this.position.z;
|
||||
this.instance.position.x = this.position.x;
|
||||
this.instance.position.y = this.position.y;
|
||||
this.instance.position.z = this.position.z;
|
||||
|
||||
instance.quaternion.x = this.quaternion.x;
|
||||
instance.quaternion.y = this.quaternion.y;
|
||||
instance.quaternion.z = this.quaternion.z;
|
||||
instance.quaternion.w = this.quaternion.w;
|
||||
this.instance.quaternion.x = this.quaternion.x;
|
||||
this.instance.quaternion.y = this.quaternion.y;
|
||||
this.instance.quaternion.z = this.quaternion.z;
|
||||
this.instance.quaternion.w = this.quaternion.w;
|
||||
|
||||
instance.scale.x = this.scale.x;
|
||||
instance.scale.y = this.scale.y;
|
||||
instance.scale.z = this.scale.z;
|
||||
this.instance.scale.x = this.scale.x;
|
||||
this.instance.scale.y = this.scale.y;
|
||||
this.instance.scale.z = this.scale.z;
|
||||
|
||||
instance.up.x = this.up.x;
|
||||
instance.up.y = this.up.y;
|
||||
instance.up.z = this.up.z;
|
||||
|
||||
return instance;
|
||||
this.instance.up.x = this.up.x;
|
||||
this.instance.up.y = this.up.y;
|
||||
this.instance.up.z = this.up.z;
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,20 +43,18 @@ GameLib.D3.Broadphase.prototype.constructor = GameLib.D3.Broadphase;
|
|||
*/
|
||||
GameLib.D3.Broadphase.prototype.createInstance = function() {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.broadphaseType === GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE) {
|
||||
instance = new CANNON.NaiveBroadphase();
|
||||
this.instance = new CANNON.NaiveBroadphase();
|
||||
} else if (this.broadphaseType === GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID) {
|
||||
instance = new CANNON.GridBroadphase();
|
||||
this.instance = new CANNON.GridBroadphase();
|
||||
} else if (this.broadphaseType === GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP) {
|
||||
instance = new CANNON.SAPBroadphase();
|
||||
this.instance = new CANNON.SAPBroadphase();
|
||||
} else {
|
||||
console.warn('Unsupported broadphase type: ' + this.broadphaseType);
|
||||
throw new Error('Unsupported broadphase type: ' + this.broadphaseType);
|
||||
}
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -66,19 +64,19 @@ GameLib.D3.Broadphase.prototype.updateInstance = function() {
|
|||
|
||||
if (this.broadphaseType === GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE) {
|
||||
if (!(this.instance instanceof CANNON.NaiveBroadphase)) {
|
||||
this.instance = new CANNON.NaiveBroadphase();
|
||||
this.createInstance();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.broadphaseType === GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID) {
|
||||
if (!(this.instance instanceof CANNON.GridBroadphase)) {
|
||||
this.instance = new CANNON.GridBroadphase();
|
||||
this.createInstance();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.broadphaseType === GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP) {
|
||||
if (!(this.instance instanceof CANNON.SAPBroadphase)) {
|
||||
this.instance = new CANNON.SAPBroadphase();
|
||||
this.createInstance();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -83,7 +83,6 @@ GameLib.D3.Camera = function(
|
|||
GameLib.Component.COMPONENT_CAMERA
|
||||
);
|
||||
|
||||
//this.needsUpdate = false;
|
||||
} ;
|
||||
|
||||
GameLib.D3.Camera.prototype = Object.create(GameLib.D3.API.Camera.prototype);
|
||||
|
@ -99,17 +98,15 @@ GameLib.D3.Camera.CAMERA_TYPE_STEREO = 0x3;
|
|||
*/
|
||||
GameLib.D3.Camera.prototype.createInstance = function() {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE ) {
|
||||
instance = new THREE.PerspectiveCamera(
|
||||
this.instance = new THREE.PerspectiveCamera(
|
||||
this.fov,
|
||||
this.aspect,
|
||||
this.near,
|
||||
this.far
|
||||
);
|
||||
} else if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
|
||||
instance = new THREE.OrthographicCamera(
|
||||
this.instance = new THREE.OrthographicCamera(
|
||||
this.minX + this.offsetX,
|
||||
this.maxX + this.offsetX,
|
||||
this.maxY,
|
||||
|
@ -118,28 +115,25 @@ GameLib.D3.Camera.prototype.createInstance = function() {
|
|||
this.maxZ
|
||||
);
|
||||
} else if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_STEREO) {
|
||||
instance = new THREE.StereoCamera();
|
||||
this.instance = new THREE.StereoCamera();
|
||||
} else {
|
||||
throw new Error('unsupported camera type : ' + this.cameraType);
|
||||
}
|
||||
|
||||
if (!instance) {
|
||||
console.log('Unsupported camera type : ' + this.cameraType);
|
||||
throw new Error('Unsupported camera type : ' + this.cameraType);
|
||||
}
|
||||
this.instance.position.x = this.position.x;
|
||||
this.instance.position.y = this.position.y;
|
||||
this.instance.position.z = this.position.z;
|
||||
|
||||
instance.position.x = this.position.x;
|
||||
instance.position.y = this.position.y;
|
||||
instance.position.z = this.position.z;
|
||||
this.instance.quaternion.x = this.quaternion.x;
|
||||
this.instance.quaternion.y = this.quaternion.y;
|
||||
this.instance.quaternion.z = this.quaternion.z;
|
||||
this.instance.quaternion.w = this.quaternion.w;
|
||||
|
||||
instance.quaternion.x = this.quaternion.x;
|
||||
instance.quaternion.y = this.quaternion.y;
|
||||
instance.quaternion.z = this.quaternion.z;
|
||||
instance.quaternion.w = this.quaternion.w;
|
||||
this.instance.lookAt(this.lookAt.instance);
|
||||
|
||||
instance.lookAt(this.lookAt.instance);
|
||||
this.instance.updateProjectionMatrix();
|
||||
|
||||
instance.updateProjectionMatrix();
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -151,16 +145,14 @@ GameLib.D3.Camera.prototype.updateInstance = function() {
|
|||
this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL &&
|
||||
this.instance instanceof THREE.PerspectiveCamera
|
||||
) {
|
||||
this.instance = this.createInstance();
|
||||
return;
|
||||
this.createInstance();
|
||||
}
|
||||
|
||||
if (
|
||||
this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE &&
|
||||
this.instance instanceof THREE.OrthographicCamera
|
||||
) {
|
||||
this.instance = this.createInstance();
|
||||
return;
|
||||
this.createInstance();
|
||||
}
|
||||
|
||||
if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
|
||||
|
|
|
@ -43,12 +43,12 @@ GameLib.D3.Canvas.prototype.constructor = GameLib.D3.Canvas;
|
|||
*/
|
||||
GameLib.D3.Canvas.prototype.createInstance = function() {
|
||||
|
||||
var instance = document.createElement('canvas');
|
||||
this.instance = document.createElement('canvas');
|
||||
|
||||
instance.width = this.width;
|
||||
instance.height = this.height;
|
||||
this.instance.width = this.width;
|
||||
this.instance.height = this.height;
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -57,8 +57,7 @@ GameLib.D3.Canvas.prototype.createInstance = function() {
|
|||
GameLib.D3.Canvas.prototype.updateInstance = function() {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||
this.instance = document.createElement('canvas');
|
||||
this.loaded = true;
|
||||
this.createInstance();
|
||||
}
|
||||
|
||||
this.instance.width = this.width;
|
||||
|
|
|
@ -25,7 +25,7 @@ GameLib.D3.Coder = function Coder(
|
|||
}
|
||||
this.coderType = coderType;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -38,17 +38,13 @@ GameLib.D3.Coder.CODER_TYPE_CODE_MIRROR = 0x1;
|
|||
* @returns {THREE.Coder}
|
||||
*/
|
||||
GameLib.D3.Coder.prototype.createInstance = function() {
|
||||
|
||||
var instance = CodeMirror;
|
||||
|
||||
return instance;
|
||||
this.instance = CodeMirror;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.D3.Coder.prototype.updateInstance = function() {
|
||||
this.instance = CodeMirror;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,15 +46,9 @@ GameLib.D3.Composer.prototype.constructor = GameLib.D3.Composer;
|
|||
|
||||
/**
|
||||
* Creates a Composer instance
|
||||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Composer.prototype.createInstance = function(update) {
|
||||
|
||||
if (!this.loaded) {
|
||||
console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name);
|
||||
return null;
|
||||
}
|
||||
GameLib.D3.Composer.prototype.createInstance = function() {
|
||||
|
||||
//TODO : Fix this too - make it nice (no circular references)
|
||||
// var instance = null;
|
||||
|
@ -83,15 +77,18 @@ GameLib.D3.Composer.prototype.createInstance = function(update) {
|
|||
// }.bind(this)
|
||||
// );
|
||||
// }
|
||||
console.log('GameLib.D3.Composer.prototype.createInstance() - fix me');
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
|
||||
//return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates Composer instance
|
||||
*/
|
||||
GameLib.D3.Composer.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
console.log('GameLib.D3.Composer.prototype.updateInstance() - fix me');
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -77,7 +77,7 @@ GameLib.D3.Controls.CONTROLS_TYPE_MOUSE = 0x3;
|
|||
* Creates a mesh instance or updates it
|
||||
*/
|
||||
GameLib.D3.Controls.prototype.createInstance = function() {
|
||||
console.log('default controls create instance');
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,7 +59,8 @@ GameLib.D3.Controls.Editor.prototype.constructor = GameLib.D3.Controls.Editor;
|
|||
* @returns {THREE.EditorControls}
|
||||
*/
|
||||
GameLib.D3.Controls.Editor.prototype.createInstance = function() {
|
||||
console.log('delaying controls instance creation - call GameLib.D3.Controls.Editor.delayInstance() to create the instance');
|
||||
console.log('delaying controls instance creation - call GameLib.D3.Controls.Editor.delayedInstance() to create the instance');
|
||||
GameLib.D3.Controls.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
GameLib.D3.Controls.Editor.prototype.delayedInstance = function() {
|
||||
|
@ -74,12 +75,10 @@ GameLib.D3.Controls.Editor.prototype.delayedInstance = function() {
|
|||
throw new Error('No dom element at time of instance');
|
||||
}
|
||||
|
||||
var instance = new THREE.EditorControls(
|
||||
this.instance = new THREE.EditorControls(
|
||||
this.camera.instance,
|
||||
this.domElement.instance
|
||||
);
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -89,12 +88,12 @@ GameLib.D3.Controls.Editor.prototype.updateInstance = function() {
|
|||
|
||||
console.warn('an update instance was called on editor controls - which, if not called from within a running system at the right time will affect the order of input event handling and cause system instability');
|
||||
|
||||
if (this.instance) {
|
||||
this.instance.dispose();
|
||||
delete this.instance;
|
||||
}
|
||||
|
||||
this.instance = this.delayedInstance();
|
||||
// if (this.instance) {
|
||||
// this.instance.dispose();
|
||||
// delete this.instance;
|
||||
// }
|
||||
//
|
||||
// this.delayedInstance();
|
||||
|
||||
GameLib.D3.Controls.prototype.updateInstance.call(this);
|
||||
};
|
||||
|
|
|
@ -32,9 +32,10 @@ GameLib.D3.Controls.Keyboard.prototype.constructor = GameLib.D3.Controls.Keyboar
|
|||
*/
|
||||
GameLib.D3.Controls.Keyboard.prototype.createInstance = function() {
|
||||
/**
|
||||
* Return true to indicate no dependencies to other components
|
||||
* Set instance to true to indicate no dependencies to other components
|
||||
*/
|
||||
return true;
|
||||
this.instance = true;
|
||||
GameLib.D3.Controls.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,9 +32,10 @@ GameLib.D3.Controls.Mouse.prototype.constructor = GameLib.D3.Controls.Mouse;
|
|||
*/
|
||||
GameLib.D3.Controls.Mouse.prototype.createInstance = function() {
|
||||
/**
|
||||
* Return true to indicate no dependencies to other components
|
||||
* Set instance to true to indicate no dependencies to other components
|
||||
*/
|
||||
return true;
|
||||
this.instance = true;
|
||||
GameLib.D3.Controls.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Touch Controls
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param apiControls GameLib.D3.API.Controls
|
||||
* @param sensitivity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Controls.Touch = function (
|
||||
|
@ -38,9 +39,10 @@ GameLib.D3.Controls.Touch.prototype.constructor = GameLib.D3.Controls.Touch;
|
|||
*/
|
||||
GameLib.D3.Controls.Touch.prototype.createInstance = function() {
|
||||
/**
|
||||
* Return true to indicate no dependencies to other components
|
||||
* Set instance to true to indicate no dependencies to other components
|
||||
*/
|
||||
return true;
|
||||
this.instance = true;
|
||||
GameLib.D3.Controls.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,23 +36,26 @@ GameLib.D3.CustomCode.prototype = Object.create(GameLib.D3.API.CustomCode.protot
|
|||
GameLib.D3.CustomCode.prototype.constructor = GameLib.D3.CustomCode;
|
||||
|
||||
GameLib.D3.CustomCode.prototype.createInstance = function() {
|
||||
|
||||
try {
|
||||
var instance = new Function('data', this.code).bind(this);
|
||||
return instance;
|
||||
this.instance = new Function('data', this.code).bind(this);
|
||||
} catch (error) {
|
||||
/**
|
||||
* Return true here to indicate that even though the compilation failed, the instance will be fine and
|
||||
* Set the instance to true here to indicate that even though the compilation failed, the instance will be fine and
|
||||
* this component loaded fine.
|
||||
*/
|
||||
return true;
|
||||
this.instance = new Function('data', "console.log('compilation failed for : " + this.name + "');").bind(this);
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.D3.CustomCode.prototype.updateInstance = function() {
|
||||
try {
|
||||
|
||||
try {
|
||||
this.instance = new Function('data', this.code).bind(this);
|
||||
this.publish(
|
||||
GameLib.Event.COMPILE_SUCCESS,
|
||||
|
@ -61,6 +64,7 @@ GameLib.D3.CustomCode.prototype.updateInstance = function() {
|
|||
}
|
||||
)
|
||||
} catch (error) {
|
||||
this.instance = new Function('data', "console.log('compilation update failed for : " + this.name + "');").bind(this);
|
||||
this.publish(
|
||||
GameLib.Event.COMPILE_FAILED,
|
||||
{
|
||||
|
@ -68,6 +72,7 @@ GameLib.D3.CustomCode.prototype.updateInstance = function() {
|
|||
}
|
||||
)
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,13 +49,16 @@ GameLib.D3.Font.prototype.createInstance = function() {
|
|||
}
|
||||
);
|
||||
|
||||
return null;
|
||||
this.instance = null;
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.D3.Font.prototype.updateInstance = function() {
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.LOAD_FONT,
|
||||
{
|
||||
|
|
|
@ -52,7 +52,7 @@ GameLib.D3.FrictionContactMaterial.prototype.constructor = GameLib.D3.FrictionCo
|
|||
*/
|
||||
GameLib.D3.FrictionContactMaterial.prototype.createInstance = function() {
|
||||
|
||||
var instance = new CANNON.ContactMaterial(
|
||||
this.instance = new CANNON.ContactMaterial(
|
||||
null,
|
||||
null,
|
||||
{
|
||||
|
@ -62,13 +62,13 @@ GameLib.D3.FrictionContactMaterial.prototype.createInstance = function() {
|
|||
}
|
||||
);
|
||||
|
||||
instance.materials = this.materials.map(
|
||||
this.instance.materials = this.materials.map(
|
||||
function(material){
|
||||
return material.instance;
|
||||
}
|
||||
);
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,18 +39,18 @@ GameLib.D3.FrictionMaterial.prototype = Object.create(GameLib.D3.API.FrictionMat
|
|||
GameLib.D3.FrictionMaterial.prototype.constructor = GameLib.D3.FrictionMaterial;
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {*}
|
||||
* create instance
|
||||
*/
|
||||
GameLib.D3.FrictionMaterial.prototype.createInstance = function() {
|
||||
|
||||
var instance = new CANNON.Material(this.name);
|
||||
this.instance = new CANNON.Material(
|
||||
this.name
|
||||
);
|
||||
|
||||
instance.friction = this.friction;
|
||||
this.instance.friction = this.friction;
|
||||
this.instance.restitution = this.restitution;
|
||||
|
||||
instance.restitution = this.restitution;
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,7 @@ GameLib.D3.Graphics = function Graphics(
|
|||
}
|
||||
this.graphicsType = graphicsType;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -38,8 +38,7 @@ GameLib.D3.Graphics.GRAPHICS_TYPE_THREE = 0x1;
|
|||
* @returns {THREE.Graphics}
|
||||
*/
|
||||
GameLib.D3.Graphics.prototype.createInstance = function() {
|
||||
var instance = THREE;
|
||||
return instance;
|
||||
this.instance = THREE;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,11 +71,13 @@ GameLib.D3.Helper = function(
|
|||
}
|
||||
this.parentEntity = parentEntity;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
|
||||
// GameLib.Component.call(
|
||||
// this,
|
||||
// GameLib.Component.COMPONENT_HELPER
|
||||
this.createInstance();
|
||||
/**
|
||||
* A helper as a component - does this make sense at all?
|
||||
*/
|
||||
// GameLib.Component.call(
|
||||
// this,
|
||||
// GameLib.Component.COMPONENT_HELPER
|
||||
// );
|
||||
};
|
||||
|
||||
|
@ -99,41 +101,47 @@ GameLib.D3.Helper.HELPER_TYPE_SKELETON = 0x6;
|
|||
*/
|
||||
GameLib.D3.Helper.prototype.createInstance = function() {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_EDGES) {
|
||||
var edges = new THREE.EdgesGeometry(this.object.instance.geometry);
|
||||
instance = new THREE.LineSegments(edges, new THREE.LineBasicMaterial({color:0x00ff00, linewidth:2}))
|
||||
this.instance = new THREE.LineSegments(
|
||||
new THREE.EdgesGeometry(
|
||||
this.object.instance.geometry
|
||||
),
|
||||
new THREE.LineBasicMaterial(
|
||||
{
|
||||
color:0x00ff00,
|
||||
linewidth:2
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT) {
|
||||
instance = new THREE.DirectionalLightHelper(this.object.instance);
|
||||
this.instance = new THREE.DirectionalLightHelper(this.object.instance);
|
||||
}
|
||||
|
||||
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT) {
|
||||
instance = new THREE.PointLightHelper(this.object.instance, 1);
|
||||
this.instance = new THREE.PointLightHelper(this.object.instance, 1);
|
||||
}
|
||||
|
||||
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT) {
|
||||
instance = new THREE.SpotLightHelper(this.object.instance);
|
||||
this.instance = new THREE.SpotLightHelper(this.object.instance);
|
||||
}
|
||||
|
||||
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_WIREFRAME) {
|
||||
instance = new THREE.WireframeGeometry(this.object.instance, 0x00FF00);
|
||||
this.instance = new THREE.WireframeGeometry(this.object.instance, 0x00FF00);
|
||||
}
|
||||
|
||||
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_SKELETON) {
|
||||
instance = new THREE.SkeletonHelper(this.object.instance);
|
||||
this.instance = new THREE.SkeletonHelper(this.object.instance);
|
||||
}
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.D3.Helper.prototype.updateInstance = function() {
|
||||
this.instance.position.copy(this.object.instance.position);
|
||||
this.instance.position.copy(this.object.instance.position);
|
||||
|
||||
if (this.object.instance.parentMesh && this.object.instance.parentMesh.instance) {
|
||||
this.instance.position.add(this.object.instance.parentMesh.instance.position);
|
||||
|
|
|
@ -47,16 +47,36 @@ GameLib.D3.Image.prototype.constructor = GameLib.D3.Image;
|
|||
*/
|
||||
GameLib.D3.Image.prototype.createInstance = function() {
|
||||
|
||||
console.log('image create instance');
|
||||
this.instance = document.createElement('img');
|
||||
|
||||
return null;
|
||||
this.instance.onload = function() {
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.IMAGE_INSTANCE_CREATED,
|
||||
{
|
||||
image: this
|
||||
}
|
||||
);
|
||||
|
||||
}.bind(this);
|
||||
|
||||
this.instance.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QoWEQMQBXD4hQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAABRSURBVGje7c8xDQAwCAAwmA3koA/PU8FB0jpo1nRc9uI4AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBgX0fjEoBa8xN1z4AAAAASUVORK5CYII=';
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.LOAD_IMAGE,
|
||||
{
|
||||
image : this
|
||||
}
|
||||
);
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.D3.Image.prototype.updateInstance = function() {
|
||||
console.log('update image instance');
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -103,13 +103,11 @@ GameLib.D3.Light.LIGHT_TYPE_SPOT = 0x4;
|
|||
*/
|
||||
GameLib.D3.Light.prototype.createInstance = function() {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (
|
||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_AMBIENT ||
|
||||
this.lightType === 'AmbientLight'
|
||||
) {
|
||||
instance = new THREE.AmbientLight(
|
||||
this.instance = new THREE.AmbientLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
);
|
||||
|
@ -117,7 +115,7 @@ GameLib.D3.Light.prototype.createInstance = function() {
|
|||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL ||
|
||||
this.lightType === 'DirectionalLight'
|
||||
) {
|
||||
instance = new THREE.DirectionalLight(
|
||||
this.instance = new THREE.DirectionalLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
);
|
||||
|
@ -125,110 +123,16 @@ GameLib.D3.Light.prototype.createInstance = function() {
|
|||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT ||
|
||||
this.lightType === 'PointLight'
|
||||
) {
|
||||
instance = new THREE.PointLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
);
|
||||
instance.distance = this.distance;
|
||||
instance.decay = this.decay;
|
||||
} else if (
|
||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT ||
|
||||
this.lightType === 'SpotLight'
|
||||
) {
|
||||
instance = new THREE.SpotLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
);
|
||||
instance.distance = this.distance;
|
||||
instance.angle = this.angle;
|
||||
instance.penumbra = this.penumbra;
|
||||
instance.decay = this.decay;
|
||||
} else {
|
||||
console.warn('unsupported light type: ' + this.lightType);
|
||||
return null;
|
||||
}
|
||||
|
||||
instance.name = this.name;
|
||||
|
||||
instance.position.x = this.position.x;
|
||||
instance.position.y = this.position.y;
|
||||
instance.position.z = this.position.z;
|
||||
|
||||
instance.scale.x = this.scale.x;
|
||||
instance.scale.y = this.scale.y;
|
||||
instance.scale.z = this.scale.z;
|
||||
|
||||
if (instance.target) {
|
||||
instance.target.position.x = this.targetPosition.x;
|
||||
instance.target.position.y = this.targetPosition.y;
|
||||
instance.target.position.z = this.targetPosition.z;
|
||||
}
|
||||
|
||||
instance.quaternion.x = this.quaternion.x;
|
||||
instance.quaternion.y = this.quaternion.y;
|
||||
instance.quaternion.z = this.quaternion.z;
|
||||
instance.quaternion.w = this.quaternion.w;
|
||||
|
||||
instance.intensity = this.intensity;
|
||||
|
||||
instance.color.set(this.color.toHex());
|
||||
|
||||
return instance;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.D3.Light.prototype.updateInstance = function() {
|
||||
var oldInstance = null;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||
console.warn('cannot update an non-existent light');
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_AMBIENT &&
|
||||
!(this.instance instanceof THREE.AmbientLight)
|
||||
) {
|
||||
oldInstance = this.instance;
|
||||
|
||||
this.instance = new THREE.AmbientLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
);
|
||||
|
||||
} else if (
|
||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL &&
|
||||
!(this.instance instanceof THREE.DirectionalLight)
|
||||
) {
|
||||
oldInstance = this.instance;
|
||||
|
||||
this.instance = new THREE.DirectionalLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
);
|
||||
|
||||
} else if (
|
||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT &&
|
||||
!(this.instance instanceof THREE.PointLight)
|
||||
) {
|
||||
oldInstance = this.instance;
|
||||
|
||||
this.instance = new THREE.PointLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
);
|
||||
this.instance.distance = this.distance;
|
||||
this.instance.decay = this.decay;
|
||||
|
||||
} else if (
|
||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT &&
|
||||
!(this.instance instanceof THREE.SpotLight)
|
||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT ||
|
||||
this.lightType === 'SpotLight'
|
||||
) {
|
||||
oldInstance = this.instance;
|
||||
|
||||
this.instance = new THREE.SpotLight(
|
||||
this.color.instance,
|
||||
this.intensity
|
||||
|
@ -237,16 +141,87 @@ GameLib.D3.Light.prototype.updateInstance = function() {
|
|||
this.instance.angle = this.angle;
|
||||
this.instance.penumbra = this.penumbra;
|
||||
this.instance.decay = this.decay;
|
||||
|
||||
} else {
|
||||
/**
|
||||
* Light type not supported or light types match
|
||||
*/
|
||||
console.warn('unsupported light type: ' + this.lightType);
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldInstance && this.parentScene) {
|
||||
this.parentScene.instance.remove(oldInstance);
|
||||
this.parentScene.instance.add(this.instance);
|
||||
this.instance.name = this.name;
|
||||
|
||||
this.instance.position.x = this.position.x;
|
||||
this.instance.position.y = this.position.y;
|
||||
this.instance.position.z = this.position.z;
|
||||
|
||||
this.instance.scale.x = this.scale.x;
|
||||
this.instance.scale.y = this.scale.y;
|
||||
this.instance.scale.z = this.scale.z;
|
||||
|
||||
if (this.instance.target) {
|
||||
this.instance.target.position.x = this.targetPosition.x;
|
||||
this.instance.target.position.y = this.targetPosition.y;
|
||||
this.instance.target.position.z = this.targetPosition.z;
|
||||
}
|
||||
|
||||
this.instance.quaternion.x = this.quaternion.x;
|
||||
this.instance.quaternion.y = this.quaternion.y;
|
||||
this.instance.quaternion.z = this.quaternion.z;
|
||||
this.instance.quaternion.w = this.quaternion.w;
|
||||
|
||||
this.instance.intensity = this.intensity;
|
||||
|
||||
this.instance.color.set(this.color.toHex());
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.D3.Light.prototype.updateInstance = function() {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||
console.warn('cannot update an non-existent light');
|
||||
return
|
||||
}
|
||||
|
||||
var lightTypeChange = false;
|
||||
|
||||
if (
|
||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_AMBIENT &&
|
||||
!(this.instance instanceof THREE.AmbientLight)
|
||||
) {
|
||||
|
||||
lightTypeChange = true;
|
||||
|
||||
} else if (
|
||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL &&
|
||||
!(this.instance instanceof THREE.DirectionalLight)
|
||||
) {
|
||||
|
||||
lightTypeChange = true;
|
||||
|
||||
} else if (
|
||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT &&
|
||||
!(this.instance instanceof THREE.PointLight)
|
||||
) {
|
||||
|
||||
lightTypeChange = true;
|
||||
|
||||
} else if (
|
||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT &&
|
||||
!(this.instance instanceof THREE.SpotLight)
|
||||
) {
|
||||
lightTypeChange = true;
|
||||
}
|
||||
|
||||
if (lightTypeChange) {
|
||||
try {
|
||||
this.parentScene.instance.remove(this.instance);
|
||||
this.createInstance();
|
||||
this.parentScene.instance.add(this.instance);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
this.instance.name = this.name;
|
||||
|
|
|
@ -74,10 +74,17 @@ GameLib.D3.LookAt.prototype = Object.create(GameLib.D3.API.LookAt.prototype);
|
|||
GameLib.D3.LookAt.prototype.constructor = GameLib.D3.LookAt;
|
||||
|
||||
GameLib.D3.LookAt.prototype.createInstance = function() {
|
||||
console.log('GameLib.D3.LookAt.prototype.createInstance()');
|
||||
return true;
|
||||
this.instance = true;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
GameLib.D3.LookAt.prototype.updateInstance = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* to API object
|
||||
* @returns {GameLib.D3.API.LookAt}
|
||||
*/
|
||||
GameLib.D3.LookAt.prototype.toApiObject = function() {
|
||||
|
||||
var apiLookAt = new GameLib.D3.API.LookAt(
|
||||
|
|
|
@ -831,41 +831,35 @@ GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance = function() {
|
|||
*/
|
||||
GameLib.D3.Material.prototype.createInstance = function() {
|
||||
|
||||
// console.log('material create instance');
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_STANDARD) {
|
||||
|
||||
instance = this.createStandardMaterialInstance();
|
||||
this.instance = this.createStandardMaterialInstance();
|
||||
|
||||
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_POINTS) {
|
||||
|
||||
instance = this.createPointsMaterialInstance();
|
||||
this.instance = this.createPointsMaterialInstance();
|
||||
|
||||
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_PHONG) {
|
||||
|
||||
instance = this.createPhongMaterialInstance();
|
||||
this.instance = this.createPhongMaterialInstance();
|
||||
|
||||
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_BASIC) {
|
||||
|
||||
instance = this.createMeshBasicMaterialInstance();
|
||||
this.instance = this.createMeshBasicMaterialInstance();
|
||||
|
||||
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC) {
|
||||
|
||||
instance = this.createLineBasicMaterialInstance();
|
||||
this.instance = this.createLineBasicMaterialInstance();
|
||||
|
||||
} else {
|
||||
console.warn("material type is not implemented yet: " + this.materialType);
|
||||
}
|
||||
|
||||
instance.needsUpdate = true;
|
||||
|
||||
this.instance = instance;
|
||||
this.instance.needsUpdate = true;
|
||||
|
||||
this.updateTextures();
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -884,35 +878,35 @@ GameLib.D3.Material.prototype.updateInstance = function() {
|
|||
|
||||
if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_STANDARD) {
|
||||
if (!(this.instance instanceof THREE.MeshStandardMaterial)) {
|
||||
this.instance = this.createStandardMaterialInstance();
|
||||
this.createInstance();
|
||||
typeChange = true;
|
||||
} else {
|
||||
this.updateStandardMaterialInstance();
|
||||
}
|
||||
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_POINTS) {
|
||||
if (!(this.instance instanceof THREE.PointsMaterial)) {
|
||||
this.instance = this.createPointsMaterialInstance();
|
||||
this.createInstance();
|
||||
typeChange = true;
|
||||
} else {
|
||||
this.updatePointsMaterialInstance();
|
||||
}
|
||||
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_PHONG) {
|
||||
if (!(this.instance instanceof THREE.MeshPhongMaterial)) {
|
||||
this.instance = this.createPhongMaterialInstance();
|
||||
this.createInstance();
|
||||
typeChange = true;
|
||||
} else {
|
||||
this.updatePhongMaterialInstance();
|
||||
}
|
||||
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_BASIC) {
|
||||
if (!(this.instance instanceof THREE.MeshBasicMaterial)) {
|
||||
this.instance = this.createMeshBasicMaterialInstance();
|
||||
this.createInstance();
|
||||
typeChange = true;
|
||||
} else {
|
||||
this.updateMeshBasicMaterialInstance();
|
||||
}
|
||||
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC) {
|
||||
if (!(this.instance instanceof THREE.LineBasicMaterial)) {
|
||||
this.instance = this.createLineBasicMaterialInstance();
|
||||
this.createInstance();
|
||||
typeChange = true;
|
||||
} else {
|
||||
this.updateLineBasicMaterialInstance();
|
||||
|
|
|
@ -440,17 +440,15 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
|||
|
||||
var geometry = this.createInstanceGeometry();
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.skeleton) {
|
||||
|
||||
if (this.materials.length === 1) {
|
||||
instance = new THREE.SkinnedMesh(
|
||||
this.instance = new THREE.SkinnedMesh(
|
||||
geometry,
|
||||
this.materials[0].instance
|
||||
)
|
||||
} else {
|
||||
instance = new THREE.SkinnedMesh(
|
||||
this.instance = new THREE.SkinnedMesh(
|
||||
geometry,
|
||||
this.materials.map(
|
||||
function(material) {
|
||||
|
@ -460,16 +458,17 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
|||
)
|
||||
}
|
||||
|
||||
instance.add(this.skeleton.rootBoneInstance);
|
||||
instance.bind(this.skeleton.instance);
|
||||
this.instance.add(this.skeleton.rootBoneInstance);
|
||||
this.instance.bind(this.skeleton.instance);
|
||||
|
||||
} else {
|
||||
if (this.materials.length === 1) {
|
||||
instance = new THREE.Mesh(
|
||||
this.instance = new THREE.Mesh(
|
||||
geometry,
|
||||
this.materials[0].instance
|
||||
)
|
||||
} else {
|
||||
instance = new THREE.Mesh(
|
||||
this.instance = new THREE.Mesh(
|
||||
geometry,
|
||||
this.materials.map(
|
||||
function(material) {
|
||||
|
@ -480,22 +479,22 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
|||
}
|
||||
}
|
||||
|
||||
instance.name = this.name;
|
||||
this.instance.name = this.name;
|
||||
|
||||
if (this.parentMesh && this.parentMesh.loaded) {
|
||||
this.parentMesh.add(instance, this);
|
||||
this.parentMesh.add(this.instance, this);
|
||||
}
|
||||
|
||||
instance.position.x = this.position.x;
|
||||
instance.position.y = this.position.y;
|
||||
instance.position.z = this.position.z;
|
||||
this.instance.position.x = this.position.x;
|
||||
this.instance.position.y = this.position.y;
|
||||
this.instance.position.z = this.position.z;
|
||||
|
||||
if (this.useQuaternion) {
|
||||
instance.quaternion.x = this.quaternion.x;
|
||||
instance.quaternion.y = this.quaternion.y;
|
||||
instance.quaternion.z = this.quaternion.z;
|
||||
instance.quaternion.w = this.quaternion.w;
|
||||
instance.quaternion.setFromAxisAngle(
|
||||
this.instance.quaternion.x = this.quaternion.x;
|
||||
this.instance.quaternion.y = this.quaternion.y;
|
||||
this.instance.quaternion.z = this.quaternion.z;
|
||||
this.instance.quaternion.w = this.quaternion.w;
|
||||
this.instance.quaternion.setFromAxisAngle(
|
||||
new THREE.Vector3(
|
||||
this.quaternion.axis.x,
|
||||
this.quaternion.axis.y,
|
||||
|
@ -504,22 +503,22 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
|||
this.quaternion.angle
|
||||
);
|
||||
} else {
|
||||
instance.rotation.x = this.rotation.x;
|
||||
instance.rotation.y = this.rotation.y;
|
||||
instance.rotation.z = this.rotation.z;
|
||||
this.instance.rotation.x = this.rotation.x;
|
||||
this.instance.rotation.y = this.rotation.y;
|
||||
this.instance.rotation.z = this.rotation.z;
|
||||
}
|
||||
|
||||
instance.scale.x = this.scale.x;
|
||||
instance.scale.y = this.scale.y;
|
||||
instance.scale.z = this.scale.z;
|
||||
this.instance.scale.x = this.scale.x;
|
||||
this.instance.scale.y = this.scale.y;
|
||||
this.instance.scale.z = this.scale.z;
|
||||
|
||||
instance.up.x = this.up.x;
|
||||
instance.up.y = this.up.y;
|
||||
instance.up.z = this.up.z;
|
||||
this.instance.up.x = this.up.x;
|
||||
this.instance.up.y = this.up.y;
|
||||
this.instance.up.z = this.up.z;
|
||||
|
||||
instance.renderOrder = this.renderOrder;
|
||||
this.instance.renderOrder = this.renderOrder;
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1297,7 +1296,16 @@ GameLib.D3.Mesh.prototype.getChildrenComponents = function() {
|
|||
typeof material[property][tProperty] !== 'string' &&
|
||||
tProperty !== 'parentEntity'
|
||||
) {
|
||||
GameLib.Utils.PushUnique(components, material[property][tProperty]);
|
||||
|
||||
if (material[property][tProperty] instanceof Array) {
|
||||
material[property][tProperty].map(
|
||||
function(object) {
|
||||
GameLib.Utils.PushUnique(components, object);
|
||||
}
|
||||
)
|
||||
} else {
|
||||
GameLib.Utils.PushUnique(components, material[property][tProperty]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,13 +56,11 @@ GameLib.D3.Mesh.Box.prototype.createInstance = function() {
|
|||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
}
|
||||
|
||||
var instance = GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
|
||||
instance.userData.width = this.width;
|
||||
instance.userData.height = this.height;
|
||||
instance.userData.depth = this.depth;
|
||||
|
||||
return instance;
|
||||
this.instance.userData.width = this.width;
|
||||
this.instance.userData.height = this.height;
|
||||
this.instance.userData.depth = this.depth;
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.Box.prototype.updateInstance = function() {
|
||||
|
|
|
@ -95,18 +95,16 @@ GameLib.D3.Mesh.Cylinder.prototype.createInstance = function() {
|
|||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
}
|
||||
|
||||
var instance = GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
|
||||
instance.userData.radiusTop = this.radiusTop;
|
||||
instance.userData.radiusBottom = this.radiusBottom;
|
||||
instance.userData.height = this.height;
|
||||
instance.userData.radiusSegments = this.radiusSegments;
|
||||
instance.userData.heightSegments = this.heightSegments;
|
||||
instance.userData.openEnded = this.openEnded;
|
||||
instance.userData.thetaStart = this.thetaStart;
|
||||
instance.userData.thetaLength = this.thetaLength;
|
||||
|
||||
return instance;
|
||||
this.instance.userData.radiusTop = this.radiusTop;
|
||||
this.instance.userData.radiusBottom = this.radiusBottom;
|
||||
this.instance.userData.height = this.height;
|
||||
this.instance.userData.radiusSegments = this.radiusSegments;
|
||||
this.instance.userData.heightSegments = this.heightSegments;
|
||||
this.instance.userData.openEnded = this.openEnded;
|
||||
this.instance.userData.thetaStart = this.thetaStart;
|
||||
this.instance.userData.thetaLength = this.thetaLength;
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.Cylinder.prototype.updateInstance = function() {
|
||||
|
|
|
@ -107,30 +107,26 @@ GameLib.D3.Mesh.Plane.prototype.createInstance = function() {
|
|||
/**
|
||||
* Now construct the mesh instance
|
||||
*/
|
||||
var instance = GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
|
||||
/**
|
||||
* Apply some plane specific data to the instance
|
||||
*/
|
||||
instance.userData.width = this.width;
|
||||
instance.userData.height = this.height;
|
||||
instance.userData.widthSegments = this.widthSegments;
|
||||
instance.userData.heightSegments = this.heightSegments;
|
||||
instance.userData.heightMapScale = this.heightMapScale;
|
||||
instance.userData.isHeightMap = this.isHeightMap;
|
||||
instance.userData.isClippingPlane = this.isClippingPlane;
|
||||
instance.userData.distanceFromOrigin = this.distanceFromOrigin;
|
||||
this.instance.userData.width = this.width;
|
||||
this.instance.userData.height = this.height;
|
||||
this.instance.userData.widthSegments = this.widthSegments;
|
||||
this.instance.userData.heightSegments = this.heightSegments;
|
||||
this.instance.userData.heightMapScale = this.heightMapScale;
|
||||
this.instance.userData.isHeightMap = this.isHeightMap;
|
||||
this.instance.userData.isClippingPlane = this.isClippingPlane;
|
||||
this.instance.userData.distanceFromOrigin = this.distanceFromOrigin;
|
||||
|
||||
if (this.isClippingPlane) {
|
||||
instance.clipping = new THREE.Plane(
|
||||
this.instance.clipping = new THREE.Plane(
|
||||
geometry.faces[0].normal,
|
||||
this.distanceFromOrigin
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,13 +55,12 @@ GameLib.D3.Mesh.Sphere.prototype.createInstance = function() {
|
|||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
}
|
||||
|
||||
var instance = GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
|
||||
instance.userData.radius = this.radius;
|
||||
instance.userData.widthSegments = this.widthSegments;
|
||||
instance.userData.heightSegments = this.heightSegments;
|
||||
this.instance.userData.radius = this.radius;
|
||||
this.instance.userData.widthSegments = this.widthSegments;
|
||||
this.instance.userData.heightSegments = this.heightSegments;
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.Sphere.prototype.updateInstance = function() {
|
||||
|
|
|
@ -109,18 +109,16 @@ GameLib.D3.Mesh.Text.prototype.createInstance = function() {
|
|||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
}
|
||||
|
||||
var instance = GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
|
||||
instance.userData.font = this.font;
|
||||
instance.userData.size = this.size;
|
||||
instance.userData.height = this.height;
|
||||
instance.userData.curveSegments = this.curveSegments;
|
||||
instance.userData.bevelEnabled = this.bevelEnabled;
|
||||
instance.userData.bevelThickness = this.bevelThickness;
|
||||
instance.userData.bevelSize = this.bevelSize;
|
||||
instance.userData.bevelSegments = this.bevelSegments;
|
||||
|
||||
return instance;
|
||||
this.instance.userData.font = this.font;
|
||||
this.instance.userData.size = this.size;
|
||||
this.instance.userData.height = this.height;
|
||||
this.instance.userData.curveSegments = this.curveSegments;
|
||||
this.instance.userData.bevelEnabled = this.bevelEnabled;
|
||||
this.instance.userData.bevelThickness = this.bevelThickness;
|
||||
this.instance.userData.bevelSize = this.bevelSize;
|
||||
this.instance.userData.bevelSegments = this.bevelSegments;
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.Text.prototype.updateInstance = function() {
|
||||
|
|
|
@ -49,57 +49,65 @@ GameLib.D3.Pass.PASS_TYPE_COPY_SHADER = 0x2;
|
|||
|
||||
/**
|
||||
* Create Pass instance
|
||||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Pass.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
}
|
||||
GameLib.D3.Pass.prototype.createInstance = function() {
|
||||
|
||||
if (this.passType === GameLib.D3.Pass.PASS_TYPE_RENDER) {
|
||||
|
||||
if (this.scene && this.camera) {
|
||||
if (!THREE.RenderPass) {
|
||||
console.warn('No THREE.RenderPass');
|
||||
throw new Error('No THREE.RenderPass');
|
||||
}
|
||||
|
||||
instance = new THREE.RenderPass(
|
||||
this.scene.instance,
|
||||
this.camera.instance
|
||||
);
|
||||
if (GameLib.Utils.UndefinedOrNull(this.scene)) {
|
||||
throw new Error('no scene object');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.camera)) {
|
||||
throw new Error('no camera object');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(THREE.RenderPass)) {
|
||||
throw new Error('no render pass library')
|
||||
}
|
||||
|
||||
this.instance = new THREE.RenderPass(
|
||||
this.scene.instance,
|
||||
this.camera.instance
|
||||
);
|
||||
|
||||
} else if (this.passType === GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
|
||||
|
||||
if (!THREE.CopyShader) {
|
||||
console.warn('No THREE.CopyShader');
|
||||
throw new Error('No THREE.CopyShader');
|
||||
if (GameLib.Utils.UndefinedOrNull(THREE.CopyShader)) {
|
||||
throw new Error('no copyshader library')
|
||||
}
|
||||
|
||||
instance = THREE.CopyShader;
|
||||
this.instance = THREE.CopyShader;
|
||||
|
||||
} else {
|
||||
console.warn('Render pass not supported yet: ' + this.passType);
|
||||
throw new Error('Render pass not supported yet: ' + this.passType);
|
||||
}
|
||||
|
||||
if (instance) {
|
||||
instance.renderToScreen = this.renderToScreen;
|
||||
}
|
||||
this.instance.renderToScreen = this.renderToScreen;
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Pass instance
|
||||
*/
|
||||
GameLib.D3.Pass.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
|
||||
if (
|
||||
this.passType === GameLib.D3.Pass.PASS_TYPE_RENDER && !(this.instance instanceof THREE.RenderPass)){
|
||||
this.createInstance();
|
||||
}
|
||||
|
||||
if (
|
||||
this.passType === GameLib.D3.Pass.PASS_TYPE_COPY_SHADER && !(this.instance instanceof THREE.CopyShader)){
|
||||
this.createInstance();
|
||||
}
|
||||
|
||||
this.instance.renderToScreen = this.renderToScreen;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -127,6 +127,7 @@ GameLib.D3.PathFollowing.prototype.createInstance = function() {
|
|||
|
||||
console.log('GameLib.D3.PathFollowing.prototype.createInstance()');
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -109,58 +109,70 @@ GameLib.D3.PhysicsWorld.prototype.constructor = GameLib.D3.PhysicsWorld;
|
|||
*/
|
||||
GameLib.D3.PhysicsWorld.prototype.createInstance = function() {
|
||||
|
||||
if (this.broadphase && this.broadphase.instance &&
|
||||
this.solver && this.solver.instance) {
|
||||
|
||||
var instance = new CANNON.World();
|
||||
instance.broadphase = this.broadphase.instance;
|
||||
instance.solver = this.solver.instance;
|
||||
instance.gravity = this.gravity.instance;
|
||||
instance.allowSleep = this.allowSleep;
|
||||
|
||||
this.contactMaterials.map(
|
||||
function(contactMaterial) {
|
||||
if (contactMaterial && contactMaterial.instance) {
|
||||
instance.addContactMaterial(contactMaterial.instance);
|
||||
} else {
|
||||
console.warn('contact materials not loaded at time of PhysicsWorld.createInstance()');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
this.rigidBodies.map(
|
||||
function(rigidBody) {
|
||||
if (rigidBody && rigidBody.instance) {
|
||||
/**
|
||||
* Ensure the rigidBody knows its parentWorld
|
||||
*/
|
||||
rigidBody.parentWorld = this;
|
||||
|
||||
/**
|
||||
* Add the rigid body to the instance world
|
||||
*/
|
||||
instance.add(rigidBody.instance);
|
||||
} else {
|
||||
console.warn('rigidbodies not loaded at time of PhysicsWorld.createInstance()');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
instance.defaultContactMaterial.friction = this.defaultContactMaterial.friction;
|
||||
instance.defaultContactMaterial.restitution = this.defaultContactMaterial.restitution;
|
||||
instance.defaultContactMaterial.contactEquationStiffness = this.defaultContactMaterial.contactEquationStiffness;
|
||||
instance.defaultContactMaterial.contactEquationRelaxation = this.defaultContactMaterial.contactEquationRelaxation;
|
||||
instance.defaultContactMaterial.frictionEquationStiffness = this.defaultContactMaterial.frictionEquationStiffness;
|
||||
instance.defaultContactMaterial.frictionEquationRelaxation = this.defaultContactMaterial.frictionEquationRelaxation;
|
||||
|
||||
return instance;
|
||||
|
||||
} else {
|
||||
console.warn('broadphase or solver not loaded during PhysicsWorld.createInstance()');
|
||||
if (GameLib.Utils.UndefinedOrNull(this.broadphase)) {
|
||||
throw new Error('no broadphase');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.broadphase.instance)) {
|
||||
throw new Error('no broadphase instance');
|
||||
}
|
||||
|
||||
return false;
|
||||
if (GameLib.Utils.UndefinedOrNull(this.solver)) {
|
||||
throw new Error('no solver');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.solver.instance)) {
|
||||
throw new Error('no solver instance');
|
||||
}
|
||||
|
||||
this.instance = new CANNON.World();
|
||||
this.instance.broadphase = this.broadphase.instance;
|
||||
this.instance.solver = this.solver.instance;
|
||||
this.instance.gravity = this.gravity.instance;
|
||||
this.instance.allowSleep = this.allowSleep;
|
||||
|
||||
this.contactMaterials.map(
|
||||
function (contactMaterial) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(contactMaterial)) {
|
||||
throw new Error('no contact material');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(contactMaterial.instance)) {
|
||||
throw new Error('no contact material instance');
|
||||
}
|
||||
|
||||
this.instance.addContactMaterial(contactMaterial.instance);
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.rigidBodies.map(
|
||||
function (rigidBody) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rigidBody)) {
|
||||
throw new Error('no rigidbody');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rigidBody.instance)) {
|
||||
throw new Error('no rigidbody instance');
|
||||
}
|
||||
|
||||
rigidBody.parentWorld = this;
|
||||
|
||||
this.instance.add(rigidBody.instance);
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.instance.defaultContactMaterial.friction = this.defaultContactMaterial.friction;
|
||||
this.instance.defaultContactMaterial.restitution = this.defaultContactMaterial.restitution;
|
||||
this.instance.defaultContactMaterial.contactEquationStiffness = this.defaultContactMaterial.contactEquationStiffness;
|
||||
this.instance.defaultContactMaterial.contactEquationRelaxation = this.defaultContactMaterial.contactEquationRelaxation;
|
||||
this.instance.defaultContactMaterial.frictionEquationStiffness = this.defaultContactMaterial.frictionEquationStiffness;
|
||||
this.instance.defaultContactMaterial.frictionEquationRelaxation = this.defaultContactMaterial.frictionEquationRelaxation;
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
GameLib.D3.PhysicsWorld.prototype.addRigidBody = function(rigidBody) {
|
||||
|
|
|
@ -25,7 +25,7 @@ GameLib.D3.Physics = function Physics(
|
|||
}
|
||||
this.physicsType = physicsType;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -37,9 +37,8 @@ GameLib.D3.Physics.PHYSICS_TYPE_CANNON = 0x1;
|
|||
/**
|
||||
* @returns {THREE.Physics}
|
||||
*/
|
||||
GameLib.D3.Physics.prototype.createInstance = function(update) {
|
||||
var instance = CANNON;
|
||||
return instance;
|
||||
GameLib.D3.Physics.prototype.createInstance = function() {
|
||||
this.instance = CANNON;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -87,24 +87,47 @@ GameLib.D3.RaycastVehicle.prototype.createInstance = function() {
|
|||
* delayedInstance somehow...
|
||||
* @type {GameLib.D3.RaycastVehicle|GameLib.D3.API.RaycastVehicle|*}
|
||||
*/
|
||||
var instance = false;
|
||||
|
||||
if (this.chassis && this.chassis.instance) {
|
||||
|
||||
instance = new CANNON.RaycastVehicle({
|
||||
chassisBody: this.chassis.instance
|
||||
});
|
||||
|
||||
this.raycastWheels.map(function(wheel){
|
||||
instance.addWheel(wheel.instance);
|
||||
});
|
||||
|
||||
if (this.parentWorld && this.parentWorld.instance) {
|
||||
instance.addToWorld(this.parentWorld.instance);
|
||||
}
|
||||
if (GameLib.Utils.UndefinedOrNull(this.chassis)) {
|
||||
throw new Error('no chassis');
|
||||
}
|
||||
|
||||
return instance;
|
||||
if (GameLib.Utils.UndefinedOrNull(this.chassis.instance)) {
|
||||
throw new Error('no chassis instance');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.parentWorld)) {
|
||||
throw new Error('no parent world');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.parentWorld.instance)) {
|
||||
throw new Error('no parent world instance');
|
||||
}
|
||||
|
||||
this.instance = new CANNON.RaycastVehicle({
|
||||
chassisBody: this.chassis.instance
|
||||
});
|
||||
|
||||
this.raycastWheels.map(
|
||||
function(wheel){
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(wheel)) {
|
||||
throw new Error('no wheel');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(wheel.instance)) {
|
||||
throw new Error('no wheel instance');
|
||||
}
|
||||
|
||||
this.instance.addWheel(wheel.instance);
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.instance.addToWorld(this.parentWorld.instance);
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.RaycastVehicle.prototype.updateInstance = function() {
|
||||
|
|
|
@ -78,7 +78,7 @@ GameLib.D3.RaycastWheel.prototype.constructor = GameLib.D3.RaycastWheel;
|
|||
*/
|
||||
GameLib.D3.RaycastWheel.prototype.createInstance = function() {
|
||||
|
||||
var instance = {
|
||||
this.instance = {
|
||||
radius: this.radius,
|
||||
directionLocal: this.directionLocal.instance,
|
||||
suspensionStiffness: this.suspensionStiffness,
|
||||
|
@ -95,7 +95,7 @@ GameLib.D3.RaycastWheel.prototype.createInstance = function() {
|
|||
useCustomSlidingRotationalSpeed: this.useCustomSlidingRotationalSpeed
|
||||
};
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
GameLib.D3.RaycastWheel.prototype.updateInstance = function() {
|
||||
|
|
|
@ -53,24 +53,29 @@ GameLib.D3.Raycaster.prototype.constructor = GameLib.D3.Raycaster;
|
|||
* Creates or updates a raycaster instance
|
||||
*/
|
||||
GameLib.D3.Raycaster.prototype.createInstance = function() {
|
||||
var instance = new THREE.Raycaster();
|
||||
|
||||
instance.set(
|
||||
this.position.instance,
|
||||
this.direction.instance
|
||||
);
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
GameLib.D3.Raycaster.prototype.updateInstance = function() {
|
||||
|
||||
this.instance = new THREE.Raycaster();
|
||||
this.instance.set(
|
||||
this.position.instance,
|
||||
this.direction.instance
|
||||
);
|
||||
|
||||
return null;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
GameLib.D3.Raycaster.prototype.updateInstance = function() {
|
||||
|
||||
this.position.instance.x = this.position.x;
|
||||
this.position.instance.y = this.position.y;
|
||||
this.position.instance.z = this.position.z;
|
||||
|
||||
this.direction.instance.x = this.direction.x;
|
||||
this.direction.instance.y = this.direction.y;
|
||||
this.direction.instance.z = this.direction.z;
|
||||
|
||||
this.instance.set(
|
||||
this.position.instance,
|
||||
this.direction.instance
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Raycaster.prototype.toApiObject = function() {
|
||||
|
|
|
@ -48,23 +48,25 @@ GameLib.D3.RenderTarget.prototype.constructor = GameLib.D3.RenderTarget;
|
|||
*/
|
||||
GameLib.D3.RenderTarget.prototype.createInstance = function() {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.texture && this.texture.loaded) {
|
||||
|
||||
instance = new THREE.WebGLRenderTarget(
|
||||
this.width,
|
||||
this.height,
|
||||
{
|
||||
stencilBuffer : this.stencilBuffer
|
||||
}
|
||||
);
|
||||
|
||||
instance.texture = this.texture.instance;
|
||||
if (GameLib.Utils.UndefinedOrNull(this.texture)) {
|
||||
throw new Error('no texture');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.texture.instance)) {
|
||||
throw new Error('no texture instance');
|
||||
}
|
||||
|
||||
return instance;
|
||||
this.instance = new THREE.WebGLRenderTarget(
|
||||
this.width,
|
||||
this.height,
|
||||
{
|
||||
stencilBuffer : this.stencilBuffer
|
||||
}
|
||||
);
|
||||
|
||||
this.instance.texture = this.texture.instance;
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -82,14 +84,13 @@ GameLib.D3.RenderTarget.prototype.updateInstance = function() {
|
|||
this.instance.texture = null;
|
||||
}
|
||||
} else {
|
||||
this.instance = this.createInstance();
|
||||
|
||||
if (this.instance) {
|
||||
try {
|
||||
this.createInstance();
|
||||
this.loaded = true;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -158,12 +158,22 @@ GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer;
|
|||
*/
|
||||
GameLib.D3.Renderer.prototype.createInstance = function() {
|
||||
|
||||
var instance = new THREE.WebGLRenderer({
|
||||
canvas : this.domElement.instance
|
||||
});
|
||||
if (GameLib.Utils.UndefinedOrNull(this.domElement)) {
|
||||
throw new Error('no dom element');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.domElement.instance)) {
|
||||
throw new Error('no dom element instance');
|
||||
}
|
||||
|
||||
this.instance = new THREE.WebGLRenderer(
|
||||
{
|
||||
canvas : this.domElement.instance
|
||||
}
|
||||
);
|
||||
|
||||
if (this.clippingPlanes.length > 0) {
|
||||
instance.clippingPlanes = this.clippingPlanes.map(
|
||||
this.instance.clippingPlanes = this.clippingPlanes.map(
|
||||
function(clippingPlane) {
|
||||
|
||||
if (!clippingPlane.isClippingPlane || !clippingPlane.instance || !clippingPlane.instance.clipping) {
|
||||
|
@ -175,14 +185,14 @@ GameLib.D3.Renderer.prototype.createInstance = function() {
|
|||
)
|
||||
}
|
||||
|
||||
instance.localClippingEnabled = this.localClipping;
|
||||
this.instance.localClippingEnabled = this.localClipping;
|
||||
|
||||
instance.setSize(
|
||||
this.instance.setSize(
|
||||
this.width,
|
||||
this.height
|
||||
);
|
||||
|
||||
instance.setClearColor(
|
||||
this.instance.setClearColor(
|
||||
new THREE.Color(
|
||||
this.clearColor.r,
|
||||
this.clearColor.g,
|
||||
|
@ -191,13 +201,14 @@ GameLib.D3.Renderer.prototype.createInstance = function() {
|
|||
1 - this.clearColor.a
|
||||
);
|
||||
|
||||
instance.domElement.width = this.width;
|
||||
instance.domElement.height = this.height;
|
||||
this.instance.domElement.width = this.width;
|
||||
this.instance.domElement.height = this.height;
|
||||
|
||||
instance.autoClear = this.autoClear;
|
||||
instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
|
||||
this.instance.autoClear = this.autoClear;
|
||||
this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -206,14 +217,14 @@ GameLib.D3.Renderer.prototype.createInstance = function() {
|
|||
GameLib.D3.Renderer.prototype.updateInstance = function() {
|
||||
|
||||
if (!this.instance) {
|
||||
this.instance = this.createInstance();
|
||||
try {
|
||||
this.createInstance();
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.instance) {
|
||||
console.warn('could not create renderer instance');
|
||||
return;
|
||||
}
|
||||
|
||||
this.instance.localClippingEnabled = this.localClipping;
|
||||
|
||||
this.instance.setSize(
|
||||
|
|
|
@ -97,7 +97,7 @@ GameLib.D3.RigidBody.prototype.constructor = GameLib.D3.RigidBody;
|
|||
*/
|
||||
GameLib.D3.RigidBody.prototype.createInstance = function() {
|
||||
|
||||
var instance = new CANNON.Body(
|
||||
this.instance = new CANNON.Body(
|
||||
{
|
||||
mass : this.mass,
|
||||
friction : this.friction,
|
||||
|
@ -117,30 +117,44 @@ GameLib.D3.RigidBody.prototype.createInstance = function() {
|
|||
}
|
||||
);
|
||||
|
||||
instance.addEventListener("sleepy",function(event){
|
||||
console.log(this.name + " is feeling sleepy...");
|
||||
}.bind(this));
|
||||
this.instance.addEventListener(
|
||||
"sleepy",
|
||||
function() {
|
||||
console.log(this.name + " is feeling sleepy...");
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
instance.addEventListener("sleep",function(event){
|
||||
console.log(this.name + " fell asleep!");
|
||||
}.bind(this));
|
||||
this.instance.addEventListener(
|
||||
"sleep",
|
||||
function() {
|
||||
console.log(this.name + " fell asleep!");
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
instance.addEventListener("wakeup",function(event){
|
||||
console.log(this.name + " woke up!");
|
||||
}.bind(this));
|
||||
this.instance.addEventListener(
|
||||
"wakeup",
|
||||
function() {
|
||||
console.log(this.name + " woke up!");
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.shapes.map(function(shape){
|
||||
|
||||
if (shape.loaded) {
|
||||
instance.addShape(shape.instance)
|
||||
} else {
|
||||
console.warn('todo : listen for shape created and add here');
|
||||
throw new Error('todo : listen for shape created and add here');
|
||||
}
|
||||
|
||||
});
|
||||
this.shapes.map(
|
||||
function(shape) {
|
||||
|
||||
return instance;
|
||||
if (GameLib.Utils.UndefinedOrNull(shape)) {
|
||||
throw new Error('no shape');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(shape.instance)) {
|
||||
throw new Error('no shape instance');
|
||||
}
|
||||
|
||||
this.instance.addShape(shape.instance)
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -159,7 +173,10 @@ GameLib.D3.RigidBody.prototype.updateInstance = function() {
|
|||
this.quaternion.axis.instance.y = this.quaternion.axis.y;
|
||||
this.quaternion.axis.instance.z = this.quaternion.axis.z;
|
||||
|
||||
this.instance.quaternion.setFromAxisAngle(this.quaternion.axis.instance, this.quaternion.angle);
|
||||
this.instance.quaternion.setFromAxisAngle(
|
||||
this.quaternion.axis.instance,
|
||||
this.quaternion.angle
|
||||
);
|
||||
|
||||
this.quaternion.x = this.instance.quaternion.x;
|
||||
this.quaternion.y = this.instance.quaternion.y;
|
||||
|
|
|
@ -151,36 +151,50 @@ GameLib.D3.Scene.prototype.constructor = GameLib.D3.Scene;
|
|||
*/
|
||||
GameLib.D3.Scene.prototype.createInstance = function() {
|
||||
|
||||
var instance = new THREE.Scene();
|
||||
this.instance = new THREE.Scene();
|
||||
|
||||
instance.name = this.name;
|
||||
this.instance.name = this.name;
|
||||
|
||||
this.meshes.map(
|
||||
function(mesh) {
|
||||
if (mesh && mesh.instance) {
|
||||
instance.add(mesh.instance);
|
||||
} else {
|
||||
console.warn('invalid mesh at point of scene create instance');
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(mesh)) {
|
||||
throw new Error('no mesh');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(mesh.instance)) {
|
||||
throw new Error('no mesh instance');
|
||||
}
|
||||
|
||||
this.instance.add(mesh.instance);
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.lights.map(
|
||||
function(light) {
|
||||
if (light && light.instance) {
|
||||
instance.add(light.instance);
|
||||
} else {
|
||||
console.warn('invalid light at point of scene create instance');
|
||||
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(light)) {
|
||||
throw new Error('no light');
|
||||
}
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(light.instance)) {
|
||||
throw new Error('no light instance');
|
||||
}
|
||||
|
||||
this.instance.add(light.instance);
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Scene.prototype.updateInstance = function() {
|
||||
|
||||
this.instance.name = this.name;
|
||||
this.instance.name = this.name;
|
||||
|
||||
/**
|
||||
* Add missing meshes
|
||||
|
|
|
@ -79,7 +79,7 @@ GameLib.D3.Shape.prototype.constructor = GameLib.D3.Shape;
|
|||
* Creates a shape instance or updates it
|
||||
*/
|
||||
GameLib.D3.Shape.prototype.createInstance = function() {
|
||||
throw new Error('Do not instantiate this class directly - use a child class instead');
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -45,11 +45,20 @@ GameLib.D3.Shape.Box.prototype.constructor = GameLib.D3.Shape.Box;
|
|||
*/
|
||||
GameLib.D3.Shape.Box.prototype.createInstance = function() {
|
||||
|
||||
var instance = new CANNON.Box(
|
||||
if (GameLib.Utils.UndefinedOrNull(this.halfExtents)) {
|
||||
throw new Error('no halfExtents');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.halfExtents.instance)) {
|
||||
throw new Error('no halfExtents instance');
|
||||
}
|
||||
|
||||
this.instance = new CANNON.Box(
|
||||
this.halfExtents.instance
|
||||
);
|
||||
|
||||
return instance;
|
||||
GameLib.D3.Shape.prototype.createInstance.call(this);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Shape.Box.prototype.updateInstance = function() {
|
||||
|
|
|
@ -107,19 +107,62 @@ GameLib.D3.Shape.ConvexHull.prototype.createInstance = function() {
|
|||
|
||||
var faceNormals = [];
|
||||
|
||||
var instance = new CANNON.ConvexPolyhedron(
|
||||
this.vertices.map(function(vertex){
|
||||
return vertex.position.instance;
|
||||
}),
|
||||
this.faces.map(function(face){
|
||||
faceNormals.push(face.normal.instance);
|
||||
return [face.v0index, face.v1index, face.v2index]
|
||||
})
|
||||
this.instance = new CANNON.ConvexPolyhedron(
|
||||
this.vertices.map(
|
||||
function(vertex) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertex)) {
|
||||
throw new Error('no vertex');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertex.position)) {
|
||||
throw new Error('no vertex position');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertex.position.instance)) {
|
||||
throw new Error('no vertex position instance');
|
||||
}
|
||||
|
||||
return vertex.position.instance;
|
||||
}
|
||||
),
|
||||
this.faces.map(
|
||||
function(face) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(face)) {
|
||||
throw new Error('no face');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(face.normal)) {
|
||||
throw new Error('no face normal');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(face.normal.instance)) {
|
||||
throw new Error('no face normal instance');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(face.v0index)) {
|
||||
throw new Error('no face v0index');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(face.v1index)) {
|
||||
throw new Error('no face v1index');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(face.v2index)) {
|
||||
throw new Error('no face v2index');
|
||||
}
|
||||
|
||||
faceNormals.push(face.normal.instance);
|
||||
|
||||
return [face.v0index, face.v1index, face.v2index];
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
instance.faceNormals = faceNormals;
|
||||
this.instance.faceNormals = faceNormals;
|
||||
|
||||
return instance;
|
||||
GameLib.D3.Shape.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,14 +55,14 @@ GameLib.D3.Shape.ConvexHull.Cylinder.prototype.constructor = GameLib.D3.Shape.Co
|
|||
*/
|
||||
GameLib.D3.Shape.ConvexHull.Cylinder.prototype.createInstance = function() {
|
||||
|
||||
var instance = new CANNON.Cylinder(
|
||||
this.instance = new CANNON.Cylinder(
|
||||
this.radiusTop,
|
||||
this.radiusBottom,
|
||||
this.height,
|
||||
this.numSegments
|
||||
);
|
||||
|
||||
return instance;
|
||||
GameLib.D3.Shape.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
GameLib.D3.Shape.ConvexHull.Cylinder.prototype.updateInstance = function() {
|
||||
|
|
|
@ -55,14 +55,16 @@ GameLib.D3.Shape.HeightMap.prototype.constructor = GameLib.D3.Shape.HeightMap;
|
|||
*/
|
||||
GameLib.D3.Shape.HeightMap.prototype.createInstance = function() {
|
||||
|
||||
var instance = new CANNON.Heightfield(
|
||||
//TODO: initialize properly and throw when errors
|
||||
|
||||
this.instance = new CANNON.Heightfield(
|
||||
this.heightData,
|
||||
{
|
||||
elemSize : this.elementSize
|
||||
}
|
||||
);
|
||||
|
||||
return instance;
|
||||
GameLib.D3.Shape.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,8 +26,11 @@ GameLib.D3.Shape.Plane.prototype.constructor = GameLib.D3.Shape.Plane;
|
|||
* @returns {GameLib.D3.Shape.Plane|*|SEA3D.Plane}
|
||||
*/
|
||||
GameLib.D3.Shape.Plane.prototype.createInstance = function() {
|
||||
var instance = new CANNON.Plane();
|
||||
return instance;
|
||||
/**
|
||||
* A plane is just a plane at z = 0, to rotate it put it inside a rigid body and rotate the body
|
||||
*/
|
||||
this.instance = new CANNON.Plane();
|
||||
GameLib.D3.Shape.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
GameLib.D3.Shape.Plane.prototype.updateInstance = function() {
|
||||
|
|
|
@ -34,11 +34,11 @@ GameLib.D3.Shape.Sphere.prototype.constructor = GameLib.D3.Shape.Sphere;
|
|||
*/
|
||||
GameLib.D3.Shape.Sphere.prototype.createInstance = function() {
|
||||
|
||||
var instance = new CANNON.Sphere(
|
||||
this.instance = new CANNON.Sphere(
|
||||
this.radius
|
||||
);
|
||||
|
||||
return instance;
|
||||
GameLib.D3.Shape.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
GameLib.D3.Shape.Sphere.prototype.updateInstance = function() {
|
||||
|
|
|
@ -41,12 +41,13 @@ GameLib.D3.Shape.TriMesh.prototype.constructor = GameLib.D3.Shape.TriMesh;
|
|||
*/
|
||||
GameLib.D3.Shape.TriMesh.prototype.createInstance = function() {
|
||||
|
||||
var instance = new CANNON.TriMesh(
|
||||
this.instance = new CANNON.TriMesh(
|
||||
this.vertices,
|
||||
this.indices
|
||||
);
|
||||
|
||||
return instance;
|
||||
GameLib.D3.Shape.prototype.createInstance.call(this);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -102,24 +102,23 @@ GameLib.D3.Skeleton.prototype.constructor = GameLib.D3.Skeleton;
|
|||
*/
|
||||
GameLib.D3.Skeleton.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
var boneInstances = this.bones.map (
|
||||
function (bone) {
|
||||
|
||||
if (update) {
|
||||
//TODO - update instance with bone info
|
||||
instance = this.instance;
|
||||
} else {
|
||||
instance = new THREE.Skeleton(
|
||||
this.bones.map (
|
||||
function (bone) {
|
||||
return bone.instance;
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
if (GameLib.Utils.UndefinedOrNull(bone)) {
|
||||
throw new Error('no bone');
|
||||
}
|
||||
|
||||
instance.useVertexTexture = this.useVertexTexture;
|
||||
if (GameLib.Utils.UndefinedOrNull(bone.instance)) {
|
||||
throw new Error('no bone instance');
|
||||
}
|
||||
|
||||
return bone.instance;
|
||||
}
|
||||
);
|
||||
|
||||
var parentBoneInstance = this.bones.reduce(
|
||||
|
||||
function (result, bone) {
|
||||
|
||||
if (result) {
|
||||
|
@ -135,13 +134,16 @@ GameLib.D3.Skeleton.prototype.createInstance = function(update) {
|
|||
null
|
||||
);
|
||||
|
||||
if (!parentBoneInstance) {
|
||||
console.warn('Did not find the main parent bone - skeleton will be broken');
|
||||
return;
|
||||
if (GameLib.Utils.UndefinedOrNull(parentBoneInstance)) {
|
||||
throw new Error('could not find parent bone instance');
|
||||
}
|
||||
|
||||
this.instance = new THREE.Skeleton(boneInstances);
|
||||
|
||||
this.rootBoneInstance = parentBoneInstance;
|
||||
|
||||
this.instance.useVertexTexture = this.useVertexTexture;
|
||||
|
||||
this.boneIdToBone = {};
|
||||
|
||||
this.bones.map(
|
||||
|
@ -150,6 +152,9 @@ GameLib.D3.Skeleton.prototype.createInstance = function(update) {
|
|||
}.bind(this)
|
||||
);
|
||||
|
||||
/**
|
||||
* TODO: check if this code does what its supposed to
|
||||
*/
|
||||
this.bones.map(
|
||||
function (__parentBoneInstance) {
|
||||
return function(bone) {
|
||||
|
@ -162,18 +167,18 @@ GameLib.D3.Skeleton.prototype.createInstance = function(update) {
|
|||
}(parentBoneInstance).bind(this)
|
||||
);
|
||||
|
||||
instance.update();
|
||||
this.instance.update();
|
||||
|
||||
instance.calculateInverses();
|
||||
this.instance.calculateInverses();
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance
|
||||
*/
|
||||
GameLib.D3.Skeleton.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -45,21 +45,18 @@ GameLib.D3.Solver.prototype.constructor = GameLib.D3.Solver;
|
|||
*/
|
||||
GameLib.D3.Solver.prototype.createInstance = function() {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.solverType === GameLib.D3.Solver.GS_SOLVER) {
|
||||
instance = new CANNON.GSSolver();
|
||||
this.instance = new CANNON.GSSolver();
|
||||
} else if (this.solverType === GameLib.D3.Solver.SPLIT_SOLVER) {
|
||||
instance = new CANNON.SplitSolver();
|
||||
this.instance = new CANNON.SplitSolver();
|
||||
} else {
|
||||
console.warn('Unsupported solver type: ' + this.solverType);
|
||||
throw new Error('Unsupported solver type: ' + this.solverType);
|
||||
throw new Error('unsupported solver type: ' + this.solverType);
|
||||
}
|
||||
|
||||
instance.tolerance = this.tolerance;
|
||||
instance.iterations = this.iterations;
|
||||
this.instance.tolerance = this.tolerance;
|
||||
this.instance.iterations = this.iterations;
|
||||
|
||||
return instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,17 +48,27 @@ GameLib.D3.Spline.prototype.constructor = GameLib.D3.Spline;
|
|||
|
||||
/**
|
||||
* Creates an instance spline
|
||||
* @param update boolean
|
||||
*/
|
||||
GameLib.D3.Spline.prototype.createInstance = function() {
|
||||
|
||||
var vertices = this.vertices.map(
|
||||
function (vertex) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertex)) {
|
||||
throw new Error('no vertex')
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertex.instance)) {
|
||||
throw new Error('no vertex instance')
|
||||
}
|
||||
|
||||
return vertex.instance;
|
||||
}
|
||||
);
|
||||
|
||||
return new THREE.CatmullRomCurve3(vertices);
|
||||
this.instance = THREE.CatmullRomCurve3(vertices);
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -68,6 +78,15 @@ GameLib.D3.Spline.prototype.updateInstance = function() {
|
|||
|
||||
var vertices = this.vertices.map(
|
||||
function (vertex) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertex)) {
|
||||
throw new Error('no vertex')
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertex.instance)) {
|
||||
throw new Error('no vertex instance')
|
||||
}
|
||||
|
||||
return vertex.instance;
|
||||
}
|
||||
);
|
||||
|
|
|
@ -60,7 +60,8 @@ GameLib.D3.Stats.prototype.resize = function() {
|
|||
* Creates a helper instance
|
||||
*/
|
||||
GameLib.D3.Stats.prototype.createInstance = function() {
|
||||
return new this.stats();
|
||||
this.instance = this.stats();
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,7 @@ GameLib.D3.Texture = function(
|
|||
apiTexture.typeId,
|
||||
apiTexture.name,
|
||||
apiTexture.image,
|
||||
apiTexture.images,
|
||||
apiTexture.wrapS,
|
||||
apiTexture.wrapT,
|
||||
apiTexture.repeat,
|
||||
|
@ -66,6 +67,17 @@ GameLib.D3.Texture = function(
|
|||
);
|
||||
}
|
||||
|
||||
this.images = this.images.map(
|
||||
function(image) {
|
||||
if (image instanceof GameLib.D3.API.Image) {
|
||||
return new GameLib.D3.Image(
|
||||
this.graphics,
|
||||
image
|
||||
);
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
if (this.canvas instanceof GameLib.D3.API.Canvas) {
|
||||
this.canvas = new GameLib.D3.Canvas(
|
||||
this.graphics,
|
||||
|
@ -78,6 +90,7 @@ GameLib.D3.Texture = function(
|
|||
GameLib.Component.COMPONENT_TEXTURE,
|
||||
{
|
||||
'image' : GameLib.D3.Image,
|
||||
'images' : [GameLib.D3.Image],
|
||||
'canvas' : GameLib.D3.Canvas
|
||||
}
|
||||
);
|
||||
|
@ -157,6 +170,7 @@ GameLib.D3.Texture.TYPE_RGBD_ENCODING = 3006; // MAXRANGE IS 256.
|
|||
|
||||
GameLib.D3.Texture.TEXTURE_TYPE_NORMAL = 0x1;
|
||||
GameLib.D3.Texture.TEXTURE_TYPE_CUBE = 0x2;
|
||||
GameLib.D3.Texture.TEXTURE_TYPE_CANVAS = 0x3;
|
||||
|
||||
/**
|
||||
* Creates an instance of our texture object
|
||||
|
@ -164,66 +178,89 @@ GameLib.D3.Texture.TEXTURE_TYPE_CUBE = 0x2;
|
|||
*/
|
||||
GameLib.D3.Texture.prototype.createInstance = function() {
|
||||
|
||||
// console.log('texture create instance');
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CUBE) {
|
||||
|
||||
if (this.image && this.image.instance) {
|
||||
if (this.images.length !== 6) {
|
||||
throw new Error('not enough images for cube texture');
|
||||
}
|
||||
|
||||
var imageInstances = this.images.map(
|
||||
function(image) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(image)) {
|
||||
throw new Error('no image');
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(image.instance)) {
|
||||
throw new Error('no image instance');
|
||||
}
|
||||
|
||||
return image.instance
|
||||
}
|
||||
);
|
||||
|
||||
this.instance = new THREE.CubeTexture(imageInstances);
|
||||
|
||||
} else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_NORMAL) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.image)) {
|
||||
|
||||
this.instance = new THREE.Texture();
|
||||
|
||||
instance = new THREE.CubeTexture(
|
||||
[
|
||||
this.image.instance,
|
||||
this.image.instance,
|
||||
this.image.instance,
|
||||
this.image.instance,
|
||||
this.image.instance,
|
||||
this.image.instance
|
||||
]
|
||||
);
|
||||
instance.needsUpdate = true;
|
||||
} else {
|
||||
instance = new THREE.CubeTexture();
|
||||
}
|
||||
|
||||
if (this.mapping !== GameLib.D3.Texture.TYPE_CUBE_REFLECTION_MAPPING &&
|
||||
this.mapping !== GameLib.D3.Texture.TYPE_CUBE_REFRACTION_MAPPING
|
||||
) {
|
||||
this.mapping = GameLib.D3.Texture.TYPE_CUBE_REFLECTION_MAPPING;
|
||||
}
|
||||
if (GameLib.Utils.UndefinedOrNull(this.image.instance)) {
|
||||
throw new Error('no image instance');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (this.image && this.image.instance) {
|
||||
instance = new THREE.Texture(
|
||||
this.instance = new THREE.Texture(
|
||||
this.image.instance
|
||||
);
|
||||
instance.needsUpdate = true;
|
||||
} else if (this.canvas && this.canvas.instance) {
|
||||
instance = new THREE.Texture(this.canvas.instance);
|
||||
|
||||
}
|
||||
|
||||
} else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CANVAS) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.canvas)) {
|
||||
|
||||
this.instance = new THREE.Texture();
|
||||
|
||||
} else {
|
||||
instance = new THREE.Texture();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.canvas.instance)) {
|
||||
throw new Error('no canvas instance');
|
||||
}
|
||||
|
||||
this.instance = new THREE.Texture(
|
||||
this.canvas.instance
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (this.mapping !== GameLib.D3.Texture.TYPE_UV_MAPPING) {
|
||||
this.mapping = GameLib.D3.Texture.TYPE_UV_MAPPING;
|
||||
}
|
||||
}
|
||||
//
|
||||
instance.name = this.name;
|
||||
instance.flipY = this.flipY;
|
||||
// instance.encoding = this.encoding;
|
||||
instance.offset.x = this.offset.x;
|
||||
instance.offset.y = this.offset.y;
|
||||
instance.repeat.x = this.repeat.x;
|
||||
instance.repeat.y = this.repeat.y;
|
||||
//instance.mapping = this.mapping;
|
||||
// instance.format = this.format;
|
||||
instance.wrapS = this.wrapS;
|
||||
instance.wrapT = this.wrapT;
|
||||
|
||||
return instance;
|
||||
/**
|
||||
* Some settings we copy from the instance
|
||||
*/
|
||||
this.mapping = this.instance.mapping;
|
||||
this.encoding = this.instance.encoding;
|
||||
this.format = this.instance.format;
|
||||
|
||||
/**
|
||||
* Others we apply to the instance
|
||||
*/
|
||||
this.instance.name = this.name;
|
||||
this.instance.flipY = this.flipY;
|
||||
this.instance.offset.x = this.offset.x;
|
||||
this.instance.offset.y = this.offset.y;
|
||||
this.instance.repeat.x = this.repeat.x;
|
||||
this.instance.repeat.y = this.repeat.y;
|
||||
this.instance.wrapS = this.wrapS;
|
||||
this.instance.wrapT = this.wrapT;
|
||||
|
||||
this.instance.needsUpdate = true;
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -231,69 +268,63 @@ GameLib.D3.Texture.prototype.createInstance = function() {
|
|||
*/
|
||||
GameLib.D3.Texture.prototype.updateInstance = function() {
|
||||
|
||||
// console.log('texture update instance');
|
||||
|
||||
var imageChanged = false;
|
||||
|
||||
if (!this.instance) {
|
||||
console.error('no texture instance');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.image && this.image.instance) {
|
||||
|
||||
if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_NORMAL) {
|
||||
|
||||
/**
|
||||
* Image overrides canvas
|
||||
*/
|
||||
if (this.instance.image !== this.image.instance) {
|
||||
|
||||
this.instance = new THREE.Texture(
|
||||
this.image.instance
|
||||
);
|
||||
this.mapping = this.instance.mapping;
|
||||
|
||||
imageChanged = true;
|
||||
}
|
||||
|
||||
} else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CUBE) {
|
||||
if (this.instance.image[0] !== this.image.instance) {
|
||||
this.instance = new THREE.CubeTexture(
|
||||
[
|
||||
this.image.instance,
|
||||
this.image.instance,
|
||||
this.image.instance,
|
||||
this.image.instance,
|
||||
this.image.instance,
|
||||
this.image.instance
|
||||
]
|
||||
);
|
||||
this.mapping = this.instance.mapping;
|
||||
|
||||
imageChanged = true;
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
this.canvas && this.canvas.instance
|
||||
) {
|
||||
if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_NORMAL) {
|
||||
console.log('update canvas instance here');
|
||||
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||
try {
|
||||
this.createInstance();
|
||||
return;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
this.instance.name = this.name;
|
||||
this.instance.flipY = this.flipY;
|
||||
// this.instance.encoding = this.encoding;
|
||||
this.instance.offset.x = this.offset.x;
|
||||
this.instance.offset.y = this.offset.y;
|
||||
this.instance.repeat.x = this.repeat.x;
|
||||
this.instance.repeat.y = this.repeat.y;
|
||||
this.instance.mapping = this.mapping;
|
||||
//this.instance.format = this.format;
|
||||
this.instance.wrapS = this.wrapS;
|
||||
this.instance.wrapT = this.wrapT;
|
||||
this.instance.needsUpdate = true;
|
||||
var imageChanged = false;
|
||||
|
||||
if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_NORMAL) {
|
||||
|
||||
if (
|
||||
GameLib.Utils.UndefinedOrNull(this.image) &&
|
||||
this.instance.image
|
||||
) {
|
||||
try {
|
||||
this.createInstance();
|
||||
imageChanged = true;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.image && this.image.instance && this.instance.image !== this.image.instance) {
|
||||
try {
|
||||
this.createInstance();
|
||||
imageChanged = true;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CANVAS) {
|
||||
|
||||
console.log('todo : canvas change check here');
|
||||
|
||||
} else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CUBE) {
|
||||
|
||||
console.log('todo : cube images change check here');
|
||||
|
||||
}
|
||||
|
||||
this.instance.name = this.name;
|
||||
this.instance.flipY = this.flipY;
|
||||
this.instance.encoding = this.encoding;
|
||||
this.instance.offset.x = this.offset.x;
|
||||
this.instance.offset.y = this.offset.y;
|
||||
this.instance.repeat.x = this.repeat.x;
|
||||
this.instance.repeat.y = this.repeat.y;
|
||||
this.instance.mapping = this.mapping;
|
||||
this.instance.format = this.format;
|
||||
this.instance.wrapS = this.wrapS;
|
||||
this.instance.wrapT = this.wrapT;
|
||||
|
||||
this.instance.needsUpdate = true;
|
||||
|
||||
if (imageChanged) {
|
||||
this.publish(
|
||||
|
@ -311,16 +342,16 @@ GameLib.D3.Texture.prototype.updateInstance = function() {
|
|||
*/
|
||||
GameLib.D3.Texture.prototype.toApiObject = function() {
|
||||
|
||||
var apiImage = null;
|
||||
if (this.image) {
|
||||
apiImage = this.image.id
|
||||
}
|
||||
|
||||
var apiTexture = new GameLib.D3.API.Texture(
|
||||
this.id,
|
||||
this.typeId,
|
||||
this.name,
|
||||
apiImage,
|
||||
GameLib.Utils.IdOrNull(this.image),
|
||||
this.images.map(
|
||||
function(image) {
|
||||
return GameLib.Utils.IdOrNull(image)
|
||||
}
|
||||
),
|
||||
this.wrapS,
|
||||
this.wrapT,
|
||||
this.repeat.toApiObject(),
|
||||
|
|
|
@ -45,14 +45,14 @@ GameLib.D3.Viewport.prototype.constructor = GameLib.D3.Viewport;
|
|||
* @returns {boolean}
|
||||
*/
|
||||
GameLib.D3.Viewport.prototype.createInstance = function() {
|
||||
return true;
|
||||
this.instance = true;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
GameLib.D3.Viewport.prototype.updateInstance = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,7 +35,8 @@ GameLib.DomElement.prototype.constructor = GameLib.DomElement;
|
|||
* @returns {*}
|
||||
*/
|
||||
GameLib.DomElement.prototype.createInstance = function() {
|
||||
return document.getElementById(this.domElementId);
|
||||
this.instance = document.getElementById(this.domElementId);
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,8 @@ GameLib.EntityManager.prototype = Object.create(GameLib.Component.prototype);
|
|||
GameLib.EntityManager.prototype.constructor = GameLib.EntityManager;
|
||||
|
||||
GameLib.EntityManager.prototype.createInstance = function() {
|
||||
return GameLib.EntityManager.Instance;
|
||||
this.instance = GameLib.EntityManager.Instance;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
GameLib.EntityManager.prototype.registerComponent = function(data) {
|
||||
|
|
|
@ -45,7 +45,8 @@ GameLib.Entity.prototype.createInstance = function() {
|
|||
/**
|
||||
* FUCK ecsjs and tiny-ecs - no client-side support and shitty code (only takes constructors as args)
|
||||
*/
|
||||
return true;
|
||||
this.instance = true;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -189,7 +190,7 @@ GameLib.Entity.prototype.removeComponent = function(component) {
|
|||
* Updates an entity instance
|
||||
*/
|
||||
GameLib.Entity.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
console.log('entity update instance called');
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,7 +63,8 @@ GameLib.GUI.prototype.constructor = GameLib.GUI;
|
|||
* Creates a helper instance
|
||||
*/
|
||||
GameLib.GUI.prototype.createInstance = function() {
|
||||
return new dat.GUI( { autoPlace: false } );
|
||||
this.instance = new dat.GUI( { autoPlace: false } );
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,7 +79,7 @@ GameLib.Matrix4 = function(
|
|||
this.grain
|
||||
);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.Matrix4.prototype = Object.create(GameLib.API.Matrix4.prototype);
|
||||
|
@ -91,21 +91,13 @@ GameLib.Matrix4.prototype.constructor = GameLib.Matrix4;
|
|||
*/
|
||||
GameLib.Matrix4.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
}
|
||||
|
||||
if (!instance) {
|
||||
instance = new THREE.Matrix4();
|
||||
}
|
||||
this.instance = new THREE.Matrix4();
|
||||
|
||||
/**
|
||||
* We transpose our matrix when we send it to three since we use a different ordering system
|
||||
* They say they use
|
||||
*/
|
||||
instance.set(
|
||||
this.instance.set(
|
||||
this.rows[0].x,
|
||||
this.rows[1].x,
|
||||
this.rows[2].x,
|
||||
|
@ -123,8 +115,6 @@ GameLib.Matrix4.prototype.createInstance = function(update) {
|
|||
this.rows[2].w,
|
||||
this.rows[3].w
|
||||
);
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -132,7 +122,24 @@ GameLib.Matrix4.prototype.createInstance = function(update) {
|
|||
*/
|
||||
GameLib.Matrix4.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
this.instance.set(
|
||||
this.rows[0].x,
|
||||
this.rows[1].x,
|
||||
this.rows[2].x,
|
||||
this.rows[3].x,
|
||||
this.rows[0].y,
|
||||
this.rows[1].y,
|
||||
this.rows[2].y,
|
||||
this.rows[3].y,
|
||||
this.rows[0].z,
|
||||
this.rows[1].z,
|
||||
this.rows[2].z,
|
||||
this.rows[3].z,
|
||||
this.rows[0].w,
|
||||
this.rows[1].w,
|
||||
this.rows[2].w,
|
||||
this.rows[3].w
|
||||
);
|
||||
|
||||
if (this.parentObject &&
|
||||
this.parentObject.updateInstance) {
|
||||
|
|
|
@ -41,7 +41,8 @@ GameLib.Mouse.prototype.constructor = GameLib.Mouse;
|
|||
* @returns {*}
|
||||
*/
|
||||
GameLib.Mouse.prototype.createInstance = function(update) {
|
||||
return true;
|
||||
this.instance = true;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -67,7 +67,7 @@ GameLib.Quaternion = function (
|
|||
}
|
||||
this.grain = grain;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.Quaternion.prototype = Object.create(GameLib.API.Quaternion.prototype);
|
||||
|
@ -75,40 +75,27 @@ GameLib.Quaternion.prototype.constructor = GameLib.Quaternion;
|
|||
|
||||
/**
|
||||
* Creates an instance quaternion
|
||||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.Quaternion.prototype.createInstance = function(update) {
|
||||
GameLib.Quaternion.prototype.createInstance = function() {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
instance.x = this.x;
|
||||
instance.y = this.y;
|
||||
instance.z = this.z;
|
||||
instance.w = this.w;
|
||||
} else {
|
||||
if (this.graphics) {
|
||||
instance = new THREE.Quaternion(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.w
|
||||
);
|
||||
}
|
||||
|
||||
if (this.physics) {
|
||||
instance = new CANNON.Quaternion(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.w
|
||||
);
|
||||
}
|
||||
if (this.graphics) {
|
||||
this.instance = new THREE.Quaternion(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.w
|
||||
);
|
||||
}
|
||||
|
||||
return instance;
|
||||
if (this.physics) {
|
||||
this.instance = new CANNON.Quaternion(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.w
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -116,7 +103,10 @@ GameLib.Quaternion.prototype.createInstance = function(update) {
|
|||
*/
|
||||
GameLib.Quaternion.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
this.instance.x = this.x;
|
||||
this.instance.y = this.y;
|
||||
this.instance.z = this.z;
|
||||
this.instance.w = this.w;
|
||||
|
||||
if (this.parentObject &&
|
||||
this.parentObject.updateInstance) {
|
||||
|
|
|
@ -51,7 +51,8 @@ GameLib.System.SYSTEM_TYPE_VISUALIZATION = 0x100;
|
|||
GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF;
|
||||
|
||||
GameLib.System.prototype.createInstance = function() {
|
||||
//console.log('GameLib.System.prototype.createInstance();');
|
||||
this.instance = true;
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -59,72 +60,8 @@ GameLib.System.prototype.createInstance = function() {
|
|||
* @override
|
||||
*/
|
||||
GameLib.System.prototype.start = function() {
|
||||
|
||||
this.started = true;
|
||||
|
||||
console.log('starting ' + this.name);
|
||||
|
||||
// if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
||||
// // this.pathFollowingObjects = GameLib.EntityManager.Instance.query([GameLib.D3.PathFollowing]);
|
||||
// // this.followObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Follow]);
|
||||
// // this.meshObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Mesh]);
|
||||
// // this.lookAtObjects = GameLib.EntityManager.Instance.query([GameLib.D3.LookAt]);
|
||||
// // this.cameraObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Camera]);
|
||||
// // this.lightObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Light]);
|
||||
// }
|
||||
//
|
||||
// this.update();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @callback
|
||||
* @override
|
||||
*/
|
||||
GameLib.System.prototype.update = function(deltaTime) {
|
||||
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
||||
|
||||
this.pathFollowingObjects.forEach(
|
||||
function(object) {
|
||||
object.update(deltaTime);
|
||||
}
|
||||
);
|
||||
|
||||
this.followObjects.forEach(
|
||||
function(object) {
|
||||
object.update(deltaTime);
|
||||
}
|
||||
);
|
||||
|
||||
this.lookAtObjects.forEach(
|
||||
function(object) {
|
||||
object.update(deltaTime);
|
||||
}
|
||||
);
|
||||
|
||||
this.meshObjects.forEach(
|
||||
function(object) {
|
||||
object.updateInstance();
|
||||
}
|
||||
);
|
||||
|
||||
this.cameraObjects.forEach(
|
||||
function(object) {
|
||||
object.updateInstance();
|
||||
}
|
||||
);
|
||||
|
||||
this.lightObjects.forEach(
|
||||
function(object) {
|
||||
object.updateInstance();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -132,20 +69,8 @@ GameLib.System.prototype.update = function(deltaTime) {
|
|||
* @override
|
||||
*/
|
||||
GameLib.System.prototype.stop = function() {
|
||||
|
||||
this.started = false;
|
||||
|
||||
console.log('stopping ' + this.name);
|
||||
|
||||
//
|
||||
// if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
||||
// // this.pathFollowingObjects = [];
|
||||
// // this.followObjects = [];
|
||||
// // this.meshObjects = [];
|
||||
// // this.lookAtObjects = [];
|
||||
// // this.cameraObjects = [];
|
||||
// // this.lightObjects = [];
|
||||
// }
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -992,7 +992,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
|||
property,
|
||||
{
|
||||
'normal': GameLib.D3.Texture.TEXTURE_TYPE_NORMAL,
|
||||
'cube': GameLib.D3.Texture.TEXTURE_TYPE_CUBE
|
||||
'cube': GameLib.D3.Texture.TEXTURE_TYPE_CUBE,
|
||||
'canvas': GameLib.D3.Texture.TEXTURE_TYPE_CANVAS
|
||||
}
|
||||
)
|
||||
);
|
||||
|
|
|
@ -164,7 +164,7 @@ GameLib.System.Input.prototype.start = function() {
|
|||
false
|
||||
);
|
||||
|
||||
editorControl.instance = editorControl.delayedInstance();
|
||||
editorControl.delayedInstance();
|
||||
|
||||
editorControl.domElement.instance.addEventListener(
|
||||
'mousewheel',
|
||||
|
|
|
@ -267,18 +267,22 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
|
|||
* because the component constructor or linking system did not know at time of 'createInstance'
|
||||
* that it required another object to fully become active
|
||||
*/
|
||||
if (!parentComponent.instance) {
|
||||
if (GameLib.Utils.UndefinedOrNull(parentComponent.instance)) {
|
||||
|
||||
parentComponent.instance = parentComponent.createInstance();
|
||||
try {
|
||||
|
||||
if (parentComponent.instance) {
|
||||
parentComponent.loaded = true;
|
||||
parentComponent.buildIdToObject();
|
||||
if (this.resolved.indexOf(parentComponent) === -1) {
|
||||
this.resolved.push(parentComponent);
|
||||
|
||||
if (parentComponent.loaded) {
|
||||
parentComponent.createInstance();
|
||||
}
|
||||
GameLib.Event.EmitInstanceEvents(parentComponent);
|
||||
|
||||
GameLib.Utils.PushUnique(this.resolved, parentComponent);
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
} else {
|
||||
/**
|
||||
* These dependencies have already been met - the parentComponent properties have changed.
|
||||
|
@ -308,16 +312,18 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
|
|||
|
||||
delete parentComponent.dependencies;
|
||||
|
||||
parentComponent.instance = parentComponent.createInstance();
|
||||
try {
|
||||
|
||||
if (parentComponent.instance) {
|
||||
parentComponent.loaded = true;
|
||||
parentComponent.buildIdToObject();
|
||||
if (this.resolved.indexOf(parentComponent) === -1) {
|
||||
this.resolved.push(parentComponent);
|
||||
|
||||
if (parentComponent.loaded) {
|
||||
parentComponent.createInstance();
|
||||
}
|
||||
|
||||
GameLib.Event.EmitInstanceEvents(parentComponent);
|
||||
GameLib.Utils.PushUnique(this.resolved, parentComponent);
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -390,6 +396,7 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) {
|
|||
component.dependencies.length > 0) {
|
||||
|
||||
component.dependencies = component.dependencies.reduce(
|
||||
|
||||
function(result, id) {
|
||||
|
||||
/**
|
||||
|
@ -397,16 +404,15 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) {
|
|||
*/
|
||||
var processedComponent = GameLib.EntityManager.Instance.findComponentById(id);
|
||||
|
||||
if (processedComponent && processedComponent.loaded) {
|
||||
if (processedComponent) {
|
||||
// if (processedComponent && processedComponent.loaded) {
|
||||
|
||||
/**
|
||||
* Link the component
|
||||
*/
|
||||
this.link(component, {component: processedComponent});
|
||||
|
||||
if (this.resolved.indexOf(processedComponent) === -1) {
|
||||
this.resolved.push(processedComponent);
|
||||
}
|
||||
GameLib.Utils.PushUnique(this.resolved, processedComponent);
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -437,6 +443,7 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) {
|
|||
}
|
||||
|
||||
return result;
|
||||
|
||||
}.bind(this),
|
||||
[]
|
||||
);
|
||||
|
@ -445,11 +452,16 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) {
|
|||
|
||||
delete component.dependencies;
|
||||
|
||||
component.instance = component.createInstance();
|
||||
if (component.instance) {
|
||||
component.loaded = true;
|
||||
component.buildIdToObject();
|
||||
GameLib.Event.EmitInstanceEvents(component);
|
||||
component.buildIdToObject();
|
||||
|
||||
if (component.loaded) {
|
||||
try {
|
||||
component.createInstance();
|
||||
//TODO: test below
|
||||
GameLib.Utils.PushUnique(this.resolved, component);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -527,17 +539,16 @@ GameLib.System.Linking.prototype.imageNotFound = function(data) {
|
|||
if (texture.dependencies.length === 0) {
|
||||
delete texture.dependencies;
|
||||
|
||||
texture.instance = texture.createInstance();
|
||||
texture.buildIdToObject();
|
||||
|
||||
if (texture.instance) {
|
||||
texture.loaded = true;
|
||||
|
||||
this.resolveDependencies(texture);
|
||||
|
||||
texture.buildIdToObject();
|
||||
|
||||
GameLib.Event.EmitInstanceEvents(texture);
|
||||
}
|
||||
if (texture.loaded) {
|
||||
try {
|
||||
texture.createInstance();
|
||||
this.resolveDependencies(texture);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
|
@ -688,34 +699,47 @@ GameLib.System.Linking.prototype.imageInstanceCreated = function(data) {
|
|||
*/
|
||||
var textures = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Texture]);
|
||||
|
||||
var materials = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Material]);
|
||||
//var materials = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Material]);
|
||||
|
||||
/**
|
||||
* For each material that uses this texture
|
||||
*/
|
||||
/**
|
||||
* Find all textures which use this image
|
||||
*/
|
||||
textures.map(function(texture){
|
||||
|
||||
materials.map(function(material){
|
||||
if (texture.image === data.image ||
|
||||
texture.images.indexOf(data.image) !== -1
|
||||
) {
|
||||
|
||||
var materialNeedsUpdate = false;
|
||||
/**
|
||||
* Ok - this image is in use
|
||||
*/
|
||||
texture.updateInstance();
|
||||
|
||||
for (var property in material) {
|
||||
if (material.hasOwnProperty(property) &&
|
||||
material[property] === texture) {
|
||||
materialNeedsUpdate = true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Find all materials that use this texture
|
||||
* This is no longer necessary - because texture updateInstance should notify materials when its image changes
|
||||
*/
|
||||
// materials.map(function(material){
|
||||
//
|
||||
// var materialNeedsUpdate = false;
|
||||
//
|
||||
// for (var property in material) {
|
||||
// if (material.hasOwnProperty(property) &&
|
||||
// material[property] === texture) {
|
||||
// materialNeedsUpdate = true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (materialNeedsUpdate) {
|
||||
// material.updateInstance();
|
||||
// }
|
||||
//
|
||||
// });
|
||||
|
||||
if (materialNeedsUpdate) {
|
||||
material.updateInstance();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
GameLib.System.Linking.prototype.solverInstanceCreated = function(data) {
|
||||
|
|
|
@ -480,15 +480,6 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
|
|||
}
|
||||
}
|
||||
|
||||
if (runtimeComponent instanceof GameLib.D3.Image) {
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.LOAD_IMAGE,
|
||||
{
|
||||
image : runtimeComponent
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (runtimeComponent) {
|
||||
loaded.push(runtimeComponent);
|
||||
}
|
||||
|
@ -811,9 +802,11 @@ GameLib.System.Storage.prototype.imageUploadComplete = function(data) {
|
|||
* Overrride this image if possible
|
||||
* @type {GameLib.D3.Image}
|
||||
*/
|
||||
image = GameLib.D3.Image.FromObject(this.graphics, imageData);
|
||||
GameLib.D3.Image.FromObject(this.graphics, imageData);
|
||||
|
||||
} else {
|
||||
image = runtimeImages.reduce(
|
||||
|
||||
function(result, runtimeImage){
|
||||
|
||||
if (imageData.id === runtimeImage.id) {
|
||||
|
@ -825,17 +818,10 @@ GameLib.System.Storage.prototype.imageUploadComplete = function(data) {
|
|||
},
|
||||
null
|
||||
);
|
||||
|
||||
image.updateInstance();
|
||||
}
|
||||
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.LOAD_IMAGE,
|
||||
{
|
||||
image : image,
|
||||
createTexture : true
|
||||
}
|
||||
);
|
||||
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
|
@ -856,13 +842,6 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) {
|
|||
|
||||
var image = GameLib.D3.Image.FromObject(this.graphics, imageData);
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.LOAD_IMAGE,
|
||||
{
|
||||
image : image
|
||||
}
|
||||
);
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.COMPONENT_CREATED,
|
||||
{
|
||||
|
@ -1052,7 +1031,7 @@ GameLib.System.Storage.prototype.loadImage = function(data) {
|
|||
window.URL.revokeObjectURL(url);
|
||||
|
||||
image.instance = img;
|
||||
image.loaded = true;
|
||||
|
||||
image.publish(
|
||||
GameLib.Event.IMAGE_INSTANCE_CREATED,
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ GameLib.Vector2 = function (
|
|||
}
|
||||
this.grain = grain;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.Vector2.prototype = Object.create(GameLib.API.Vector2.prototype);
|
||||
|
@ -48,22 +48,10 @@ GameLib.Vector2.prototype.constructor = GameLib.Vector2;
|
|||
|
||||
/**
|
||||
* Creates an instance vector2
|
||||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.Vector2.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
instance.x = this.x;
|
||||
instance.y = this.y;
|
||||
} else {
|
||||
instance = new THREE.Vector2(this.x, this.y);
|
||||
}
|
||||
|
||||
return instance;
|
||||
GameLib.Vector2.prototype.createInstance = function() {
|
||||
this.instance = new THREE.Vector2(this.x, this.y);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -71,7 +59,8 @@ GameLib.Vector2.prototype.createInstance = function(update) {
|
|||
*/
|
||||
GameLib.Vector2.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
this.instance.x = this.x;
|
||||
this.instance.y = this.y;
|
||||
|
||||
if (this.parentObject &&
|
||||
this.parentObject.updateInstance) {
|
||||
|
|
|
@ -52,7 +52,7 @@ GameLib.Vector3 = function (
|
|||
}
|
||||
this.grain = grain;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.Vector3.prototype = Object.create(GameLib.API.Vector3.prototype);
|
||||
|
@ -64,23 +64,20 @@ GameLib.Vector3.prototype.constructor = GameLib.Vector3;
|
|||
*/
|
||||
GameLib.Vector3.prototype.createInstance = function() {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.graphics) {
|
||||
instance = new THREE.Vector3(
|
||||
this.instance = new THREE.Vector3(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z
|
||||
);
|
||||
} else if (this.physics) {
|
||||
instance = new CANNON.Vec3(
|
||||
this.instance = new CANNON.Vec3(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z
|
||||
)
|
||||
}
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,32 +42,23 @@ GameLib.Vector4 = function (
|
|||
}
|
||||
this.grain = grain;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.Vector4.prototype = Object.create(GameLib.API.Vector4.prototype);
|
||||
GameLib.Vector4.prototype.constructor = GameLib.Vector4;
|
||||
|
||||
/**
|
||||
* Creates an instance vector3
|
||||
* @param update
|
||||
* Creates an instance vector4
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.Vector4.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
instance.x = this.x;
|
||||
instance.y = this.y;
|
||||
instance.z = this.z;
|
||||
instance.w = this.w;
|
||||
} else {
|
||||
instance = new THREE.Quaternion(this.x, this.y, this.z, this.w);
|
||||
}
|
||||
|
||||
return instance;
|
||||
GameLib.Vector4.prototype.createInstance = function() {
|
||||
this.instance = new THREE.Quaternion(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.w
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -75,7 +66,10 @@ GameLib.Vector4.prototype.createInstance = function(update) {
|
|||
*/
|
||||
GameLib.Vector4.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
this.instance.x = this.x;
|
||||
this.instance.y = this.y;
|
||||
this.instance.z = this.z;
|
||||
this.instance.w = this.w;
|
||||
|
||||
if (this.parentObject &&
|
||||
this.parentObject.updateInstance) {
|
||||
|
|
Loading…
Reference in New Issue