Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save philogb/396146 to your computer and use it in GitHub Desktop.
Save philogb/396146 to your computer and use it in GitHub Desktop.
//I think that the main problem with the code is that
//Particle inherits from Object3D, but you couldn't reuse that same code to
//make another object inherit from Particle, since the original Particle constructor
//is overridden by Object3Ds. So my approach would be:
THREE.Particle = function (material) {
THREE.Object3D.call(this);
this.size = 1;
this.material = material;
};
THREE.Particle.prototype = new THREE.Object3D();
THREE.Particle.prototype.constructor = THREE.Particle;
var particle = new THREE.Particle();
alert(particle instanceof THREE.Object3D); // true
alert(particle instanceof THREE.Particle); // true
//...And here's a code that tests it completely:
var THREE = {};
THREE.Object3D = function(){};
THREE.Object3D.prototype.constructor = THREE.Object3D;
THREE.Particle = function (material) {
THREE.Object3D.call(this);
this.size = 1;
this.material = material;
};
THREE.Particle.prototype = new THREE.Object3D();
THREE.Particle.prototype.constructor = THREE.Particle;
var particle = new THREE.Particle();
alert(particle instanceof THREE.Object3D); // true
alert(particle instanceof THREE.Particle); // true
@mrdoob
Copy link

mrdoob commented May 10, 2010

True, I didn't tried doing another level. That does the trick! :D

THREE.Particle = function (material) {

    THREE.Object3D.call(this);

    this.size = 1,
    this.material = material;
}

THREE.Particle.prototype = new THREE.Object3D();
THREE.Particle.prototype.constructor = THREE.Particle;

THREE.Particle2 = function(material) {

    THREE.Particle.call(this, material);

    this.size = 3;
}

THREE.Particle2.prototype = new THREE.Particle();
THREE.Particle2.prototype.constructor = THREE.Particle2;

//

var particle = new THREE.Particle2();

alert(particle instanceof THREE.Object3D); // true
alert(particle instanceof THREE.Particle); // true
alert(particle instanceof THREE.Particle2); // true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment