Class: Avatar

Avatar(scene, folder, shadowGenerator)

GLTF 3D Avatar. Once GLTF file is loaded, skeleton is inspected for existing arms, legs and head that can be animated. Animation groups are also inspected and optionally modified. Optional fixes can be applied to an avatar, typically position of an avatar, or changing the animation.

Constructor

new Avatar(scene, folder, shadowGenerator)

Parameters:
Name Type Description
scene
folder ServerFolder with the content
shadowGenerator optional to cast shadows
Source:

Classes

Avatar

Members

animateArms

Wheter to generate animations for arm movement, default true
Source:

body

Once the avatar is loaded an processed, body contains body parts, e.g. body.leftArm, body.rightLeg, body.neck
Source:

debug

Debug output, default false
Source:

fixes

Object containing fixes
Source:

folder

ServerFolder with content path
Source:

fps

Animation frames per second, default 10
Source:

groundHeight

Height of the ground, default 0
Source:

info

Object containing author, license, source, title
Source:

mirror

Mirror mode, default true. (Switch left/right side)
Source:

name

Name of the avatar/user
Source:

parentMesh

Parent mesh of the avatar, used for movement and attachment
Source:

rootMesh

Original root mesh of the avatar, used to scale the avatar
Source:

shadowGenerator

Optional ShadowGenerator
Source:

skeleton

Contains the skeleton once the avatar is loaded and processed
Source:

userHeight

Height of the user, default 1.8
Source:

Methods

absVector(vec)

Returns absolute value of vector, i.e. Math.abs() of every value
Parameters:
Name Type Description
vec Vector3 to get absolute
Source:

bendArm(arm, length)

Bend/stretch arm to a length
Parameters:
Name Type Description
arm
length
Source:

bendLeg(leg, length)

Bend/stretch leg to a length
Parameters:
Name Type Description
leg
length
Source:

calcLength(limb)

Returns lenght of an arm or leg, in absolute world coordinates.
Parameters:
Name Type Description
limb an arm or leg
Source:
Returns:
total length of lower and upper arm/leg

castShadows(shadowGenerator)

Adds or remove all avatar meshes to given ShadowGenerator.
Parameters:
Name Type Description
shadowGenerator removes shadows if null
Source:

changed()

Called when avatar size/height changes, TODO notify listeners
Source:

crouch(height)

Crouch a bit
Parameters:
Name Type Description
height how much
Source:

dispose()

Dispose of everything
Source:

drawVector()

Debugging helper, draws a vector between given points
Source:

euler(node)

Converts rotation quaternion of a node to euler angles
Parameters:
Name Type Description
node
Source:
Returns:
Vector3 containing rotation around x,y,z

getAnimationGroups()

Returns all animation groups of this avatar. Applies fixes first, if any.
Source:

getUrl()

Returns file name of this avatar, consisting of folder name and scene file name
Source:

groundLevel(y)

Sets the ground level
Parameters:
Name Type Description
y height of the ground at current position
Source:

headPos()

Returns position of the the head 'bone'
Source:

jump(height)

Moves the avatar to given height above the ground
Parameters:
Name Type Description
height jump how high
Source:

load(success, progress, failure)

Loads the avatar.
Parameters:
Name Type Description
success callback to execute on success
progress optional progress indicator, passed progress event
failure TODO
Source:

(async) loadFixes()

Load fixes from json file in the same folder, with the same name, and suffix .fixes. Called from load().
Source:

lookAt(t)

Look at given target. Head position is calculated without any bone limits.
Parameters:
Name Type Description
t target Vector3
Source:

reachFor(arm, t)

Move given arm towards given target. Uses simplified 2-joint IK.
Parameters:
Name Type Description
arm arm to move
t target position
Source:

replace(avatar)

Utility method, dispose of avatar and return this one.
Parameters:
Name Type Description
avatar optional avatar to dispose of
Source:

resize()

Resize the avatar taking into account userHeight and headPos.
Source:

rise(height)

Rise a bit
Parameters:
Name Type Description
height rise how much
Source:

roundVector(vec)

Returns rounded value of vector, i.e. Math.round() of every value
Parameters:
Name Type Description
vec Vector3 to round
Source:

(async) setName(name)

Set the name and display it above the avatar
Parameters:
Name Type Description
name
Source:

setPosition(pos)

Set avatar position.
Parameters:
Name Type Description
pos postion
Source:

setRotation(quat)

Set avatar rotation
Parameters:
Name Type Description
quat Quaternion
Source:

sliceAnimation(animation, start, end)

Slice an animation
Parameters:
Name Type Description
animation Animation to slice
start starting key
end ending key
Source:
Returns:
new Animation containing slice of original animation

sliceGroup(group, start, end)

Slice an animation group
Parameters:
Name Type Description
group AnimationGroup to slice
start starting key
end ending key
Source:
Returns:
new AnimationGroup containing slice of original animations

standUp()

Stand up straight, at the ground, legs fully stretched
Source:

startAnimation(animationName)

Start a given animation
Parameters:
Name Type Description
animationName animation to start
Source:

sum(vector)

Returns total weight of a vector, x+y+z
Parameters:
Name Type Description
vector Vector3 to sum
Source:

toDegrees(rot)

Converts euler radians to degrees
Parameters:
Name Type Description
rot Vector3 rotation around x,y,z
Source:
Returns:
Vector3 containing degrees around x,y,z

trackHeight(height)

Track user height: character may crouch or raise, or jump, depending on heights of avatar and user.
Parameters:
Name Type Description
height current user height
Source: