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

animations

Optional custom animations
Source:

body

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

cache

fetch API cache control - use no-cache in development
Source:

debug

Debug output, default false
Source:

displayName

Whether to display the name above the head, defaults to value of static displayName
Source:

displayName

Whether to display the name above the head, default true
Source:

displayText

Should written/spoken text be displayed above the head, default true
Source:

displayText

Should written/spoken text be displayed above the head, defaults to value of static displayText
Source:

file

File name, default scene.gltf
Source:

fixes

Object containing fixes
Source:

folder

ServerFolder with content path
Source:

fps

Animation frames per second, default 10
Source:

generateAnimations

Wheter to generate animations for arms, legs and body (crouch/jump) movement, default true
Source:

groundHeight

Height of the ground, default 0
Source:

info

Object containing author, license, source, title
Source:

name

Name of the avatar/user
Source:

parentMesh

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

returnToRest

Return to rest after cloning, default true (otherwise keeps the pose)
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:

turnAround

GLTF characters are facing the user when loaded, turn it around, default false. Does not apply to cloned characters, only to the first one actually loaded.
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:

animationBlending()

Enable or disable animation blending for all animation of all groups
Source:

armDirectionCharacter()

Point arm to given direction, in character space
Source:

armDirectionLocal()

Point arm to given direction, in arm space
Source:

attachAnimations()

Create an animation group from given object and attach it to the character.
Source:

bendArm()

Bend/stretch arm to a 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:

disableNodes()

Disable nodes marked in fixes file
Source:

dispose()

Dispose of everything
Source:

drawVector()

Debugging helper, draws a vector between given points
Source:

enableNodes(nodeIds, enable)

Enable/disable given nodes
Parameters:
Name Type Description
nodeIds array of node identifiers
enable true/false
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:
Returns head 'bone'
Source:

headPos()

Returns position of the the head 'bone'
Source:

height()

Returns current height - distance head to feet
Source:

jump(height)

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

load(success, failure)

Loads the avatar.
Parameters:
Name Type Description
success callback to execute on success
failure executed if loading fails
Source:

loadAnimations()

Load an animation group from an url
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:

postProcess()

Apply fixes after loading/instantiation
Source:

processAnimations()

Processes all animation in an animation group.
Source:
Returns:
object suitable for saving

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:

recompute()

After resizing and some other manipulations, matrices may need to be recomputed in a reliable way. How to do it depends on babylon.js version.
Source:

renderBodyPosition()

Renders crouch/raise changes to body: either generates the animation, or changes this.rootMesh position right away, depending on this.generateAnimations flag.
Source:

renderLimbRotation()

Move an arm or leg, optionally creates/updates arm animation depending on this.generateAnimations flag
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:

saveAnimations()

Saves all animations in given animation group. Opens save file dialog.
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, startTime, endTime)

Slice an animation group
Parameters:
Name Type Description
group AnimationGroup to slice
startTime slice starting time
endTime slice ending time
Source:
Returns:
new AnimationGroup containing slice of original animations

standUp()

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

startAnimation(animationName, loop, speedRatio)

Start a given animation
Parameters:
Name Type Description
animationName animation to start
loop if set, changes AnimationGroup.loopAnimation property
speedRatio if set, changes AnimationGroup.speedRatio
Source:

stopAnimation()

Stop an animation. To allow for blending, just turns off looping rather than stopping it right away, unless forced.
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: