Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
b971e3c2
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,发现更多精彩内容 >>
提交
b971e3c2
编写于
9月 24, 2015
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AMFLoader: Clean up.
上级
af0b4346
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
239 addition
and
230 deletion
+239
-230
examples/js/loaders/AMFLoader.js
examples/js/loaders/AMFLoader.js
+239
-230
未找到文件。
examples/js/loaders/AMFLoader.js
浏览文件 @
b971e3c2
...
...
@@ -48,448 +48,457 @@ THREE.AMFLoader.prototype = {
parse
:
function
(
data
)
{
var
amfName
=
""
;
var
amfAuthor
=
""
;
var
amfScale
=
1.0
;
var
amfMaterials
=
{};
var
amfObjects
=
{};
function
loadDocument
(
data
)
{
var
xmldata
=
this
.
_loadDocument
(
data
);
var
view
=
new
DataView
(
data
);
amfScale
=
this
.
_loadDocumentScale
(
xmldata
);
var
magic
=
String
.
fromCharCode
(
view
.
getUint8
(
0
),
view
.
getUint8
(
1
)
);
var
documentchildren
=
xmldata
.
documentElement
.
children
;
if
(
magic
===
"
PK
"
)
{
for
(
var
i
=
0
;
i
<
documentchildren
.
length
;
i
++
)
{
console
.
log
(
"
Loading Zip
"
);
var
zip
=
null
;
var
file
=
null
;
if
(
documentchildren
[
i
].
nodeName
===
'
metadata
'
)
{
try
{
if
(
documentchildren
[
i
].
attributes
[
'
type
'
]
!==
undefined
)
{
zip
=
new
JSZip
(
data
);
if
(
documentchildren
[
i
].
attributes
[
'
type
'
].
value
===
'
name
'
)
{
}
catch
(
e
)
{
amfName
=
documentchildren
[
i
].
textContent
;
if
(
e
instanceof
ReferenceError
)
{
}
else
if
(
documentchildren
[
i
].
attributes
[
'
type
'
].
value
===
'
author
'
)
{
amfAuthor
=
documentchildren
[
i
].
textContent
;
console
.
log
(
"
jszip missing and file is compressed.
"
);
return
null
;
}
}
}
else
if
(
documentchildren
[
i
].
nodeName
===
'
material
'
)
{
var
loadedmaterial
=
this
.
_loadMaterials
(
documentchildren
[
i
]
);
amfMaterials
[
loadedmaterial
.
id
]
=
loadedmaterial
.
material
;
}
else
if
(
documentchildren
[
i
].
nodeName
===
'
object
'
)
{
for
(
file
in
zip
.
files
)
{
var
loadedobject
=
this
.
_loadObject
(
documentchildren
[
i
]
);
amfObjects
[
loadedobject
.
id
]
=
loadedobject
.
obj
;
}
}
if
(
file
.
toLowerCase
().
endsWith
(
"
.amf
"
)
)
{
var
sceneobject
=
new
THREE
.
Object3D
()
;
break
;
sceneobject
.
name
=
amfName
;
sceneobject
.
userData
.
author
=
amfAuthor
;
sceneobject
.
userData
.
loader
=
"
AMF
"
;
}
var
defaultmaterial
=
new
THREE
.
MeshPhongMaterial
(
{
shading
:
THREE
.
FlatShading
,
color
:
0xaaaaff
}
);
}
for
(
var
objid
in
amfObjects
)
{
console
.
log
(
"
Trying to load file asset:
"
+
file
);
view
=
new
DataView
(
zip
.
file
(
file
).
asArrayBuffer
()
);
var
newobject
=
new
THREE
.
Object3D
();
}
for
(
var
meshi
=
0
;
meshi
<
amfObjects
[
objid
].
meshes
.
length
;
meshi
++
)
{
if
(
TextDecoder
===
undefined
)
{
var
meshvertices
=
Float32Array
.
from
(
amfObjects
[
objid
].
meshes
[
meshi
].
vertices
);
var
vertices
=
new
THREE
.
BufferAttribute
(
Float32Array
.
from
(
meshvertices
),
3
);
var
objdefaultmaterial
=
defaultmaterial
;
console
.
log
(
"
TextDecoder not present. Please use TextDecoder polyfill.
"
);
return
null
;
if
(
amfObjects
[
objid
].
meshes
[
meshi
].
color
)
{
}
var
color
=
amfObjects
[
objid
].
meshes
[
meshi
].
color
;
objdefaultmaterial
=
defaultmaterial
.
clone
();
objdefaultmaterial
.
color
=
new
THREE
.
Color
(
color
.
r
,
color
.
g
,
color
.
b
);
var
filetext
=
new
TextDecoder
(
'
utf-8
'
).
decode
(
view
);
if
(
color
.
a
!=
1.0
)
{
var
xmldata
=
new
DOMParser
().
parseFromString
(
filetext
,
'
application/xml
'
);
objdefaultmaterial
.
transparent
=
true
;
objdefaultmaterial
.
opacity
=
color
.
a
;
if
(
xmldata
.
documentElement
.
nodeName
.
toLowerCase
()
!==
"
amf
"
)
{
}
console
.
log
(
"
Error loading AMF - no AMF document found.
"
);
return
null
;
}
}
for
(
var
voli
=
0
;
voli
<
amfObjects
[
objid
].
meshes
[
meshi
].
volumes
.
length
;
voli
++
)
{
return
xmldata
;
var
currvolume
=
amfObjects
[
objid
].
meshes
[
meshi
].
volumes
[
voli
];
var
newgeometry
=
new
THREE
.
BufferGeometry
();
var
indexes
=
Uint32Array
.
from
(
currvolume
.
triangles
);
var
normals
=
new
Uint32Array
(
vertices
.
array
.
length
);
}
var
material
=
objdefaultmaterial
;
function
loadDocumentScale
(
xmldata
)
{
newgeometry
.
setIndex
(
new
THREE
.
BufferAttribute
(
indexes
,
1
)
);
newgeometry
.
addAttribute
(
'
position
'
,
vertices
.
clone
()
);
var
scale
=
1.0
;
if
(
amfMaterials
[
currvolume
.
materialid
]
!==
undefined
)
{
var
unit
=
'
millimeter
'
;
material
=
amfMaterials
[
currvolume
.
materialid
];
if
(
xmldata
.
documentElement
.
attributes
[
'
unit
'
]
!==
undefined
)
{
}
unit
=
xmldata
.
documentElement
.
attributes
[
'
unit
'
].
value
.
toLowerCase
();
newgeometry
.
scale
(
amfScale
,
amfScale
,
amfScale
);
}
var
newmesh
=
new
THREE
.
Mesh
(
newgeometry
,
material
.
clone
()
);
var
scale_units
=
{
'
millimeter
'
:
1.0
,
'
inch
'
:
25.4
,
'
feet
'
:
304.8
,
'
meter
'
:
1000.0
,
'
micron
'
:
0.001
};
newobject
.
add
(
newmesh
);
if
(
scale_units
[
unit
]
!==
undefined
)
{
}
scale
=
scale_units
[
unit
];
}
sceneobject
.
add
(
newobject
);
}
console
.
log
(
"
Unit scale:
"
+
scale
);
return
scale
;
return
sceneobject
;
}
},
function
loadMaterials
(
node
)
{
_loadDocument
:
function
(
data
)
{
var
mat
=
node
;
var
view
=
new
DataView
(
data
);
var
loadedmaterial
=
null
;
var
matname
=
"
AMF Material
"
;
var
matid
=
mat
.
attributes
[
'
id
'
].
textContent
;
var
color
;
var
magic
=
String
.
fromCharCode
(
view
.
getUint8
(
0
),
view
.
getUint8
(
1
)
);
for
(
var
i
=
0
;
i
<
mat
.
children
.
length
;
i
++
)
{
if
(
magic
===
"
PK
"
)
{
var
matchildel
=
mat
.
children
[
i
];
console
.
log
(
"
Loading Zip
"
);
var
zip
=
null
;
var
file
=
null
;
if
(
matchildel
.
nodeName
===
"
metadata
"
&&
matchildel
.
attributes
[
'
type
'
]
!==
undefined
)
{
try
{
if
(
matchildel
.
attributes
[
'
type
'
].
value
===
'
name
'
)
{
zip
=
new
JSZip
(
data
)
;
matname
=
matchildel
.
textContent
;
}
catch
(
e
)
{
}
if
(
e
instanceof
ReferenceError
)
{
}
else
if
(
matchildel
.
nodeName
===
'
color
'
)
{
console
.
log
(
"
jszip missing and file is compressed.
"
);
return
null
;
color
=
loadColor
(
matchildel
);
}
}
for
(
file
in
zip
.
files
)
{
loadedmaterial
=
new
THREE
.
MeshPhongMaterial
(
{
shading
:
THREE
.
FlatShading
,
color
:
new
THREE
.
Color
(
color
.
r
,
color
.
g
,
color
.
b
),
name
:
matname
}
);
if
(
file
.
toLowerCase
().
endsWith
(
"
.amf
"
)
)
{
if
(
color
.
opacity
!==
1.0
)
{
break
;
}
loadedmaterial
.
transparent
=
true
;
loadedmaterial
.
opacity
=
color
.
opacity
;
}
console
.
log
(
"
Trying to load file asset:
"
+
file
);
view
=
new
DataView
(
zip
.
file
(
file
).
asArrayBuffer
()
);
return
{
'
id
'
:
matid
,
'
material
'
:
loadedmaterial
};
}
if
(
TextDecoder
===
undefined
)
{
function
loadColor
(
node
)
{
console
.
log
(
"
TextDecoder not present. Please use TextDecoder polyfill.
"
);
return
null
;
var
color
=
{
'
r
'
:
1.0
,
'
g
'
:
1.0
,
'
b
'
:
1.0
,
'
a
'
:
1.0
,
opacity
:
1.0
};
}
for
(
var
i
=
0
;
i
<
node
.
children
.
length
;
i
++
)
{
var
filetext
=
new
TextDecoder
(
'
utf-8
'
).
decode
(
view
)
;
var
matcolor
=
node
.
children
[
i
]
;
var
xmldata
=
new
DOMParser
().
parseFromString
(
filetext
,
'
application/xml
'
);
if
(
matcolor
.
nodeName
===
'
r
'
)
{
if
(
xmldata
.
documentElement
.
nodeName
.
toLowerCase
()
!==
"
amf
"
)
{
color
.
r
=
matcolor
.
textContent
;
console
.
log
(
"
Error loading AMF - no AMF document found.
"
);
return
null
;
}
else
if
(
matcolor
.
nodeName
===
'
g
'
)
{
}
color
.
g
=
matcolor
.
textContent
;
return
xmldata
;
}
else
if
(
matcolor
.
nodeName
===
'
b
'
)
{
},
color
.
b
=
matcolor
.
textContent
;
_loadDocumentScale
:
function
(
xmldata
)
{
}
else
if
(
matcolor
.
nodeName
===
'
a
'
)
{
var
scale
=
1.0
;
color
.
opacity
=
matcolor
.
textContent
;
var
unit
=
'
millimeter
'
;
}
if
(
xmldata
.
documentElement
.
attributes
[
'
unit
'
]
!==
undefined
)
{
}
unit
=
xmldata
.
documentElement
.
attributes
[
'
unit
'
].
value
.
toLowerCase
()
;
return
color
;
}
var
scale_units
=
{
'
millimeter
'
:
1.0
,
'
inch
'
:
25.4
,
'
feet
'
:
304.8
,
'
meter
'
:
1000.0
,
'
micron
'
:
0.001
};
function
loadMeshVolume
(
node
)
{
if
(
scale_units
[
unit
]
!==
undefined
)
{
var
volume
=
{
"
name
"
:
""
,
"
triangles
"
:
[],
"
materialid
"
:
null
};
scale
=
scale_units
[
unit
]
;
var
currvolumenode
=
node
.
firstElementChild
;
}
if
(
node
.
attributes
[
'
materialid
'
]
!==
undefined
)
{
console
.
log
(
"
Unit scale:
"
+
scale
);
return
scale
;
volume
.
materialid
=
node
.
attributes
[
'
materialid
'
].
nodeValue
;
},
}
_loadMaterials
:
function
(
node
)
{
while
(
currvolume
node
)
{
var
mat
=
node
;
if
(
currvolumenode
.
nodeName
===
"
metadata
"
)
{
var
loadedmaterial
=
null
;
var
matname
=
"
AMF Material
"
;
var
matid
=
mat
.
attributes
[
'
id
'
].
textContent
;
var
color
;
if
(
currvolumenode
.
attributes
[
'
type
'
]
!==
undefined
)
{
for
(
var
i
=
0
;
i
<
mat
.
children
.
length
;
i
++
)
{
if
(
currvolumenode
.
attributes
[
'
type
'
].
value
===
'
name
'
)
{
var
matchildel
=
mat
.
children
[
i
]
;
volume
.
name
=
currvolumenode
.
textContent
;
if
(
matchildel
.
nodeName
===
"
metadata
"
&&
matchildel
.
attributes
[
'
type
'
]
!==
undefined
)
{
}
}
if
(
matchildel
.
attributes
[
'
type
'
].
value
===
'
name
'
)
{
}
else
if
(
currvolumenode
.
nodeName
===
"
triangle
"
)
{
matname
=
matchildel
.
textContent
;
var
trianglenode
=
currvolumenode
.
firstElementChild
;
}
while
(
trianglenode
)
{
}
else
if
(
matchildel
.
nodeName
===
'
color
'
)
{
if
(
trianglenode
.
nodeName
===
"
v1
"
||
trianglenode
.
nodeName
===
"
v2
"
||
trianglenode
.
nodeName
===
"
v3
"
)
{
volume
.
triangles
.
push
(
trianglenode
.
textContent
);
}
color
=
this
.
_loadColor
(
matchildel
);
trianglenode
=
trianglenode
.
nextElementSibling
;
}
}
currvolumenode
=
currvolumenode
.
nextElementSibling
;
}
return
volume
;
}
loadedmaterial
=
new
THREE
.
MeshPhongMaterial
(
{
shading
:
THREE
.
FlatShading
,
color
:
new
THREE
.
Color
(
color
.
r
,
color
.
g
,
color
.
b
),
name
:
matname
}
);
function
loadMeshVertices
(
node
)
{
if
(
color
.
opacity
!==
1.0
)
{
var
vert_array
=
[];
loadedmaterial
.
transparent
=
true
;
loadedmaterial
.
opacity
=
color
.
opacity
;
var
currverticesnode
=
node
.
firstElementChild
;
}
while
(
currverticesnode
)
{
return
{
'
id
'
:
matid
,
'
material
'
:
loadedmaterial
};
if
(
currverticesnode
.
nodeName
===
"
vertex
"
)
{
},
var
vnode
=
currverticesnode
.
firstElementChild
;
_loadColor
:
function
(
node
)
{
while
(
v
node
)
{
var
color
=
{
'
r
'
:
1.0
,
'
g
'
:
1.0
,
'
b
'
:
1.0
,
'
a
'
:
1.0
,
opacity
:
1.0
};
if
(
vnode
.
nodeName
===
"
coordinates
"
)
{
for
(
var
i
=
0
;
i
<
node
.
children
.
length
;
i
++
)
{
var
coordnode
=
vnode
.
firstElementChild
;
var
matcolor
=
node
.
children
[
i
];
while
(
coordnode
)
{
if
(
matcolor
.
nodeName
===
'
r
'
)
{
if
(
coordnode
.
nodeName
===
"
x
"
||
coordnode
.
nodeName
===
"
y
"
||
coordnode
.
nodeName
===
"
z
"
)
{
color
.
r
=
matcolor
.
textContent
;
vert_array
.
push
(
coordnode
.
textContent
)
;
}
else
if
(
matcolor
.
nodeName
===
'
g
'
)
{
}
color
.
g
=
matcolor
.
textContent
;
coordnode
=
coordnode
.
nextElementSibling
;
}
else
if
(
matcolor
.
nodeName
===
'
b
'
)
{
}
color
.
b
=
matcolor
.
textContent
;
}
vnode
=
vnode
.
nextElementSibling
;
}
else
if
(
matcolor
.
nodeName
===
'
a
'
)
{
}
color
.
opacity
=
matcolor
.
textContent
;
}
currverticesnode
=
currverticesnode
.
nextElementSibling
;
}
return
vert_array
;
}
return
color
;
function
loadObject
(
node
)
{
},
"
use strict
"
;
_loadMeshVolume
:
function
(
node
)
{
var
objid
=
node
.
attributes
[
'
id
'
].
textContent
;
var
loadedobject
=
{
"
name
"
:
"
amfobject
"
,
"
meshes
"
:
[]
};
var
volume
=
{
"
name
"
:
""
,
"
triangles
"
:
[],
"
materialid
"
:
null
}
;
var
currcolor
=
null
;
var
currvolume
node
=
node
.
firstElementChild
;
var
currobj
node
=
node
.
firstElementChild
;
if
(
node
.
attributes
[
'
materialid
'
]
!==
undefined
)
{
while
(
currobjnode
)
{
volume
.
materialid
=
node
.
attributes
[
'
materialid
'
].
nodeValue
;
if
(
currobjnode
.
nodeName
===
"
metadata
"
)
{
}
if
(
currobjnode
.
attributes
[
'
type
'
]
!==
undefined
)
{
while
(
currvolumenode
)
{
if
(
currobjnode
.
attributes
[
'
type
'
].
value
===
'
name
'
)
{
if
(
currvolumenode
.
nodeName
===
"
metadata
"
)
{
loadedobject
.
name
=
currobjnode
.
textContent
;
if
(
currvolumenode
.
attributes
[
'
type
'
]
!==
undefined
)
{
}
if
(
currvolumenode
.
attributes
[
'
type
'
].
value
===
'
name
'
)
{
}
volume
.
name
=
currvolumenode
.
textContent
;
}
else
if
(
currobjnode
.
nodeName
===
"
color
"
)
{
}
currcolor
=
loadColor
(
currobjnode
);
}
}
else
if
(
currobjnode
.
nodeName
===
"
mesh
"
)
{
var
currmeshnode
=
currobjnode
.
firstElementChild
;
var
mesh
=
{
"
vertices
"
:
[],
"
volumes
"
:
[],
"
color
"
:
currcolor
};
while
(
currmeshnode
)
{
}
else
if
(
currvolumenode
.
nodeName
===
"
triangle
"
)
{
if
(
currmeshnode
.
nodeName
===
"
vertices
"
)
{
var
trianglenode
=
currvolumenode
.
firstElementChild
;
mesh
.
vertices
=
mesh
.
vertices
.
concat
(
loadMeshVertices
(
currmeshnode
)
)
;
while
(
trianglenode
)
{
}
else
if
(
currmeshnode
.
nodeName
===
"
volume
"
)
{
if
(
trianglenode
.
nodeName
===
"
v1
"
||
trianglenode
.
nodeName
===
"
v2
"
||
trianglenode
.
nodeName
===
"
v3
"
)
{
mesh
.
volumes
.
push
(
loadMeshVolume
(
currmeshnode
)
);
volume
.
triangles
.
push
(
trianglenode
.
textContent
);
}
currmeshnode
=
currmeshnode
.
nextElementSibling
;
}
trianglenode
=
trianglenode
.
nextElementSibling
;
loadedobject
.
meshes
.
push
(
mesh
)
;
}
currobjnode
=
currobjnode
.
nextElementSibling
;
}
currvolumenode
=
currvolumenode
.
nextElementSibling
;
}
return
{
'
id
'
:
objid
,
'
obj
'
:
loadedobject
};
return
volume
;
}
},
//
_loadMeshVertices
:
function
(
node
)
{
var
xmldata
=
loadDocument
(
data
);
var
vert_array
=
[];
var
amfName
=
""
;
var
amfAuthor
=
""
;
var
amfScale
=
loadDocumentScale
(
xmldata
);
var
amfMaterials
=
{};
var
amfObjects
=
{};
var
c
urrverticesnode
=
node
.
firstElementChild
;
var
c
hildren
=
xmldata
.
documentElement
.
children
;
while
(
currverticesnode
)
{
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
if
(
currverticesnode
.
nodeName
===
"
vertex
"
)
{
var
child
=
children
[
i
];
var
vnode
=
currverticesnode
.
firstElementChild
;
if
(
child
.
nodeName
===
'
metadata
'
)
{
while
(
vnode
)
{
if
(
child
.
attributes
[
'
type
'
]
!==
undefined
)
{
if
(
vnode
.
nodeName
===
"
coordinates
"
)
{
if
(
child
.
attributes
[
'
type
'
].
value
===
'
name
'
)
{
var
coordnode
=
vnode
.
firstElementChild
;
amfName
=
child
.
textContent
;
while
(
coordnode
)
{
}
else
if
(
child
.
attributes
[
'
type
'
].
value
===
'
author
'
)
{
if
(
coordnode
.
nodeName
===
"
x
"
||
coordnode
.
nodeName
===
"
y
"
||
coordnode
.
nodeName
===
"
z
"
)
{
amfAuthor
=
child
.
textContent
;
vert_array
.
push
(
coordnode
.
textContent
);
}
}
}
coordnode
=
coordnode
.
nextElementSibling
;
}
else
if
(
child
.
nodeName
===
'
material
'
)
{
}
var
loadedmaterial
=
loadMaterials
(
child
);
amfMaterials
[
loadedmaterial
.
id
]
=
loadedmaterial
.
material
;
}
vnode
=
vnode
.
nextElementSibling
;
}
else
if
(
child
.
nodeName
===
'
object
'
)
{
}
var
loadedobject
=
loadObject
(
child
);
amfObjects
[
loadedobject
.
id
]
=
loadedobject
.
obj
;
}
currverticesnode
=
currverticesnode
.
nextElementSibling
;
}
return
vert_array
;
var
sceneobject
=
new
THREE
.
Group
()
;
},
sceneobject
.
name
=
amfName
;
sceneobject
.
userData
.
author
=
amfAuthor
;
sceneobject
.
userData
.
loader
=
"
AMF
"
;
_loadObject
:
function
(
node
)
{
var
defaultmaterial
=
new
THREE
.
MeshPhongMaterial
(
{
color
:
0xaaaaff
,
shading
:
THREE
.
FlatShading
}
);
"
use strict
"
;
for
(
var
id
in
amfObjects
)
{
var
objid
=
node
.
attributes
[
'
id
'
].
textContent
;
var
loadedobject
=
{
"
name
"
:
"
amfobject
"
,
"
meshes
"
:
[]
};
var
meshes
=
amfObjects
[
id
].
meshes
;
var
currcolor
=
null
;
var
newobject
=
new
THREE
.
Group
()
;
var
currobjnode
=
node
.
firstElementChild
;
for
(
var
i
=
0
;
i
<
meshes
.
length
;
i
++
)
{
while
(
currobjnode
)
{
var
mesh
=
meshes
[
i
];
if
(
currobjnode
.
nodeName
===
"
metadata
"
)
{
var
meshvertices
=
Float32Array
.
from
(
mesh
.
vertices
);
var
vertices
=
new
THREE
.
BufferAttribute
(
Float32Array
.
from
(
meshvertices
),
3
);
var
objdefaultmaterial
=
defaultmaterial
;
if
(
mesh
.
color
)
{
if
(
currobjnode
.
attributes
[
'
type
'
]
!==
undefined
)
{
var
color
=
mesh
.
color
;
objdefaultmaterial
=
defaultmaterial
.
clone
();
objdefaultmaterial
.
color
=
new
THREE
.
Color
(
color
.
r
,
color
.
g
,
color
.
b
);
if
(
c
urrobjnode
.
attributes
[
'
type
'
].
value
===
'
name
'
)
{
if
(
c
olor
.
a
!==
1.0
)
{
loadedobject
.
name
=
currobjnode
.
textContent
;
objdefaultmaterial
.
transparent
=
true
;
objdefaultmaterial
.
opacity
=
color
.
a
;
}
}
}
else
if
(
currobjnode
.
nodeName
===
"
color
"
)
{
currcolor
=
this
.
_loadColor
(
currobjnode
);
var
volumes
=
mesh
.
volumes
;
}
else
if
(
currobjnode
.
nodeName
===
"
mesh
"
)
{
for
(
var
j
=
0
;
j
<
volumes
.
length
;
j
++
)
{
var
currmeshnode
=
currobjnode
.
firstElementChild
;
var
mesh
=
{
"
vertices
"
:
[],
"
volumes
"
:
[],
"
color
"
:
currcolor
};
var
volume
=
volumes
[
j
];
while
(
currmeshnode
)
{
var
newgeometry
=
new
THREE
.
BufferGeometry
();
var
indexes
=
Uint32Array
.
from
(
volume
.
triangles
);
var
normals
=
new
Uint32Array
(
vertices
.
array
.
length
);
if
(
currmeshnode
.
nodeName
===
"
vertices
"
)
{
var
material
=
objdefaultmaterial
;
mesh
.
vertices
=
mesh
.
vertices
.
concat
(
this
.
_loadMeshVertices
(
currmeshnode
)
);
newgeometry
.
setIndex
(
new
THREE
.
BufferAttribute
(
indexes
,
1
)
);
newgeometry
.
addAttribute
(
'
position
'
,
vertices
.
clone
()
);
}
else
if
(
currmeshnode
.
nodeName
===
"
volume
"
)
{
if
(
amfMaterials
[
volume
.
materialid
]
!==
undefined
)
{
m
esh
.
volumes
.
push
(
this
.
_loadMeshVolume
(
currmeshnode
)
)
;
m
aterial
=
amfMaterials
[
volume
.
materialid
]
;
}
currmeshnode
=
currmeshnode
.
nextElementSibling
;
newgeometry
.
scale
(
amfScale
,
amfScale
,
amfScale
);
newobject
.
add
(
new
THREE
.
Mesh
(
newgeometry
,
material
.
clone
()
)
);
}
loadedobject
.
meshes
.
push
(
mesh
);
}
currobjnode
=
currobjnode
.
nextElementSibling
;
sceneobject
.
add
(
newobject
)
;
}
return
{
'
id
'
:
objid
,
'
obj
'
:
loadedobject
}
;
return
sceneobject
;
}
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录