Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
36394ef1
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,发现更多精彩内容 >>
提交
36394ef1
编写于
5月 12, 2015
作者:
R
Ricardo Cabello
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6552 from kovacsv/ObjExporterNormalFix
Apply normal matrix to exported normals in OBJExporter.
上级
e1fb3f13
23d15a1b
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
31 addition
and
19 deletion
+31
-19
examples/index.html
examples/index.html
+1
-0
examples/js/exporters/OBJExporter.js
examples/js/exporters/OBJExporter.js
+13
-16
examples/webgl_exporter_obj.html
examples/webgl_exporter_obj.html
+17
-3
未找到文件。
examples/index.html
浏览文件 @
36394ef1
...
...
@@ -271,6 +271,7 @@
"
webgl_loader_utf8
"
,
"
webgl_loader_vrml
"
,
"
webgl_loader_vtk
"
,
"
webgl_exporter_obj
"
,
"
webgl_lod
"
,
"
webgl_marchingcubes
"
,
"
webgl_materials
"
,
...
...
examples/js/exporters/OBJExporter.js
浏览文件 @
36394ef1
...
...
@@ -45,8 +45,9 @@ THREE.OBJExporter.prototype = {
var
faces
=
geometry
.
faces
;
var
faceVertexUvs
=
geometry
.
faceVertexUvs
[
0
];
var
hasVertexUvs
=
(
faces
.
length
===
faceVertexUvs
.
length
);
if
(
faces
.
length
===
faceVertexUvs
.
length
)
{
if
(
hasVertexUvs
)
{
for
(
var
i
=
0
,
l
=
faceVertexUvs
.
length
;
i
<
l
;
i
++
)
{
...
...
@@ -55,7 +56,6 @@ THREE.OBJExporter.prototype = {
for
(
var
j
=
0
;
j
<
vertexUvs
.
length
;
j
++
)
{
var
uv
=
vertexUvs
[
j
];
vertex
.
applyMatrix4
(
mesh
.
matrixWorld
);
output
+=
'
vt
'
+
uv
.
x
+
'
'
+
uv
.
y
+
'
\n
'
;
...
...
@@ -65,19 +65,13 @@ THREE.OBJExporter.prototype = {
}
}
else
{
for
(
var
i
=
0
,
l
=
faces
.
length
*
3
;
i
<
l
;
i
++
)
{
output
+=
'
vt 0 0
\n
'
;
nbVertexUvs
++
;
}
}
// normals
var
normalMatrixWorld
=
new
THREE
.
Matrix3
();
normalMatrixWorld
.
getNormalMatrix
(
mesh
.
matrixWorld
);
for
(
var
i
=
0
,
l
=
faces
.
length
;
i
<
l
;
i
++
)
{
var
face
=
faces
[
i
];
...
...
@@ -87,7 +81,8 @@ THREE.OBJExporter.prototype = {
for
(
var
j
=
0
;
j
<
vertexNormals
.
length
;
j
++
)
{
var
normal
=
vertexNormals
[
j
];
var
normal
=
vertexNormals
[
j
].
clone
();
normal
.
applyMatrix3
(
normalMatrixWorld
).
normalize
();
output
+=
'
vn
'
+
normal
.
x
+
'
'
+
normal
.
y
+
'
'
+
normal
.
z
+
'
\n
'
;
nbNormals
++
;
...
...
@@ -96,7 +91,8 @@ THREE.OBJExporter.prototype = {
}
else
{
var
normal
=
face
.
normal
;
var
normal
=
face
.
normal
.
clone
();
normal
.
applyMatrix3
(
normalMatrixWorld
).
normalize
();
for
(
var
j
=
0
;
j
<
3
;
j
++
)
{
...
...
@@ -112,14 +108,15 @@ THREE.OBJExporter.prototype = {
// faces
for
(
var
i
=
0
,
j
=
1
,
l
=
faces
.
length
;
i
<
l
;
i
++
,
j
+=
3
)
{
var
face
=
faces
[
i
];
output
+=
'
f
'
;
output
+=
(
indexVertex
+
face
.
a
+
1
)
+
'
/
'
+
(
indexVertexUvs
+
j
)
+
'
/
'
+
(
indexNormals
+
j
)
+
'
'
;
output
+=
(
indexVertex
+
face
.
b
+
1
)
+
'
/
'
+
(
indexVertexUvs
+
j
+
1
)
+
'
/
'
+
(
indexNormals
+
j
+
1
)
+
'
'
;
output
+=
(
indexVertex
+
face
.
c
+
1
)
+
'
/
'
+
(
indexVertexUvs
+
j
+
2
)
+
'
/
'
+
(
indexNormals
+
j
+
2
)
+
'
\n
'
;
output
+=
(
indexVertex
+
face
.
a
+
1
)
+
'
/
'
+
(
hasVertexUvs
?
(
indexVertexUvs
+
j
)
:
''
)
+
'
/
'
+
(
indexNormals
+
j
)
+
'
'
;
output
+=
(
indexVertex
+
face
.
b
+
1
)
+
'
/
'
+
(
hasVertexUvs
?
(
indexVertexUvs
+
j
+
1
)
:
''
)
+
'
/
'
+
(
indexNormals
+
j
+
1
)
+
'
'
;
output
+=
(
indexVertex
+
face
.
c
+
1
)
+
'
/
'
+
(
hasVertexUvs
?
(
indexVertexUvs
+
j
+
2
)
:
''
)
+
'
/
'
+
(
indexNormals
+
j
+
2
)
+
'
\n
'
;
}
...
...
examples/webgl_exporter_obj.html
浏览文件 @
36394ef1
...
...
@@ -55,7 +55,8 @@
<span
class=
"link"
id=
"triangle"
>
triangle
</span>
,
<span
class=
"link"
id=
"cube"
>
cube
</span>
,
<span
class=
"link"
id=
"cylinder"
>
cylinder
</span>
,
<span
class=
"link"
id=
"both"
>
both
</span>
<span
class=
"link"
id=
"both"
>
both
</span>
,
<span
class=
"link"
id=
"transformed"
>
transformed
</span>
-
<span
class=
"link"
id=
"export"
>
export to obj
</span>
</div>
...
...
@@ -81,11 +82,14 @@
for
(
var
i
=
0
;
i
<
scene
.
children
.
length
;
i
++
)
{
var
current
=
scene
.
children
[
i
];
if
(
current
instanceof
THREE
.
Mesh
)
{
current
.
geometry
.
dispose
();
scene
.
remove
(
current
);
i
--
;
}
}
console
.
log
(
renderer
.
info
);
if
(
type
==
1
)
{
var
material
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0x00cc00
}
);
var
geometry
=
new
THREE
.
Geometry
();
...
...
@@ -104,7 +108,7 @@
var
material
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0x00cc00
}
);
var
geometry
=
new
THREE
.
CylinderGeometry
(
50
,
50
,
100
,
30
,
1
);
scene
.
add
(
new
THREE
.
Mesh
(
geometry
,
material
)
);
}
else
if
(
type
==
4
)
{
}
else
if
(
type
==
4
||
type
==
5
)
{
var
material
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0x00cc00
}
);
var
geometry
=
new
THREE
.
Geometry
();
...
...
@@ -115,14 +119,23 @@
geometry
.
computeFaceNormals
();
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
mesh
.
position
.
x
=
-
200
;
if
(
type
==
5
)
{
mesh
.
rotation
.
y
=
Math
.
PI
/
4.0
;
}
scene
.
add
(
mesh
);
var
geometry2
=
new
THREE
.
BoxGeometry
(
100
,
100
,
100
);
var
mesh2
=
new
THREE
.
Mesh
(
geometry2
,
material
);
if
(
type
==
5
)
{
mesh2
.
rotation
.
y
=
Math
.
PI
/
4.0
;
}
scene
.
add
(
mesh2
);
var
geometry3
=
new
THREE
.
CylinderGeometry
(
50
,
50
,
100
,
30
,
1
);
var
mesh3
=
new
THREE
.
Mesh
(
geometry3
,
material
);
if
(
type
==
5
)
{
mesh3
.
rotation
.
y
=
Math
.
PI
/
4.0
;
}
mesh3
.
position
.
x
=
200
;
scene
.
add
(
mesh3
);
...
...
@@ -155,6 +168,7 @@
document
.
getElementById
(
'
cube
'
).
addEventListener
(
'
click
'
,
function
()
{
addGeometry
(
2
);
});
document
.
getElementById
(
'
cylinder
'
).
addEventListener
(
'
click
'
,
function
()
{
addGeometry
(
3
);
});
document
.
getElementById
(
'
both
'
).
addEventListener
(
'
click
'
,
function
()
{
addGeometry
(
4
);
});
document
.
getElementById
(
'
transformed
'
).
addEventListener
(
'
click
'
,
function
()
{
addGeometry
(
5
);
});
exportButton
=
document
.
getElementById
(
'
export
'
);
exportButton
.
addEventListener
(
'
click
'
,
function
()
{
exportToObj
();
});
...
...
@@ -206,7 +220,7 @@
camera
.
position
.
x
+=
(
mouseX
-
camera
.
position
.
x
)
*
.
05
;
camera
.
position
.
y
+=
(
-
mouseY
-
camera
.
position
.
y
)
*
.
05
;
camera
.
lookAt
(
new
THREE
.
Vector3
(
0.0
,
0.0
,
0.0
)
);
camera
.
lookAt
(
scene
.
position
);
light
.
position
.
set
(
camera
.
position
.
x
,
camera
.
position
.
y
,
camera
.
position
.
z
).
normalize
();
renderer
.
render
(
scene
,
camera
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录