Graphics Reference
In-Depth Information
How it works...
In this recipe, we use one of the standard ways JavaScript provides to create objects
that inherit from other objects. We defined the following:
THREE.FixedBoxGeometry.prototype=
Object.create( THREE.Geometry.prototype );
This code fragment tells JavaScript that THREE.FixedBoxGeometry is created, it
inherits all the properties and functions from THREE.Geometry , which has its own
constructor. This is the reason we also add the following call to our new object:
THREE.Geometry.call( this );
This calls the constructor of the THREE.Geometry object whenever our own custom
object is created.
There is more to prototype-based inheritance than what's explained in this short
recipe. If you want to know more about prototype-based inheritance, the Mozilla
guys have a great explanation on how inheritance using the prototype property
works at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inherit-
ance_and_the_prototype_chain .
There's more...
In this recipe, we've wrapped an existing Three.js object to create our custom object.
You can also apply this same approach for objects that are created completely
from scratch. For instance, you can create THREE.TerrainGeometry from the
JavaScript code we used in the Creating geometries from heightmaps recipe to cre-
ate a 3D terrain.
Search WWH ::




Custom Search