H3DU.Scene3D
H3DU.Scene3D(canvasOrContext)
An object that holds a rendering context for rendering 3D objects.
Parameters
canvasOrContext
(Type: WebGLRenderingContext | WebGL2RenderingContext | Object)
A WebGL context to associate with this scene, or an HTML canvas element to create a WebGL context from, or an object, such as H3DU.Scene3D, that implements a no-argumentgetContext
method that returns a WebGL context.
Members
- BACK
Back side of a triangle. - CCW
Counterclockwise winding. - CW
Clockwise winding, the opposite of counterclockwise winding. - FRONT
Front side of a triangle. - FRONT_AND_BACK
Back and front sides of a triangle. - NONE
No face culling. - shapes
Deprecated: Shapes should now be managed in H3DU.Batch3D objects, rather than through this class.
Methods
- addShape
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. - clear
Clears the color, depth, and stencil buffers used in this scene, if any. - clearDepth
Clears the depth buffer used in this scene, if any. - createBuffer
Creates a frame buffer object associated with this scene. - cullFace
Specifies which kinds of triangle faces are culled (not drawn) when rendering this scene. - dispose
Disposes all resources used by this object. - frontFace
Specifies the winding of front faces. - getAspect
Gets the ratio of viewport width to viewport height for this scene (getWidth() divided by getHeight()). - getAutoResize
Gets whether to check whether to resize the canvas when the render() method is called. - getCanvas
Gets the HTML canvas associated with this scene. - getClearColor
Gets the color used when clearing the screen each frame. - getClientAspect
Gets the ratio of width to height for this scene, as actually displayed on the screen. - getClientHeight
Gets the height for this scene as actually displayed on the screen. - getClientWidth
Gets the width for this scene as actually displayed on the screen. - getContext
Returns the WebGL context associated with this scene. - getHeight
Gets the viewport height for this scene. - 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. - 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. - 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. - getWidth
Gets the viewport width for this scene. - loadAndMapTexture
Deprecated: Use the H3DU.TextureLoader method loadAndMapTexturesAll instead. - loadAndMapTextures
Deprecated: Use the H3DU.TextureLoader method loadAndMapTexturesAll instead. - loadTexture
Deprecated: Use the H3DU.TextureLoader method loadTexture or loadTexturesAll instead. - makeShape
Deprecated: Use the H3DU.Shape constructor instead. - primitiveCount
Deprecated: Use theprimitiveCount
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. - removeShape
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. - render
Renders all shapes added to this scene. - setAmbient
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. - setAutoResize
Sets whether to check whether to resize the canvas when the render() method is called. - setClearColor
Sets the color used when clearing the screen each frame. - setDimensions
Sets the viewport width and height for this scene. - setDirectionalLight
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. - setFrustum
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. - setLightParams
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. - setLookAt
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. - setOrtho
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. - setOrtho2D
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. - setOrtho2DAspect
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. - setOrthoAspect
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. - setPerspective
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. - setPointLight
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. - setProjectionMatrix
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. - setUseDevicePixelRatio
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. - setViewMatrix
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. - useFilter
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. - useProgram
Deprecated: Instead of this method, use the "setShader" program of individual shapes to set the shader programs they use. - 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.
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
shape
(Type: H3DU.Shape | H3DU.ShapeGroup)
A 3D shape.
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
value
(Type: number)
If this is H3DU.Scene3D.BACK, H3DU.Scene3D.FRONT, or H3DU.Scene3D.FRONT_AND_BACK, enables face culling of the specified faces. For any other value, disables face culling. By default, face culling is disabled.
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
value
(Type: number)
If this is H3DU.Scene3D.CW, clockwise triangles are front-facing. For any other value, counterclockwise triangles are front-facing, which is the default behavior. If using a left-handed coordinate system, set this value to H3DU.Scene3D.CW.
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
texture
(Type: string | H3DU.Texture)
String giving the URL of the image to load, or an H3DU.Texture object whose data may or may not be loaded.
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
textureFiles
(Type: Array.<string>)
A list of URLs of the image to load.resolve
(Type: function) (optional)
Called for each URL that is loaded successfully and uploaded to a texture buffer (the argument will be an H3DU.Texture object.)reject
(Type: function) (optional)
Called for each URL for which an error occurs (the argument will be the data passed upon rejection).
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
name
(Type: string)
URL of the image to load.
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
mesh
(Type: H3DU.Mesh)
A geometric mesh object. The shape created will use the mesh in its current state and won't track future changes.
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
shape
(Type: H3DU.Shape | H3DU.ShapeGroup)
The 3D shape to remove.
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
renderPasses
(Type: Array.<H3DU.RenderPass> | H3DU.Batch3D)
An array of scenes to draw, or a single batch to render. Can currently be null.
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
r
(Type: Array.<number> | number | string)
Array of three or four color components; or the red color component (0-1); or a string specifying an HTML or CSS color.g
(Type: number)
Green color component (0-1). May be null or omitted if a string or array is given as the "r" parameter.b
(Type: number)
Blue color component (0-1). May be null or omitted if a string or array is given as the "r" parameter.a
(Type: number) (optional)
Alpha color component (0-1). Currently not used.
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
value
(Type: Boolean)
If true, will check whether to resize the canvas when the render() method is called. Default is true.
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
r
(Type: Array.<number> | number | string)
Array of three or four color components; or the red color component (0-1); or a string specifying an HTML or CSS color.g
(Type: number)
Green color component (0-1). May be null or omitted if a string or array is given as the "r" parameter.b
(Type: number)
Blue color component (0-1). May be null or omitted if a string or array is given as the "r" parameter.a
(Type: number) (optional)
Alpha color component (0-1). If the "r" parameter is given and this parameter is null, undefined, or omitted, this value is treated as 1.0.
Return Value
This object. (Type: H3DU.Scene3D)
H3DU.Scene3D#setDimensions(width, height)
Sets the viewport width and height for this scene.
Parameters
width
(Type: number)
Width of the scene, in pixels. Will be rounded up.height
(Type: number)
Height of the scene, in pixels. Will be rounded up.
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
index
(Type: number)
Zero-based index of the light to set. The first light has index 0, the second has index 1, and so on. Will be created if the light doesn't exist.position
(Type: Array.<number>)
A 3-element vector giving the direction of the light, along the X, Y, and Z axes, respectively. May be null, in which case the default is (0, 0, 1).diffuse
(Type: Array.<number>) (optional)
A color vector or string giving the diffuse color of the light. If null, undefined, or omitted, the default is (1, 1, 1, 1) for light index 0 and (0, 0, 0, 0) otherwise.specular
(Type: Array.<number>) (optional)
A color vector or string giving the color of specular highlights caused by the light. If null, undefined, or omitted, the default is (1, 1, 1) for light index 0 and (0, 0, 0) otherwise.
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
left
(Type: number)
X coordinate of the point where the left clipping plane meets the near clipping plane.right
(Type: number)
X coordinate of the point where the right clipping plane meets the near clipping plane.bottom
(Type: number)
Y coordinate of the point where the bottom clipping plane meets the near clipping plane.top
(Type: number)
Y coordinate of the point where the top clipping plane meets the near clipping plane.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.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
index
(Type: number)
Zero-based index of the light to set. The first light has index 0, the second has index 1, and so on. Will be created if the light doesn't exist.params
(Type: Object)
An object as described in H3DU.LightSource.setParams.
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
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.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
left
(Type: number)
Leftmost coordinate of the 3D view.right
(Type: number)
Rightmost coordinate of the 3D view. (Note that right can be greater than left or vice versa.)bottom
(Type: number)
Bottommost coordinate of the 3D view.top
(Type: number)
Topmost coordinate of the 3D view. (Note that top can be greater than bottom or vice versa.)near
(Type: number)
Distance from the camera to the near clipping plane. A positive value means the plane is in front of the viewer.far
(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.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
left
(Type: number)
Leftmost coordinate of the 2D view.right
(Type: number)
Rightmost coordinate of the 2D view. (Note that right can be greater than left or vice versa.)bottom
(Type: number)
Bottommost coordinate of the 2D view.top
(Type: number)
Topmost coordinate of the 2D view. (Note that top can be greater than bottom or vice versa.)
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
left
(Type: number)
Leftmost coordinate of the view rectangle.right
(Type: number)
Rightmost coordinate of the view rectangle. (Note that right can be greater than left or vice versa.)bottom
(Type: number)
Bottommost coordinate of the view rectangle.top
(Type: number)
Topmost coordinate of the view rectangle. (Note that top can be greater than bottom or vice versa.)aspect
(Type: number) (optional)
Desired aspect ratio of the viewport (ratio of width to height). If null, undefined, or omitted, uses this scene's aspect ratio instead.
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
left
(Type: number)
Leftmost coordinate of the view rectangle.right
(Type: number)
Rightmost coordinate of the view rectangle. (Note that right can be greater than left or vice versa.)bottom
(Type: number)
Bottommost coordinate of the view rectangle.top
(Type: number)
Topmost coordinate of the view rectangle. (Note that top can be greater than bottom or vice versa.)near
(Type: number)
Distance from the camera to the near clipping plane. A positive value means the plane is in front of the viewer.far
(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.aspect
(Type: number) (optional)
Desired aspect ratio of the viewport (ratio of width to height). If null, undefined, or omitted, uses this scene's aspect ratio instead.
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
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.)aspect
(Type: number)
The ratio of width to height of the viewport, usually the scene's aspect ratio (getAspect() or getClientAspect()).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.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
index
(Type: number)
Zero-based index of the light to set. The first light has index 0, the second has index 1, and so on.position
(Type: Array.<number>)
Light position. (See H3DU.LightSource#position.)diffuse
(Type: Array.<number>) (optional)
A color vector or string giving the diffuse color of the light. If null, undefined, or omitted, the default is (1, 1, 1, 1) for light index 0 and (0, 0, 0, 0) otherwise.specular
(Type: Array.<number>) (optional)
A color vector or string giving the color of specular highlights caused by the light. If null, undefined, or omitted, the default is (1, 1, 1) for light index 0 and (0, 0, 0) otherwise.
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
matrix
(Type: Array.<number>)
A 16-element matrix (4x4).
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
value
(Type: Boolean)
If true, use the device's pixel ratio when setting the viewport's dimensions. Default is true.
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
matrix
(Type: Array.<number>)
A 16-element matrix (4x4).
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
filterProgram
(Type: H3DU.ShaderProgram | string | null)
The shader program to use.
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
program
(Type: H3DU.ShaderProgram | null)
No longer used.
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)