abandon pre-create idea
parent
87051a584d
commit
ee72894565
|
@ -128,7 +128,7 @@ GameLib.Component.prototype.performInstanceCreation = function() {
|
||||||
|
|
||||||
GameLib.Component.prototype.createInstance = function() {
|
GameLib.Component.prototype.createInstance = function() {
|
||||||
|
|
||||||
console.log('create instance : '+ this.name);
|
// console.log('create instance : '+ this.name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When you do actually call 'createInstance' - it is wise to state we are no longer delayed - we assume the caller
|
* When you do actually call 'createInstance' - it is wise to state we are no longer delayed - we assume the caller
|
||||||
|
|
|
@ -114,7 +114,7 @@ GameLib.D3.API.ParticleEngine = function(
|
||||||
this.distanceType = distanceType;
|
this.distanceType = distanceType;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(minDistance)) {
|
if (GameLib.Utils.UndefinedOrNull(minDistance)) {
|
||||||
minDistance = 1;
|
minDistance = 0;
|
||||||
}
|
}
|
||||||
this.minDistance = minDistance;
|
this.minDistance = minDistance;
|
||||||
|
|
||||||
|
|
|
@ -158,53 +158,57 @@ GameLib.D3.ParticleEngine.prototype.createInstance = function() {
|
||||||
|
|
||||||
this.frequency = Number(1 / this.particlesPerSecond);
|
this.frequency = Number(1 / this.particlesPerSecond);
|
||||||
|
|
||||||
this.parentMesh = null;
|
var apiMesh = new GameLib.D3.API.Mesh(
|
||||||
|
null,
|
||||||
|
GameLib.D3.Mesh.MESH_TYPE_PLANE,
|
||||||
|
'Particle Mesh',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
this.materials,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
for (var i = 0; i < this.particlesPerSecond; i++) {
|
this.parentMesh = new GameLib.D3.Mesh.Plane(
|
||||||
|
this.graphics,
|
||||||
|
apiMesh,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
if (i === 0) {
|
|
||||||
|
|
||||||
var apiMesh = new GameLib.D3.API.Mesh(
|
// for (var i = 0; i < this.particlesPerSecond; i++) {
|
||||||
null,
|
//
|
||||||
GameLib.D3.Mesh.MESH_TYPE_PLANE,
|
// if (i === 0) {
|
||||||
'Particle Mesh',
|
//
|
||||||
null,
|
//
|
||||||
null,
|
//
|
||||||
this.materials,
|
//
|
||||||
null
|
// this.parentMesh.useQuaternion = false;
|
||||||
);
|
//
|
||||||
|
// this.parentMesh.position.setFrom(this.position);
|
||||||
|
// this.parentMesh.rotation.setFrom(this.rotation);
|
||||||
|
// this.parentMesh.scale.setFrom(this.scale);
|
||||||
|
//
|
||||||
|
// this.parentMesh.instance.lookAt(this.lookAt.instance);
|
||||||
|
//
|
||||||
|
// this.meshes.push(this.parentMesh);
|
||||||
|
//
|
||||||
|
// } else {
|
||||||
|
//
|
||||||
|
// var mesh = this.parentMesh.clone();
|
||||||
|
//
|
||||||
|
// mesh.parentMesh = this.parentMesh;
|
||||||
|
//
|
||||||
|
// mesh.updateInstance();
|
||||||
|
//
|
||||||
|
// this.meshes.push(mesh);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
this.parentMesh = new GameLib.D3.Mesh.Plane(
|
// this.updateDistances();
|
||||||
this.graphics,
|
|
||||||
apiMesh,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1
|
|
||||||
);
|
|
||||||
|
|
||||||
this.parentMesh.useQuaternion = false;
|
|
||||||
|
|
||||||
this.parentMesh.position.setFrom(this.position);
|
|
||||||
this.parentMesh.rotation.setFrom(this.rotation);
|
|
||||||
this.parentMesh.scale.setFrom(this.scale);
|
|
||||||
|
|
||||||
this.meshes.push(this.parentMesh);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
var mesh = this.parentMesh.clone();
|
|
||||||
|
|
||||||
mesh.parentMesh = this.parentMesh;
|
|
||||||
|
|
||||||
mesh.updateInstance();
|
|
||||||
|
|
||||||
this.meshes.push(mesh);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateDistances();
|
|
||||||
|
|
||||||
this.instance = true;/* {
|
this.instance = true;/* {
|
||||||
parentMesh : this.parentMesh.instance,
|
parentMesh : this.parentMesh.instance,
|
||||||
|
@ -226,41 +230,41 @@ GameLib.D3.ParticleEngine.prototype.createInstance = function() {
|
||||||
GameLib.Component.prototype.createInstance.call(this);
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.ParticleEngine.prototype.updateDistances = function() {
|
// GameLib.D3.ParticleEngine.prototype.updateDistances = function() {
|
||||||
|
//
|
||||||
var distanceGrain = 1;
|
// var distanceGrain = 1;
|
||||||
|
//
|
||||||
if (this.particlesPerSecond > 1) {
|
// if (this.particlesPerSecond > 1) {
|
||||||
distanceGrain = Number(1 / (this.particlesPerSecond - 1));
|
// distanceGrain = Number(1 / (this.particlesPerSecond - 1));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
var minDistance = this.direction.clone().multiply(this.minDistance, true);
|
// var minDistance = this.direction.clone().multiply(this.minDistance, true);
|
||||||
minDistance.parentObject = null;
|
// minDistance.parentObject = null;
|
||||||
minDistance.updateInstance();
|
// minDistance.updateInstance();
|
||||||
|
//
|
||||||
var maxDistance = this.direction.clone().multiply(this.maxDistance, true);
|
// var maxDistance = this.direction.clone().multiply(this.maxDistance, true);
|
||||||
maxDistance.parentObject = null;
|
// maxDistance.parentObject = null;
|
||||||
maxDistance.updateInstance();
|
// maxDistance.updateInstance();
|
||||||
|
//
|
||||||
this.meshes.map(
|
// this.meshes.map(
|
||||||
function(mesh, index) {
|
// function(mesh, index) {
|
||||||
|
//
|
||||||
if (index === 0) {
|
// if (index === 0) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
var distance = minDistance.instance.lerp(maxDistance.instance, (index * distanceGrain));
|
// var distance = minDistance.instance.lerp(maxDistance.instance, (index * distanceGrain));
|
||||||
|
//
|
||||||
mesh.position.x = this.direction.x * (distance.x);
|
// mesh.position.x = this.direction.x * (distance.x);
|
||||||
mesh.position.y = this.direction.y * (distance.y);
|
// mesh.position.y = this.direction.y * (distance.y);
|
||||||
mesh.position.z = this.direction.z * (distance.z);
|
// mesh.position.z = this.direction.z * (distance.z);
|
||||||
|
//
|
||||||
mesh.updateInstancePosition();
|
// mesh.updateInstancePosition();
|
||||||
|
//
|
||||||
}.bind(this)
|
// }.bind(this)
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
};
|
// };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the instance with the current state
|
* Updates the instance with the current state
|
||||||
|
@ -283,7 +287,7 @@ GameLib.D3.ParticleEngine.prototype.updateInstance = function(property) {
|
||||||
this.parentMesh.scale.setFrom(this.scale);
|
this.parentMesh.scale.setFrom(this.scale);
|
||||||
this.parentMesh.updateInstanceScale();
|
this.parentMesh.updateInstanceScale();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'particlesPerSecond') {
|
if (property === 'particlesPerSecond') {
|
||||||
|
|
||||||
console.log('particles per second or max distance');
|
console.log('particles per second or max distance');
|
||||||
|
@ -305,7 +309,14 @@ GameLib.D3.ParticleEngine.prototype.updateInstance = function(property) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'minDistance' || property === 'maxDistance') {
|
if (property === 'minDistance' || property === 'maxDistance') {
|
||||||
this.updateDistances();
|
// this.updateDistances();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'lookAt') {
|
||||||
|
this.lookAt.instance.x = this.lookAt.x;
|
||||||
|
this.lookAt.instance.y = this.lookAt.y;
|
||||||
|
this.lookAt.instance.z = this.lookAt.z;
|
||||||
|
this.parentMesh.instance.lookAt(this.lookAt.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
//GameLib.Event.Emit(GameLib.Event.PARTICLE_INSTANCE_UPDATED, {component:this});
|
//GameLib.Event.Emit(GameLib.Event.PARTICLE_INSTANCE_UPDATED, {component:this});
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
/**
|
/**
|
||||||
* System takes care of updating all the entities (based on their component data)
|
* System takes care of updating all the entities (based on their component data)
|
||||||
* @param graphics
|
* @param graphics
|
||||||
|
* @param camera
|
||||||
* @param apiSystem GameLib.API.System
|
* @param apiSystem GameLib.API.System
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.System.Particle = function(
|
GameLib.System.Particle = function(
|
||||||
graphics,
|
graphics,
|
||||||
|
camera,
|
||||||
apiSystem
|
apiSystem
|
||||||
) {
|
) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
@ -23,6 +25,8 @@ GameLib.System.Particle = function(
|
||||||
*/
|
*/
|
||||||
this.engines = [];
|
this.engines = [];
|
||||||
|
|
||||||
|
this.camera = camera;
|
||||||
|
|
||||||
this.totalTime = 0;
|
this.totalTime = 0;
|
||||||
|
|
||||||
this.beforeRenderSubscription = null;
|
this.beforeRenderSubscription = null;
|
||||||
|
@ -40,6 +44,8 @@ GameLib.System.Particle.prototype.start = function() {
|
||||||
|
|
||||||
this.particleEngines = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine);
|
this.particleEngines = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine);
|
||||||
|
|
||||||
|
//this.camera = GameLib.EntityManager.Instance.defaultRenderer.camera;
|
||||||
|
|
||||||
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
|
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
|
||||||
GameLib.Event.INSTANCE_CREATED,
|
GameLib.Event.INSTANCE_CREATED,
|
||||||
this.instanceCreated.bind(this)
|
this.instanceCreated.bind(this)
|
||||||
|
@ -124,10 +130,19 @@ GameLib.System.Particle.prototype.beforeRender = function(data) {
|
||||||
|
|
||||||
particleEngine.elapsed += data.delta;
|
particleEngine.elapsed += data.delta;
|
||||||
|
|
||||||
if (particleEngine.elapsed > particleEngine.frequency) {
|
// var position = this.camera.position.instance.clone();
|
||||||
particleEngine.elapsed = 0;
|
// var lookAt = this.camera.lookAt.instance.clone();
|
||||||
console.log('change time');
|
//
|
||||||
}
|
// var direction = lookAt.sub(position).negate();
|
||||||
|
//
|
||||||
|
// particleEngine.lookAt.setFrom(direction);
|
||||||
|
// particleEngine.updateInstance('lookAt');
|
||||||
|
|
||||||
|
|
||||||
|
// if (particleEngine.elapsed > particleEngine.frequency) {
|
||||||
|
// particleEngine.elapsed = 0;
|
||||||
|
// console.log('change time');
|
||||||
|
// }
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue