Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object3D: Add animations property. #20738

Merged
merged 1 commit into from
Nov 22, 2020
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions docs/api/ar/animation/AnimationClip.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ <h3>[method:this resetDuration]()</h3>
يضبط [page:.duration duration] للمقطع على أطول مدة [page:KeyframeTrack] ممكنة.
</p>

<h3>[method:Object toJSON]()</h3>
<p>
Returns a JSON object representing the serialized animation clip.
</p>

<h3>[method:this trim]()</h3>
<p>
اقتطاع كل المسارات حسب مدة المقطع.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/en/animation/AnimationClip.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ <h3>[method:this resetDuration]()</h3>
[page:KeyframeTrack].
</p>

<h3>[method:Object toJSON]()</h3>
<p>
Returns a JSON object representing the serialized animation clip.
</p>

<h3>[method:this trim]()</h3>
<p>
Trims all tracks to the clip's duration.
Expand Down
3 changes: 3 additions & 0 deletions docs/api/en/core/Object3D.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ <h3>[name]()</h3>

<h2>Properties</h2>

<h3>[property:AnimationClip animations]</h3>
<p>Array with object's animation clips.</p>

<h3>[property:Boolean castShadow]</h3>
<p>Whether the object gets rendered into shadow map. Default is *false*.</p>

Expand Down
7 changes: 5 additions & 2 deletions docs/api/en/loaders/ObjectLoader.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ <h3>[method:Object3D parseTextures]( [param:Object json] )</h3>
This is used [page:.parse] to parse any textures in the JSON structure.
</p>

<h3>[method:Object3D parseObject]( [param:Object json] )</h3>
<h3>[method:Object3D parseObject]( [param:Object json], [param:BufferGeometry geometries], [param:Material materials], [param:AnimationClip animations] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />
[page:Object json] — required. The JSON source to parse.<br />
[page:BufferGeometry geometries] — required. The geometries of the JSON.<br />
[page:Material materials] — required. The materials of the JSON.<br />
[page:AnimationClip animations] — required. The animations of the JSON.<br /><br />

This is used [page:.parse] to parse any objects in the JSON structure.
Objects can be of the following types:
Expand Down
5 changes: 5 additions & 0 deletions docs/api/zh/animation/AnimationClip.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ <h3>[method:this resetDuration]()</h3>
将剪辑的持续时间([page:.duration duration])设为最长的关键帧轨道([page:KeyframeTrack])的持续时间。
</p>

<h3>[method:Object toJSON]()</h3>
<p>
Returns a JSON object representing the serialized animation clip.
</p>

<h3>[method:this trim]()</h3>
<p>
修剪所有的轨道到该剪辑的持续时间。
Expand Down
3 changes: 3 additions & 0 deletions docs/api/zh/core/Object3D.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ <h3>[name]()</h3>

<h2>属性</h2>

<h3>[property:AnimationClip animations]</h3>
<p>Array with object's animation clips.</p>

<h3>[property:Boolean castShadow]</h3>
<p>对象是否被渲染到阴影贴图中。默认值为*false*。</p>

Expand Down
7 changes: 5 additions & 2 deletions docs/api/zh/loaders/ObjectLoader.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ <h3>[method:Object3D parseTextures]( [param:Object json] )</h3>
此函数通过[page:.parse]来解析JSON结构中任意纹理。
</p>

<h3>[method:Object3D parseObject]( [param:Object json] )</h3>
<h3>[method:Object3D parseObject]( [param:Object json], [param:BufferGeometry geometries], [param:Material materials], [param:AnimationClip animations] )</h3>
<p>
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />
[page:Object json] — 必选参数,需要被解析的JSON源。<br />
[page:BufferGeometry geometries] — required. The geometries of the JSON.<br />
[page:Material materials] — required. The materials of the JSON.<br />
[page:AnimationClip animations] — required. The animations of the JSON.<br /><br />

此函数通过[page:.parse]来解析JSON结构中任意对象。
对象可以为如下类型:
Expand Down
54 changes: 1 addition & 53 deletions editor/js/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ function Editor() {

this.materialsRefCounter = new Map(); // tracks how often is a material used by a 3D object

this.animations = {};
this.mixer = new THREE.AnimationMixer( this.scene );

this.selected = null;
Expand Down Expand Up @@ -357,16 +356,6 @@ Editor.prototype = {

},

addAnimations: function ( object, animations ) {

if ( animations.length > 0 ) {

this.animations[ object.uuid ] = animations;

}

},

//

addCamera: function ( camera ) {
Expand Down Expand Up @@ -664,50 +653,10 @@ Editor.prototype = {

} );

// animations

var animationsJSON = json.animations;

for ( var i = 0; i < animationsJSON.length; i ++ ) {

var objectJSON = animationsJSON[ i ];
var animations = [];

for ( var j = 0; j < objectJSON.animations.length; j ++ ) {

animations.push( THREE.AnimationClip.parse( objectJSON.animations[ j ] ) );

}

this.animations[ objectJSON.uuid ] = animations;

}

},

toJSON: function () {

// animations

var animations = this.animations;
var animationsJSON = [];

for ( var entry in animations ) {

var objectAnimations = animations[ entry ];
var objectJSON = { uuid: entry, animations: [] };

for ( var i = 0; i < objectAnimations.length; i ++ ) {

var objectAnimation = objectAnimations[ i ];
objectJSON.animations.push( THREE.AnimationClip.toJSON( objectAnimation ) );

}

animationsJSON.push( objectJSON );

}

// scripts clean up

var scene = this.scene;
Expand Down Expand Up @@ -741,8 +690,7 @@ Editor.prototype = {
camera: this.camera.toJSON(),
scene: this.scene.toJSON(),
scripts: this.scripts,
history: this.history.toJSON(),
animations: animationsJSON
history: this.history.toJSON()

};

Expand Down
13 changes: 6 additions & 7 deletions editor/js/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function Loader( editor ) {

collada.scene.name = filename;

editor.addAnimations( collada.scene, collada.animations );
collada.scene.animations.push( ...collada.animations );
editor.execute( new AddObjectCommand( editor, collada.scene ) );

}, false );
Expand Down Expand Up @@ -226,7 +226,6 @@ function Loader( editor ) {
var loader = new FBXLoader( manager );
var object = loader.parse( contents );

editor.addAnimations( object, object.animations );
editor.execute( new AddObjectCommand( editor, object ) );

}, false );
Expand All @@ -250,7 +249,7 @@ function Loader( editor ) {
var scene = result.scene;
scene.name = filename;

editor.addAnimations( scene, result.animations );
scene.animations.push( ...result.animations );
editor.execute( new AddObjectCommand( editor, scene ) );

} );
Expand Down Expand Up @@ -287,7 +286,7 @@ function Loader( editor ) {
var scene = result.scene;
scene.name = filename;

editor.addAnimations( scene, result.animations );
scene.animations.push( ...result.animations );
editor.execute( new AddObjectCommand( editor, scene ) );

} );
Expand Down Expand Up @@ -386,7 +385,7 @@ function Loader( editor ) {
mesh.mixer = new THREE.AnimationMixer( mesh );
mesh.name = filename;

editor.addAnimations( mesh, geometry.animations );
mesh.animations.push( ...geometry.animations );
editor.execute( new AddObjectCommand( editor, mesh ) );

}, false );
Expand Down Expand Up @@ -720,7 +719,7 @@ function Loader( editor ) {

var scene = result.scene;

editor.addAnimations( scene, result.animations );
scene.animations.push( ...result.animations );
editor.execute( new AddObjectCommand( editor, scene ) );

} );
Expand All @@ -738,7 +737,7 @@ function Loader( editor ) {

var scene = result.scene;

editor.addAnimations( scene, result.animations );
scene.animations.push( ...result.animations );
editor.execute( new AddObjectCommand( editor, scene ) );

} );
Expand Down
8 changes: 3 additions & 5 deletions editor/js/Sidebar.Animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ function SidebarAnimation( editor ) {

signals.objectSelected.add( function ( object ) {

var animations = editor.animations[ object !== null ? object.uuid : '' ];
if ( object !== null && object.animations.length > 0 ) {

if ( animations !== undefined ) {
var animations = object.animations;

container.setDisplay( '' );

Expand Down Expand Up @@ -42,9 +42,7 @@ function SidebarAnimation( editor ) {

signals.objectRemoved.add( function ( object ) {

var animations = editor.animations[ object !== null ? object.uuid : '' ];

if ( animations !== undefined ) {
if ( object !== null && object.animations.length > 0 ) {

mixer.uncacheRoot( object );

Expand Down
1 change: 1 addition & 0 deletions src/animation/AnimationClip.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class AnimationClip {
validate(): boolean;
optimize(): AnimationClip;
clone(): AnimationClip;
toJSON( clip: AnimationClip ): any;

static CreateFromMorphTargetSequence(
name: string,
Expand Down
11 changes: 10 additions & 1 deletion src/animation/AnimationClip.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ Object.assign( AnimationClip, {

}

return new AnimationClip( json.name, json.duration, tracks, json.blendMode );
const clip = new AnimationClip( json.name, json.duration, tracks, json.blendMode );
clip.uuid = json.uuid;

return clip;

},

Expand Down Expand Up @@ -460,6 +463,12 @@ Object.assign( AnimationClip.prototype, {

return new AnimationClip( this.name, this.duration, tracks, this.blendMode );

},

toJSON: function () {

return AnimationClip.toJSON( this );

}

} );
Expand Down
7 changes: 7 additions & 0 deletions src/core/Object3D.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Raycaster } from './Raycaster';
import { EventDispatcher } from './EventDispatcher';
import { BufferGeometry } from './BufferGeometry';
import { Intersection } from './Raycaster';
import { AnimationClip } from '../animation/AnimationClip';

/**
* Base class for scene graph objects
Expand Down Expand Up @@ -153,6 +154,12 @@ export class Object3D extends EventDispatcher {
*/
renderOrder: number;

/**
* Array with animation clips.
* @default []
*/
animations: AnimationClip[];

/**
* An object that can be used to store custom data about the Object3d. It should not hold references to functions as these will not be cloned.
* @default {}
Expand Down
23 changes: 22 additions & 1 deletion src/core/Object3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ function Object3D() {
this.frustumCulled = true;
this.renderOrder = 0;

this.animations = [];

this.userData = {};

}
Expand Down Expand Up @@ -659,7 +661,8 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
textures: {},
images: {},
shapes: {},
skeletons: {}
skeletons: {},
animations: {}
};

output.metadata = {
Expand Down Expand Up @@ -795,6 +798,22 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),

}

//

if ( this.animations.length > 0 ) {

object.animations = [];

for ( let i = 0; i < this.animations.length; i ++ ) {

const animation = this.animations[ i ];

object.animations.push( serialize( meta.animations, animation ) );

}

}

if ( isRootObject ) {

const geometries = extractFromCache( meta.geometries );
Expand All @@ -803,13 +822,15 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
const images = extractFromCache( meta.images );
const shapes = extractFromCache( meta.shapes );
const skeletons = extractFromCache( meta.skeletons );
const animations = extractFromCache( meta.animations );

if ( geometries.length > 0 ) output.geometries = geometries;
if ( materials.length > 0 ) output.materials = materials;
if ( textures.length > 0 ) output.textures = textures;
if ( images.length > 0 ) output.images = images;
if ( shapes.length > 0 ) output.shapes = shapes;
if ( skeletons.length > 0 ) output.skeletons = skeletons;
if ( animations.length > 0 ) output.animations = animations;

}

Expand Down
3 changes: 2 additions & 1 deletion src/loaders/ObjectLoader.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export class ObjectLoader extends Loader {
parseObject<T extends Object3D>(
data: any,
geometries: any[],
materials: Material[]
materials: Material[],
animations: AnimationClip[]
): T;

}
Loading