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

SkinnedMesh/Skeleton: Added serialization/deserialization #15413

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
66 changes: 48 additions & 18 deletions docs/api/en/loaders/ObjectLoader.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ <h3>[property:String resourcePath]</h3>

<h2>Methods</h2>

<h3>[method:ObjectLoader bindSkeletons]( [param:Object3D object], [param:Array skeletons] )</h3>
<p>
[page:Object3D object] — required. The parsed object hierarchy.<br /><br />
[page:Array skeletons] — required. An array of parsed skeletons.<br /><br />

Used to bind skeletons to objects of type [page:SkinnedMesh].
</p>

<h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
<p>
[page:String url] — the path or URL to the file. This can also be a
Expand All @@ -100,7 +108,6 @@ <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Func
Begin loading from url and call onLoad with the parsed response content.
</p>


<h3>[method:Object3D parse]( [param:Object json], [param:Function onLoad] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />
Expand All @@ -111,46 +118,41 @@ <h3>[method:Object3D parse]( [param:Object json], [param:Function onLoad] )</h3
a previously loaded JSON structure.
</p>

<h3>[method:Object3D parseGeometries]( [param:Object json] )</h3>
<h3>[method:Array parseAnimations]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />

This is used [page:.parse] to parse any [page:Geometry geometries] or [page:BufferGeometry buffer geometries] in the JSON structure.
This is used by [page:.parse]() to parse any animations in the JSON structure, using [page:AnimationClip.parse]().
</p>

<h3>[method:Object3D parseMaterials]( [param:Object json] )</h3>
<h3>[method:Object parseGeometries]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />

This is used [page:.parse] to parse any materials in the JSON structure using [page:MaterialLoader].
This is used by [page:.parse]() to parse any geometries in the JSON structure.
</p>

<h3>[method:Object3D parseAnimations]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />

This is used [page:.parse] to parse any animations in the JSON structure, using [page:AnimationClip.parse].
</p>

<h3>[method:Object3D parseImages]( [param:Object json] )</h3>
<h3>[method:Object parseImages]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />

This is used [page:.parse] to parse any images in the JSON structure, using [page:ImageLoader].
</p>

<h3>[method:Object3D parseTextures]( [param:Object json] )</h3>
<h3>[method:Object parseMaterials]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />

This is used [page:.parse] to parse any textures in the JSON structure.
This is used by [page:.parse]() to parse any materials in the JSON structure using [page:MaterialLoader].
</p>

<h3>[method:Object3D parseObject]( [param:Object json] )</h3>
<h3>[method:Object3D parseObject]( [param:Object data], [param:Object geometries], [param:Object materials] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />
[page:Object data] — required. The JSON source to parse.<br /><br />
[page:Object geometries] — The parsed geometries.<br /><br />
[page:Object materials] — The parsed materials.<br /><br />

This is used [page:.parse] to parse any objects in the JSON structure.
This is used by [page:.parse]() to parse any objects in the JSON structure.
Objects can be of the following types:

<ul>
Expand Down Expand Up @@ -178,9 +180,15 @@ <h3>[method:Object3D parseObject]( [param:Object json] )</h3>
<li>
[page:HemisphereLight]
</li>
<li>
[page:SkinnedMesh]
</li>
<li>
[page:Mesh]
</li>
<li>
[page:Bone]
</li>
<li>
[page:LOD]
</li>
Expand All @@ -206,6 +214,28 @@ <h3>[method:Object3D parseObject]( [param:Object json] )</h3>
</ul>
</p>

<h3>[method:Object parseShapes]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />

This is used by [page:.parse]() to parse any shapes in the JSON structure.
</p>

<h3>[method:Object parseSkeletons]( [param:Object json], [param:Object3D object] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />
[page:Object3D object] — required. A hierarchy of 3D objects which is used to query the bones.<br /><br />

This is used by [page:.parse]() to parse any skeletons in the JSON structure.
</p>

<h3>[method:Object parseTextures]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />

This is used by [page:.parse]() to parse any textures in the JSON structure.
</p>

<h3>[method:ObjectLoader setCrossOrigin]( [param:String value] )</h3>
<p>
[page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
Expand Down
17 changes: 17 additions & 0 deletions docs/api/en/objects/Skeleton.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ <h3>[property:DataTexture boneTexture]</h3>
The [page:DataTexture] holding the bone data when using a vertex texture.
</p>

<h3>[property:Number boneTextureSize]</h3>
<p>
The size of the bone texture.
</p>


<h2>Methods</h2>

Expand All @@ -92,10 +97,22 @@ <h3>[method:null calculateInverses]()</h3>
<p>Generates the [page:.boneInverses boneInverses] array if not provided in the constructor.</p>


<h3>[method:Skeleton fromJSON]( [param:Object json], [param:Object3D object])</h3>
<p>Creates the skeleton by the given JSON data and object hierarchy.</p>


<h3>[method:Skeleton init]()</h3>
<p>Initializes [page:.boneMatrices] and [page:.boneInverses] if necessary.</p>


<h3>[method:null pose]()</h3>
<p>Returns the skeleton to the base pose.</p>


<h3>[method:Object toJSON]()</h3>
<p>Serializes this skeleton object.</p>


<h3>[method:null update]()</h3>
<p>
Updates the [page:Float32Array boneMatrices] and [page:DataTexture boneTexture] after changing the bones.
Expand Down
72 changes: 51 additions & 21 deletions docs/api/zh/loaders/ObjectLoader.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ <h2>属性</h2>

<h3>[property:String crossOrigin]</h3>
<p>
如果设置了,在开始加载前, 将为图片分配 [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin]
属性,其值为 *crossOrigin*, 默认为"anonymous"。
如果设置了,在开始加载前, 将为图片分配 [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin]
属性,其值为 *crossOrigin*, 默认为"anonymous"。
</p>

<h3>[property:LoadingManager manager]</h3>
Expand All @@ -88,6 +88,14 @@ <h3>[property:String texturePath]</h3>

<h2>方法</h2>

<h3>[method:ObjectLoader bindSkeletons]( [param:Object3D object], [param:Array skeletons] )</h3>
<p>
[page:Object3D object] — TODO.<br /><br />
[page:Array skeletons] — TODO.<br /><br />

TODO
</p>

<h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
<p>
[page:String url] — 文件的URL或者路径,也可以为
Expand All @@ -97,58 +105,74 @@ <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Func
[page:Function onError] — 在加载错误时被调用。<br />
</p>
<p>
从URL中进行加载,并将被解析的响应内容传递给onLoad。
从URL中进行加载,并将被解析的响应内容传递给onLoad。
</p>


<h3>[method:Object3D parse]( [param:Object json], [param:Function onLoad] )</h3>
<h3>[method:Object3D parse]( [param:Object json], [param:Function onLoad] )</h3>
<p>
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />
[page:Function onLoad] — 当解析完成时被调用,其中参数被解析为[page:Object3D object].<br /><br />

解析一个<em>JSON</em>结构,并返回一个threejs对象.
解析一个<em>JSON</em>结构,并返回一个threejs对象.
内部使用[page:.load]进行加载, 但也可以直接用于解析先前加载的JSON结构。
</p>

<h3>[method:Object3D parseGeometries]( [param:Object json] )</h3>
<h3>[method:Object parseGeometries]( [param:Object json] )</h3>
<p>
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />

此函数以JSON结构,用[page:.parse]去解析[page:Geometry geometries]或[page:BufferGeometry buffer geometries]。
此函数以JSON结构,用[page:.parse]去解析[page:Geometry geometries]或[page:BufferGeometry buffer geometries]。
</p>

<h3>[method:Object3D parseMaterials]( [param:Object json] )</h3>
<h3>[method:Object parseMaterials]( [param:Object json] )</h3>
<p>
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />

此函数通过[page:.parse]来使用[page:MaterialLoader],以解析JSON结构中任意材质。
</p>

<h3>[method:Object3D parseAnimations]( [param:Object json] )</h3>
<h3>[method:Array parseAnimations]( [param:Object json] )</h3>
<p>
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />

此函数通过[page:.parse]来使用[page:AnimationClip.parse], 以解析JSON结构中任意动画。
</p>
</p>

<h3>[method:Object parseImages]( [param:Object json] )</h3>
<p>
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />
此函数通过[page:.parse]来使用[page:ImageLoader], 以解析JSON结构中任意图片。
</p>

<h3>[method:Object3D parseImages]( [param:Object json] )</h3>
<h3>[method:Object parseShapes]( [param:Object json] )</h3>
<p>
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />
[page:Object json] — TODO.<br /><br />

此函数通过[page:.parse]来使用[page:ImageLoader], 以解析JSON结构中任意图片。
TODO.
</p>

<h3>[method:Object3D parseTextures]( [param:Object json] )</h3>
<h3>[method:Object parseSkeletons]( [param:Object json], [param:Object3D object] )</h3>
<p>
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />
此函数通过[page:.parse]来解析JSON结构中任意纹理。
[page:Object json] — TODO.<br /><br />
[page:Object3D object] — TODO.<br /><br />

TODO.
</p>

<h3>[method:Object parseTextures]( [param:Object json] )</h3>
<p>
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />
此函数通过[page:.parse]来解析JSON结构中任意纹理。
</p>

<h3>[method:Object3D parseObject]( [param:Object json] )</h3>
<h3>[method:Object3D parseObject]( [param:Object data], [param:Object geometries], [param:Object materials] )</h3>
<p>
[page:Object json] — 必选参数,需要被解析的JSON源。<br /><br />
[page:Object data] — 必选参数,需要被解析的JSON源。<br /><br />
[page:Object geometries] — TODO.<br /><br />
[page:Object materials] — TODO.<br /><br />

此函数通过[page:.parse]来解析JSON结构中任意对象。
此函数通过[page:.parse]来解析JSON结构中任意对象。
对象可以为如下类型:

<ul>
Expand Down Expand Up @@ -176,9 +200,15 @@ <h3>[method:Object3D parseObject]( [param:Object json] )</h3>
<li>
[page:HemisphereLight]
</li>
<li>
[page:SkinnedMesh]
</li>
<li>
[page:Mesh]
</li>
<li>
[page:Bone]
</li>
<li>
[page:LOD]
</li>
Expand Down
19 changes: 18 additions & 1 deletion docs/api/zh/objects/Skeleton.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ <h3>[property:DataTexture boneTexture]</h3>
当使用顶点纹理时,[page:DataTexture]保存着骨骼数据。
</p>

<h3>[property:Number boneTextureSize]</h3>
<p>
TODO
</p>


<h2>方法</h2>

Expand All @@ -90,10 +95,22 @@ <h3>[method:null calculateInverses]()</h3>
</p>


<h3>[method:Skeleton fromJSON]( [param:Object json], [param:Object3D object])</h3>
<p>TODO</p>


<h3>[method:Skeleton init]()</h3>
<p>TODO</p>


<h3>[method:null pose]()</h3>
<p>返回骨架的基础姿势。</p>


<h3>[method:Object toJSON]()</h3>
<p>TODO</p>


<h3>[method:null update]()</h3>
<p>
在改变骨骼后,更新[page:Float32Array boneMatrices] 和 [page:DataTexture boneTexture]的值。
Expand All @@ -102,7 +119,7 @@ <h3>[method:null update]()</h3>

<h3>[method:Bone getBoneByName]( [param:String name] )</h3>
<p>

name —— 匹配Bone对象中.name属性的字符串。<br /><br />
在骨架中的骨骼数组中遍览,并返回第一个能够和name匹配上的骨骼对象。<br />
</p>
Expand Down
25 changes: 24 additions & 1 deletion src/core/BufferGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,30 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy

var attribute = attributes[ key ];

var array = Array.prototype.slice.call( attribute.array );
var array;

if ( attribute.isInterleavedBufferAttribute ) {
Copy link
Collaborator Author

@Mugen87 Mugen87 Dec 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary since some glTF models might have interleaved buffer data like in webgl_animation_skinning_blending. This code section creates normal BufferAttributes in order to ensure correct buffer data.


var count = attribute.count;
var itemSize = attribute.itemSize;
array = attribute.array.slice( 0, count * itemSize );

var s = 0;

for ( var i = 0; i < count; ++ i ) {

array[ s ++ ] = attribute.getX( i );
if ( itemSize >= 2 ) array[ s ++ ] = attribute.getY( i );
if ( itemSize >= 3 ) array[ s ++ ] = attribute.getZ( i );
if ( itemSize >= 4 ) array[ s ++ ] = attribute.getW( i );

}

} else {

array = Array.prototype.slice.call( attribute.array );

}

data.data.attributes[ key ] = {
itemSize: attribute.itemSize,
Expand Down
Loading