Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
37ae761f
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,发现更多精彩内容 >>
未验证
提交
37ae761f
编写于
3月 13, 2018
作者:
M
Mr.doob
提交者:
GitHub
3月 13, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13536 from takahirox/GLTFExporterMultiMaterial
GLTFExporter: Multi-material support
上级
1d6d3c77
2d1a8977
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
95 addition
and
52 deletion
+95
-52
examples/js/exporters/GLTFExporter.js
examples/js/exporters/GLTFExporter.js
+95
-52
未找到文件。
examples/js/exporters/GLTFExporter.js
浏览文件 @
37ae761f
...
...
@@ -169,10 +169,12 @@ THREE.GLTFExporter.prototype = {
/**
* Get the min and max vectors from the given attribute
* @param {THREE.BufferAttribute} attribute Attribute to find the min/max
* @param {THREE.BufferAttribute} attribute Attribute to find the min/max in range from start to start + count
* @param {Integer} start
* @param {Integer} count
* @return {Object} Object containing the `min` and `max` values (As an array of attribute.itemSize components)
*/
function
getMinMax
(
attribute
)
{
function
getMinMax
(
attribute
,
start
,
count
)
{
var
output
=
{
...
...
@@ -181,7 +183,7 @@ THREE.GLTFExporter.prototype = {
};
for
(
var
i
=
0
;
i
<
attribute
.
count
;
i
++
)
{
for
(
var
i
=
start
;
i
<
start
+
count
;
i
++
)
{
for
(
var
a
=
0
;
a
<
attribute
.
itemSize
;
a
++
)
{
...
...
@@ -393,9 +395,11 @@ THREE.GLTFExporter.prototype = {
* Process attribute to generate an accessor
* @param {THREE.BufferAttribute} attribute Attribute to process
* @param {THREE.BufferGeometry} geometry (Optional) Geometry used for truncated draw range
* @param {Integer} start (Optional)
* @param {Integer} count (Optional)
* @return {Integer} Index of the processed accessor on the "accessors" array
*/
function
processAccessor
(
attribute
,
geometry
)
{
function
processAccessor
(
attribute
,
geometry
,
start
,
count
)
{
if
(
!
outputJSON
.
accessors
)
{
...
...
@@ -434,27 +438,33 @@ THREE.GLTFExporter.prototype = {
}
var
minMax
=
getMinMax
(
attribute
);
var
start
=
0
;
var
count
=
attribute
.
count
;
if
(
start
===
undefined
)
start
=
0
;
if
(
count
===
undefined
)
count
=
attribute
.
count
;
// @TODO Indexed buffer geometry with drawRange not supported yet
if
(
options
.
truncateDrawRange
&&
geometry
!==
undefined
&&
geometry
.
index
===
null
)
{
start
=
geometry
.
drawRange
.
start
;
count
=
geometry
.
drawRange
.
count
!==
Infinity
?
geometry
.
drawRange
.
count
:
attribute
.
count
;
var
end
=
start
+
count
;
var
end2
=
geometry
.
drawRange
.
count
===
Infinity
?
attribute
.
count
:
geometry
.
drawRange
.
start
+
geometry
.
drawRange
.
count
;
start
=
Math
.
max
(
start
,
geometry
.
drawRange
.
start
);
count
=
Math
.
min
(
end
,
end2
)
-
start
;
if
(
count
<
0
)
count
=
0
;
}
var
minMax
=
getMinMax
(
attribute
,
start
,
count
);
var
bufferViewTarget
;
// If geometry isn't provided, don't infer the target usage of the bufferView. For
// animation samplers, target must not be set.
if
(
geometry
!==
undefined
)
{
var
isVertexAttributes
=
componentType
===
WEBGL_CONSTANTS
.
FLOAT
;
bufferViewTarget
=
isVertexAttributes
?
WEBGL_CONSTANTS
.
ARRAY_BUFFER
:
WEBGL_CONSTANTS
.
ELEMENT_ARRAY_BUFFER
;
bufferViewTarget
=
attribute
===
geometry
.
index
?
WEBGL_CONSTANTS
.
ELEMENT_ARRAY_BUFFER
:
WEBGL_CONSTANTS
.
ARRAY_BUFFER
;
}
...
...
@@ -888,43 +898,11 @@ THREE.GLTFExporter.prototype = {
}
var
gltfMesh
=
{
primitives
:
[
{
mode
:
mode
,
attributes
:
{},
}
]
};
var
material
=
processMaterial
(
mesh
.
material
);
if
(
material
!==
null
)
{
gltfMesh
.
primitives
[
0
].
material
=
material
;
}
if
(
geometry
.
index
)
{
gltfMesh
.
primitives
[
0
].
indices
=
processAccessor
(
geometry
.
index
,
geometry
);
}
else
if
(
options
.
forceIndices
)
{
var
numFaces
=
geometry
.
attributes
.
position
.
count
;
var
indices
=
new
Uint32Array
(
numFaces
);
for
(
var
i
=
0
;
i
<
numFaces
;
i
++
)
{
var
gltfMesh
=
{};
indices
[
i
]
=
i
;
}
gltfMesh
.
primitives
[
0
].
indices
=
processAccessor
(
new
THREE
.
Uint32BufferAttribute
(
indices
,
1
),
geometry
);
}
// We've just one primitive per mesh
var
gltfAttributes
=
gltfMesh
.
primitives
[
0
].
attributes
;
var
attributes
=
{};
var
primitives
=
[];
var
targets
=
[];
// Conversion between attributes names in threejs and gltf spec
var
nameConversion
=
{
...
...
@@ -946,7 +924,7 @@ THREE.GLTFExporter.prototype = {
if
(
attributeName
.
substr
(
0
,
5
)
!==
'
MORPH
'
)
{
gltfA
ttributes
[
attributeName
]
=
processAccessor
(
attribute
,
geometry
);
a
ttributes
[
attributeName
]
=
processAccessor
(
attribute
,
geometry
);
}
...
...
@@ -969,8 +947,6 @@ THREE.GLTFExporter.prototype = {
}
gltfMesh
.
primitives
[
0
].
targets
=
[];
for
(
var
i
=
0
;
i
<
mesh
.
morphTargetInfluences
.
length
;
++
i
)
{
var
target
=
{};
...
...
@@ -1021,7 +997,7 @@ THREE.GLTFExporter.prototype = {
}
gltfMesh
.
primitives
[
0
].
targets
.
push
(
target
);
targets
.
push
(
target
);
weights
.
push
(
mesh
.
morphTargetInfluences
[
i
]
);
if
(
mesh
.
morphTargetDictionary
!==
undefined
)
targetNames
.
push
(
reverseDictionary
[
i
]
);
...
...
@@ -1039,6 +1015,73 @@ THREE.GLTFExporter.prototype = {
}
var
forceIndices
=
options
.
forceIndices
;
var
isMultiMaterial
=
Array
.
isArray
(
mesh
.
material
);
if
(
!
forceIndices
&&
geometry
.
index
===
null
&&
isMultiMaterial
)
{
// temporal workaround.
console
.
warn
(
'
THREE.GLTFExporter: Creating index for non-indexed multi-material mesh.
'
);
forceIndices
=
true
;
}
var
didForceIndices
=
false
;
if
(
geometry
.
index
===
null
&&
forceIndices
)
{
var
indices
=
[];
for
(
var
i
=
0
,
il
=
geometry
.
attributes
.
position
.
count
;
i
<
il
;
i
++
)
{
indices
[
i
]
=
i
;
}
geometry
.
setIndex
(
indices
);
didForceIndices
=
true
;
}
var
materials
=
isMultiMaterial
?
mesh
.
material
:
[
mesh
.
material
]
;
var
groups
=
isMultiMaterial
?
mesh
.
geometry
.
groups
:
[
{
materialIndex
:
0
,
start
:
undefined
,
count
:
undefined
}
];
for
(
var
i
=
0
,
il
=
groups
.
length
;
i
<
il
;
i
++
)
{
var
primitive
=
{
mode
:
mode
,
attributes
:
attributes
,
};
if
(
targets
.
length
>
0
)
primitive
.
targets
=
targets
;
var
material
=
processMaterial
(
materials
[
groups
[
i
].
materialIndex
]
);
if
(
material
!==
null
)
{
primitive
.
material
=
material
;
}
if
(
geometry
.
index
!==
null
)
{
primitive
.
indices
=
processAccessor
(
geometry
.
index
,
geometry
,
groups
[
i
].
start
,
groups
[
i
].
count
);
}
primitives
.
push
(
primitive
);
}
if
(
didForceIndices
)
{
geometry
.
setIndex
(
null
);
}
gltfMesh
.
primitives
=
primitives
;
outputJSON
.
meshes
.
push
(
gltfMesh
);
return
outputJSON
.
meshes
.
length
-
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录