GltfModel
Description
This component establishes custom geometry on an entity.
Properties
Property | Type | Default | Description |
---|---|---|---|
url (Required) | string | "" | The source url. |
animationClip | string | "" | The name of the animationClip attached to the model to play. The Wildcard * is also accepted, and will set the model to play through every animation. |
loop | boolean | false | Whether the animation clip restarts after it finishes playing or not |
paused | boolean | false | Whether the animation clip is paused |
time | number | 0 | Time in seconds of animationClip to jump to |
timeScale | number | 1 | Scaling factor for the time. 0 causes the animation to pause. Negative values cause the animation to play backwards. |
collider | boolean | false | Whether the animation should update the physics collider. |
reverse | boolean | false | If set, the animation will play in reverse when it finishes playing forward (together counts as one loop iteration) |
repetitions | number | -1 | If set along with ‘loop’, the number of times the loop will be repeated (-1 means loop forever) |
crossFadeDuration | number | 0 | The time in seconds that will be spent blending between animations when a new animation is started (and an existing animation is playing) |
Functions
Get
Returns a read-only reference.
Example
ecs.GltfModel.get(world, component.eid)
Set
Ensures the component exists on the entity, then assigns the (optional) data to the component.
Example
ecs.GltfModel.set(world, component.eid, {
url: './assets/doty.glb',
animationClip: 'idle',
loop: false,
paused: false,
time: 0,
timeScale: 1,
collider: false,
reverse: false,
repetitions: -1,
crossFadeDuration: 0
})
Mutate
Perform an update to the component within a callback function. Return true
to indicate no changes made.
Example
ecs.GltfModel.mutate(world, component.eid, (cursor) => {
cursor.timeScale = 0.5;
cursor.loop = true;
return false;
})
Remove
Removes the component from the entity.
Example
ecs.GltfModel.remove(world, component.eid)
Has
Returns true
if the component is present on the entity.
Example
ecs.GltfModel.has(world, component.eid)
Reset
Adds, or resets the component to its default state.
Example
ecs.GltfModel.reset(world, component.eid)
Advanced Functions
Cursor
Returns a mutable reference. Cursors are reused so only one cursor for each component can exist at a time.
Example
ecs.GltfModel.cursor(world, component.eid)
Acquire
Same behavior as cursor, but commit must be called after the cursor is done being used.
Example
ecs.GltfModel.acquire(world, component.eid)