Skip to content

Commit 4d05b7b

Browse files
authored
Merge pull request #20454 from Mugen87/dev51
Editor: Support animation export with GLTFExporter.
2 parents 7603c0b + f966357 commit 4d05b7b

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

editor/js/Editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ Editor.prototype = {
357357

358358
},
359359

360-
addAnimation: function ( object, animations ) {
360+
addAnimations: function ( object, animations ) {
361361

362362
if ( animations.length > 0 ) {
363363

editor/js/Loader.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function Loader( editor ) {
169169

170170
collada.scene.name = filename;
171171

172-
editor.addAnimation( collada.scene, collada.animations );
172+
editor.addAnimations( collada.scene, collada.animations );
173173
editor.execute( new AddObjectCommand( editor, collada.scene ) );
174174

175175
}, false );
@@ -210,7 +210,7 @@ function Loader( editor ) {
210210
var loader = new FBXLoader( manager );
211211
var object = loader.parse( contents );
212212

213-
editor.addAnimation( object, object.animations );
213+
editor.addAnimations( object, object.animations );
214214
editor.execute( new AddObjectCommand( editor, object ) );
215215

216216
}, false );
@@ -234,7 +234,7 @@ function Loader( editor ) {
234234
var scene = result.scene;
235235
scene.name = filename;
236236

237-
editor.addAnimation( scene, result.animations );
237+
editor.addAnimations( scene, result.animations );
238238
editor.execute( new AddObjectCommand( editor, scene ) );
239239

240240
} );
@@ -271,7 +271,7 @@ function Loader( editor ) {
271271
var scene = result.scene;
272272
scene.name = filename;
273273

274-
editor.addAnimation( scene, result.animations );
274+
editor.addAnimations( scene, result.animations );
275275
editor.execute( new AddObjectCommand( editor, scene ) );
276276

277277
} );
@@ -370,7 +370,7 @@ function Loader( editor ) {
370370
mesh.mixer = new THREE.AnimationMixer( mesh );
371371
mesh.name = filename;
372372

373-
editor.addAnimation( mesh, geometry.animations );
373+
editor.addAnimations( mesh, geometry.animations );
374374
editor.execute( new AddObjectCommand( editor, mesh ) );
375375

376376
}, false );
@@ -682,7 +682,7 @@ function Loader( editor ) {
682682

683683
var scene = result.scene;
684684

685-
editor.addAnimation( scene, result.animations );
685+
editor.addAnimations( scene, result.animations );
686686
editor.execute( new AddObjectCommand( editor, scene ) );
687687

688688
} );
@@ -700,7 +700,7 @@ function Loader( editor ) {
700700

701701
var scene = result.scene;
702702

703-
editor.addAnimation( scene, result.animations );
703+
editor.addAnimations( scene, result.animations );
704704
editor.execute( new AddObjectCommand( editor, scene ) );
705705

706706
} );

editor/js/Menubar.File.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,16 @@ function MenubarFile( editor ) {
245245
option.setTextContent( strings.getKey( 'menubar/file/export/glb' ) );
246246
option.onClick( function () {
247247

248+
var scene = editor.scene;
249+
var animations = getAnimations( scene );
250+
248251
var exporter = new GLTFExporter();
249252

250-
exporter.parse( editor.scene, function ( result ) {
253+
exporter.parse( scene, function ( result ) {
251254

252255
saveArrayBuffer( result, 'scene.glb' );
253256

254-
}, { binary: true } );
257+
}, { binary: true, animations: animations } );
255258

256259
} );
257260
options.add( option );
@@ -263,13 +266,16 @@ function MenubarFile( editor ) {
263266
option.setTextContent( strings.getKey( 'menubar/file/export/gltf' ) );
264267
option.onClick( function () {
265268

269+
var scene = editor.scene;
270+
var animations = getAnimations( scene );
271+
266272
var exporter = new GLTFExporter();
267273

268274
exporter.parse( editor.scene, function ( result ) {
269275

270276
saveString( JSON.stringify( result, null, 2 ), 'scene.gltf' );
271277

272-
} );
278+
}, { animations: animations } );
273279

274280

275281
} );
@@ -471,6 +477,22 @@ function MenubarFile( editor ) {
471477

472478
}
473479

480+
function getAnimations( scene ) {
481+
482+
var animations = [];
483+
484+
scene.traverse( function ( object ) {
485+
486+
var objectAnimations = editor.animations[ object.uuid ];
487+
488+
if ( objectAnimations !== undefined ) animations.push( ... objectAnimations );
489+
490+
} );
491+
492+
return animations;
493+
494+
}
495+
474496
return container;
475497

476498
}

0 commit comments

Comments
 (0)