Class JSC3D.Viewer
Viewer
Viewer is the main class of JSC3D. It provides presentation of and interaction with a simple static 3D scene
which can either be given as the url of the scene file, or be manually constructed and passed in. It
also provides some settings to adjust the mode and quality of the rendering.
Viewer should be constructed with an existing canvas object where to perform the rendering.
Viewer provides 3 way to specify the scene:
1. Use setParameter() method before initilization and set 'SceneUrl' parameter with a valid url
that describes where to load the scene.
2. Use replaceSceneFromUrl() method, passing in a valid url to load/replace scene at runtime.
3. Use replaceScene() method, passing in a manually constructed scene object to replace the current one
at runtime.
Defined in: jsc3d.js.
Constructor Attributes | Constructor Name and Description |
---|---|
JSC3D.Viewer(canvas, parameters)
|
Method Attributes | Method Name and Description |
---|---|
enableDefaultInputHandler(enabled)
Enable/Disable the default mouse and key event handling routines.
|
|
getScene()
Get the current scene.
|
|
init()
Initialize viewer for rendering and interactions.
|
|
Check if WebGL is enabled for rendering.
|
|
pick(clientX, clientY)
Query information at a given position on the canvas.
|
|
replaceScene(scene)
Replace the current scene with a given scene.
|
|
replaceSceneFromUrl(sceneUrl)
Load a new scene from the given url to replace the current scene.
|
|
reportError(message)
Show information about a fatal error.
|
|
reportProgress(task, progress)
Show progress with information on current time-cosuming task.
|
|
Reset the current scene to its initial state.
|
|
rotate(rotX, rotY, rotZ)
Rotate the scene with given angles around Cardinal axes.
|
|
setBackgroudImageFromUrl(backgroundImageUrl)
Specify the url for the background image.
|
|
setDefinition(definition)
Set quality level of rendering.
|
|
setMouseUsage(usage)
Set control of mouse pointer.
|
|
setParameter(name, value)
Set the initial value for a parameter to parameterize the viewer.
|
|
setRenderMode(mode)
Set render mode.
|
|
setSphereMapFromUrl(sphereMapUrl)
Specify a new image from the given url which will be used for applying sphere mapping.
|
|
update(repaintOnly)
Ask viewer to render a new frame or just repaint last frame.
|
- Parameters:
- {Boolean} enabled
- true to enable the default handler; false to disable them.
- Returns:
- {JSC3D.Scene} the current scene.
- Returns:
- {Boolean} true if WebGL is enabled; false if WebGL is not enabled or unavailable.
- Parameters:
- {Number} clientX
- client x coordinate on the current page.
- {Number} clientY
- client y coordinate on the current page.
- Returns:
- {JSC3D.PickInfo} a PickInfo object which holds the result.
- Parameters:
- {JSC3D.Scene} scene
- the given scene.
- Parameters:
- {String} sceneUrl
- url string that describes where to load the new scene.
- Parameters:
- {String} message
- text information about this error.
- Parameters:
- {String} task
- text information about current task.
- {Number} progress
- progress of current task. this should be a number between 0 and 1.
- Parameters:
- {Number} rotX
- rotation angle around X-axis in degrees.
- {Number} rotY
- rotation angle around Y-axis in degrees.
- {Number} rotZ
- rotation angle around Z-axis in degrees.
- Parameters:
- {String} backgroundImageUrl
- url string for the background image.
Available quality levels are:
'low': low-quality rendering will be applied, with highest performance;
'standard': normal-quality rendering will be applied, with modest performace;
'high': high-quality rendering will be applied, with lowest performace.
- Parameters:
- definition
'default': default mouse control will be used;
'free': this tells {JSC3D.Viewer} a user-defined mouse control will be adopted. This is often used together with viewer.enableDefaultInputHandler(false) and viewer.onmousedown, viewer.onmouseup and/or viewer.onmousemove overridden.
'rotate': mouse will be used to rotate the scene;
'zoom': mouse will be used to do zooming.
'pan': mouse will be used to do panning.
- Parameters:
- {String} usage
- control of mouse pointer to be set.
- Deprecated:
- This method is obsolete since version 1.5.0 and may be removed in the future.
Available parameters are:
'SceneUrl': url string that describes where to load the scene, default to '';
'InitRotationX': initial rotation angle around x-axis for the whole scene, default to 0;
'InitRotationY': initial rotation angle around y-axis for the whole scene, default to 0;
'InitRotationZ': initial rotation angle around z-axis for the whole scene, default to 0;
'CreaseAngle': an angle to control the shading smoothness between faces. Two adjacent faces will be shaded with discontinuity at the edge if the angle between their normals exceeds this value. Not used by default;
'ModelColor': fallback color for all meshes, default to '#caa618';
'BackgroundColor1': color at the top of the background, default to '#ffffff';
'BackgroundColor2': color at the bottom of the background, default to '#383840';
'BackgroundImageUrl': url string that describes where to load the image used for background, default to '';
'RenderMode': render mode, default to 'flat';
'Definition': quality level of rendering, default to 'standard';
'MipMapping': turn on/off mip-mapping, default to 'off';
'SphereMapUrl': url string that describes where to load the image used for sphere mapping, default to '';
'ProgressBar': turn on/off the progress bar when loading, default to 'on'. By turning off the default progress bar, a user defined loading indicator can be used instead;
'Renderer': set to 'webgl' to enable WebGL for rendering, default to ''.
- Parameters:
- {String} name
- name of the parameter to set.
- value
- new value for the parameter.
Available render modes are:
'point': render meshes as point clouds;
'wireframe': render meshes as wireframe;
'flat': render meshes as solid objects using flat shading;
'smooth': render meshes as solid objects using smooth shading;
'texture': render meshes as solid textured objects, no lighting will be apllied;
'textureflat': render meshes as solid textured objects, lighting will be calculated per face;
'texturesmooth': render meshes as solid textured objects, lighting will be calculated per vertex and interpolated.
- Parameters:
- {String} mode
- new render mode.
- Parameters:
- {String} sphereMapUrl
- url string that describes where to load the image.
- Parameters:
- {Boolean} repaintOnly
- true to repaint last frame; false(default) to render a new frame.