Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
a46a88ee
T
three.js
项目概览
Ablesons
/
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,发现更多精彩内容 >>
提交
a46a88ee
编写于
8月 22, 2013
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'blender-transform-armature' of
https://github.com/rmx/three.js
into dev
上级
25ddedc6
d8280746
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
59 addition
and
37 deletion
+59
-37
utils/exporters/blender/2.66/scripts/addons/io_mesh_threejs/export_threejs.py
...der/2.66/scripts/addons/io_mesh_threejs/export_threejs.py
+59
-37
未找到文件。
utils/exporters/blender/2.66/scripts/addons/io_mesh_threejs/export_threejs.py
浏览文件 @
a46a88ee
...
...
@@ -697,6 +697,25 @@ def generate_uvs(uv_layers, option_uv_coords):
return
","
.
join
(
"[%s]"
%
n
for
n
in
layers
)
# ##############################################################################
# Model exporter - armature
# (only the first armature will exported)
# ##############################################################################
def
get_armature
():
if
len
(
bpy
.
data
.
armatures
)
==
0
:
print
(
"Warning: no armatures in the scene"
)
return
None
,
None
armature
=
bpy
.
data
.
armatures
[
0
]
# Someone please figure out a proper way to get the armature node
for
object
in
bpy
.
data
.
objects
:
if
object
.
type
==
'ARMATURE'
:
return
armature
,
object
print
(
"Warning: no node of type 'ARMATURE' in the scene"
)
return
None
,
None
# ##############################################################################
# Model exporter - bones
# (only the first armature will exported)
...
...
@@ -704,39 +723,39 @@ def generate_uvs(uv_layers, option_uv_coords):
def
generate_bones
(
option_bones
,
flipyz
):
if
not
option_bones
or
len
(
bpy
.
data
.
armatures
)
==
0
:
if
not
option_bones
:
return
""
,
0
hierarchy
=
[]
armature
,
armatureObject
=
get_armature
()
if
armature
is
None
or
armatureObject
is
None
:
return
""
,
0
armature
=
bpy
.
data
.
armatures
[
0
]
hierarchy
=
[
]
TEMPLATE_BONE
=
'{"parent":%d,"name":"%s","pos":[%g,%g,%g],"rotq":[0,0,0,1]}'
for
bone
in
armature
.
bones
:
bonePos
=
None
boneIndex
=
None
if
bone
.
parent
==
None
:
if
flipyz
:
joint
=
TEMPLATE_BONE
%
(
-
1
,
bone
.
name
,
bone
.
head
.
x
,
bone
.
head
.
z
,
-
bone
.
head
.
y
)
hierarchy
.
append
(
joint
)
else
:
joint
=
TEMPLATE_BONE
%
(
-
1
,
bone
.
name
,
bone
.
head
.
x
,
bone
.
head
.
y
,
bone
.
head
.
z
)
hierarchy
.
append
(
joint
)
bonePos
=
bone
.
head_local
boneIndex
=
-
1
else
:
index
=
i
=
0
bonePos
=
bone
.
head_local
-
bone
.
parent
.
head_local
boneIndex
=
i
=
0
for
parent
in
armature
.
bones
:
if
parent
.
name
==
bone
.
parent
.
name
:
i
ndex
=
i
boneI
ndex
=
i
i
+=
1
position
=
bone
.
head_local
-
bone
.
parent
.
head_local
if
flipyz
:
joint
=
TEMPLATE_BONE
%
(
index
,
bone
.
name
,
position
.
x
,
position
.
z
,
-
position
.
y
)
hierarchy
.
append
(
joint
)
else
:
joint
=
TEMPLATE_BONE
%
(
index
,
bone
.
name
,
position
.
x
,
position
.
y
,
position
.
z
)
hierarchy
.
append
(
joint
)
bonePosWorld
=
armatureObject
.
matrix_world
*
bonePos
if
flipyz
:
joint
=
TEMPLATE_BONE
%
(
boneIndex
,
bone
.
name
,
bonePosWorld
.
x
,
bonePosWorld
.
z
,
-
bonePosWorld
.
y
)
hierarchy
.
append
(
joint
)
else
:
joint
=
TEMPLATE_BONE
%
(
boneIndex
,
bone
.
name
,
bonePosWorld
.
x
,
bonePosWorld
.
y
,
bonePosWorld
.
z
)
hierarchy
.
append
(
joint
)
bones_string
=
","
.
join
(
hierarchy
)
return
bones_string
,
len
(
armature
.
bones
)
...
...
@@ -754,7 +773,7 @@ def generate_indices_and_weights(meshes, option_skinning):
indices
=
[]
weights
=
[]
armature
=
bpy
.
data
.
armatures
[
0
]
armature
,
armatureObject
=
get_armature
()
for
mesh
,
object
in
meshes
:
...
...
@@ -828,13 +847,18 @@ def generate_indices_and_weights(meshes, option_skinning):
def
generate_animation
(
option_animation_skeletal
,
option_frame_step
,
flipyz
):
if
not
option_animation_skeletal
or
len
(
bpy
.
data
.
actions
)
==
0
or
len
(
bpy
.
data
.
armatures
)
==
0
:
if
not
option_animation_skeletal
or
len
(
bpy
.
data
.
actions
)
==
0
:
return
""
# TODO: Add scaling influences
action
=
bpy
.
data
.
actions
[
0
]
armature
=
bpy
.
data
.
armatures
[
0
]
armature
,
armatureObject
=
get_armature
()
if
armature
is
None
or
armatureObject
is
None
:
return
""
,
0
armatureMat
=
armatureObject
.
matrix_world
l
,
r
,
s
=
armatureMat
.
decompose
()
armatureRotMat
=
r
.
to_matrix
()
parents
=
[]
parent_index
=
-
1
...
...
@@ -857,8 +881,8 @@ def generate_animation(option_animation_skeletal, option_frame_step, flipyz):
for
frame
in
range
(
int
(
start_frame
),
int
(
end_frame
/
option_frame_step
)
+
1
):
pos
,
pchange
=
position
(
hierarchy
,
frame
*
option_frame_step
)
rot
,
rchange
=
rotation
(
hierarchy
,
frame
*
option_frame_step
)
pos
,
pchange
=
position
(
hierarchy
,
frame
*
option_frame_step
,
action
,
armatureMat
)
rot
,
rchange
=
rotation
(
hierarchy
,
frame
*
option_frame_step
,
action
,
armatureRotMat
)
if
flipyz
:
px
,
py
,
pz
=
pos
.
x
,
pos
.
z
,
-
pos
.
y
...
...
@@ -930,16 +954,13 @@ def handle_position_channel(channel, frame, position):
return
change
def
position
(
bone
,
frame
):
def
position
(
bone
,
frame
,
action
,
armatureMatrix
):
position
=
mathutils
.
Vector
((
0
,
0
,
0
))
change
=
False
action
=
bpy
.
data
.
actions
[
0
]
ngroups
=
len
(
action
.
groups
)
if
ngroups
>
0
:
index
=
0
...
...
@@ -982,7 +1003,7 @@ def position(bone, frame):
position
.
y
+=
(
bone
.
head
*
parentInvertedLocalMatrix
).
y
+
parentHeadTailDiff
.
y
position
.
z
+=
(
bone
.
head
*
parentInvertedLocalMatrix
).
z
+
parentHeadTailDiff
.
z
return
position
,
change
return
armatureMatrix
*
position
,
change
def
handle_rotation_channel
(
channel
,
frame
,
rotation
):
...
...
@@ -1010,7 +1031,7 @@ def handle_rotation_channel(channel, frame, rotation):
return
change
def
rotation
(
bone
,
frame
):
def
rotation
(
bone
,
frame
,
action
,
armatureMatrix
):
# TODO: calculate rotation also from rotation_euler channels
...
...
@@ -1018,23 +1039,23 @@ def rotation(bone, frame):
change
=
False
action
=
bpy
.
data
.
actions
[
0
]
ngroups
=
len
(
action
.
groups
)
# animation grouped by bones
if
ngroups
>
0
:
index
=
0
index
=
-
1
for
i
in
range
(
ngroups
):
if
action
.
groups
[
i
].
name
==
bone
.
name
:
index
=
i
for
channel
in
action
.
groups
[
index
].
channels
:
if
"quaternion"
in
channel
.
data_path
:
hasChanged
=
handle_rotation_channel
(
channel
,
frame
,
rotation
)
change
=
change
or
hasChanged
if
index
>
-
1
:
for
channel
in
action
.
groups
[
index
].
channels
:
if
"quaternion"
in
channel
.
data_path
:
hasChanged
=
handle_rotation_channel
(
channel
,
frame
,
rotation
)
change
=
change
or
hasChanged
# animation in raw fcurves
...
...
@@ -1050,6 +1071,7 @@ def rotation(bone, frame):
rot3
=
rotation
.
to_3d
()
rotation
.
xyz
=
rot3
*
bone
.
matrix_local
.
inverted
()
rotation
.
xyz
=
armatureMatrix
*
rotation
.
xyz
return
rotation
,
change
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录