Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions type_templates/glb.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default e => {
}

app.glb = null;
const animationMixers = [];
app.mixer = null;
const uvScrolls = [];
const physicsIds = [];
app.physicsIds = physicsIds;
Expand Down Expand Up @@ -77,17 +77,21 @@ export default e => {
const _loadHubsComponents = () => {
const _loadAnimations = () => {
const animationEnabled = !!(app.getComponent('animation') ?? true);
if (animationEnabled) {
const idleAnimation = animations.find(a => a.name === 'idle');

if (animationEnabled && animations.length > 0){

app.mixer = new THREE.AnimationMixer(o); // create the animation mixer with the root of the glb file

const userIdle = app.getComponent('idleAnimation');
const idleString = typeof userIdle === 'string' ? userIdle : 'idle';

const idleAnimation = animations.find(a => a.name === idleString);
const clips = idleAnimation ? [idleAnimation] : animations;
for (const clip of clips) {
const mixer = new THREE.AnimationMixer(o);

const action = mixer.clipAction(clip);
const action = app.mixer.clipAction(clip);
action.play();

animationMixers.push(mixer);
}

}
};
const petComponent = app.getComponent('pet');
Expand Down Expand Up @@ -286,8 +290,8 @@ export default e => {
useFrame(({timestamp, timeDiff}) => {
const _updateAnimation = () => {
const deltaSeconds = timeDiff / 1000;
for (const mixer of animationMixers) {
mixer.update(deltaSeconds);
if (app.mixer){
app.mixer.update(deltaSeconds);
app.updateMatrixWorld();
}
};
Expand All @@ -313,11 +317,10 @@ export default e => {
});

app.stop = () => {
for (const mixer of animationMixers) {
console.log('got mixer', mixer);
mixer.stopAllAction();
if (app.mixer){
app.mixer.stopAllAction();
app.mixer = null;
}
animationMixers.length = 0;
};

return app;
Expand Down