Graphics Reference
In-Depth Information
How to do it...
Extending Three.js with a custom geometry is fairly easy and only takes a couple of
simple steps:
1. The first thing we need to do is create a new JavaScript object that contains
the logic and properties of our new Three.js geometry. For this recipe, we'll
create FixedBoxGeometry , which acts exactly like THREE.BoxGeometry
but uses the same values for its height, width, and depth. For this recipe, we
create this new object in the setupCustomObject function:
function setupCustomObject() {
// First define the object.
THREE.FixedBoxGeometry = function (
width, segments) {
// first call the parent constructor
THREE.Geometry.call( this );
this.width = width;
this.segments = segments;
// we need to set
// - vertices in the parent object
// - faces in the parent object
// - uv mapping in the parent
object
// normally we'd create them here
ourselves
// in this case, we just reuse the
once
// from the boxgeometry.
var boxGeometry = new
THREE.BoxGeometry(
this.width,
this.width,
this.width, this.segments,
this.segments);
this.vertices =
boxGeometry.vertices;
this.faces = boxGeometry.faces;
Search WWH ::




Custom Search