Having a background in AS3/Away3D, I am new to THREE.js and I am trying to create a custom object class that extends THREE.Object3D for my scene. CustomObject will contain behavioral properties and methods, with each instance having its own data object determining its appearance and behavior. Keeping this code encapsulated will help tidy up my main.js file.
However, I am facing an issue where I can't directly add an instance of the class to my scene. Currently, I can only add the mesh using the CustomObject.getMesh() method. Is there a way to add the instance of the class directly to the scene for rendering? Below is a basic attempt I have made based on online resources and the /src directory:
function CustomObject(){
THREE.Object3D.call( this );
this.type = 'CustomObject';
this.geometry = new THREE.BoxGeometry( 540, 540, 14 );
this.mesh = new THREE.Mesh( this.geometry, new THREE.MeshLambertMaterial( { color: 0xff0000 } ) );
}
CustomObject.prototype = Object.create( THREE.Object3D.prototype );
CustomObject.prototype.constructor = THREE.Object3D;
CustomObject.prototype.getMesh = function(){
return this.mesh;
}
I am looking to directly add the CustomObject class to the scene for better object management. Any guidance on how this can be achieved would be greatly appreciated.
Thank you in advance!
David