BoxBufferGeometry, PlaneBufferGeometry lack default values, resulting in invalid vertex data

Description of the problem

Creating a BoxBufferGeometry() with anything less than all first three parameters (width, height, depth) results in an instance that has its attributes.position partially to completely filled with NaN.
jsFiddles: rev dev – check console for both of them
Doing so with BoxGeometry results in box.vertices with just one to four Vector3 elements, depending on how many parameters were supplied.

The same is also true for PlaneBufferGeometry and PlaneGeometry:

function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
BufferGeometry.call( this );
this.type = ‘PlaneBufferGeometry’;
this.parameters = {
width: width,
height: height,
widthSegments: widthSegments,
heightSegments: heightSegments
};
var width_half = width / 2;
var height_half = height / 2;

width and height are never set.

Other geometries avoid this by having defaults, for comparison:

radius = radius || 50;
segments = segments !== undefined ? Math.max( 3, segments ) : 8;
thetaStart = thetaStart !== undefined ? thetaStart : 0;
thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;

radiusTop = radiusTop !== undefined ? radiusTop : 20;
radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
height = height !== undefined ? height : 100;
radialSegments = Math.floor( radialSegments ) || 8;
heightSegments = Math.floor( heightSegments ) || 1;
openEnded = openEnded !== undefined ? openEnded : false;
thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
thetaLength = thetaLength !== undefined ? thetaLength : 2.0 * Math.PI;
Three.js version
  • Dev
  • r87
Browser
  • All of them
OS
  • All of them
Hardware Requirements (graphics card, VR Device, …)

Author: Fantashit

1 thought on “BoxBufferGeometry, PlaneBufferGeometry lack default values, resulting in invalid vertex data

  1. Good find! I think it can’t hurt to define some default values. Maybe the following:

    BoxBufferGeometry: 10 for width, height and depth
    PlaneBufferGeometry: 10 for width, height

    @mrdoob @WestLangley Are these values okay for you?

    We also need to update the docs.

Comments are closed.