Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
a2ed0276
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a2ed0276
编写于
3月 06, 2017
作者:
M
Mr.doob
提交者:
GitHub
3月 06, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10935 from Mugen87/dev
Skeleton Animation: Clean up
上级
4bfcc583
97de6b48
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
80 addition
and
58 deletion
+80
-58
docs/api/objects/SkinnedMesh.html
docs/api/objects/SkinnedMesh.html
+4
-1
src/objects/Skeleton.js
src/objects/Skeleton.js
+15
-16
src/objects/SkinnedMesh.js
src/objects/SkinnedMesh.js
+61
-41
未找到文件。
docs/api/objects/SkinnedMesh.html
浏览文件 @
a2ed0276
...
...
@@ -152,7 +152,10 @@
Updates the [page:Matrix4 MatrixWorld].
</div>
<h3>
[method:null initBones]()
</h3>
<div>
Creates an array of hierarchical [page:Bone bones] objects from the internal geometry.
</div>
<h2>
Source
</h2>
...
...
src/objects/Skeleton.js
浏览文件 @
a2ed0276
...
...
@@ -9,8 +9,6 @@ import { Matrix4 } from '../math/Matrix4';
function
Skeleton
(
bones
,
boneInverses
)
{
this
.
identityMatrix
=
new
Matrix4
();
// copy the bone array
bones
=
bones
||
[];
...
...
@@ -36,7 +34,7 @@ function Skeleton( bones, boneInverses ) {
this
.
boneInverses
=
[];
for
(
var
b
=
0
,
bl
=
this
.
bones
.
length
;
b
<
bl
;
b
++
)
{
for
(
var
i
=
0
,
il
=
this
.
bones
.
length
;
i
<
il
;
i
++
)
{
this
.
boneInverses
.
push
(
new
Matrix4
()
);
...
...
@@ -54,13 +52,13 @@ Object.assign( Skeleton.prototype, {
this
.
boneInverses
=
[];
for
(
var
b
=
0
,
bl
=
this
.
bones
.
length
;
b
<
bl
;
b
++
)
{
for
(
var
i
=
0
,
il
=
this
.
bones
.
length
;
i
<
il
;
i
++
)
{
var
inverse
=
new
Matrix4
();
if
(
this
.
bones
[
b
]
)
{
if
(
this
.
bones
[
i
]
)
{
inverse
.
getInverse
(
this
.
bones
[
b
].
matrixWorld
);
inverse
.
getInverse
(
this
.
bones
[
i
].
matrixWorld
);
}
...
...
@@ -72,17 +70,17 @@ Object.assign( Skeleton.prototype, {
pose
:
function
()
{
var
bone
;
var
bone
,
i
,
il
;
// recover the bind-time world matrices
for
(
var
b
=
0
,
bl
=
this
.
bones
.
length
;
b
<
bl
;
b
++
)
{
for
(
i
=
0
,
il
=
this
.
bones
.
length
;
i
<
il
;
i
++
)
{
bone
=
this
.
bones
[
b
];
bone
=
this
.
bones
[
i
];
if
(
bone
)
{
bone
.
matrixWorld
.
getInverse
(
this
.
boneInverses
[
b
]
);
bone
.
matrixWorld
.
getInverse
(
this
.
boneInverses
[
i
]
);
}
...
...
@@ -90,9 +88,9 @@ Object.assign( Skeleton.prototype, {
// compute the local matrices, positions, rotations and scales
for
(
var
b
=
0
,
bl
=
this
.
bones
.
length
;
b
<
bl
;
b
++
)
{
for
(
i
=
0
,
il
=
this
.
bones
.
length
;
i
<
il
;
i
++
)
{
bone
=
this
.
bones
[
b
];
bone
=
this
.
bones
[
i
];
if
(
bone
)
{
...
...
@@ -118,6 +116,7 @@ Object.assign( Skeleton.prototype, {
update
:
(
function
()
{
var
offsetMatrix
=
new
Matrix4
();
var
identityMatrix
=
new
Matrix4
();
return
function
update
()
{
...
...
@@ -128,14 +127,14 @@ Object.assign( Skeleton.prototype, {
// flatten bone matrices to array
for
(
var
b
=
0
,
bl
=
bones
.
length
;
b
<
bl
;
b
++
)
{
for
(
var
i
=
0
,
il
=
bones
.
length
;
i
<
il
;
i
++
)
{
// compute the offset between the current and the original transform
var
matrix
=
bones
[
b
]
?
bones
[
b
].
matrixWorld
:
this
.
identityMatrix
;
var
matrix
=
bones
[
i
]
?
bones
[
i
].
matrixWorld
:
identityMatrix
;
offsetMatrix
.
multiplyMatrices
(
matrix
,
boneInverses
[
b
]
);
offsetMatrix
.
toArray
(
boneMatrices
,
b
*
16
);
offsetMatrix
.
multiplyMatrices
(
matrix
,
boneInverses
[
i
]
);
offsetMatrix
.
toArray
(
boneMatrices
,
i
*
16
);
}
...
...
src/objects/SkinnedMesh.js
浏览文件 @
a2ed0276
...
...
@@ -18,28 +18,45 @@ function SkinnedMesh( geometry, material ) {
this
.
type
=
'
SkinnedMesh
'
;
this
.
bindMode
=
"
attached
"
;
this
.
bindMode
=
'
attached
'
;
this
.
bindMatrix
=
new
Matrix4
();
this
.
bindMatrixInverse
=
new
Matrix4
();
// init bones
var
bones
=
this
.
initBones
();
var
skeleton
=
new
Skeleton
(
bones
);
// TODO: remove bone creation as there is no reason (other than
// convenience) for THREE.SkinnedMesh to do this.
this
.
bind
(
skeleton
,
this
.
matrixWorld
);
var
bones
=
[];
this
.
normalizeSkinWeights
();
}
SkinnedMesh
.
prototype
=
Object
.
assign
(
Object
.
create
(
Mesh
.
prototype
),
{
constructor
:
SkinnedMesh
,
isSkinnedMesh
:
true
,
initBones
:
function
()
{
var
bones
=
[],
bone
,
gbone
;
var
i
,
il
;
if
(
this
.
geometry
&&
this
.
geometry
.
bones
!==
undefined
)
{
var
bone
,
gbone
;
// first, create array of 'Bone' objects from geometry data
for
(
i
=
0
,
il
=
this
.
geometry
.
bones
.
length
;
i
<
il
;
i
++
)
{
for
(
var
b
=
0
,
bl
=
this
.
geometry
.
bones
.
length
;
b
<
bl
;
++
b
)
{
gbone
=
this
.
geometry
.
bones
[
i
];
gbone
=
this
.
geometry
.
bones
[
b
];
// create new 'Bone' object
bone
=
new
Bone
();
bones
.
push
(
bone
);
// apply values
bone
.
name
=
gbone
.
name
;
bone
.
position
.
fromArray
(
gbone
.
pos
);
bone
.
quaternion
.
fromArray
(
gbone
.
rotq
);
...
...
@@ -47,18 +64,23 @@ function SkinnedMesh( geometry, material ) {
}
for
(
var
b
=
0
,
bl
=
this
.
geometry
.
bones
.
length
;
b
<
bl
;
++
b
)
{
// second, create bone hierarchy
gbone
=
this
.
geometry
.
bones
[
b
];
for
(
i
=
0
,
il
=
this
.
geometry
.
bones
.
length
;
i
<
il
;
i
++
)
{
if
(
gbone
.
parent
!==
-
1
&&
gbone
.
parent
!==
null
&&
bones
[
gbone
.
parent
]
!==
undefined
)
{
gbone
=
this
.
geometry
.
bones
[
i
];
bones
[
gbone
.
parent
].
add
(
bones
[
b
]
);
if
(
(
gbone
.
parent
!==
-
1
)
&&
(
gbone
.
parent
!==
null
)
&&
(
bones
[
gbone
.
parent
]
!==
undefined
)
)
{
// subsequent bones in the hierarchy
bones
[
gbone
.
parent
].
add
(
bones
[
i
]
);
}
else
{
this
.
add
(
bones
[
b
]
);
// topmost bone, immediate child of the skinned mesh
this
.
add
(
bones
[
i
]
);
}
...
...
@@ -66,18 +88,14 @@ function SkinnedMesh( geometry, material ) {
}
this
.
normalizeSkinWeights
();
// now the bones are part of the scene graph and children of the skinned mesh.
// let's update the corresponding matrices
this
.
updateMatrixWorld
(
true
);
this
.
bind
(
new
Skeleton
(
bones
),
this
.
matrixWorld
);
}
SkinnedMesh
.
prototype
=
Object
.
assign
(
Object
.
create
(
Mesh
.
prototype
),
{
constructor
:
SkinnedMesh
,
return
bones
;
isSkinnedMesh
:
true
,
}
,
bind
:
function
(
skeleton
,
bindMatrix
)
{
...
...
@@ -106,13 +124,15 @@ SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
normalizeSkinWeights
:
function
()
{
var
scale
,
i
;
if
(
this
.
geometry
&&
this
.
geometry
.
isGeometry
)
{
for
(
var
i
=
0
;
i
<
this
.
geometry
.
skinWeights
.
length
;
i
++
)
{
for
(
i
=
0
;
i
<
this
.
geometry
.
skinWeights
.
length
;
i
++
)
{
var
sw
=
this
.
geometry
.
skinWeights
[
i
];
var
scale
=
1.0
/
sw
.
lengthManhattan
();
scale
=
1.0
/
sw
.
lengthManhattan
();
if
(
scale
!==
Infinity
)
{
...
...
@@ -132,14 +152,14 @@ SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
var
skinWeight
=
this
.
geometry
.
attributes
.
skinWeight
;
for
(
var
i
=
0
;
i
<
skinWeight
.
count
;
i
++
)
{
for
(
i
=
0
;
i
<
skinWeight
.
count
;
i
++
)
{
vec
.
x
=
skinWeight
.
getX
(
i
);
vec
.
y
=
skinWeight
.
getY
(
i
);
vec
.
z
=
skinWeight
.
getZ
(
i
);
vec
.
w
=
skinWeight
.
getW
(
i
);
var
scale
=
1.0
/
vec
.
lengthManhattan
();
scale
=
1.0
/
vec
.
lengthManhattan
();
if
(
scale
!==
Infinity
)
{
...
...
@@ -159,21 +179,21 @@ SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
},
updateMatrixWorld
:
function
()
{
updateMatrixWorld
:
function
(
force
)
{
Mesh
.
prototype
.
updateMatrixWorld
.
call
(
this
,
tru
e
);
Mesh
.
prototype
.
updateMatrixWorld
.
call
(
this
,
forc
e
);
if
(
this
.
bindMode
===
"
attached
"
)
{
if
(
this
.
bindMode
===
'
attached
'
)
{
this
.
bindMatrixInverse
.
getInverse
(
this
.
matrixWorld
);
}
else
if
(
this
.
bindMode
===
"
detached
"
)
{
}
else
if
(
this
.
bindMode
===
'
detached
'
)
{
this
.
bindMatrixInverse
.
getInverse
(
this
.
bindMatrix
);
}
else
{
console
.
warn
(
'
THREE.SkinnedMesh
u
nrecognized bindMode:
'
+
this
.
bindMode
);
console
.
warn
(
'
THREE.SkinnedMesh
: U
nrecognized bindMode:
'
+
this
.
bindMode
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录