abandon pre-create idea

beta.r3js.org
-=yb4f310 2017-11-06 10:17:01 +01:00
parent 87051a584d
commit ee72894565
4 changed files with 112 additions and 86 deletions

View File

@ -128,7 +128,7 @@ GameLib.Component.prototype.performInstanceCreation = 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

View File

@ -114,7 +114,7 @@ GameLib.D3.API.ParticleEngine = function(
this.distanceType = distanceType;
if (GameLib.Utils.UndefinedOrNull(minDistance)) {
minDistance = 1;
minDistance = 0;
}
this.minDistance = minDistance;

View File

@ -158,53 +158,57 @@ GameLib.D3.ParticleEngine.prototype.createInstance = function() {
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(
null,
GameLib.D3.Mesh.MESH_TYPE_PLANE,
'Particle Mesh',
null,
null,
this.materials,
null
);
// for (var i = 0; i < this.particlesPerSecond; i++) {
//
// if (i === 0) {
//
//
//
//
// 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.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.updateDistances();
this.instance = true;/* {
parentMesh : this.parentMesh.instance,
@ -226,41 +230,41 @@ GameLib.D3.ParticleEngine.prototype.createInstance = function() {
GameLib.Component.prototype.createInstance.call(this);
};
GameLib.D3.ParticleEngine.prototype.updateDistances = function() {
var distanceGrain = 1;
if (this.particlesPerSecond > 1) {
distanceGrain = Number(1 / (this.particlesPerSecond - 1));
}
var minDistance = this.direction.clone().multiply(this.minDistance, true);
minDistance.parentObject = null;
minDistance.updateInstance();
var maxDistance = this.direction.clone().multiply(this.maxDistance, true);
maxDistance.parentObject = null;
maxDistance.updateInstance();
this.meshes.map(
function(mesh, index) {
if (index === 0) {
return;
}
var distance = minDistance.instance.lerp(maxDistance.instance, (index * distanceGrain));
mesh.position.x = this.direction.x * (distance.x);
mesh.position.y = this.direction.y * (distance.y);
mesh.position.z = this.direction.z * (distance.z);
mesh.updateInstancePosition();
}.bind(this)
);
};
// GameLib.D3.ParticleEngine.prototype.updateDistances = function() {
//
// var distanceGrain = 1;
//
// if (this.particlesPerSecond > 1) {
// distanceGrain = Number(1 / (this.particlesPerSecond - 1));
// }
//
// var minDistance = this.direction.clone().multiply(this.minDistance, true);
// minDistance.parentObject = null;
// minDistance.updateInstance();
//
// var maxDistance = this.direction.clone().multiply(this.maxDistance, true);
// maxDistance.parentObject = null;
// maxDistance.updateInstance();
//
// this.meshes.map(
// function(mesh, index) {
//
// if (index === 0) {
// return;
// }
//
// var distance = minDistance.instance.lerp(maxDistance.instance, (index * distanceGrain));
//
// mesh.position.x = this.direction.x * (distance.x);
// mesh.position.y = this.direction.y * (distance.y);
// mesh.position.z = this.direction.z * (distance.z);
//
// mesh.updateInstancePosition();
//
// }.bind(this)
// );
//
// };
/**
* 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.updateInstanceScale();
}
if (property === 'particlesPerSecond') {
console.log('particles per second or max distance');
@ -305,7 +309,14 @@ GameLib.D3.ParticleEngine.prototype.updateInstance = function(property) {
}
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});

View File

@ -1,11 +1,13 @@
/**
* System takes care of updating all the entities (based on their component data)
* @param graphics
* @param camera
* @param apiSystem GameLib.API.System
* @constructor
*/
GameLib.System.Particle = function(
graphics,
camera,
apiSystem
) {
this.graphics = graphics;
@ -23,6 +25,8 @@ GameLib.System.Particle = function(
*/
this.engines = [];
this.camera = camera;
this.totalTime = 0;
this.beforeRenderSubscription = null;
@ -40,6 +44,8 @@ GameLib.System.Particle.prototype.start = function() {
this.particleEngines = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine);
//this.camera = GameLib.EntityManager.Instance.defaultRenderer.camera;
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED,
this.instanceCreated.bind(this)
@ -124,10 +130,19 @@ GameLib.System.Particle.prototype.beforeRender = function(data) {
particleEngine.elapsed += data.delta;
if (particleEngine.elapsed > particleEngine.frequency) {
particleEngine.elapsed = 0;
console.log('change time');
}
// var position = this.camera.position.instance.clone();
// var lookAt = this.camera.lookAt.instance.clone();
//
// 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)
)