# H3DU.Batch3D

### H3DU.Batch3D()

A `Batch3D`

represents a so-called "scene graph". It holds
3D objects which will be drawn to the screen, as well as the camera's projection, the camera's
position, and light sources to illuminate the 3D scene.

#### Parameters

### Methods

- addShape

Adds a 3D shape to this batch of shapes, at the end of the list of shapes. - forFilter

Creates a batch whose purpose is to render the contents of a frame buffer using a particular shader. - getLights

Gets the light sources used by this batch. - getProjectionMatrix

Gets the current projection matrix for this batch of shapes. - getProjectionViewMatrix

Gets the current projection matrix multiplied by the current view matrix for this batch of shapes. - getShape

Gets the shape or shape group located in this batch at the given index. - getViewMatrix

Gets the current view matrix for this batch of shapes. - ortho2DAspect

Uses a 2D orthographic projection for this batch. - orthoAspect

Uses an orthographic projection for this batch. - perspectiveAspect

Uses a perspective projection for this batch. - primitiveCount

Gets the number of primitives (triangles, lines, and points) composed by all shapes in this batch of shapes. - removeShape

Removes all instances of a 3D shape from this batch of shapes. - setLookAt

Sets this batch's view matrix to represent a camera view. - setProjectionMatrix

Sets the projection matrix for this batch. - setShape

Sets a shape or shape group at the given index in this batch. - setViewMatrix

Sets the current view matrix for this batch of shapes. - shapeCount

Returns the number of shapes and/or shape groups that are direct children of this batch. - vertexCount

Gets the number of vertices composed by all shapes in this batch of shapes.

### H3DU.Batch3D#addShape(shape)

Adds a 3D shape to this batch of shapes, at the end of the list of shapes. Its reference, not a copy, will be stored in the 3D scene's list of shapes. Its parent will be set to no parent.

#### Parameters

`shape`

(Type: H3DU.Shape | H3DU.ShapeGroup)

A 3D shape. Throws an error if null.

#### Return Value

This object. (Type: H3DU.Batch3D)

### (static) H3DU.Batch3D.forFilter(scene, fbo, shader)

Creates a batch whose purpose is to render the contents of a frame buffer using a particular shader. This is often used to apply a graphics filter to that frame buffer's contents. See the Graphics Filters tutorial.

#### Parameters

`scene`

(Type: H3DU.Scene3D)

Scene to associate with the returned batch.`fbo`

(Type: H3DU.FrameBufferInfo)

Identifies a frame buffer whose contents will be rendered to the batch.`shader`

(Type: H3DU.ShaderInfo)

Contains information about the shader to use when rendering the contents of the frame buffer

#### Return Value

The created batch. (Type: H3DU.Batch3D)

### H3DU.Batch3D#getLights()

Gets the light sources used by this batch.

#### Return Value

Return value. (Type: H3DU.Lights)

### H3DU.Batch3D#getProjectionMatrix()

Gets the current projection matrix for this batch of shapes.

#### Return Value

A 4x4 matrix used as the current projection matrix. (Type: Array.<number>)

### H3DU.Batch3D#getProjectionViewMatrix()

Gets the current projection matrix multiplied by the current view matrix for this batch of shapes.

#### Return Value

A 4x4 matrix used as the current projection-view matrix. (Type: Array.<number>)

### H3DU.Batch3D#getShape(index)

Gets the shape or shape group located in this batch at the given index.

#### Parameters

`index`

(Type: number)

Integer index, starting from 0, of the shape or shape group to set.

#### Return Value

The shape or shape group located in this batch at the given index, or null if none is found there. (Type: H3DU.Shape | H3DU.ShapeGroup)

### H3DU.Batch3D#getViewMatrix()

Gets the current view matrix for this batch of shapes.

#### Return Value

Return value. (Type: Array.<number>)

### H3DU.Batch3D#ortho2DAspect(l, r, b, t)

Uses a 2D orthographic projection for this batch. It will be adjusted to the scene's aspect ratio each time this batch is rendered.

The near and far clipping planes will be set to -1 and 1, respectively.

If the view rectangle's aspect ratio doesn't match the desired aspect ratio, the view rectangle will be centered on the 3D scene's viewport or otherwise moved and scaled so as to keep the entire view rectangle visible without stretching or squishing it.

#### Parameters

`l`

(Type: number)

Leftmost coordinate of the view rectangle.`r`

(Type: number)

Rightmost coordinate of the view rectangle. (Note that right can be greater than left or vice versa.)`b`

(Type: number)

Bottommost coordinate of the view rectangle.`t`

(Type: number)

Topmost coordinate of the view rectangle. (Note that top can be greater than bottom or vice versa.)

#### Return Value

This object. (Type: H3DU.Batch3D)

### H3DU.Batch3D#orthoAspect(l, r, b, t, e, f)

Uses an orthographic projection for this batch. It will be adjusted to the scene's aspect ratio each time this batch is rendered.

In this projection, the left clipping plane is parallel to the right clipping plane and the top to the bottom.

If the view rectangle's aspect ratio doesn't match the desired aspect ratio, the view rectangle will be centered on the 3D scene's viewport or otherwise moved and scaled so as to keep the entire view rectangle visible without stretching or squishing it.

#### Parameters

`l`

(Type: number)

Leftmost coordinate of the view rectangle.`r`

(Type: number)

Rightmost coordinate of the view rectangle. (Note that right can be greater than left or vice versa.)`b`

(Type: number)

Bottommost coordinate of the view rectangle.`t`

(Type: number)

Topmost coordinate of the view rectangle. (Note that top can be greater than bottom or vice versa.)`e`

(Type: number)

Distance from the camera to the near clipping plane. A positive value means the plane is in front of the viewer.`f`

(Type: number)

Distance from the camera to the far clipping plane. A positive value means the plane is in front of the viewer. (Note that near can be greater than far or vice versa.) The absolute difference between near and far should be as small as the application can accept.

#### Return Value

This object. (Type: H3DU.Batch3D)

### H3DU.Batch3D#perspectiveAspect(fov, near, far)

Uses a perspective projection for this batch. It will be adjusted to the scene's aspect ratio each time this batch is rendered.

For considerations when choosing the "near" and "far" parameters, see H3DU.Math.mat4perspective.

#### Parameters

`fov`

(Type: number)

Y axis field of view, in degrees. Should be less than 180 degrees. (The smaller this number, the bigger close objects appear to be. As a result, zooming out can be implemented by raising this value, and zooming in by lowering it.)`near`

(Type: number)

The distance from the camera to the near clipping plane. Objects closer than this distance won't be seen.`far`

(Type: number)

The distance from the camera to the far clipping plane. Objects beyond this distance will be too far to be seen.

#### Return Value

This object. (Type: H3DU.Batch3D)

### H3DU.Batch3D#primitiveCount()

Gets the number of primitives (triangles, lines, and points) composed by all shapes in this batch of shapes.

#### Return Value

Return value. (Type: number)

### H3DU.Batch3D#removeShape(shape)

Removes all instances of a 3D shape from this batch of shapes.

#### Parameters

`shape`

(Type: H3DU.Shape | H3DU.ShapeGroup)

The 3D shape to remove.

#### Return Value

This object. (Type: H3DU.Batch3D)

### H3DU.Batch3D#setLookAt(eye, [center], [up])

Sets this batch's view matrix to represent a camera view.
This method takes a camera's position (`eye`

), and the point the camera is viewing
(`center`

).

#### Parameters

`eye`

(Type: Array.<number>)

A 3-element vector specifying the camera position in world space.`center`

(Type: Array.<number>) (optional)

A 3-element vector specifying the point in world space that the camera is looking at. May be null or omitted, in which case the default is the coordinates (0,0,0).`up`

(Type: Array.<number>) (optional)

A 3-element vector specifying the direction from the center of the camera to its top. This parameter may be null or omitted, in which case the default is the vector (0, 1, 0), the vector that results when the camera is held upright. This vector must not point in the same or opposite direction as the camera's view direction. (For best results, rotate the vector (0, 1, 0) so it points perpendicular to the camera's view direction.)

#### Return Value

This object. (Type: H3DU.Batch3D)

### H3DU.Batch3D#setProjectionMatrix(mat)

Sets the projection matrix for this batch.

#### Parameters

`mat`

(Type: Array.<number>)

A 16-element matrix (4x4).

#### Return Value

This object. (Type: H3DU.Batch3D)

### H3DU.Batch3D#setShape(index, shape)

Sets a shape or shape group at the given index in this batch.

#### Parameters

`index`

(Type: number)

Integer index, starting from 0, to set the shape or shape group at.`shape`

(Type: H3DU.Shape | H3DU.ShapeGroup)

Shape object to set at the given index.

#### Return Value

This object. (Type: H3DU.Batch3D)

### H3DU.Batch3D#setViewMatrix(mat)

Sets the current view matrix for this batch of shapes.

#### Parameters

`mat`

(Type: Array.<number>)

A 4x4 matrix to use as the view matrix.

#### Return Value

This object. (Type: H3DU.Batch3D)

### H3DU.Batch3D#shapeCount()

Returns the number of shapes and/or shape groups that are direct children of this batch.

#### Return Value

Return value. (Type: number)

### H3DU.Batch3D#vertexCount()

Gets the number of vertices composed by all shapes in this batch of shapes.

#### Return Value

Return value. (Type: number)