Shape
An object that associates a geometric mesh (the shape of the object) with a transformation matrix (which defines the object’s position and size). See the “Creating Shapes” tutorial.
Parameters
mesh
(Type: MeshBuffer)
A mesh in the form of a buffer object. Cannot be null.
Methods
- copy
Makes a copy of this object. - getBounds
Finds a bounding box that holds all vertices in this shape. - getMatrix
Gets the transformation matrix used by this shape. - getMeshBuffer
Returns a reference to the mesh buffer used by this shape. - getTransform
Returns the transform used by this shape object. - getVisible
Gets whether this shape will be drawn on rendering. - primitiveCount
Gets the number of primitives (triangles, lines, and points) composed by all shapes in this scene. - setPosition
Sets the relative position of this shape from its original position. - setQuaternion
Sets this object’s rotation in the form of a quaternion. - setScale
Sets the scale of this shape relative to its original size. - setTransform
Sets this shape’s transformation to a copy of the given transformation. - setVisible
Sets whether this shape will be drawn on rendering. - vertexCount
Gets the number of vertices composed by all shapes in this scene.
Makes a copy of this object. The copied object will have its own version of the transform. The copied shape won’t have a parent.
Return Value
A copy of this object. (Type: Shape)
Finds a bounding box that holds all vertices in this shape. The bounding box is not guaranteed to be the tightest, and the box will be transformed to world space using this object’s transform.
Return Value
An array of six numbers describing an axis-aligned bounding box that fits all vertices in the shape. The first three numbers are the smallest-valued X, Y, and Z coordinates, and the last three are the largest-valued X, Y, and Z coordinates. If the shape has no vertices, returns the array [Inf, Inf, Inf, -Inf, -Inf, -Inf]. (Type: Array.<number>)
Gets the transformation matrix used by this shape. See Transform#getMatrix.
Return Value
The current transformation matrix. (Type: Array.<number>)
Returns a reference to the mesh buffer used by this shape.
Return Value
Return value. (Type: MeshBuffer)
Returns the transform used by this shape object. The transform won’t be copied.
Return Value
Return value. (Type: Transform)
Gets whether this shape will be drawn on rendering.
Return Value
True if this shape will be visible; otherwise, false. (Type: boolean)
Gets the number of primitives (triangles, lines, and points) composed by all shapes in this scene.
Return Value
Return value. (Type: number)
### Shape#setPosition(x, [y], [z])
Sets the relative position of this shape from its original position. See Transform#setPosition
Parameters
-
x
(Type: Array.<number>number)
The X coordinate. If “y” and “z” are null, undefined, or omitted, this is instead a 3-element array giving the X, Y, and Z coordinates, or a single number giving the coordinate for all three dimensions. y
(Type: number) (optional)
The Y coordinate. If “x” is an array, this parameter may be omitted.z
(Type: number) (optional)
The Z coordinate. If “x” is an array, this parameter may be omitted.
Return Value
This object. (Type: Shape)
Examples
// Set the relative position to 2 units along X axis, 4 units along Y axis, // and 5 units along Z axis shape.setPosition(2,4,5); // same, but passing an array shape.setPosition([2,4,5]);
Sets this object’s rotation in the form of a quaternion. See Transform#setQuaternion.
Parameters
quat
(Type: Array.<number>)
A four-element array describing the rotation.
Return Value
This object. (Type: Shape)
Examples
// rotate the shape 40 units about X axis, 20 units about Y axis, // and 50 units about Z axis shape.setQuaternion(H3DU.MathUtil.quatFromTaitBryan(40,20,50)); // rotate the shape 20 units about Y axis shape.setQuaternion(H3DU.MathUtil.quatFromAxisAngle(20,0,1,0));
### Shape#setScale(x, [y], [z])
Sets the scale of this shape relative to its original size. See Transform#setScale
Parameters
-
x
(Type: numberArray.<number>)
X axis scaling factor for this shape object. If “y” and “z” are null, undefined, or omitted, this is instead a 3-element array giving the scaling factors for the X, Y, and Z dimensions, respectively, or a single number giving the scaling factor for all three dimensions. y
(Type: number) (optional)
Y axis scaling factor for this shape object.z
(Type: number) (optional)
Z axis scaling factor for this shape object.
Return Value
This object. (Type: Shape)
Examples
// scale the shape by 2x in all axes shape.setScale(2,2,2); // same, but passing an array shape.setScale([2,2,2]);
### Shape#setTransform(transform)
Sets this shape’s transformation to a copy of the given transformation.
Parameters
transform
(Type: Transform)
The transformation to set to a copy of.
Return Value
This object. (Type: Shape)
Sets whether this shape will be drawn on rendering.
Parameters
value
(Type: boolean)
True if this shape will be visible; otherwise, false.
Return Value
This object. (Type: Shape)
Gets the number of vertices composed by all shapes in this scene.
Return Value
Return value. (Type: number)