Mesh Molecule

From oWiki

Jump to: navigation, search

Contents



Preference Dialog

File:Mesh_pref.png

Attributes

type

string  ( r )
Type of this molecule, 'mesh'.

pref.name

string  ( r )
The scriptable name for this molecule. This name can be set using rename method 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.url

string  ( r, w )
Specifies the URL of this mesh file.

pref.skeletonURL

string  ( r, w )
Specifies the URL of the skeleton file associated with this mesh.

pref.soundURL

string  ( r, w )
Specifies the URL of the audio file attached to this mesh.

pref.terrainClampping

bool  ( r, w )
Specifies whether this mesh will clamp to the terrain, if any.

pref.x

float  ( r, w )
Specifies the x coordinate of this mesh's position.

pref.y

float  ( r, w )
Specifies the y coordinate of this mesh's position.

pref.z

float  ( r, w )
Specifies the z coordinate of this mesh's position.

pref.sx

float  ( r, w )
Specifies the x component of this mesh's scale.

pref.sy

float  ( r, w )
Specifies the y component of this mesh's scale.

pref.sz

float  ( r, w )
Specifies the z component of this mesh's scale.

pref.dx

float  ( r, w )
Specifies the x-dimension of this mesh's size.

pref.dy

float  ( r, w )
Specifies the y-dimension of this mesh's size.

pref.dz

float  ( r, w )
Specifies the z-dimension of this mesh's size.

pref.fX

float  ( r, w )
Specifies the x compnent of this mesh's orientation as quaternion.

pref.fY

float  ( r, w )
Specifies the y compnent of this mesh's orientation as quaternion.

pref.fZ

float  ( r, w )
Specifies the z compnent of this mesh's orientation as quaternion.

pref.fW

float  ( r, w )
Specifies the w compnent of this mesh's orientation as quaternion.

numSubEntities

int  ( r )
Returns the number of sub-entities this mesh entity is made of.

numSubMeshes

int  ( r )
Returns the number of sub-meshes this mesh entity is made of.

numPoses

int  ( r )
Returns the number of poses this mesh entity has for performing vertex animation.

hasSkeleton

bool  ( r )
Check if this mesh has skeleton.

renderQueueGroup

int  ( r, w )
Gets/Sets the rendering queue position of this mesh. Render queues are grouped to allow you to more tightly control the ordering of rendered objects. If you do not call this method, all Entity objects default to the default queue, which is fine for most objects. You may want to alter this if you want this entity to always appear in front of other objects, e.g. for a 3D menu system or such.

renderingDistance

float  ( r, w )
Gets/Sets the distance at which the object is no longer rendered.

volume

float, [0.0, 1.0]  ( r, w )
Gets/Sets the volume of the sound attached to this mesh.

currentTime

float  ( r, w )
Gets/Sets the playback position (in secs) of the sound attached to this mesh.

duration

float  ( r )
Gets the duration (in secs) of the sound attached to this mesh.

status

int  ( r )
Polls for the current sound playing status.
Possible return values are:

Value Description
AL_PLAYING A sound track is playing.
AL_STOPPED Sound track has stopped.


Methods

rename(n)

n: string

Rename this molecule.

show()

show this mesh

hide()

hide this mesh.

update()

Force molecule to redraw with the current set of attributes.

clone()

Return: a molecule

Create a clone of this molecule.

attach(droplet)

droplet: a droplet object (e.g. app.box.droplet)

Attach this molecule to a droplet.

detach()

Remove this molecule from its droplet.

deleteMod()

Delete this molecule.

serialize()

Return: string

Serialize this molecule into its JSON representation.

getBounds()

Return: Vector3

Returns the dimension of the bounding box of this mesh.

setPosition( v )

v: Vector3

Sets the position of this mesh.

getPosition()

Return: Vector3

Returns the current position of this mesh.

setSize( v )

v: Vector3

Sets the dimension of this mesh.

getSize()

Return: Vector3

Returns the current dimension of this mesh.

setScale( v )

v: Vector3

Sets the scaling factor applied to this mesh.

getScale()

Return: Vector3

Returns the current scaling applied to this mesh.

scale( v )

v: Vector3

Scales this mesh, combining it's current scale with the passed in scaling factor, v.

translate( v, ts )

v: Vector3
ts: int

Translate this mesh along Cartesian axes. v is the movement along the axes.

Possible values for ts are:

Value Description
TS_LOCAL Transform is relative to the local space.
TS_PARENT Transform is relative to the space of the parent node.
TS_WORLD Transform is relative to world space.

translate( m3, v, ts )

m3: A 3x3 Matrix. See Matrix3
v: Vector3
ts: int

Translate this mesh along arbitrary axes.

roll( a, ts )

a: int as degree
ts: int

Rotate the mesh around the Z-axis, in space ts.

pitch( a, ts )

a: int as degree
ts: int

Rotate the mesh around the X-axis, in space ts.

yaw( a, ts )

a: int as degree
ts: int

Rotate the mesh around the Y-axis, in space ts.

rotate( v, a, ts )

v: Vector3
a: int as degree
ts: int

Rotate this mesh around an arbitrary axis, in space ts.

setVisible( b, cascade )

b: bool
cascade: bool (optional)

Makes all objects attached to this node become visible / invisible. By default, cascade is false.

flipVisibility( cascade )

cascade: bool (optional)

Inverts the visibility of all objects attached to this node. By default, cascade is false.

attachTo( entity )

entity: molecule

Attach this mesh to another 3D entity in scene.

detachFrom( entity )

entity: molecule (optional)

Detach this mesh from another 3D entity in scene.

setInheritOrientation( b )

b: bool

Tells the node whether it should inherit orientation from it's parent node.

getInheritOrientation( )

Return: bool

Returns true if this node is affected by orientation applied to the parent node.

setInheritScale( b )

b: bool
cascade: bool (optional)

Tells the node whether it should inherit scaling factors from it's parent node. By default, cascade is false.

getInheritScale()

Return: bool

Returns true if this node is affected by scaling factors applied to the parent node.

resetOrientation()

Resets the nodes orientation (local axes as world axes, no rotation).

setInitialDir( v )

v: Vector3

Defines the initial direction this mesh is facing.

setCastShadows( b )

b: bool

Specifies whether this mesh cast shadow.

setMaterialName( m )

m: string

Applies material to this mesh.

getMaterialName( i )

i: int
Return: string

Gets the material name applied to the selected sub-entity at index i.

getBones()

Return: array

Returns the bones of this mesh as an array of bone names.

getRootBones()

Return: array

Returns the root bones of this mesh as an array of bone names.

rollBone( id, d )

id: string
d: float as degree

Roll the named bone by the given degree around its local Z-axis.

pitchBone( id, d )

id: string
d: float as degree

Rotate the named bone by the given degree around its local X-axis.

yawBone( id, d )

id: string
d: float as degree

Rotate the named bone by the given degree around its local Y-axis.

rotateBone( id, v, d )

id: string
v: Vector3
d: float as degree

Rotate the named bone by the given degree around the given v axis.

attachObjectToBone( id, o, q, p )

id: string
o: molecule
q: Quaternion
p: Vector3

This method can be used to attach another object to an animated part of this mesh, by attaching it to a bone in the skeleton (with an offset if required). As this mesh is animated, the attached object will move relative to the bone to which it is attached.

q is an adjustment to the orientation of the attached object, relative to the bone.
p is an adjustment to the position of the attached object, relative to the bone.

detachObjectFromBone( o )

o: molecule

Detach the given object from bone.

detachBoneFromTrack( id, t )

id: string
t: string

Remove a bone from a previous defined animation track. This is necessary in order to manually control bone movement, if a scripted animation has already been defined involving this bone.

enableAutoTracking( entity, dir, pos )

entity: molecule
dir: Vector3
pos: Vector3

If you enable auto-tracking, this mesh will automatically rotate to point it's -Z at the target every frame, no matter how the target moves.

dir is the local vector considered to be the usual 'direction' of the mesh; normally the local -Z but can be another direction.
pos is the target point in local space of the target node instead of the origin of the target node, for changing the look-at point.

disableAutoTracking()

Disable auto tracking of another entity.

getTracks()

Return: array

Gets the build-in animation tracks as an array of names.

enableTrack( n, b )

n: string
b: bool
Return: array

Enable/Disable the named animation track.

playTrack( id, rate, loop )

id: string
rate: float
loop: bool

Play the named animation track. Specify rate to change the rate of playback and set loop to 1 to loop back to the beginning when the animation ends.

pauseTrack()

Pause the animation.

resumeTrack()

Resume the animation.

stopTrack()

Stop the animation.

getTimePosition()

Return: float

Gets the current time position of the animation track.

setTimePosition( t )

t: float

Sets the current time position of the animation track.

addTime( n, t )

n: string
t: float in msec

Modifies the time position of the named animation track, adjusting for animation length.

This method loops at the edges if looping is enabled.

isPlaying()

Return: 0 or 1

Returns 1 if an animation track is currently playing.

attachSkeleton( url )

url: string

Attach a skeleton to the mesh, replace the existing one if any.

getSubEntity( i )

i: int
Return: a SubEntity object

Returns the SubEntity object at index i.

getSubMesh( i )

i: int
Return: a SubMesh object

Returns the SubMesh object at index i.

getPose( i )

i: int
Return: a Pose object

Returns the Pose object at index i.

createVertexAnimation( name, time )

name: string
time: float

Create a vertex animation with the given name and length of time in seconds.

createVertexTrack( name, handle, type, trackname )

name: string
handle: int
type: int
trackname: string

For the named vertex animation, create a track with the given trackname, handle, and type.

handle: used for accessing the track later. Must be unique within this Animation, and is used to identify the target. For example when applied to a Mesh, the handle must reference the index of the geometry being modified; 0 for the shared geometry, and 1+ for SubMesh geometry with the same index-1.

Possible vertex animation types are:

Value Description
VAT_NONE No animation.
VAT_MORPH Morph animation is made up of many interpolated snapshot keyframes.
VAT_POSE Pose animation is made up of a single delta pose keyframe.

addVertexKeyFrame( trackname, type, time )

trackname: string
type: int
time: float
Return: a VertexKeyFrame object

Adds a vertex animation key frame, of VKF_MORPH or VKF_POSE type, at the given time offset in seconds.

refreshAnimationStates()

Updates the internal animation state set to include the latest available animations from the attached skeleton.

getNumKeyFrames( trackname )

trackname: string
Return: int

Returns the number of key frames in the animation track given by trackname.

newSequence()

Return: an AnimationSequence object

You can use AnimationSequence to create a sequence of animation tracks with smooth transition/blending between tracks.

newBlend()

Return: an AnimationBlender object

You can use AnimationBlender to create a blend of animation tracks using bone-weighting.

attachSound( url )

url: string

Attach an audio track to the mesh, replace the existing one if any. The attached audio moves with the mesh during animation and creates 3D sound effect. Use Camera.listen() to hear the sound effects.

playSound( loop )

loop: bool

Play the attached sound track, loops if necessary.

pauseSound()

Pause the sound track.

stopSound()

Stop the sound track.

rewindSound()

Rewind the sound track to the beginning.

enableCollision( prmShape, size )

prmShape: int
size: Vector3

Enable collision detection for this mesh.

prmShape is the shape of the detection surface. size is the size of the bounding box for the mesh.
Possible values for prmShape are:

Value Description
PRM_BOX Standard primitive Box.
PRM_ELLIPSOID Becomes a sphere when the size is the same for all 3 axis.
PRM_CYLINDER Standard primitive cylinder.
PRM_CAPSULE A cylinder with rounded tips.
PRM_CONE Standard primitive cone.
PRM_CAPSULE Standard primitive capsule.
PRM_CHAMFERCYLINDER Filled-donut shape primitive.
PRM_CONVEXHULL "wrap" around a set cloud of vertices. a convex hull is the smallest possible convex shape that fully encloses all points supplied.
PRM_PYRAMID Standard primitive pyramid.
PRM_TREE A primitive that is built dynamically from the vertice and index information of the mesh.

setCollisionMaterial( mat )

mat: string

Defines a collision material for this mesh. The material property will determine the behavior of collision against another mesh with the same or different material.

setCollidable( mat, b )

mat: string
b: bool

Set the materials defined by the interaction between the given material and the material of the mesh to be collidable or non-collidable by default.

setFriction( mat, statf, dynf )

mat: string
statf: float
dynf: float

Set the default coefficients of friction defined by the interaction between the given material and the material of the mesh. statf is static and dynf is dynamic coefficient. Default values for the default material are: Static: 0.9, Dynamic: 0.5.

setElasticity( mat, val )

mat: string
val: float

Sets the default coefficients of restitution (elasticity) for the material defined by the interaction between the given material and the material of the mesh. val must be a positive value. It is recommended that it be set to a value lower or equal to 1.0, default value is 0.4.

setSoftness( mat, val )

mat: string
val: float

Sets the default softness coefficients for the material defined by the interaction between the given material and the material of the mesh. val must be a positive value. It is recommended that it be set to value lower or equal to 1.0 A low value for val will make the material soft. A typical value is 0.15, default value is 0.1.

setSurfaceThickness( mat, val )

mat: string
val: float

Sets the surface thickness for the material defined by the interaction between the given material and the material of the mesh. val must be a positive value.

installPreCollisionCallback( mat, script )

mat: string
script: molecule

Install a pre-collision callback. The script molecule is called when a collision is about to happen between the given material and material of the mesh. Returning 0 from the script causes the collision to be ignored. Returning 1 will receive the subsequent collision callbacks. The input parameter, params, contains the following members:

params.me: the name of the mesh that is listening for collision.
params.peer: the name of the other mesh that triggers the collision.

installCollisionCallback( mat, script )

mat: string
script: molecule

Install a collision callback. The script molecule is called when a collision happens between the given material and material of the mesh. Returning 0 from the script causes the collision to be ignored. Returning 1 will receive the subsequent collision callbacks. The input parameter, params, contains the following members:

params.me: the name of the mesh that is listening for collision.
params.peer: the name of the other mesh that triggers the collision.
params.contacts: an array of Vector3. The points of collision.

setContactSoftness( i, val )

This function can only be called during collision callback.
i: int
val: float

Sets the softness coefficient of the indexed contact point in the params.contacts array.

setContactFrictionState( i, val, n )

This function can only be called during collision callback.
i: int
val: float
n: int

Enable or disable friction calculation for the indexed contact point in the params.contacts array.
val is the friction state, 0 makes the contact frictionless along the index tangent vector.
n is the index to the tangent vector. 0 for primary tangent vector or 1 for the secondary tangent vector.

setContactFriction( i, statf, dynf, n )

This function can only be called during collision callback.
i: int
statf: float
dynf: float
n: int

Sets the coefficients of friction along the selected tangent vector and for the indexed contact point in the params.contacts array.
statf is the static and dynf the dynamic coefficient.
n is the index to the tangent vector. 0 for primary tangent vector or 1 for the secondary tangent vector.

setContactElasticity( i, val )

This function can only be called during collision callback.
i: int
val: float

Sets the elasticity for the indexed contact point in the params.contacts array.

setContactNormalDirection( i, dir )

This function can only be called during collision callback.
i: int
dir: Vector3

This function changes the basis of the contact point to one where the contact normal is aligned to the new direction vector and the tangent direction are recalculated to be perpendicular to the new contact normal.

setContactNormalAcceleration( i, val )

This function can only be called during collision callback.
i: int
val: float

Force the contact point to have a non-zero acceleration along the contact normal.

rotateTangentDirections( i, dir )

This function can only be called during collision callback.
i: int
dir: Vector3

Rotate the tangent direction of the contact until the primary direction is aligned with the given direction, dir.

setContactTangentAcceleration( i, val, n )

This function can only be called during collision callback.
i: int
val: float
n: int

Force the contact point to have a non-zero acceleration along the surface plane.
n is the index to the tangent vector. 0 for primary tangent vector or 1 for the secondary tangent vector.

freeze()

Freezes the mesh. Removing it from physics simulation.

resume()

Resumes physics simulation for this mesh.

replicate( type, dim, mul, rpos, rsca, rori )

type: 0 or 1
dim: Vector3
mul: Vector3
rpos: Vector3
rsca: Vector3
rori: Vector3

Replicate the mesh.

type defines the method of replication.
dim is the box inside which each replicated entity is located.
mul is the multiplicity of the replication along the xyz-axes.
rpos introduces randomness to the position of each replicated entity in the box. Valid values are from (0, 0, 0) to (1, 1, 1).
rsca introduces randomness to the scale of each replicated entity in the box. Valid values are from (0, 0, 0) to (1, 1, 1).
rori introduces randomness to the orientation of each replicated entity in the box. Valid values are from (0, 0, 0) to (1, 1, 1).

undoReplicate()

Undo replication.

playGroupTrack( id, loop, offset_randomness, rate_randomness )

id: string
loop: bool
offset_randomness: float
rate_randomness: float

Play the named animation track of all replicated entities.

loop decides if the track loops.
offset_randomness introduces random offset from the beginning of the track for each replicant.
rate_randomness introduces random speed of track playing for each replicant.

pauseGroupTrack()

Pause group animation.

resumeGroupTrack()

Resume group animation.

stopGroupTrack()

Stop group animation.

playIndexedTrack( id, x, y, z, loop, offset_randomness, rate_randomness )

id: string
x: int
y: int
z: int
loop: bool
offset_randomness: float
rate_randomness: float

Play the named animation track of the selected entities by [x, y, z].

loop decides if the track loops.
offset_randomness introduces random offset from the beginning of the track to the selected replicant.
rate_randomness introduces random speed of track playing to the selected replicant.

pauseIndexedTrack()

Pause indexed animation.

resumeIndexedTrack()

Resume indexed animation.

stopIndexedTrack()

Stop indexed animation.

setMass( mass )

mass: float

Set the weight of this mesh.

setVelocity( dir )

dir: Vector3

Set the velocity of this mesh.

setGroupMass( mass, type, randomness )

mass: float
type: int
randomness: float

Assign weight to all replicated entities.

Possible values for type are:

Value Description
0 uniform assignment.
1 mass according to scale with main entity as 1.0.
2 random. mass as mass + mass * randomness * (-1, 1).

setGroupVelocity( dir, type, randomness )

dir: Vector3
type: int
randomness: float

Assign velocity to all replicated entities.

Possible values for type are:

Value Description
0 uniform assignment.
1 random amplitude but same direction given by dir.
2 apply to entity's current direction, same amplitude.
2 apply to entity's current direction, random amplitude.
2 random direction of non-zero axis, speed.x + speed.x * randomness * (-1, 1)

setIndexedMass( x, y, z, mass, type, randomness )

Same as setGroupMass but apply to only the entity selected by [x, y, z].

setIndexedVelocity: function(x, y, z, dir, type, randomness)

Same as setGroupVelocity but apply to only the entity selected by [x, y, z].

applyForce( force, dir, pos, time )

force: float
dir: Vector3
pos: Vector3
time: float

Apply a force of amplitude force and direction dir at a world position pos and for a time period given by time.

applyLocalForce( force, dir, pos, time )

force: float
dir: Vector3
pos: Vector3
time: float

Apply a force of amplitude force and direction dir at a mesh's local position pos and for a time period given by time.

applyTorque( amp, dir, time )

amp: float
dir: Vector3
time: float

Apply a torque to this mesh with amplitude amp and direction dir for a time period given by time.

setCenterOfMass( c )

c: Vector3

Sets the center of mass for this mesh.

getCenterOfMass()

Return: Vector3

Returns the location of this mesh's center of mass.

buildTangentVector()

Regenerate tangent vector along the mesh's surface.

When applying normal map, the mesh must have its surface tangents defined. If not, you can called this function to regenerate surface tangents.

Personal tools