Menu - Top - Home - Donate to Me

H3DU.Scene3D

Back to documentation index.

H3DU.Scene3D(canvasOrContext)

An object that holds a rendering context for rendering 3D objects.

Parameters

Members

Methods

H3DU.Scene3D.BACK (constant)

Back side of a triangle. By default, triangles with clockwise winding are back-facing.

H3DU.Scene3D.CCW (constant)

Counterclockwise winding. A triangle has counterclockwise winding (or orientation) if its vertices are ordered in a counterclockwise path from the first to second to third to first vertex, in the triangle's two-dimensional projection in window coordinates (which roughly correspond to its location on the screen or frame buffer).

H3DU.Scene3D.CW (constant)

Clockwise winding, the opposite of counterclockwise winding.

H3DU.Scene3D.FRONT (constant)

Front side of a triangle. By default, triangles with counterclockwise winding are front-facing.

H3DU.Scene3D.FRONT_AND_BACK (constant)

Back and front sides of a triangle.

H3DU.Scene3D.NONE (constant)

No face culling.

H3DU.Scene3D#shapes

Deprecated: Shapes should now be managed in H3DU.Batch3D objects, rather than through this class.

An array of shapes that are part of the scene.

H3DU.Scene3D#addShape(shape)

Deprecated: Use the addShape method of individual H3DU.Batch3D instances instead. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Adds a 3D shape to this scene. 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

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#clear()

Clears the color, depth, and stencil buffers used in this scene, if any.

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#clearDepth()

Clears the depth buffer used in this scene, if any.

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#createBuffer()

Creates a frame buffer object associated with this scene.

Return Value

A buffer with the same size as this scene. (Type: H3DU.FrameBuffer)

H3DU.Scene3D#cullFace(value)

Specifies which kinds of triangle faces are culled (not drawn) when rendering this scene.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#dispose()

Disposes all resources used by this object.

Return Value

This method doesn't return a value. (Type: void)

H3DU.Scene3D#frontFace(value)

Specifies the winding of front faces.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#getAspect()

Gets the ratio of viewport width to viewport height for this scene (getWidth() divided by getHeight()). Note that if auto-resizing is enabled, this value may change after each call to the render() method.

Return Value

Aspect ratio, or 1 if height is 0. (Type: number)

H3DU.Scene3D#getAutoResize()

Gets whether to check whether to resize the canvas when the render() method is called.

Return Value

Return value. (Type: boolean)

H3DU.Scene3D#getCanvas()

Gets the HTML canvas associated with this scene.

Return Value

Return value. (Type: Object)

H3DU.Scene3D#getClearColor()

Gets the color used when clearing the screen each frame.

Return Value

An array of four numbers, from 0 through 1, specifying the red, green, blue, and alpha components of the color. (Type: Array.<number>)

H3DU.Scene3D#getClientAspect()

Gets the ratio of width to height for this scene, as actually displayed on the screen.

Return Value

Aspect ratio, or 1 if height is 0. (Type: number)

H3DU.Scene3D#getClientHeight()

Gets the height for this scene as actually displayed on the screen.

Return Value

Return value. (Type: number)

H3DU.Scene3D#getClientWidth()

Gets the width for this scene as actually displayed on the screen.

Return Value

Return value. (Type: number)

H3DU.Scene3D#getContext()

Returns the WebGL context associated with this scene.

Return Value

Return value. (Type: WebGLRenderingContext | WebGL2RenderingContext)

H3DU.Scene3D#getHeight()

Gets the viewport height for this scene. Note that if auto-resizing is enabled, this value may change after each call to the render() method.

Return Value

Return value. (Type: number)

H3DU.Scene3D#getLights()

Deprecated: Use the removeShape method of individual H3DU.Batch3D instances instead. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Gets the light sources used in this scene.

Return Value

The light sources used in this scene. (Type: H3DU.Lights)

H3DU.Scene3D#getProjectionMatrix()

Deprecated: Use H3DU.Batch3D instead. To get the projection matrix of a Batch3D, call its getProjectionMatrix method. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Gets the current projection matrix for this scene.

Return Value

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

H3DU.Scene3D#getViewMatrix()

Deprecated: Use H3DU.Batch3D instead. To get the view matrix of a Batch3D, call its getViewMatrix method. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Gets the current view matrix for this scene.

Return Value

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

H3DU.Scene3D#getWidth()

Gets the viewport width for this scene. Note that if auto-resizing is enabled, this value may change after each call to the render() method.

Return Value

Return value. (Type: number)

H3DU.Scene3D#loadAndMapTexture(texture)

Deprecated: Use the H3DU.TextureLoader method loadAndMapTexturesAll instead.

Loads a texture from an image URL and uploads it to a texture buffer object.

Parameters

Return Value

A promise that is resolved when the image is loaded successfully and uploaded to a texture buffer (the result will be an H3DU.Texture object), and is rejected when an error occurs. Returns null if the object is neither an H3DU.Texture nor a string. (Type: Promise)

H3DU.Scene3D#loadAndMapTextures(textureFiles, [resolve], [reject])

Deprecated: Use the H3DU.TextureLoader method loadAndMapTexturesAll instead.

Loads one or more textures from an image URL and uploads each of them to a texture buffer object.

Parameters

Return Value

A promise that is resolved when all the URLs in the textureFiles array are either resolved or rejected. The result will be an object with three properties: "successes", "failures", and "results". See H3DU.getPromiseResults. (Type: Promise)

H3DU.Scene3D#loadTexture(name)

Deprecated: Use the H3DU.TextureLoader method loadTexture or loadTexturesAll instead.

Loads a texture from an image URL.

Parameters

Return Value

A promise that is resolved when the image is loaded successfully (the result will be an H3DU.Texture object), and is rejected when an error occurs. (Type: Promise)

H3DU.Scene3D#makeShape(mesh)

Deprecated: Use the H3DU.Shape constructor instead.

Creates a buffer from a geometric mesh and returns a shape object.

Parameters

Return Value

The generated shape object. (Type: H3DU.Shape)

H3DU.Scene3D#primitiveCount()

Deprecated: Use the primitiveCount method of H3DU.Batch3D objects instead. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

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

Return Value

Return value. (Type: number)

H3DU.Scene3D#removeShape(shape)

Deprecated: Use the removeShape method of individual H3DU.Batch3D instances instead. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Removes all instances of a 3D shape from this scene.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#render(renderPasses)

Renders all shapes added to this scene. This is usually called in a render loop, such as H3DU.renderLoop.

NOTE: For compatibility, the "render" function with a null or omitted parameter will clear the color buffer and depth buffer. This compatibility option may be dropped in the future.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setAmbient(r, g, b, [a])

Deprecated: Use the Lights method setAmbient instead and the H3DU.Batch3D method getLights. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets the color of the scene's ambient light.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setAutoResize(value)

Sets whether to check whether to resize the canvas when the render() method is called.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setClearColor(r, g, b, [a])

Sets the color used when clearing the screen each frame. This color is black by default.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setDimensions(width, height)

Sets the viewport width and height for this scene.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setDirectionalLight(index, position, [diffuse], [specular])

Deprecated: Use the Lights method setDirectionalLight instead and the H3DU.Batch3D method getLights. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets a light source in this scene to a directional light.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setFrustum(left, right, bottom, top, near, far)

Deprecated: Instead of this method, use H3DU.Batch3D#setProjectionMatrix in conjunction with H3DU.Math.mat4frustum. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets this scene's projection matrix to a perspective projection that defines the view frustum, or the limits in the camera's view.

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

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setLightParams(index, params)

Deprecated: Use the Lights method setParams instead and the H3DU.Batch3D method getLights. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets parameters for a light in this scene.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

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

Deprecated: Instead of this method, use H3DU.Batch3D#setLookAt. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets this scene'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

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setOrtho(left, right, bottom, top, near, far)

Deprecated: Instead of this method, use H3DU.Batch3D#setProjectionMatrix in conjunction with H3DU.Math.mat4ortho. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets this scene's projection matrix to an orthographic projection. In this projection, the left clipping plane is parallel to the right clipping plane and the top to the bottom.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setOrtho2D(left, right, bottom, top)

Deprecated: Instead of this method, use H3DU.Batch3D#setProjectionMatrix in conjunction with H3DU.Math.mat4ortho2d. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets this scene's projection matrix to a 2D orthographic projection. The near and far clipping planes will be set to -1 and 1, respectively.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setOrtho2DAspect(left, right, bottom, top, [aspect])

Deprecated: Instead of this method, use H3DU.Batch3D#setProjectionMatrix in conjunction with H3DU.Math.mat4ortho2dAspect. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets this scene's projection matrix to a 2D orthographic projection. 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

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setOrthoAspect(left, right, bottom, top, near, far, [aspect])

Deprecated: Instead of this method, use H3DU.Batch3D#setProjectionMatrix in conjunction with H3DU.Math.mat4orthoAspect. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets this scene's projection matrix to an orthographic projection. 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

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setPerspective(fov, aspect, near, far)

Deprecated: Instead of this method, use H3DU.Batch3D#setProjectionMatrix in conjunction with H3DU.Math.mat4perspective. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets this scene's projection matrix to a perspective projection.

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

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

Example

// Set the perspective projection. Camera has a 45-degree field of view
// and will see objects from 0.1 to 100 units away.
scene.setPerspective(45,scene.getClientAspect(),0.1,100);

H3DU.Scene3D#setPointLight(index, position, [diffuse], [specular])

Deprecated: Use the LightSource method setPointLight instead and the H3DU.Batch3D method getLights. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets a light source in this scene to a point light.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setProjectionMatrix(matrix)

Deprecated: Instead of this method, use H3DU.Batch3D#setProjectionMatrix. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets the projection matrix for this object. The projection matrix can also be set using the H3DU.Scene3D#setFrustum, H3DU.Scene3D#setOrtho, H3DU.Scene3D#setOrtho2D, and H3DU.Scene3D#setPerspective methods.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setUseDevicePixelRatio(value)

Sets whether to use the device's pixel ratio (if supported by the browser) in addition to the canvas's size when setting the viewport's dimensions.

When this value changes, the H3DU.Scene3D will automatically adjust the viewport.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#setViewMatrix(matrix)

Deprecated: Instead of this method, use H3DU.Batch3D#setViewMatrix in conjunction with H3DU.Math.mat4ortho2dAspect. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Sets this scene's view matrix. The view matrix can also be set using the H3DU.Scene3D#setLookAt method.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#useFilter(filterProgram)

Deprecated: Use the H3DU.Batch3D.forFilter method to create a batch for rendering filter effects from a frame buffer, or use the H3DU.Batch3D.useShader method. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

Uses a shader program to apply a texture filter after the scene is rendered.

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#useProgram(program)

Deprecated: Instead of this method, use the "setShader" program of individual shapes to set the shader programs they use.

Has no effect. (In previous versions, this method changed the active shader program for this scene and prepared this object for the new program.)

Parameters

Return Value

This object. (Type: H3DU.Scene3D)

H3DU.Scene3D#vertexCount()

Deprecated: Use the vertexCount method of H3DU.Batch3D objects instead. For compatibility, existing code that doesn't use H3DU.Batch3D can still call this method until it renders a custom H3DU.Batch3D. This compatibility behavior may be dropped in the future.

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

Return Value

Return value. (Type: number)

Back to documentation index.