parent particle engine

beta.r3js.org
-=yb4f310 2018-01-14 14:13:35 +01:00
parent 3c67d28eff
commit 3f8bec4c8e
7 changed files with 63 additions and 138 deletions

View File

@ -21,7 +21,7 @@
* @param scaleType
* @param rotationType
* @param rotationFn
* @param parentEngine
* @param parentParticleEngine
* @param parentEntity
* @constructor
*/
@ -47,7 +47,7 @@ GameLib.D3.API.Particle = function(
rotationType,
rotation,
rotationFn,
parentEngine,
parentParticleEngine,
parentEntity
) {
@ -156,10 +156,10 @@ GameLib.D3.API.Particle = function(
}
this.rotationFn = rotationFn;
if (GameLib.Utils.UndefinedOrNull(parentEngine)) {
parentEngine = null;
if (GameLib.Utils.UndefinedOrNull(parentParticleEngine)) {
parentParticleEngine = null;
}
this.parentEngine = parentEngine;
this.parentParticleEngine = parentParticleEngine;
GameLib.API.Component.call(
this,
@ -209,7 +209,7 @@ GameLib.D3.API.Particle.FromObject = function(objectParticle) {
objectParticle.rotationType,
GameLib.API.Vector3.FromObject(objectParticle.rotation),
objectParticle.rotationFn,
objectParticle.parentEngine,
objectParticle.parentParticleEngine,
objectParticle.parentEntity
);

View File

@ -32,27 +32,17 @@ GameLib.D3.ParticleEngine = function(
apiParticleEngine.parentEntity
);
if (this.position instanceof GameLib.API.Vector3) {
this.position = new GameLib.Vector3(
graphics,
this.position,
this
);
} else {
console.warn('position not instance of API.Vector3');
throw new Error('position not instance of API.Vector3');
}
this.position = new GameLib.Vector3(
graphics,
this.position,
this
);
if (this.direction instanceof GameLib.API.Vector3) {
this.direction = new GameLib.Vector3(
graphics,
this.direction,
this
);
} else {
console.warn('direction not instance of API.Vector3');
throw new Error('direction not instance of API.Vector3');
}
this.direction = new GameLib.Vector3(
graphics,
this.direction,
this
);
if (this.camera instanceof GameLib.D3.API.Camera) {
this.camera = new GameLib.D3.Camera(

View File

@ -39,7 +39,7 @@ GameLib.D3.Particle = function(
apiParticle.rotationType,
apiParticle.rotation,
apiParticle.rotationFn,
apiParticle.parentEngine,
apiParticle.parentParticleEngine,
apiParticle.parentEntity
);
@ -50,55 +50,35 @@ GameLib.D3.Particle = function(
)
}
if (this.positionOffset instanceof GameLib.API.Vector3) {
this.positionOffset = new GameLib.Vector3(
graphics,
this.positionOffset,
this
);
} else {
console.warn('positionOffset not instance of API.Vector3');
throw new Error('positionOffset not instance of API.Vector3');
}
this.positionOffset = new GameLib.Vector3(
graphics,
this.positionOffset,
this
);
if (this.direction instanceof GameLib.API.Vector3) {
this.direction = new GameLib.Vector3(
graphics,
this.direction,
this
);
} else {
console.warn('direction not instance of API.Vector3');
throw new Error('direction not instance of API.Vector3');
}
this.direction = new GameLib.Vector3(
graphics,
this.direction,
this
);
if (this.scale instanceof GameLib.API.Vector3) {
this.scale = new GameLib.Vector3(
graphics,
this.scale,
this
);
} else {
console.warn('scale not instance of API.Vector3');
throw new Error('scale not instance of API.Vector3');
}
this.scale = new GameLib.Vector3(
graphics,
this.scale,
this
);
if (this.rotation instanceof GameLib.API.Vector3) {
this.rotation = new GameLib.Vector3(
graphics,
this.rotation,
this
);
} else {
console.warn('rotation not instance of API.Vector3');
throw new Error('rotation not instance of API.Vector3');
}
this.rotation = new GameLib.Vector3(
graphics,
this.rotation,
this
);
GameLib.Component.call(
this,
{
mesh : GameLib.D3.Mesh,
parentEngine : GameLib.D3.ParticleEngine
parentParticleEngine : GameLib.D3.ParticleEngine
}
);
@ -198,7 +178,7 @@ GameLib.D3.Particle.prototype.cloneInstance = function() {
var clone = GameLib.Component.prototype.cloneInstance.call(this);
clone.position = this.parentEngine.position.instance.clone();
clone.position = this.parentParticleEngine.position.instance.clone();
clone.material = this.mesh.materials[0].instance.clone();
@ -365,7 +345,7 @@ GameLib.D3.Particle.prototype.toApiObject = function() {
this.rotationType,
this.rotation.toApiObject(),
this.rotationFn,
GameLib.Utils.IdOrNull(this.parentEngine),
GameLib.Utils.IdOrNull(this.parentParticleEngine),
GameLib.Utils.IdOrNull(this.parentEntity)
);

View File

@ -64,6 +64,10 @@ GameLib.EntityManager.prototype.createInstance = function() {
GameLib.Component.prototype.createInstance.call(this);
};
GameLib.EntityManager.prototype.updateInstance = function() {
console.log('todo: entitymanager updateInstance()')
};
GameLib.EntityManager.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.Entity) {
this.addEntity(data.component);

View File

@ -410,18 +410,23 @@ GameLib.System.Input.prototype.registerMouseControls = function(mouseControl) {
);
};
/**
* TODO: change the input mode so that when in 'edit' mode - editor controls take effect only, otherwise the normal
* TODO: keyboard / mouse /touch controls are in effect
* @param editorControl
*/
GameLib.System.Input.prototype.registerEditorControls = function(editorControl) {
/**
* If we already have mouse controls, we don't want to add another event listener onto the DOM
* In the 'Flammentraum' example, we need the mouse controls
*/
this.mouseControls.map(
function(mouseControl) {
if (mouseControl.domElement.instance === editorControl.domElement.instance) {
this.deRegisterMouseControls(mouseControl);
}
}.bind(this)
);
// this.mouseControls.map(
// function(mouseControl) {
// if (mouseControl.domElement.instance === editorControl.domElement.instance) {
// this.deRegisterMouseControls(mouseControl);
// }
// }.bind(this)
// );
/**
* If we already have keyboard controls, we don't want to add another event listener onto the DOM

View File

@ -669,13 +669,13 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) {
}
if (
data.component.parentEngine &&
typeof data.component.parentEngine === 'string'
data.component.parentParticleEngine &&
typeof data.component.parentParticleEngine === 'string'
) {
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PARTICLE_ENGINE).map(
function (particleEngine) {
if (data.component.parentEngine === particleEngine.id) {
data.component.parentEngine = particleEngine;
if (data.component.parentParticleEngine === particleEngine.id) {
data.component.parentParticleEngine = particleEngine;
}
}
);

View File

@ -6,9 +6,6 @@
* @param onImageLoaded
* @param onImageProgress
* @param onImageError
* @param onComponentLoaded
* @param onComponentProgress
* @param onComponentError
* @constructor
*/
GameLib.System.Storage = function(
@ -17,10 +14,7 @@ GameLib.System.Storage = function(
apiUploadUrl,
onImageLoaded,
onImageProgress,
onImageError,
onComponentLoaded,
onComponentProgress,
onComponentError
onImageError
) {
GameLib.System.call(
this,
@ -53,21 +47,6 @@ GameLib.System.Storage = function(
}
this.onImageError = onImageError;
if (GameLib.Utils.UndefinedOrNull(onComponentLoaded)) {
onComponentLoaded = null;
}
this.onComponentLoaded = onComponentLoaded;
if (GameLib.Utils.UndefinedOrNull(onComponentProgress)) {
onComponentProgress = null;
}
this.onComponentProgress = onComponentProgress;
if (GameLib.Utils.UndefinedOrNull(onComponentError)) {
onComponentError = null;
}
this.onComponentError = onComponentError;
this.loaded = [];
this.loading = [];
this.failed = [];
@ -301,10 +280,6 @@ GameLib.System.Storage.prototype.createRuntimeObject = function(responseText, cl
var object = JSON.parse(responseText);
} catch (errorObject) {
if (this.onComponentError) {
this.onComponentError(errorObject);
}
if (clientErrorCallback) {
clientErrorCallback({
message : errorObject.message || 'JSON parse error'
@ -321,10 +296,6 @@ GameLib.System.Storage.prototype.createRuntimeObject = function(responseText, cl
if (object.result !== 'success') {
if (this.onComponentError) {
this.onComponentError(id, object);
}
if (clientErrorCallback) {
clientErrorCallback({
message : object.message || 'Server load error'
@ -528,10 +499,6 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
}
);
if (__system.onComponentLoaded) {
__system.onComponentLoaded(runtimeComponent);
}
if (__system.loading.length === __system.loaded.length) {
console.log('loaded ' + __system.loaded.length + ' components');
@ -552,33 +519,12 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
}(this);
xhr.onprogress = function(__id) {
return function (progressEvent) {
var progress = 0;
if (progressEvent.total !== 0) {
progress = Math.round(Number(progressEvent.loaded / progressEvent.total) * 100);
}
if (this.onComponentProgress) {
this.onComponentProgress(__id, progress)
}
}.bind(this);
}(id);
xhr.onerror = function(__id) {
return function (error) {
console.warn('component load failed for component ID ' + __id);
if (this.onComponentError) {
this.onComponentError(__id, error)
}
if (clientErrorCallback) {
clientErrorCallback({
message : 'xhr request failure'
})
clientErrorCallback(error || {message:'xhr failure'})
}
}.bind(this);
}(id);