Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
c119abca
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,发现更多精彩内容 >>
提交
c119abca
编写于
3月 21, 2011
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge remote branch 'alteredq/experimental' into experimental
上级
5a0a200c
044a27b5
变更
18
展开全部
隐藏空白更改
内联
并排
Showing
18 changed file
with
689 addition
and
716 deletion
+689
-716
build/Three.js
build/Three.js
+21
-20
build/custom/ThreeCanvas.js
build/custom/ThreeCanvas.js
+75
-77
build/custom/ThreeDOM.js
build/custom/ThreeDOM.js
+49
-53
build/custom/ThreeExtras.js
build/custom/ThreeExtras.js
+92
-70
build/custom/ThreeSVG.js
build/custom/ThreeSVG.js
+95
-97
build/custom/ThreeWebGL.js
build/custom/ThreeWebGL.js
+176
-179
examples/obj/cubecolors/cubecolors.js
examples/obj/cubecolors/cubecolors.js
+10
-13
examples/obj/leeperrysmith/LeePerrySmith.js
examples/obj/leeperrysmith/LeePerrySmith.js
+17
-16
examples/webgl_geometry_blenderexport_colors.html
examples/webgl_geometry_blenderexport_colors.html
+4
-5
examples/webgl_materials_normalmap.html
examples/webgl_materials_normalmap.html
+4
-4
examples/webgl_materials_normalmap2.html
examples/webgl_materials_normalmap2.html
+4
-3
src/extras/io/BinaryLoader.js
src/extras/io/BinaryLoader.js
+2
-2
src/extras/io/JSONLoader.js
src/extras/io/JSONLoader.js
+6
-3
src/extras/io/Loader.js
src/extras/io/Loader.js
+1
-1
src/materials/Material.js
src/materials/Material.js
+4
-3
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+1
-1
utils/exporters/blender/2.56/scripts/op/io_mesh_threejs/__init__.py
...rters/blender/2.56/scripts/op/io_mesh_threejs/__init__.py
+4
-3
utils/exporters/blender/2.56/scripts/op/io_mesh_threejs/export_threejs.py
...blender/2.56/scripts/op/io_mesh_threejs/export_threejs.py
+124
-166
未找到文件。
build/Three.js
浏览文件 @
c119abca
此差异已折叠。
点击以展开。
build/custom/ThreeCanvas.js
浏览文件 @
c119abca
此差异已折叠。
点击以展开。
build/custom/ThreeDOM.js
浏览文件 @
c119abca
此差异已折叠。
点击以展开。
build/custom/ThreeExtras.js
浏览文件 @
c119abca
此差异已折叠。
点击以展开。
build/custom/ThreeSVG.js
浏览文件 @
c119abca
此差异已折叠。
点击以展开。
build/custom/ThreeWebGL.js
浏览文件 @
c119abca
此差异已折叠。
点击以展开。
examples/obj/cubecolors/cubecolors.js
浏览文件 @
c119abca
此差异已折叠。
点击以展开。
examples/obj/leeperrysmith/LeePerrySmith.js
浏览文件 @
c119abca
此差异已折叠。
点击以展开。
examples/webgl_geometry_blenderexport_colors.html
浏览文件 @
c119abca
...
...
@@ -33,9 +33,8 @@
<div
id=
"container"
></div>
<div
id=
"info"
><a
href=
"http://github.com/mrdoob/three.js"
target=
"_blank"
>
three.js
</a>
webgl - io blender - vertex colors
</div>
<script
type=
"text/javascript"
src=
"../build/custom/ThreeWebGL.js"
></script>
<script
type=
"text/javascript"
src=
"../build/custom/ThreeExtras.js"
></script>
<script
type=
"text/javascript"
src=
"../build/Three.js"
></script>
<script
type=
"text/javascript"
src=
"js/Detector.js"
></script>
<script
type=
"text/javascript"
src=
"js/RequestAnimationFrame.js"
></script>
<script
type=
"text/javascript"
src=
"js/Stats.js"
></script>
...
...
@@ -74,8 +73,8 @@
light
.
position
.
normalize
();
scene
.
addLight
(
light
);
var
loader
=
new
THREE
.
Loader
();
loader
.
load
Ascii
(
{
model
:
"
obj/cubecolors/cubecolors.js
"
,
callback
:
createScene
}
);
var
loader
=
new
THREE
.
JSON
Loader
();
loader
.
load
(
{
model
:
"
obj/cubecolors/cubecolors.js
"
,
callback
:
createScene
}
);
renderer
=
new
THREE
.
WebGLRenderer
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
...
...
examples/webgl_materials_normalmap.html
浏览文件 @
c119abca
...
...
@@ -160,10 +160,10 @@
var
material2
=
new
THREE
.
MeshPhongMaterial
(
{
color
:
diffuse
,
specular
:
specular
,
ambient
:
ambient
,
shininess
:
shininess
}
);
loader
=
new
THREE
.
Loader
(
true
);
loader
=
new
THREE
.
Binary
Loader
(
true
);
document
.
body
.
appendChild
(
loader
.
statusDomElement
);
loader
.
load
Binary
(
{
model
:
"
obj/ninja/NinjaLo_bin.js
"
,
callback
:
function
(
geometry
)
{
createScene
(
geometry
,
scale
,
material1
,
material2
)
}
}
);
loader
.
load
(
{
model
:
"
obj/ninja/NinjaLo_bin.js
"
,
callback
:
function
(
geometry
)
{
createScene
(
geometry
,
scale
,
material1
,
material2
)
}
}
);
webglRenderer
=
new
THREE
.
WebGLRenderer
();
webglRenderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
...
...
@@ -187,9 +187,9 @@
function
createScene
(
geometry
,
scale
,
material1
,
material2
)
{
geometry
.
computeTangents
();
//
geometry.computeTangents();
mesh1
=
SceneUtils
.
addMesh
(
scene
,
geometry
,
scale
,
-
scale
*
12
,
0
,
0
,
0
,
0
,
0
,
material1
);
//
mesh1 = SceneUtils.addMesh( scene, geometry, scale, -scale * 12, 0, 0, 0,0,0, material1 );
mesh2
=
SceneUtils
.
addMesh
(
scene
,
geometry
,
scale
,
scale
*
12
,
0
,
0
,
0
,
0
,
0
,
material2
);
loader
.
statusDomElement
.
style
.
display
=
"
none
"
;
...
...
examples/webgl_materials_normalmap2.html
浏览文件 @
c119abca
...
...
@@ -141,10 +141,10 @@
var
parameters
=
{
fragmentShader
:
shader
.
fragmentShader
,
vertexShader
:
shader
.
vertexShader
,
uniforms
:
uniforms
};
var
material
=
new
THREE
.
MeshShaderMaterial
(
parameters
);
loader
=
new
THREE
.
Loader
(
true
);
loader
=
new
THREE
.
JSON
Loader
(
true
);
document
.
body
.
appendChild
(
loader
.
statusDomElement
);
loader
.
load
Ascii
(
{
model
:
"
obj/leeperrysmith/LeePerrySmith.js
"
,
callback
:
function
(
geometry
)
{
createScene
(
geometry
,
100
,
material
)
}
}
);
loader
.
load
(
{
model
:
"
obj/leeperrysmith/LeePerrySmith.js
"
,
callback
:
function
(
geometry
)
{
createScene
(
geometry
,
100
,
material
)
}
}
);
webglRenderer
=
new
THREE
.
WebGLRenderer
();
webglRenderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
...
...
@@ -166,8 +166,9 @@
function
createScene
(
geometry
,
scale
,
material
)
{
geometry
.
computeTangents
();
//
geometry.computeTangents();
material
=
new
THREE
.
MeshFaceMaterial
();
mesh1
=
SceneUtils
.
addMesh
(
scene
,
geometry
,
scale
,
0
,
-
50
,
0
,
0
,
0
,
0
,
material
);
loader
.
statusDomElement
.
style
.
display
=
"
none
"
;
...
...
src/extras/io/BinaryLoader.js
浏览文件 @
c119abca
...
...
@@ -507,7 +507,7 @@ THREE.BinaryLoader.prototype = {
u3
=
uvs
[
uvc
*
2
];
v3
=
uvs
[
uvc
*
2
+
1
];
THREE
.
BinaryLoader
.
prototype
.
uv3
(
scope
.
uvs
,
u1
,
v1
,
u2
,
v2
,
u3
,
v3
);
THREE
.
BinaryLoader
.
prototype
.
uv3
(
scope
.
faceVertexUvs
[
0
]
,
u1
,
v1
,
u2
,
v2
,
u3
,
v3
);
}
...
...
@@ -532,7 +532,7 @@ THREE.BinaryLoader.prototype = {
u4
=
uvs
[
uvd
*
2
];
v4
=
uvs
[
uvd
*
2
+
1
];
THREE
.
BinaryLoader
.
prototype
.
uv4
(
scope
.
uvs
,
u1
,
v1
,
u2
,
v2
,
u3
,
v3
,
u4
,
v4
);
THREE
.
BinaryLoader
.
prototype
.
uv4
(
scope
.
faceVertexUvs
[
0
]
,
u1
,
v1
,
u2
,
v2
,
u3
,
v3
,
u4
,
v4
);
}
...
...
src/extras/io/JSONLoader.js
浏览文件 @
c119abca
...
...
@@ -88,10 +88,11 @@ THREE.JSONLoader.prototype = {
faces
=
json
.
faces
,
vertices
=
json
.
vertices
,
normals
=
json
.
normals
,
colors
=
json
.
colors
,
nUvLayers
=
0
;
// dis
c
ard empty arrays
// dis
reg
ard empty arrays
for
(
i
=
0
;
i
<
json
.
uvs
.
length
;
i
++
)
{
...
...
@@ -256,9 +257,11 @@ THREE.JSONLoader.prototype = {
for
(
i
=
0
;
i
<
nVertices
;
i
++
)
{
color
=
new
THREE
.
Color
(
faces
[
offset
++
]
);
colorIndex
=
faces
[
offset
++
];
color
=
new
THREE
.
Color
(
colors
[
colorIndex
]
);
face
.
vertexColors
.
push
(
color
);
}
}
...
...
src/extras/io/Loader.js
浏览文件 @
c119abca
...
...
@@ -121,7 +121,7 @@ THREE.Loader.prototype = {
// defaults
mtype
=
"
MeshLambertMaterial
"
;
mpars
=
{
color
:
0xeeeeee
,
opacity
:
1.0
,
map
:
null
,
lightMap
:
null
,
vertexColors
:
m
.
vertexColors
};
mpars
=
{
color
:
0xeeeeee
,
opacity
:
1.0
,
map
:
null
,
lightMap
:
null
,
vertexColors
:
m
.
vertexColors
?
THREE
.
VertexColors
:
false
};
// parameters from model file
...
...
src/materials/Material.js
浏览文件 @
c119abca
...
...
@@ -2,10 +2,11 @@
* @author mr.doob / http://mrdoob.com/
*/
THREE
.
FlatShading
=
0
;
THREE
.
SmoothShading
=
1
;
THREE
.
NoShading
=
0
;
THREE
.
FlatShading
=
1
;
THREE
.
SmoothShading
=
2
;
THREE
.
Material
Colors
=
0
;
THREE
.
No
Colors
=
0
;
THREE
.
FaceColors
=
1
;
THREE
.
VertexColors
=
2
;
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
c119abca
...
...
@@ -1177,7 +1177,7 @@ THREE.WebGLRenderer = function ( parameters ) {
}
}
if
(
dirtyColors
&&
o
bj_colors
.
length
)
{
if
(
dirtyColors
&&
o
ffset_color
>
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webGLColorBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
colorArray
,
hint
);
...
...
utils/exporters/blender/2.56/scripts/op/io_mesh_threejs/__init__.py
浏览文件 @
c119abca
...
...
@@ -17,10 +17,11 @@
# ##### END GPL LICENSE BLOCK #####
# To support reload properly, try to access a package var, if it's there, reload everything
if
"bpy"
in
locals
():
import
sys
reload
(
sys
.
modules
.
get
(
"io_mesh_threejs.export_threejs"
,
sys
))
if
"bpy"
in
locals
():
import
imp
if
"export_threejs"
in
locals
():
imp
.
reload
(
export_threejs
)
import
bpy
from
bpy.props
import
*
...
...
utils/exporters/blender/2.56/scripts/op/io_mesh_threejs/export_threejs.py
浏览文件 @
c119abca
...
...
@@ -57,12 +57,17 @@ TEMPLATE_FILE_ASCII = """\
*
* vertices: %(nvertex)d
* faces: %(nface)d
* normals: %(nnormal)d
* uvs: %(nuv)d
* colors: %(ncolor)d
* materials: %(nmaterial)d
*
*/
var model = {
'version' : 2,
'materials': [%(materials)s],
'normals': [%(normals)s],
...
...
@@ -71,17 +76,9 @@ var model = {
'colors': [%(colors)s],
'uvs': [%(uvs)s],
'triangles': [%(triangles)s],
'trianglesUvs': [%(trianglesUvs)s],
'trianglesNormals': [%(trianglesNormals)s],
'trianglesNormalsUvs': [%(trianglesNormalsUvs)s],
'uvs': [[%(uvs)s]],
'quads': [%(quads)s],
'quadsUvs': [%(quadsUvs)s],
'quadsNormals': [%(quadsNormals)s],
'quadsNormalsUvs': [%(quadsNormalsUvs)s],
'faces': [%(faces)s],
'end': (new Date).getTime()
...
...
@@ -92,24 +89,9 @@ postMessage( model );
TEMPLATE_VERTEX
=
"%f,%f,%f"
TEMPLATE_UV_TRI
=
"%f,%f,%f,%f,%f,%f"
TEMPLATE_UV_QUAD
=
"%f,%f,%f,%f,%f,%f,%f,%f"
TEMPLATE_TRI
=
"%d,%d,%d,%d"
TEMPLATE_QUAD
=
"%d,%d,%d,%d,%d"
TEMPLATE_TRI_UV
=
"%d,%d,%d,%d,%d,%d,%d"
TEMPLATE_QUAD_UV
=
"%d,%d,%d,%d,%d,%d,%d,%d,%d"
TEMPLATE_TRI_N
=
"%d,%d,%d,%d,%d,%d,%d"
TEMPLATE_QUAD_N
=
"%d,%d,%d,%d,%d,%d,%d,%d,%d"
TEMPLATE_TRI_N_UV
=
"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"
TEMPLATE_QUAD_N_UV
=
"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"
TEMPLATE_N
=
"%f,%f,%f"
TEMPLATE_C
=
"%f,%f,%f"
TEMPLATE_UV
=
"%f,%f"
TEMPLATE_C
=
"0x%06x"
# #####################################################
# Utils
...
...
@@ -127,14 +109,21 @@ def get_normal_indices(v, normals, mesh):
n
.
append
(
normals
[
veckey3d
(
mv
[
i
].
normal
)]
)
return
n
def
get_uv_indices
(
f
,
uvs
,
mesh
):
def
get_uv_indices
(
f
ace_index
,
uvs
,
mesh
):
uv
=
[]
face_index
=
f
[
1
]
uv_layer
=
mesh
.
uv_textures
.
active
.
data
for
i
in
uv_layer
[
face_index
].
uv
:
uv
.
append
(
uvs
[
veckey2d
(
i
)]
)
return
uv
def
get_color_indices
(
v
,
normals
,
mesh
):
# TODO: make it proper
# this just reuses vertex indices as color indices
n
=
[]
for
i
in
range
(
len
(
v
)):
n
.
append
(
v
[
i
]
)
return
n
# #####################################################
# Alignment
# #####################################################
...
...
@@ -221,131 +210,100 @@ def generate_vertex(v):
def
generate_normal
(
n
):
return
TEMPLATE_N
%
(
n
[
0
],
n
[
1
],
n
[
2
])
def
generate_vertex_color
(
c
):
return
TEMPLATE_C
%
(
c
[
0
],
c
[
1
],
c
[
2
])
hexcolor
=
(
int
(
c
[
0
]
*
255
)
<<
16
)
+
(
int
(
c
[
1
]
*
255
)
<<
8
)
+
int
(
c
[
2
]
*
255
)
return
TEMPLATE_C
%
hexcolor
def
generate_uv
(
uv
):
return
TEMPLATE_UV
%
(
uv
[
0
],
1.0
-
uv
[
1
])
def
generate_triangle
(
f
):
v
=
f
[
0
].
vertices
m
=
f
[
0
].
material_index
return
TEMPLATE_TRI
%
(
v
[
0
],
v
[
1
],
v
[
2
],
m
)
def
generate_quad
(
f
):
v
=
f
[
0
].
vertices
m
=
f
[
0
].
material_index
return
TEMPLATE_QUAD
%
(
v
[
0
],
v
[
1
],
v
[
2
],
v
[
3
],
m
)
def
generate_triangle_n
(
f
,
normals
,
mesh
):
v
=
f
[
0
].
vertices
m
=
f
[
0
].
material_index
n
=
get_normal_indices
(
v
,
normals
,
mesh
)
return
TEMPLATE_TRI_N
%
(
v
[
0
],
v
[
1
],
v
[
2
],
m
,
n
[
0
],
n
[
1
],
n
[
2
])
def
generate_quad_n
(
f
,
normals
,
mesh
):
v
=
f
[
0
].
vertices
m
=
f
[
0
].
material_index
n
=
get_normal_indices
(
v
,
normals
,
mesh
)
return
TEMPLATE_QUAD_N
%
(
v
[
0
],
v
[
1
],
v
[
2
],
v
[
3
],
m
,
n
[
0
],
n
[
1
],
n
[
2
],
n
[
3
])
def
generate_triangle_uv
(
f
,
uvs
,
mesh
):
v
=
f
[
0
].
vertices
m
=
f
[
0
].
material_index
uv
=
get_uv_indices
(
f
,
uvs
,
mesh
)
return
TEMPLATE_TRI_UV
%
(
v
[
0
],
v
[
1
],
v
[
2
],
m
,
uv
[
0
],
uv
[
1
],
uv
[
2
])
def
generate_quad_uv
(
f
,
uvs
,
mesh
):
v
=
f
[
0
].
vertices
m
=
f
[
0
].
material_index
uv
=
get_uv_indices
(
f
,
uvs
,
mesh
)
return
TEMPLATE_QUAD_UV
%
(
v
[
0
],
v
[
1
],
v
[
2
],
v
[
3
],
m
,
uv
[
0
],
uv
[
1
],
uv
[
2
],
uv
[
3
])
def
generate_triangle_n_uv
(
f
,
normals
,
uvs
,
mesh
):
v
=
f
[
0
].
vertices
m
=
f
[
0
].
material_index
n
=
get_normal_indices
(
v
,
normals
,
mesh
)
uv
=
get_uv_indices
(
f
,
uvs
,
mesh
)
return
TEMPLATE_TRI_N_UV
%
(
v
[
0
],
v
[
1
],
v
[
2
],
m
,
n
[
0
],
n
[
1
],
n
[
2
],
uv
[
0
],
uv
[
1
],
uv
[
2
])
def
generate_quad_n_uv
(
f
,
normals
,
uvs
,
mesh
):
v
=
f
[
0
].
vertices
m
=
f
[
0
].
material_index
n
=
get_normal_indices
(
v
,
normals
,
mesh
)
uv
=
get_uv_indices
(
f
,
uvs
,
mesh
)
return
TEMPLATE_QUAD_N_UV
%
(
v
[
0
],
v
[
1
],
v
[
2
],
v
[
3
],
m
,
n
[
0
],
n
[
1
],
n
[
2
],
n
[
3
],
uv
[
0
],
uv
[
1
],
uv
[
2
],
uv
[
3
])
# #####################################################
# Faces
# #####################################################
def
sort_faces
(
faces
,
use_normals
,
use_uv_coords
):
data
=
{
'triangles_flat'
:
[],
'triangles_flat_uv'
:
[],
'triangles_smooth'
:
[],
'triangles_smooth_uv'
:
[],
'quads_flat'
:
[],
'quads_flat_uv'
:
[],
'quads_smooth'
:
[],
'quads_smooth_uv'
:
[]
}
for
i
,
f
in
enumerate
(
faces
):
if
len
(
f
.
vertices
)
==
3
:
if
use_normals
and
use_uv_coords
:
data
[
'triangles_smooth_uv'
].
append
([
f
,
i
])
elif
use_normals
and
not
use_uv_coords
:
data
[
'triangles_smooth'
].
append
([
f
,
i
])
elif
use_uv_coords
:
data
[
'triangles_flat_uv'
].
append
([
f
,
i
])
else
:
data
[
'triangles_flat'
].
append
([
f
,
i
])
def
setBit
(
value
,
position
,
on
):
if
on
:
mask
=
1
<<
position
return
(
value
|
mask
)
else
:
mask
=
~
(
1
<<
position
)
return
(
value
&
mask
)
def
generate_face
(
f
,
i
,
normals
,
uvs
,
colors
,
mesh
,
use_normals
,
use_colors
,
use_uv_coords
):
isTriangle
=
(
len
(
f
.
vertices
)
==
3
)
if
isTriangle
:
nVertices
=
3
else
:
nVertices
=
4
hasMaterial
=
True
# for the moment objects without materials get default material
hasFaceUvs
=
False
# not supported in Blender
hasFaceVertexUvs
=
use_uv_coords
elif
len
(
f
.
vertices
)
==
4
:
hasFaceNormals
=
False
# don't export any face normals (as they are computed in engine)
hasFaceVertexNormals
=
use_normals
hasFaceColors
=
False
# not supported in Blender
hasFaceVertexColors
=
use_colors
faceType
=
0
faceType
=
setBit
(
faceType
,
0
,
not
isTriangle
)
faceType
=
setBit
(
faceType
,
1
,
hasMaterial
)
faceType
=
setBit
(
faceType
,
2
,
hasFaceUvs
)
faceType
=
setBit
(
faceType
,
3
,
hasFaceVertexUvs
)
faceType
=
setBit
(
faceType
,
4
,
hasFaceNormals
)
faceType
=
setBit
(
faceType
,
5
,
hasFaceVertexNormals
)
faceType
=
setBit
(
faceType
,
6
,
hasFaceColors
)
faceType
=
setBit
(
faceType
,
7
,
hasFaceVertexColors
)
faceData
=
[]
# order is important, must match order in JSONLoader
# face type
# vertex indices
# material index
# face uvs index
# face vertex uvs indices
# face color index
# face vertex colors indices
faceData
.
append
(
faceType
)
# must clamp in case on polygons bigger than quads
for
i
in
range
(
nVertices
):
index
=
f
.
vertices
[
i
]
faceData
.
append
(
index
)
if
hasMaterial
:
faceData
.
append
(
f
.
material_index
)
if
hasFaceVertexUvs
:
uv
=
get_uv_indices
(
i
,
uvs
,
mesh
)
for
i
in
range
(
nVertices
):
index
=
uv
[
i
]
faceData
.
append
(
index
)
if
hasFaceVertexNormals
:
n
=
get_normal_indices
(
f
.
vertices
,
normals
,
mesh
)
for
i
in
range
(
nVertices
):
index
=
n
[
i
]
faceData
.
append
(
index
)
if
hasFaceVertexColors
:
c
=
get_color_indices
(
f
.
vertices
,
colors
,
mesh
)
for
i
in
range
(
nVertices
):
index
=
c
[
i
]
faceData
.
append
(
index
)
if
use_normals
and
use_uv_coords
:
data
[
'quads_smooth_uv'
].
append
([
f
,
i
])
elif
use_normals
and
not
use_uv_coords
:
data
[
'quads_smooth'
].
append
([
f
,
i
])
elif
use_uv_coords
:
data
[
'quads_flat_uv'
].
append
([
f
,
i
])
else
:
data
[
'quads_flat'
].
append
([
f
,
i
])
return
","
.
join
(
map
(
str
,
faceData
)
)
return
data
# #####################################################
# Normals
# #####################################################
def
extract_vertex_normals
(
mesh
,
use_normals
):
if
not
use_normals
:
return
{}
return
{}
,
0
count
=
0
normals
=
{}
...
...
@@ -357,7 +315,7 @@ def extract_vertex_normals(mesh, use_normals):
normals
[
key
]
=
count
count
+=
1
return
normals
return
normals
,
count
def
generate_normals
(
normals
,
use_normals
):
if
not
use_normals
:
...
...
@@ -373,8 +331,11 @@ def generate_normals(normals, use_normals):
# Vertex colors
# #####################################################
def
extract_vertex_colors
(
mesh
,
use_colors
):
# TODO: handle properly per face vertex colors
if
not
use_colors
:
return
{}
return
{}
,
0
colors
=
{}
...
...
@@ -392,11 +353,12 @@ def extract_vertex_colors(mesh, use_colors):
colors
[
vertex_index
]
=
fc
[
0
],
fc
[
1
],
fc
[
2
]
# make sure all vertices have some color
for
i
in
range
(
len
(
mesh
.
vertices
)):
count
=
len
(
mesh
.
vertices
)
for
i
in
range
(
count
):
if
i
not
in
colors
:
colors
[
i
]
=
(
0
,
0
,
0
)
return
colors
return
colors
,
count
def
generate_vertex_colors
(
colors
,
use_colors
):
if
not
use_colors
:
...
...
@@ -413,7 +375,7 @@ def generate_vertex_colors(colors, use_colors):
# #####################################################
def
extract_uvs
(
mesh
,
use_uv_coords
):
if
not
use_uv_coords
:
return
{}
return
{}
,
0
count
=
0
uvs
=
{}
...
...
@@ -427,7 +389,7 @@ def extract_uvs(mesh, use_uv_coords):
uvs
[
key
]
=
count
count
+=
1
return
uvs
return
uvs
,
count
def
generate_uvs
(
uvs
,
use_uv_coords
):
if
not
use_uv_coords
:
...
...
@@ -499,7 +461,7 @@ def generate_materials(mtl, materials, use_colors):
mtl_string
=
"
\t
{
\n
%s
\n\t
}"
%
mtl_raw
mtl_array
.
append
([
index
,
mtl_string
])
return
",
\n\n
"
.
join
([
m
for
i
,
m
in
sorted
(
mtl_array
)])
return
",
\n\n
"
.
join
([
m
for
i
,
m
in
sorted
(
mtl_array
)])
,
len
(
mtl_array
)
def
extract_materials
(
mesh
,
scene
):
world
=
scene
.
world
...
...
@@ -580,34 +542,30 @@ def generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, al
elif
align_model
==
3
:
top
(
vertices
)
sfaces
=
sort_faces
(
mesh
.
faces
,
use_normals
,
use_uv_coords
)
normals
=
extract_vertex_normals
(
mesh
,
use_normals
)
colors
=
extract_vertex_colors
(
mesh
,
use_colors
)
uvs
=
extract_uvs
(
mesh
,
use_uv_coords
)
normals
,
nnormal
=
extract_vertex_normals
(
mesh
,
use_normals
)
colors
,
ncolor
=
extract_vertex_colors
(
mesh
,
use_colors
)
uvs
,
nuv
=
extract_uvs
(
mesh
,
use_uv_coords
)
mstring
,
nmaterial
=
generate_materials_string
(
mesh
,
scene
,
use_colors
)
text
=
TEMPLATE_FILE_ASCII
%
{
"vertices"
:
","
.
join
(
generate_vertex
(
v
)
for
v
in
vertices
),
"triangles"
:
","
.
join
(
generate_triangle
(
f
)
for
f
in
sfaces
[
'triangles_flat'
]),
"trianglesUvs"
:
","
.
join
(
generate_triangle_uv
(
f
,
uvs
,
mesh
)
for
f
in
sfaces
[
'triangles_flat_uv'
]),
"trianglesNormals"
:
","
.
join
(
generate_triangle_n
(
f
,
normals
,
mesh
)
for
f
in
sfaces
[
'triangles_smooth'
]),
"trianglesNormalsUvs"
:
","
.
join
(
generate_triangle_n_uv
(
f
,
normals
,
uvs
,
mesh
)
for
f
in
sfaces
[
'triangles_smooth_uv'
]),
"quads"
:
","
.
join
(
generate_quad
(
f
)
for
f
in
sfaces
[
'quads_flat'
]),
"quadsUvs"
:
","
.
join
(
generate_quad_uv
(
f
,
uvs
,
mesh
)
for
f
in
sfaces
[
'quads_flat_uv'
]),
"quadsNormals"
:
","
.
join
(
generate_quad_n
(
f
,
normals
,
mesh
)
for
f
in
sfaces
[
'quads_smooth'
]),
"quadsNormalsUvs"
:
","
.
join
(
generate_quad_n_uv
(
f
,
normals
,
uvs
,
mesh
)
for
f
in
sfaces
[
'quads_smooth_uv'
]),
"nvertex"
:
len
(
mesh
.
vertices
),
"nface"
:
len
(
mesh
.
faces
),
"nuv"
:
nuv
,
"nnormal"
:
nnormal
,
"ncolor"
:
ncolor
,
"nmaterial"
:
nmaterial
,
"uvs"
:
generate_uvs
(
uvs
,
use_uv_coords
),
"normals"
:
generate_normals
(
normals
,
use_normals
),
"colors"
:
generate_vertex_colors
(
colors
,
use_colors
),
"materials"
:
generate_materials_string
(
mesh
,
scene
,
use_colors
),
"materials"
:
mstring
,
"vertices"
:
","
.
join
(
generate_vertex
(
v
)
for
v
in
vertices
),
"faces"
:
","
.
join
(
generate_face
(
f
,
i
,
normals
,
uvs
,
colors
,
mesh
,
use_normals
,
use_colors
,
use_uv_coords
)
for
i
,
f
in
enumerate
(
mesh
.
faces
))
"nvertex"
:
len
(
mesh
.
vertices
),
"nface"
:
len
(
mesh
.
faces
),
"nmaterial"
:
0
}
return
text
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录