Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
8c06add8
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,发现更多精彩内容 >>
提交
8c06add8
编写于
10月 20, 2012
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Editor: refactored scene exporter to handle properly hierarchies.
上级
c828dbbd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
161 addition
and
105 deletion
+161
-105
examples/js/exporters/SceneExporter.js
examples/js/exporters/SceneExporter.js
+161
-105
未找到文件。
examples/js/exporters/SceneExporter.js
浏览文件 @
8c06add8
...
...
@@ -14,8 +14,6 @@ THREE.SceneExporter.prototype = {
var
rotation
=
Vector3String
(
scene
.
rotation
);
var
scale
=
Vector3String
(
scene
.
scale
);
// todo: extract all scene elements
var
nobjects
=
0
;
var
ngeometries
=
0
;
var
nmaterials
=
0
;
...
...
@@ -30,8 +28,6 @@ THREE.SceneExporter.prototype = {
var
materialsMap
=
{};
var
texturesMap
=
{};
// todo: make object creation properly recursive
var
checkTexture
=
function
(
map
)
{
if
(
!
map
)
return
;
...
...
@@ -46,51 +42,83 @@ THREE.SceneExporter.prototype = {
};
scene
.
traverse
(
function
(
node
)
{
var
linesArray
=
[];
if
(
node
instanceof
THREE
.
Mesh
)
{
function
createObjectsList
(
object
,
pad
)
{
objectsArray
.
push
(
ObjectString
(
node
)
);
nobjects
+=
1
;
for
(
var
i
=
0
;
i
<
object
.
children
.
length
;
i
++
)
{
if
(
!
(
node
.
geometry
.
id
in
geometriesMap
)
)
{
var
node
=
object
.
children
[
i
];
geometriesMap
[
node
.
geometry
.
id
]
=
true
;
geometriesArray
.
push
(
GeometryString
(
node
.
geometry
)
);
ngeometries
+=
1
;
if
(
node
instanceof
THREE
.
Mesh
)
{
}
linesArray
.
push
(
MeshString
(
node
,
pad
)
);
nobjects
+=
1
;
if
(
!
(
node
.
geometry
.
id
in
geometriesMap
)
)
{
geometriesMap
[
node
.
geometry
.
id
]
=
true
;
geometriesArray
.
push
(
GeometryString
(
node
.
geometry
)
);
ngeometries
+=
1
;
}
if
(
!
(
node
.
material
.
id
in
materialsMap
)
)
{
materialsMap
[
node
.
material
.
id
]
=
true
;
materialsArray
.
push
(
MaterialString
(
node
.
material
)
);
nmaterials
+=
1
;
checkTexture
(
node
.
material
.
map
);
checkTexture
(
node
.
material
.
envMap
);
checkTexture
(
node
.
material
.
lightMap
);
checkTexture
(
node
.
material
.
specularMap
);
checkTexture
(
node
.
material
.
bumpMap
);
checkTexture
(
node
.
material
.
normalMap
);
if
(
!
(
node
.
material
.
id
in
materialsMap
)
)
{
}
materialsMap
[
node
.
material
.
id
]
=
true
;
materialsArray
.
push
(
MaterialString
(
node
.
material
)
);
nmaterials
+=
1
;
}
else
if
(
node
instanceof
THREE
.
Light
)
{
checkTexture
(
node
.
material
.
map
);
checkTexture
(
node
.
material
.
envMap
);
checkTexture
(
node
.
material
.
lightMap
);
checkTexture
(
node
.
material
.
specularMap
);
checkTexture
(
node
.
material
.
bumpMap
);
checkTexture
(
node
.
material
.
normalMap
);
linesArray
.
push
(
LightString
(
node
,
pad
)
);
nobjects
+=
1
;
}
else
if
(
node
instanceof
THREE
.
Camera
)
{
linesArray
.
push
(
CameraString
(
node
,
pad
)
);
nobjects
+=
1
;
}
else
if
(
node
instanceof
THREE
.
Object3D
)
{
linesArray
.
push
(
ObjectString
(
node
,
pad
)
);
nobjects
+=
1
;
}
}
else
if
(
node
instanceof
THREE
.
Light
)
{
if
(
node
.
children
.
length
>
0
)
{
objectsArray
.
push
(
LightString
(
node
)
);
nobjects
+=
1
;
linesArray
.
push
(
PaddingString
(
pad
+
1
)
+
'
\t\t
"children" : {
'
);
}
else
if
(
node
instanceof
THREE
.
Camera
)
{
}
createObjectsList
(
node
,
pad
+
2
);
objectsArray
.
push
(
CameraString
(
node
)
);
nobjects
+=
1
;
if
(
node
.
children
.
length
>
0
)
{
linesArray
.
push
(
PaddingString
(
pad
+
1
)
+
"
\t\t
}
"
);
}
linesArray
.
push
(
PaddingString
(
pad
)
+
"
\t\t
}
"
+
(
i
<
object
.
children
.
length
-
1
?
"
,
\n
"
:
""
)
);
}
}
);
}
createObjectsList
(
scene
,
0
);
var
objects
=
linesArray
.
join
(
"
\n
"
);
var
objects
=
generateMultiLineString
(
objectsArray
,
"
,
\n\n\t
"
);
var
geometries
=
generateMultiLineString
(
geometriesArray
,
"
,
\n\n\t
"
);
var
materials
=
generateMultiLineString
(
materialsArray
,
"
,
\n\n\t
"
);
var
textures
=
generateMultiLineString
(
texturesArray
,
"
,
\n\n\t
"
);
...
...
@@ -142,75 +170,81 @@ THREE.SceneExporter.prototype = {
}
function
PaddingString
(
n
)
{
var
output
=
""
;
for
(
var
i
=
0
;
i
<
n
;
i
++
)
output
+=
"
\t
"
;
return
output
;
}
//
function
LightString
(
l
)
{
function
LightString
(
o
,
n
)
{
if
(
l
instanceof
THREE
.
AmbientLight
)
{
if
(
o
instanceof
THREE
.
AmbientLight
)
{
var
output
=
[
'
\t
'
+
LabelString
(
getObjectName
(
l
)
)
+
'
: {
'
,
'
\t
\t
'
+
LabelString
(
getObjectName
(
o
)
)
+
'
: {
'
,
'
"type" : AmbientLight,
'
,
'
"color" :
'
+
l
.
color
.
getHex
(),
'
}
'
'
"color" :
'
+
o
.
color
.
getHex
()
+
(
o
.
children
.
length
?
'
,
'
:
''
)
];
}
else
if
(
l
instanceof
THREE
.
DirectionalLight
)
{
}
else
if
(
o
instanceof
THREE
.
DirectionalLight
)
{
var
output
=
[
'
\t
'
+
LabelString
(
getObjectName
(
l
)
)
+
'
: {
'
,
'
\t
\t
'
+
LabelString
(
getObjectName
(
o
)
)
+
'
: {
'
,
'
"type" : DirectionalLight,
'
,
'
"color" :
'
+
l
.
color
.
getHex
()
+
'
,
'
,
'
"intensity" :
'
+
l
.
intensity
+
'
,
'
,
'
"direction" :
'
+
Vector3String
(
l
.
position
),
'
}
'
'
"color" :
'
+
o
.
color
.
getHex
()
+
'
,
'
,
'
"intensity" :
'
+
o
.
intensity
+
'
,
'
,
'
"direction" :
'
+
Vector3String
(
o
.
position
)
+
(
o
.
children
.
length
?
'
,
'
:
''
)
];
}
else
if
(
l
instanceof
THREE
.
PointLight
)
{
}
else
if
(
o
instanceof
THREE
.
PointLight
)
{
var
output
=
[
'
\t
'
+
LabelString
(
getObjectName
(
l
)
)
+
'
: {
'
,
'
\t
\t
'
+
LabelString
(
getObjectName
(
o
)
)
+
'
: {
'
,
'
"type" : PointLight,
'
,
'
"color" :
'
+
l
.
color
.
getHex
()
+
'
,
'
,
'
"intensity" :
'
+
l
.
intensity
+
'
,
'
,
'
"position" :
'
+
Vector3String
(
l
.
position
)
+
'
,
'
,
'
"distance" :
'
+
l
.
distance
,
'
}
'
'
"color" :
'
+
o
.
color
.
getHex
()
+
'
,
'
,
'
"intensity" :
'
+
o
.
intensity
+
'
,
'
,
'
"position" :
'
+
Vector3String
(
o
.
position
)
+
'
,
'
,
'
"distance" :
'
+
o
.
distance
+
(
o
.
children
.
length
?
'
,
'
:
''
)
];
}
else
if
(
l
instanceof
THREE
.
SpotLight
)
{
}
else
if
(
o
instanceof
THREE
.
SpotLight
)
{
var
output
=
[
'
\t
'
+
LabelString
(
getObjectName
(
l
)
)
+
'
: {
'
,
'
\t
\t
'
+
LabelString
(
getObjectName
(
o
)
)
+
'
: {
'
,
'
"type" : SpotLight,
'
,
'
"color" :
'
+
l
.
color
.
getHex
()
+
'
,
'
,
'
"intensity" :
'
+
l
.
intensity
+
'
,
'
,
'
"position" :
'
+
Vector3String
(
l
.
position
)
+
'
,
'
,
'
"distance" :
'
+
l
.
distance
+
'
,
'
,
'
"angle" :
'
+
l
.
angle
+
'
,
'
,
'
"exponent" :
'
+
l
.
exponent
,
'
}
'
'
"color" :
'
+
o
.
color
.
getHex
()
+
'
,
'
,
'
"intensity" :
'
+
o
.
intensity
+
'
,
'
,
'
"position" :
'
+
Vector3String
(
o
.
position
)
+
'
,
'
,
'
"distance" :
'
+
o
.
distance
+
'
,
'
,
'
"angle" :
'
+
o
.
angle
+
'
,
'
,
'
"exponent" :
'
+
o
.
exponent
+
(
o
.
children
.
length
?
'
,
'
:
''
)
];
}
else
if
(
l
instanceof
THREE
.
HemisphereLight
)
{
}
else
if
(
o
instanceof
THREE
.
HemisphereLight
)
{
var
output
=
[
'
\t
'
+
LabelString
(
getObjectName
(
l
)
)
+
'
: {
'
,
'
\t
\t
'
+
LabelString
(
getObjectName
(
o
)
)
+
'
: {
'
,
'
"type" : HemisphereLight,
'
,
'
"skyColor" :
'
+
l
.
color
.
getHex
()
+
'
,
'
,
'
"groundColor" :
'
+
l
.
groundColor
.
getHex
()
+
'
,
'
,
'
"intensity" :
'
+
l
.
intensity
+
'
,
'
,
'
"position" :
'
+
Vector3String
(
l
.
position
),
'
}
'
'
"skyColor" :
'
+
o
.
color
.
getHex
()
+
'
,
'
,
'
"groundColor" :
'
+
o
.
groundColor
.
getHex
()
+
'
,
'
,
'
"intensity" :
'
+
o
.
intensity
+
'
,
'
,
'
"position" :
'
+
Vector3String
(
o
.
position
)
+
(
o
.
children
.
length
?
'
,
'
:
''
)
];
...
...
@@ -220,41 +254,39 @@ THREE.SceneExporter.prototype = {
}
return
output
.
join
(
'
\n\t\t
'
);
return
generateMultiLineString
(
output
,
'
\n\t\t
'
,
n
);
}
function
CameraString
(
c
)
{
function
CameraString
(
o
,
n
)
{
if
(
c
instanceof
THREE
.
PerspectiveCamera
)
{
if
(
o
instanceof
THREE
.
PerspectiveCamera
)
{
var
output
=
[
'
\t
'
+
LabelString
(
getObjectName
(
c
)
)
+
'
: {
'
,
'
\t
\t
'
+
LabelString
(
getObjectName
(
o
)
)
+
'
: {
'
,
'
"type" : PerspectiveCamera,
'
,
'
"fov":
'
+
c
.
fov
+
'
,
'
,
'
"aspect":
'
+
c
.
aspect
+
'
,
'
,
'
"near":
'
+
c
.
near
+
'
,
'
,
'
"far":
'
+
c
.
far
+
'
,
'
,
'
"position" :
'
+
Vector3String
(
c
.
position
),
'
}
'
'
"fov":
'
+
o
.
fov
+
'
,
'
,
'
"aspect":
'
+
o
.
aspect
+
'
,
'
,
'
"near":
'
+
o
.
near
+
'
,
'
,
'
"far":
'
+
o
.
far
+
'
,
'
,
'
"position" :
'
+
Vector3String
(
o
.
position
)
+
(
o
.
children
.
length
?
'
,
'
:
''
)
];
}
else
if
(
c
instanceof
THREE
.
OrthographicCamera
)
{
}
else
if
(
o
instanceof
THREE
.
OrthographicCamera
)
{
var
output
=
[
'
\t
'
+
LabelString
(
getObjectName
(
c
)
)
+
'
: {
'
,
'
\t
\t
'
+
LabelString
(
getObjectName
(
o
)
)
+
'
: {
'
,
'
"type" : OrthographicCamera,
'
,
'
"left":
'
+
c
.
left
+
'
,
'
,
'
"right":
'
+
c
.
right
+
'
,
'
,
'
"top":
'
+
c
.
top
+
'
,
'
,
'
"bottom":
'
+
c
.
bottom
+
'
,
'
,
'
"near":
'
+
c
.
near
+
'
,
'
,
'
"far":
'
+
c
.
far
+
'
,
'
,
'
"position" :
'
+
Vector3String
(
c
.
position
),
'
}
'
'
"left":
'
+
o
.
left
+
'
,
'
,
'
"right":
'
+
o
.
right
+
'
,
'
,
'
"top":
'
+
o
.
top
+
'
,
'
,
'
"bottom":
'
+
o
.
bottom
+
'
,
'
,
'
"near":
'
+
o
.
near
+
'
,
'
,
'
"far":
'
+
o
.
far
+
'
,
'
,
'
"position" :
'
+
Vector3String
(
o
.
position
)
+
(
o
.
children
.
length
?
'
,
'
:
''
)
];
...
...
@@ -264,29 +296,46 @@ THREE.SceneExporter.prototype = {
}
return
output
.
join
(
'
\n\t\t
'
);
return
generateMultiLineString
(
output
,
'
\n\t\t
'
,
n
);
}
function
ObjectString
(
o
,
n
)
{
var
output
=
[
'
\t\t
'
+
LabelString
(
getObjectName
(
o
)
)
+
'
: {
'
,
'
"position" :
'
+
Vector3String
(
o
.
position
)
+
'
,
'
,
'
"rotation" :
'
+
Vector3String
(
o
.
rotation
)
+
'
,
'
,
'
"scale" :
'
+
Vector3String
(
o
.
scale
)
+
'
,
'
,
'
"visible" :
'
+
o
.
visible
+
(
o
.
children
.
length
?
'
,
'
:
''
)
];
return
generateMultiLineString
(
output
,
'
\n\t\t
'
,
n
);
}
function
ObjectString
(
o
)
{
function
MeshString
(
o
,
n
)
{
var
output
=
[
'
\t
'
+
LabelString
(
getObjectName
(
o
)
)
+
'
: {
'
,
'
\t
\t
'
+
LabelString
(
getObjectName
(
o
)
)
+
'
: {
'
,
'
"geometry" :
'
+
LabelString
(
getGeometryName
(
o
.
geometry
)
)
+
'
,
'
,
'
"materials": [
'
+
LabelString
(
getMaterialName
(
o
.
material
)
)
+
'
],
'
,
'
"position" :
'
+
Vector3String
(
o
.
position
)
+
'
,
'
,
'
"rotation" :
'
+
Vector3String
(
o
.
rotation
)
+
'
,
'
,
'
"scale" :
'
+
Vector3String
(
o
.
scale
)
+
'
,
'
,
'
"visible" :
'
+
o
.
visible
,
'
}
'
'
"visible" :
'
+
o
.
visible
+
(
o
.
children
.
length
?
'
,
'
:
''
)
];
return
output
.
join
(
'
\n\t\t
'
);
return
generateMultiLineString
(
output
,
'
\n\t\t
'
,
n
);
}
//
function
GeometryString
(
g
)
{
if
(
g
instanceof
THREE
.
SphereGeometry
)
{
...
...
@@ -298,7 +347,7 @@ THREE.SceneExporter.prototype = {
'
"radius" :
'
+
g
.
radius
+
'
,
'
,
'
"widthSegments" :
'
+
g
.
widthSegments
+
'
,
'
,
'
"heightSegments" :
'
+
g
.
heightSegments
+
'
,
'
,
'
}
'
,
'
}
'
];
...
...
@@ -314,7 +363,7 @@ THREE.SceneExporter.prototype = {
'
"widthSegments" :
'
+
g
.
widthSegments
+
'
,
'
,
'
"heightSegments" :
'
+
g
.
heightSegments
+
'
,
'
,
'
"depthSegments" :
'
+
g
.
depthSegments
+
'
,
'
,
'
}
'
,
'
}
'
];
...
...
@@ -328,7 +377,7 @@ THREE.SceneExporter.prototype = {
'
"height" :
'
+
g
.
height
+
'
,
'
,
'
"widthSegments" :
'
+
g
.
widthSegments
+
'
,
'
,
'
"heightSegments" :
'
+
g
.
heightSegments
+
'
,
'
,
'
}
'
,
'
}
'
];
...
...
@@ -341,7 +390,7 @@ THREE.SceneExporter.prototype = {
'
\t
'
+
LabelString
(
getGeometryName
(
g
)
)
+
'
: {
'
,
'
"type" :
'
+
LabelString
(
g
.
sourceType
)
+
'
,
'
,
'
"url" :
'
+
LabelString
(
g
.
sourceFile
),
'
}
'
,
'
}
'
];
...
...
@@ -383,7 +432,7 @@ THREE.SceneExporter.prototype = {
'
"wireframe" :
'
+
m
.
wireframe
+
'
,
'
,
'
"wireframeLinewidth" :
'
+
m
.
wireframeLinewidth
,
'
}
'
,
'
}
'
,
'
}
'
];
...
...
@@ -410,7 +459,7 @@ THREE.SceneExporter.prototype = {
'
"wireframe" :
'
+
m
.
wireframe
+
'
,
'
,
'
"wireframeLinewidth" :
'
+
m
.
wireframeLinewidth
,
'
}
'
,
'
}
'
,
'
}
'
];
...
...
@@ -441,7 +490,7 @@ THREE.SceneExporter.prototype = {
'
"wireframe" :
'
+
m
.
wireframe
+
'
,
'
,
'
"wireframeLinewidth" :
'
+
m
.
wireframeLinewidth
,
'
}
'
,
'
}
'
,
'
}
'
];
...
...
@@ -457,7 +506,7 @@ THREE.SceneExporter.prototype = {
'
"wireframe" :
'
+
m
.
wireframe
+
'
,
'
,
'
"wireframeLinewidth" :
'
+
m
.
wireframeLinewidth
,
'
}
'
,
'
}
'
,
'
}
'
];
...
...
@@ -473,7 +522,7 @@ THREE.SceneExporter.prototype = {
'
"wireframe" :
'
+
m
.
wireframe
+
'
,
'
,
'
"wireframeLinewidth" :
'
+
m
.
wireframeLinewidth
,
'
}
'
,
'
}
'
,
'
}
'
];
...
...
@@ -484,7 +533,7 @@ THREE.SceneExporter.prototype = {
'
\t
'
+
LabelString
(
getMaterialName
(
m
)
)
+
'
: {
'
,
'
"type" : "MeshFaceMaterial",
'
,
'
"parameters" : {}
'
,
'
}
'
,
'
}
'
];
...
...
@@ -509,7 +558,7 @@ THREE.SceneExporter.prototype = {
'
"magFilter" :
'
+
NumConstantString
(
t
.
magFilter
)
+
'
,
'
,
'
"minFilter" :
'
+
NumConstantString
(
t
.
minFilter
)
+
'
,
'
,
'
"anisotropy" :
'
+
t
.
anisotropy
,
'
}
'
,
'
}
'
];
...
...
@@ -519,13 +568,20 @@ THREE.SceneExporter.prototype = {
//
function
generateMultiLineString
(
lines
,
separator
)
{
function
generateMultiLineString
(
lines
,
separator
,
padding
)
{
var
cleanLines
=
[];
for
(
var
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
if
(
lines
[
i
]
)
cleanLines
.
push
(
lines
[
i
]
);
var
line
=
lines
[
i
];
if
(
line
)
{
if
(
padding
)
line
=
PaddingString
(
padding
)
+
line
;
cleanLines
.
push
(
line
);
}
}
...
...
@@ -576,7 +632,7 @@ THREE.SceneExporter.prototype = {
'
"objects" :
'
,
'
{
'
,
'
\t
'
+
objects
,
objects
,
'
},
'
,
''
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录