Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
237c6656
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,发现更多精彩内容 >>
提交
237c6656
编写于
11月 10, 2010
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge remote branch 'alteredq/master'
上级
f34ca2e4
ca7e2fc9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
101 addition
and
10 deletion
+101
-10
utils/exporters/blender/2.54/scripts/op/io_mesh_threejs_slim/__init__.py
.../blender/2.54/scripts/op/io_mesh_threejs_slim/__init__.py
+6
-0
utils/exporters/blender/2.54/scripts/op/io_mesh_threejs_slim/export_threejs_slim.py
...54/scripts/op/io_mesh_threejs_slim/export_threejs_slim.py
+93
-8
utils/exporters/convert_obj_threejs.py
utils/exporters/convert_obj_threejs.py
+1
-1
utils/exporters/convert_obj_threejs_slim.py
utils/exporters/convert_obj_threejs_slim.py
+1
-1
未找到文件。
utils/exporters/blender/2.54/scripts/op/io_mesh_threejs_slim/__init__.py
浏览文件 @
237c6656
...
...
@@ -37,6 +37,9 @@ class ExportTHREEJSSlim(bpy.types.Operator, ExportHelper):
use_modifiers
=
BoolProperty
(
name
=
"Apply Modifiers"
,
description
=
"Apply modifiers to the exported mesh"
,
default
=
True
)
use_normals
=
BoolProperty
(
name
=
"Normals"
,
description
=
"Export normals"
,
default
=
True
)
use_uv_coords
=
BoolProperty
(
name
=
"UVs"
,
description
=
"Export texture coordinates"
,
default
=
True
)
align_types
=
[(
"None"
,
"None"
,
"None"
),
(
"Center"
,
"Center"
,
"Center"
),
(
"Bottom"
,
"Bottom"
,
"Bottom"
),
(
"Top"
,
"Top"
,
"Top"
)]
align_model
=
EnumProperty
(
name
=
"Align model"
,
description
=
"Align model"
,
items
=
align_types
,
default
=
"Center"
)
@
classmethod
def
poll
(
cls
,
context
):
...
...
@@ -57,9 +60,12 @@ class ExportTHREEJSSlim(bpy.types.Operator, ExportHelper):
row
=
layout
.
row
()
row
.
prop
(
self
.
properties
,
"use_modifiers"
)
row
=
layout
.
row
()
row
.
prop
(
self
.
properties
,
"use_normals"
)
row
=
layout
.
row
()
row
.
prop
(
self
.
properties
,
"use_uv_coords"
)
row
=
layout
.
row
()
row
.
prop
(
self
.
properties
,
"align_model"
)
def
menu_func
(
self
,
context
):
...
...
utils/exporters/blender/2.54/scripts/op/io_mesh_threejs_slim/export_threejs_slim.py
浏览文件 @
237c6656
...
...
@@ -41,9 +41,6 @@ import random
# #####################################################
# Configuration
# #####################################################
ALIGN
=
"center"
# center bottom top none
SHADING
=
"smooth"
# smooth flat
TYPE
=
"ascii"
# ascii binary
# default colors for debugging (each material gets one distinct color):
# white, red, green, blue, yellow, cyan, magenta
...
...
@@ -131,6 +128,84 @@ def get_uv_indices(f, uvs, mesh):
uv
.
append
(
uvs
[
veckey2d
(
i
)]
)
return
uv
# #####################################################
# Alignment
# #####################################################
def
bbox
(
vertices
):
"""Compute bounding box of vertex array.
"""
if
len
(
vertices
)
>
0
:
minx
=
maxx
=
vertices
[
0
].
co
.
x
miny
=
maxy
=
vertices
[
0
].
co
.
y
minz
=
maxz
=
vertices
[
0
].
co
.
z
for
v
in
vertices
[
1
:]:
if
v
.
co
.
x
<
minx
:
minx
=
v
.
co
.
x
elif
v
.
co
.
x
>
maxx
:
maxx
=
v
.
co
.
x
if
v
.
co
.
y
<
miny
:
miny
=
v
.
co
.
y
elif
v
.
co
.
y
>
maxy
:
maxy
=
v
.
co
.
y
if
v
.
co
.
z
<
minz
:
minz
=
v
.
co
.
z
elif
v
.
co
.
z
>
maxz
:
maxz
=
v
.
co
.
z
return
{
'x'
:[
minx
,
maxx
],
'y'
:[
miny
,
maxy
],
'z'
:[
minz
,
maxz
]
}
else
:
return
{
'x'
:[
0
,
0
],
'y'
:[
0
,
0
],
'z'
:[
0
,
0
]
}
def
translate
(
vertices
,
t
):
"""Translate array of vertices by vector t.
"""
for
i
in
range
(
len
(
vertices
)):
vertices
[
i
].
co
.
x
+=
t
[
0
]
vertices
[
i
].
co
.
y
+=
t
[
1
]
vertices
[
i
].
co
.
z
+=
t
[
2
]
def
center
(
vertices
):
"""Center model (middle of bounding box).
"""
bb
=
bbox
(
vertices
)
cx
=
bb
[
'x'
][
0
]
+
(
bb
[
'x'
][
1
]
-
bb
[
'x'
][
0
])
/
2.0
cy
=
bb
[
'y'
][
0
]
+
(
bb
[
'y'
][
1
]
-
bb
[
'y'
][
0
])
/
2.0
cz
=
bb
[
'z'
][
0
]
+
(
bb
[
'z'
][
1
]
-
bb
[
'z'
][
0
])
/
2.0
translate
(
vertices
,
[
-
cx
,
-
cy
,
-
cz
])
def
top
(
vertices
):
"""Align top of the model with the floor (Y-axis) and center it around X and Z.
"""
bb
=
bbox
(
vertices
)
cx
=
bb
[
'x'
][
0
]
+
(
bb
[
'x'
][
1
]
-
bb
[
'x'
][
0
])
/
2.0
cy
=
bb
[
'y'
][
1
]
cz
=
bb
[
'z'
][
0
]
+
(
bb
[
'z'
][
1
]
-
bb
[
'z'
][
0
])
/
2.0
translate
(
vertices
,
[
-
cx
,
-
cy
,
-
cz
])
def
bottom
(
vertices
):
"""Align bottom of the model with the floor (Y-axis) and center it around X and Z.
"""
bb
=
bbox
(
vertices
)
cx
=
bb
[
'x'
][
0
]
+
(
bb
[
'x'
][
1
]
-
bb
[
'x'
][
0
])
/
2.0
cy
=
bb
[
'y'
][
0
]
cz
=
bb
[
'z'
][
0
]
+
(
bb
[
'z'
][
1
]
-
bb
[
'z'
][
0
])
/
2.0
translate
(
vertices
,
[
-
cx
,
-
cy
,
-
cz
])
# #####################################################
# Elements
# #####################################################
...
...
@@ -398,7 +473,7 @@ def extract_materials(mesh, scene):
# http://www.blender.org/documentation/blender_python_api_2_54_0/bpy.types.Material.html#bpy.types.Material.specular_hardness
materials
[
m
.
name
][
"specular_coef"
]
=
m
.
specular_hardness
if
m
.
active_texture
:
if
m
.
active_texture
and
m
.
active_texture
.
type
==
'IMAGE'
:
fn
=
bpy
.
path
.
abspath
(
m
.
active_texture
.
image
.
filepath
)
fn
=
os
.
path
.
normpath
(
fn
)
fn_strip
=
os
.
path
.
basename
(
fn
)
...
...
@@ -428,14 +503,24 @@ def generate_materials_string(mesh, scene):
# #####################################################
# ASCII exporter
# #####################################################
def
generate_ascii_model
(
mesh
,
scene
,
use_normals
,
use_uv_coords
):
def
generate_ascii_model
(
mesh
,
scene
,
use_normals
,
use_uv_coords
,
align_model
):
vertices
=
mesh
.
vertices
[:]
if
align_model
==
1
:
center
(
vertices
)
elif
align_model
==
2
:
bottom
(
vertices
)
elif
align_model
==
3
:
top
(
vertices
)
sfaces
=
sort_faces
(
mesh
.
faces
,
use_normals
,
use_uv_coords
)
normals
=
extract_vertex_normals
(
mesh
,
use_normals
)
uvs
=
extract_uvs
(
mesh
,
use_uv_coords
)
text
=
TEMPLATE_FILE_ASCII
%
{
"vertices"
:
","
.
join
(
generate_vertex
(
v
)
for
v
in
mesh
.
vertices
),
"vertices"
:
","
.
join
(
generate_vertex
(
v
)
for
v
in
vertices
),
"triangles"
:
","
.
join
(
generate_triangle
(
f
)
for
f
in
sfaces
[
'triangles_flat'
]),
"triangles_n"
:
","
.
join
(
generate_triangle_n
(
f
,
normals
,
mesh
)
for
f
in
sfaces
[
'triangles_smooth'
]),
...
...
@@ -462,7 +547,7 @@ def generate_ascii_model(mesh, scene, use_normals, use_uv_coords):
# #####################################################
# Main
# #####################################################
def
save
(
operator
,
context
,
filepath
=
""
,
use_modifiers
=
True
,
use_normals
=
True
,
use_uv_coords
=
True
):
def
save
(
operator
,
context
,
filepath
=
""
,
use_modifiers
=
True
,
use_normals
=
True
,
use_uv_coords
=
True
,
align_model
=
1
):
def
rvec3d
(
v
):
return
round
(
v
[
0
],
6
),
round
(
v
[
1
],
6
),
round
(
v
[
2
],
6
)
...
...
@@ -508,7 +593,7 @@ def save(operator, context, filepath="", use_modifiers=True, use_normals=True, u
if
not
active_uv_layer
:
use_uv_coords
=
False
text
=
generate_ascii_model
(
mesh
,
scene
,
use_normals
,
use_uv_coords
)
text
=
generate_ascii_model
(
mesh
,
scene
,
use_normals
,
use_uv_coords
,
align_model
)
file
=
open
(
filepath
,
'w'
)
file
.
write
(
text
)
file
.
close
()
...
...
utils/exporters/convert_obj_threejs.py
浏览文件 @
237c6656
...
...
@@ -393,7 +393,7 @@ def bottom(vertices):
cy
=
bb
[
'y'
][
0
]
cz
=
bb
[
'z'
][
0
]
+
(
bb
[
'z'
][
1
]
-
bb
[
'z'
][
0
])
/
2.0
translate
(
vertices
,
[
-
cx
,
cy
,
-
cz
])
translate
(
vertices
,
[
-
cx
,
-
cy
,
-
cz
])
def
normalize
(
v
):
"""Normalize 3d vector"""
...
...
utils/exporters/convert_obj_threejs_slim.py
浏览文件 @
237c6656
...
...
@@ -314,7 +314,7 @@ def bottom(vertices):
cy
=
bb
[
'y'
][
0
]
cz
=
bb
[
'z'
][
0
]
+
(
bb
[
'z'
][
1
]
-
bb
[
'z'
][
0
])
/
2.0
translate
(
vertices
,
[
-
cx
,
cy
,
-
cz
])
translate
(
vertices
,
[
-
cx
,
-
cy
,
-
cz
])
def
normalize
(
v
):
"""Normalize 3d vector"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录