Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
dad80588
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,发现更多精彩内容 >>
提交
dad80588
编写于
5月 12, 2019
作者:
M
Mugen87
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
3MFLoader: Add support for components.
上级
e712bafd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
131 addition
and
31 deletion
+131
-31
examples/js/loaders/3MFLoader.js
examples/js/loaders/3MFLoader.js
+131
-31
未找到文件。
examples/js/loaders/3MFLoader.js
浏览文件 @
dad80588
...
...
@@ -205,10 +205,11 @@ THREE.ThreeMFLoader.prototype = {
}
function
parseBasematerialsNode
(
basematerialsNode
)
{
function
parseBasematerialsNode
(
/* basematerialsNode */
)
{
}
function
parseMeshNode
(
meshNode
,
extensions
)
{
function
parseMeshNode
(
meshNode
)
{
var
meshData
=
{};
...
...
@@ -300,6 +301,59 @@ THREE.ThreeMFLoader.prototype = {
function
parseComponentsNode
(
componentsNode
)
{
var
components
=
[];
var
componentNodes
=
componentsNode
.
querySelectorAll
(
'
component
'
);
for
(
var
i
=
0
;
i
<
componentNodes
.
length
;
i
++
)
{
var
componentNode
=
componentNodes
[
i
];
var
componentData
=
parseComponentNode
(
componentNode
);
components
.
push
(
componentData
);
}
return
components
;
}
function
parseComponentNode
(
componentNode
)
{
var
componentData
=
{};
componentData
[
'
objectId
'
]
=
componentNode
.
getAttribute
(
'
objectid
'
);
// required
var
transform
=
componentNode
.
getAttribute
(
'
transform
'
);
if
(
transform
)
{
componentData
[
'
transform
'
]
=
parseTransform
(
transform
);
}
return
componentData
;
}
function
parseTransform
(
transform
)
{
var
t
=
[];
transform
.
split
(
'
'
).
forEach
(
function
(
s
)
{
t
.
push
(
parseFloat
(
s
)
);
}
);
var
matrix
=
new
THREE
.
Matrix4
();
matrix
.
set
(
t
[
0
],
t
[
3
],
t
[
6
],
t
[
9
],
t
[
1
],
t
[
4
],
t
[
7
],
t
[
10
],
t
[
2
],
t
[
5
],
t
[
8
],
t
[
11
],
0.0
,
0.0
,
0.0
,
1.0
);
return
matrix
;
}
function
parseObjectNode
(
objectNode
)
{
...
...
@@ -411,25 +465,13 @@ THREE.ThreeMFLoader.prototype = {
var
itemNode
=
itemNodes
[
i
];
var
buildItem
=
{
object
i
d
:
itemNode
.
getAttribute
(
'
objectid
'
)
object
I
d
:
itemNode
.
getAttribute
(
'
objectid
'
)
};
var
transform
=
itemNode
.
getAttribute
(
'
transform
'
);
if
(
transform
)
{
var
t
=
[];
transform
.
split
(
'
'
).
forEach
(
function
(
s
)
{
t
.
push
(
parseFloat
(
s
)
);
}
);
var
mat4
=
new
THREE
.
Matrix4
();
buildItem
[
'
transform
'
]
=
mat4
.
set
(
t
[
0
],
t
[
3
],
t
[
6
],
t
[
9
],
t
[
1
],
t
[
4
],
t
[
7
],
t
[
10
],
t
[
2
],
t
[
5
],
t
[
8
],
t
[
11
],
0.0
,
0.0
,
0.0
,
1.0
);
buildItem
[
'
transform
'
]
=
parseTransform
(
transform
);
}
...
...
@@ -472,7 +514,7 @@ THREE.ThreeMFLoader.prototype = {
}
function
buildMesh
(
meshData
,
data3mf
)
{
function
buildMesh
(
meshData
)
{
var
geometry
=
new
THREE
.
BufferGeometry
();
geometry
.
setIndex
(
new
THREE
.
BufferAttribute
(
meshData
[
'
triangles
'
],
1
)
);
...
...
@@ -505,7 +547,7 @@ THREE.ThreeMFLoader.prototype = {
}
function
applyExtensions
(
extensions
,
meshData
,
modelXml
,
data3mf
)
{
function
applyExtensions
(
extensions
,
meshData
,
modelXml
)
{
if
(
!
extensions
)
{
...
...
@@ -543,10 +585,10 @@ THREE.ThreeMFLoader.prototype = {
}
function
build
Meshe
s
(
data3mf
)
{
function
build
Object
s
(
data3mf
)
{
var
modelsData
=
data3mf
.
model
;
var
meshe
s
=
{};
var
object
s
=
{};
var
modelsKeys
=
Object
.
keys
(
modelsData
);
for
(
var
i
=
0
;
i
<
modelsKeys
.
length
;
i
++
)
{
...
...
@@ -563,18 +605,34 @@ THREE.ThreeMFLoader.prototype = {
var
objectId
=
objectIds
[
j
];
var
objectData
=
modelData
[
'
resources
'
][
'
object
'
][
objectId
];
var
meshData
=
objectData
[
'
mesh
'
];
applyExtensions
(
extensions
,
meshData
,
modelXml
,
data3mf
);
meshes
[
objectId
]
=
buildMesh
(
meshData
,
data3mf
);
if
(
meshData
)
{
applyExtensions
(
extensions
,
meshData
,
modelXml
);
objects
[
objectId
]
=
{
isMesh
:
true
,
mesh
:
buildMesh
(
meshData
)
};
}
else
{
objects
[
objectId
]
=
{
isComposite
:
true
,
components
:
objectData
[
'
components
'
]
};
}
}
}
return
meshe
s
;
return
object
s
;
}
function
build
(
meshe
s
,
refs
,
data3mf
)
{
function
build
(
object
s
,
refs
,
data3mf
)
{
var
group
=
new
THREE
.
Group
();
var
buildData
=
data3mf
.
model
[
refs
[
'
target
'
].
substring
(
1
)
][
'
build
'
];
...
...
@@ -582,15 +640,57 @@ THREE.ThreeMFLoader.prototype = {
for
(
var
i
=
0
;
i
<
buildData
.
length
;
i
++
)
{
var
buildItem
=
buildData
[
i
];
var
mesh
=
meshes
[
buildItem
[
'
objecti
d
'
]
];
var
object
=
objects
[
buildItem
[
'
objectI
d
'
]
];
if
(
buildItem
[
'
transform
'
]
)
{
if
(
object
.
isComposite
)
{
mesh
.
geometry
.
applyMatrix
(
buildItem
[
'
transform
'
]
);
var
composite
=
new
THREE
.
Group
();
var
components
=
object
.
components
;
}
// add meshes to composite object
for
(
var
j
=
0
;
j
<
components
.
length
;
j
++
)
{
var
component
=
components
[
j
];
var
mesh
=
objects
[
component
.
objectId
].
mesh
.
clone
();
var
transform
=
component
.
transform
;
if
(
transform
)
{
mesh
.
applyMatrix
(
transform
);
}
composite
.
add
(
mesh
);
}
group
.
add
(
mesh
);
// transform composite if necessary
if
(
buildItem
[
'
transform
'
]
)
{
composite
.
applyMatrix
(
buildItem
[
'
transform
'
]
);
}
group
.
add
(
composite
);
}
else
{
var
mesh
=
object
.
mesh
;
var
transform
=
buildItem
[
'
transform
'
];
if
(
transform
)
{
mesh
.
applyMatrix
(
transform
);
}
group
.
add
(
mesh
);
}
}
...
...
@@ -599,9 +699,9 @@ THREE.ThreeMFLoader.prototype = {
}
var
data3mf
=
loadDocument
(
data
);
var
meshes
=
buildMeshe
s
(
data3mf
);
var
objects
=
buildObject
s
(
data3mf
);
return
build
(
meshe
s
,
data3mf
[
'
rels
'
],
data3mf
);
return
build
(
object
s
,
data3mf
[
'
rels
'
],
data3mf
);
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录