Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange javascript instantiation
    primarykey
    data
    text
    <p>I'm trying to implement Stemkoskis excellent particle engine (<a href="http://stemkoski.github.io/Three.js/Particle-Engine.html" rel="nofollow">http://stemkoski.github.io/Three.js/Particle-Engine.html</a>) but with multiple instances of his "class". But the problem is that when adding multiple instances, all other instances gets the last added instances properties regarding tween size (sizeTween)</p> <p>Here is his source: <a href="http://stemkoski.github.io/Three.js/js/ParticleEngine.js" rel="nofollow">http://stemkoski.github.io/Three.js/js/ParticleEngine.js</a></p> <p>And instantiation: <a href="http://stemkoski.github.io/Three.js/js/ParticleEngineExamples.js" rel="nofollow">http://stemkoski.github.io/Three.js/js/ParticleEngineExamples.js</a></p> <p>I've tried to google up my knowledge about so called "classes" in javascript and all seems to make sense with the Tween instantiation class and all "classes" are using the 'this' pointer. But still it doesn't make sense that I cannot instantiate two different objects. I wonder if it has something to do with the shaders, but that doesn't make sense either since I can instantiate two different types of particles but it seems to be the Tween that stays the same.</p> <p>I just wonder if someone can give me a hint if there are some issues with his code that makes multiple instances fail to be unique? (I've tried with Fireball and Snow (in the demo).</p> <p>Any hint would be great. Spent 8 hours today and I still don't get it.</p> <p>Here is my code where I use the code from ParticleEngine.js file. </p> <pre><code>// Clouds var cloud = new Cloud(); cloud.Create(0,0,0, 4, scene); objects.push(cloud); // this makes the Draw function gets called in each instance // Sun var sun = new Sun(); sun.Create(0,200,0, scene); objects.push(sun); // this makes the Draw function gets called in each instance // My own classes // Baseclass function Object3D() { this.mesh; Object3D.prototype.GetObject = function() { return this.mesh; }; Object3D.prototype.Draw = function() { //draw object }; } // Class that creates the snow function Cloud() { Object3D.call(this); Cloud.prototype.Create = function(x ,y ,z, s, scene) { var engine = new ParticleEngine(); engine.setValues( {positionStyle : Type.CUBE, positionBase : new THREE.Vector3( 0, 0, 0 ), positionSpread : new THREE.Vector3( 200, 0, 200 ), positionRadius : 0.1, velocityStyle : Type.CUBE, velocityBase : new THREE.Vector3( 0, -300, 0 ), velocitySpread : new THREE.Vector3( 150, 20, 150 ), accelerationBase : new THREE.Vector3( 0, -5,0 ), sizeTween : new Tween( [0, 0.25], [1, 10] ), colorBase : new THREE.Vector3(0.66, 1.0, 0.9), // H,S,L opacityTween : new Tween( [2, 3], [0.8, 0] ), blendStyle : THREE.AdditiveBlending, angleBase : 0, angleSpread : 720, angleVelocityBase : 0, angleVelocitySpread : 60, particleTexture : THREE.ImageUtils.loadTexture( 'textures/snowflake.png' ), particlesPerSecond : Math.random()*50+100, particleDeathAge : 10.5, // emitterDeathAge : 60 }); engine.initialize(); this.engine = engine; }; Cloud.prototype.Draw = function(time) { this.engine.update(time * 0.00005); }; } Cloud.prototype = new Object3D(); Cloud.prototype.constructor = Cloud; // Class that creates the fireball effect function Sun() { Object3D.call(this); Sun.prototype.Create = function(x, y, z, scene) { var sunEngine = new ParticleEngine(); sunEngine.setValues( { positionStyle : Type.SPHERE, positionBase : new THREE.Vector3(0, 200, 0), positionRadius : 2, sizeTween : new Tween( [0, 0.4], [1, 150] ), opacityTween : new Tween( [0.7, 1], [1, 0] ), colorBase : new THREE.Vector3(0.02, 1, 0.4), blendStyle : THREE.AdditiveBlending, velocityStyle : Type.SPHERE, speedBase : 40, speedSpread : 8, particleTexture : THREE.ImageUtils.loadTexture( 'textures/smokeparticle.png' ), particlesPerSecond : 60, particleDeathAge: 1.5, //emitterDeathAge : 60 }); sunEngine.initialize(); this.sunEngine = sunEngine; }; Sun.prototype.Draw = function(time) { this.sunEngine.update(time * 0.00005 ); }; } Sun.prototype = new Object3D(); Sun.prototype.constructor = Sun; </code></pre> <p>In the first instance (Cloud/Snow) I set:</p> <pre><code>sizeTween : new Tween( [0, 0.25], [1, 10] ), </code></pre> <p>And then I initiate the "Sun" class with this property:</p> <pre><code>sizeTween : new Tween( [0, 0.4], [1, 150] ), </code></pre> <p>And the clouds, initiated first, gets the same values for sizeTween as the last added one. And this is the core problem I've got.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload