Camera Molecule

Add a 3D scene.

Summary
Camera Molecule
Preference Dialog
Properties
typestring, ( r )
pref.namestring, ( r )
pref.enableWhenstring, ( r, w )
pref.disableWhenstring, ( r, w )
pref.scenestring, ( r, w )
pref.lookatstring, ( r, w )
pref.xfloat, ( r, w )
pref.yfloat, ( r, w )
pref.zfloat, ( r, w )
pref.axfloat, ( r, w )
pref.ayfloat, ( r, w )
pref.azfloat, ( r, w )
pref.dxfloat, ( r, w )
pref.dyfloat, ( r, w )
pref.dzfloat, ( r, w )
pref.nearfloat, ( r, w )
pref.farfloat, ( r, w )
pref.brint [0, 255], ( r, w )
pref.bgint [0, 255], ( r, w )
pref.bbint [0, 255], ( r, w )
pref.ambrint [0, 255], ( r, w )
pref.ambgint [0, 255], ( r, w )
pref.ambbint [0, 255], ( r, w )
pref.fXfloat, ( r, w )
pref.fYfloat, ( r, w )
pref.fZfloat, ( r, w )
pref.fWfloat, ( r, w )
pref.modestring, ( r, w )
pref.autobool, ( r, w )
pref.aspectratiofloat, ( r, w )
pref.fovyint, ( r, w )
pref.manualbool, ( r, w )
pref.antialiasbool, ( r, w )
positionobject, ( r, w )
rotationobject, ( r, w )
worldPositionobject, ( r )
worldRotationobject, ( r )
zoomfloat, ( r, w )
upobject, ( r )
rightobject, ( r )
sceneobject, ( r )
rendererobject, ( r )
cameraobject, ( r )
projectorobject, ( r )
depthBufferobject, ( r )
targetobject/string, ( r, w )
orthographicbool, ( r, w )
pausedbool, ( r )
Functions
attach
detach
delete
rename
clone
serialize
render
createRenderTarget
createDataTexture
rayCastSelect
rayCastPoint
rayCastDetect
translate
roll
pitch
yaw
rotate
getScreenCoords
projectOnScreen
enableAutoTracking
disableAutoTracking
listen
pause
resume
attachTo
detachFrom
createJoint

Preference Dialog

Properties

type

string, ( r )

Type of this molecule, camera.

pref.name

string, ( r )

The scriptable name for this molecule.  This name can be set using rename function dynamically.

pref.enableWhen

string, ( r, w )

Specifies the event that activates this molecule.  Default is load.

pref.disableWhen

string, ( r, w )

Specifies the event that deactivates this molecule.  Default is none.

pref.scene

string, ( r, w )

Specifies the scene name associated with this camera.

pref.lookat

string, ( r, w )

Specifies the name of the mesh or manualobject molecule that this camera is aiming at.

pref.x

float, ( r, w )

Specifies the x coordinate of this camera’s position.

pref.y

float, ( r, w )

Specifies the y coordinate of this camera’s position.

pref.z

float, ( r, w )

Specifies the z coordinate of this camera’s position.

pref.ax

float, ( r, w )

Specifies the x coordinate of a point this camera is aiming at.

pref.ay

float, ( r, w )

Specifies the y coordinate of a point this camera is aiming at.

pref.az

float, ( r, w )

Specifies the z coordinate of a point this camera is aiming at.

pref.dx

float, ( r, w )

Specifies the x direction of this camera.

pref.dy

float, ( r, w )

Specifies the y direction of this camera.

pref.dz

float, ( r, w )

Specifies the z direction of this camera.

pref.near

float, ( r, w )

Specifies the distance of the near clipping plane.

pref.far

float, ( r, w )

Specifies the distance of the far clipping plane.

pref.br

int [0, 255], ( r, w )

Specifies the RED component of the background color.

pref.bg

int [0, 255], ( r, w )

Specifies the GREEN component of the background color.

pref.bb

int [0, 255], ( r, w )

Specifies the BLUE component of the background color.

pref.ambr

int [0, 255], ( r, w )

Specifies the RED component of the ambient color.

pref.ambg

int [0, 255], ( r, w )

Specifies the GREEN component of the ambient color.

pref.ambb

int [0, 255], ( r, w )

Specifies the BLUE component of the ambient color.

pref.fX

float, ( r, w )

Specifies the x component of the camera’s orientation as Quaternion.

pref.fY

float, ( r, w )

Specifies the y component of the camera’s orientation as Quaternion.

pref.fZ

float, ( r, w )

Specifies the z component of the camera’s orientation as Quaternion.

pref.fW

float, ( r, w )

Specifies the w component of the camera’s orientation as Quaternion.

pref.mode

string, ( r, w )

Specifies the rendering mode.

solidSolid polygons are rendered.
wireframeWireframe models are rendered.  Not implemented yet.

pref.auto

bool, ( r, w )

Whether aspect ratio will automatically be recalculated when a viewport changes its size.  Default to false.

pref.aspectratio

float, ( r, w )

Get/Set the aspect ratio of the camera viewport.  Default to 1.3333.

pref.fovy

int, ( r, w )

Sets the Y-dimension Field Of View (FOV) of the frustum in degree.  Field Of View (FOV) is the angle made between the frustum’s position, and the edges of the ‘screen’ onto which the scene is projected.  High values (90+ degrees) result in a wide-angle, fish-eye kind of view, low values (30- degrees) in a stretched, telescopic kind of view.  Typical values are between 45 and 60 degrees.  This value represents the VERTICAL field-of-view.  The horizontal field of view is calculated from this depending on the dimensions of the viewport (they will only be the same if the viewport is square).  Default to 45 degree.

pref.manual

bool, ( r, w )

Specifies whether this camera is to be rendered manually.  Default to false.

pref.antialias

bool, ( r, w )

Specifies whether to use the webgl’s antialiasing algorithm.  Default to true.

position

object, ( r, w )

Get/Set the camera’s position in {x:v1, y:v2, z:v3} format.

rotation

object, ( r, w )

Get/Set the camera’s rotation in {x:deg1, y:deg2, z:deg3} format.

worldPosition

object, ( r )

Returns the camera’s world position in {x:v1, y:v2, z:v3} format.

worldRotation

object, ( r )

Returns the camera’s world rotation in {x:deg1, y:deg2, z:deg3} format.

zoom

float, ( r, w )

Get/Set the camera’s zoom value.

up

object, ( r )

Returns the camera’s up vector.

right

object, ( r )

Returns the camera’s right vector.

scene

object, ( r )

Returns the camera’s scene object.

renderer

object, ( r )

Returns the camera’s webgl renderer.

camera

object, ( r )

Returns the camera’s internal camera object.

projector

object, ( r )

Returns a projector object which can be used to project/unproject a scene vector based on a given camera view.

depthBuffer

object, ( r )

Returns the camera’s depth buffer.

target

object/string, ( r, w )

Get/Set the current active render target (THREE.WebGLRenderTarget).

orthographic

bool, ( r, w )

Switches between perspective and orthographic camera mode.

paused

bool, ( r )

Check if physic simulation is currently paused.

Functions

attach

attach(droplet);

Attach this molecule to the given droplet.

Parameters

droplet(object) a droplet.

Returns

N/A

detach

detach();

Remove this molecule from its droplet.

Parameters

N/A

Returns

N/A

delete

delete();

Delete this molecule.

Parameters

N/A

Returns

N/A

rename

rename(name);

Rename this molecule.

Parameters

name(string) a new name.

Returns

N/A

clone

clone();

Create a clone of this molecule.

Parameters

N/A

Returns

(object) a molecule.

serialize

serialize();

Serialize this molecule into its JSON representation.

Parameters

N/A

Returns

(string) JSON representation of a molecule.

render

render(renderTarget, scene, camera, forceClear);

Render this camera’s scene into the given render target.

Parameters

renderTarget(object) a valid render target.
scene(object) scene to be rendered.
camera(object) camera’s view.
forceClear(bool) clear buffer content before render.  Default to false.

Returns

N/A

createRenderTarget

createRenderTarget(name, width, height, format);

Create a render target with the given name, dimension, and formats and store it in an internal array.

Parameters

name(string) render target name.
width(number) width in pixels.  Default to droplet width.
height(number) height in pixels.  Default to droplet height.
format(object) optional render target formats.

Returns

(object) the newly created render target which is set active immediately and is accessible by this molecule’s target property.

createDataTexture

createDataTexture(data, width, height, format, type);

Create a data texture from the given initial data arrayBufferView, dimension, format, and type.

Parameters

data(arrayBufferView) initial data array.
width(number) width in pixels.
height(number) height in pixels.
format(number) The default is THREE.RGBAFormat for the texture.  Other formats are: THREE.AlphaFormat, THREE.RGBFormat, THREE.LuminanceFormat, and THREE.LuminanceAlphaFormat.
type(number) the data type.  The default is THREE.FloatType.  Other types are: THREE.ByteType, THREE.ShortType, THREE.UnsignedShortType, THREE.IntType, THREE.UnsignedIntType, THREE.UnsignedByteType, THREE.UnsignedShort4444Type, THREE.UnsignedShort5551Type, and THREE.UnsignedShort565Type.

Returns

(object) a newly created texture.

rayCastSelect

rayCastSelect(x, y);

Given a 2D point (x, y) in the droplet, this function returns an array of objects each containing the following information,

id(string) an internal identifier of the molecule that intersects this ray.
name(string) the name of the intersecting molecule.
molecule(object) the molecule itself.
point(object) the intersecting point.
distance(float) the distance of intersect to the camera.
face(object) the mesh’s face at the intersect.

The array is sorted by distance from near to far.

Parameters

x(int) x-coordinate relative to the top left corner of a droplet.
y(int) y-coordinate relative to the top left corner of a droplet.

Returns

(array) an array of objects containing intersects’ information.

rayCastPoint

rayCastPoint(x, y, d);

Given a 2D point (x, y) within the droplet and a distance d into the 3D scene, this function returns the location in the 3D scene.

Parameters

x(int) x-coordinate relative to the top left corner of a droplet.
y(int) y-coordinate relative to the top left corner of a droplet.
d(float) distance into the scene.

Returns

(object) Vector3 of the point location.

rayCastDetect

rayCastDetect(origin, direction, near, far);

This function creates a ray at the origin with given direction and returns an array of intersects between the two given distances, near and far.  Each intersect in the array contains the following information,

id(string) an internal identifier of the molecule that intersects this ray.
name(string) the name of the intersecting molecule.
molecule(object) the molecule itself.
point(object) the intersecting point.
distance(float) the distance of intersect to the camera.
face(object) the mesh’s face at the intersect.

The array is sorted by distance from near to far.

Parameters

origin(Vector3) the ray origin.
direction(Vector3) the ray direction.
near(float) the near distance to begin detection.  Default to 0.
far(float) the far distance to end detection.  Default to Infinity.

Returns

(array) an array of objects containing intersects’ information.

translate

translate(v3, ts);

Translate this camera by the given vector v3 and in the coordinate space given by ts.

Parameters

v3(object) a Vector3.
ts(constant) TS_LOCAL, TS_PARENT, or TS_WORLD.  Default to TS_LOCAL.

Returns

N/A

roll

roll(d, ts);

Roll this camera by the given degree d and in the coordinate space given by ts.

Parameters

d(float) an angle in degree.
ts(constant) TS_LOCAL, TS_PARENT, or TS_WORLD.  Default to TS_LOCAL.

Returns

N/A

pitch

pitch(d, ts);

Pitch this camera by the given degree d and in the coordinate space given by ts.

Parameters

d(float) an angle in degree.
ts(constant) TS_LOCAL, TS_PARENT, or TS_WORLD.  Default to TS_LOCAL.

Returns

N/A

yaw

yaw(d, ts);

Yaw this camera by the given degree d and in the coordinate space given by ts.

Parameters

d(float) an angle in degree.
ts(constant) TS_LOCAL, TS_PARENT, or TS_WORLD.  Default to TS_LOCAL.

Returns

N/A

rotate

rotate(axis, d, ts);

Rotate this camera by the given degree d around the axis and in the coordinate space given by ts.

Parameters

axis(object) a Vector3.
d(float) an angle in degree.
ts(constant) TS_LOCAL, TS_PARENT, or TS_WORLD.  Default to TS_LOCAL.

Returns

N/A

getScreenCoords

getScreenCoords(entity, pos);

Returns the entity’s position on screen relative to the top left corner of a droplet.  The pos option specifies which part of the entity is being queried.

Parameters

entity(object) a mesh, light, manualobject, or particle molecule.
pos(string) center, min, or max.

Returns

(object) a Vector2 in pixels.

projectOnScreen

projectOnScreen(entity);

Projects the entity’s position on screen.  Unlike getScreenCoords, this returns the normalized screen position ranging between 0 and 1.

Parameters

entity(object) a mesh, light, manualobject, or particle molecule.

Returns

(object) a Vector2.

enableAutoTracking

enableAutoTracking(entity, offset);

Makes this camera aim at an entity, with an optional offset, at all time.

Parameters

entity(object) a mesh, light, manualobject, or particle molecule.
offset(object) a Vector3.

Returns

N/A

disableAutoTracking

disableAutoTracking();

Disable auto tracking.

Parameters

N/A

Returns

N/A

listen

listen();

Enables this camera to listen to Web Audio sound sources in the scene.

Parameters

N/A

Returns

N/A

pause

pause();

Pause physics simulation.

Parameters

N/A

Returns

N/A

resume

resume();

Resume physics simulation.

Parameters

N/A

Returns

N/A

attachTo

attachTo(entity);

Attach this camera to the given 3D entity.

Parameters

entity(object) a mesh, light, manualobject, or particle molecule.

Returns

N/A

detachFrom

detachFrom();

Detach this camera from its parent, if any.

Parameters

N/A

Returns

N/A

createJoint

createJoint(type, entity1, entity2, pos, axis);

Create a joint between 2 entities in the scene.  The joint can be any one of the 5 types (point, hinge, slider, conetwist, dof).

pointThis joint allows objects to be bound to a certain point in the scene (if entity2 is omitted), and can be used to constrain two objects together at a point between them.  The axis parameter is not applicable for this joint type.
hingeThe hinge joint limits the movement of an object to act as if it were on a hinge, such as a door.  Like the point joint, the hinge can be created with either 1 or 2 entities.  The axis is the direction along which the hinge lies.
sliderThe slider joint will constrain the linear movement of an object to align with the given axis.  Examples are a sliding door or the lifting mechanism on a fork lift.  Like the point and hinge joints, the second entity is an optional parameter.
conetwistThe cone twist joint limits the movement and rotation between two entities in a manner similar to human joints like the shoulder or ankle.  In this joint type, both entities are required.  The axis parameter is not applicable for this joint type.
dofThe degree of freedom joint yields full control over how the entities should be constrained both in linear and angular movement.

Parameters

type(const) JOINT_POINT, JOINT_HINGE, JOINT_SLIDER, JOINT_CONETWIST, or JOINT_DOF;
entity1(object) a mesh or manualobject molecule.
entity2(object) a mesh or manualobject molecule.
pos(object) a Vector3.
axis(object) a Vector3.

Returns

(object) a Joint3D object.

A physical joint.
Close