Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
f64fac67
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,发现更多精彩内容 >>
提交
f64fac67
编写于
8月 23, 2017
作者:
M
Mr.doob
提交者:
GitHub
8月 23, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12029 from fernandojsg/truncateDrawRange
GLTFExporter: "truncateDrawRange" option added
上级
1ab1bb2e
17f5b3d5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
76 addition
and
18 deletion
+76
-18
examples/js/exporters/GLTFExporter.js
examples/js/exporters/GLTFExporter.js
+36
-18
examples/misc_exporter_gltf.html
examples/misc_exporter_gltf.html
+40
-0
未找到文件。
examples/js/exporters/GLTFExporter.js
浏览文件 @
f64fac67
...
...
@@ -59,7 +59,8 @@ THREE.GLTFExporter.prototype = {
var
DEFAULT_OPTIONS
=
{
trs
:
false
,
onlyVisible
:
true
onlyVisible
:
true
,
truncateDrawRange
:
true
};
options
=
Object
.
assign
(
{},
DEFAULT_OPTIONS
,
options
);
...
...
@@ -132,7 +133,7 @@ THREE.GLTFExporter.prototype = {
* @param {Integer} componentType Component type (Unsigned short, unsigned int or float)
* @return {Integer} Index of the buffer created (Currently always 0)
*/
function
processBuffer
(
attribute
,
componentType
)
{
function
processBuffer
(
attribute
,
componentType
,
start
,
count
)
{
if
(
!
outputJSON
.
buffers
)
{
...
...
@@ -149,13 +150,15 @@ THREE.GLTFExporter.prototype = {
}
var
offset
=
0
;
var
componentSize
=
componentType
===
WEBGL_CONSTANTS
.
UNSIGNED_SHORT
?
2
:
4
;
// Create a new dataview and dump the attribute's array into it
var
dataView
=
new
DataView
(
new
ArrayBuffer
(
attribute
.
array
.
byteLength
)
)
;
var
byteLength
=
count
*
attribute
.
itemSize
*
componentSize
;
var
offset
=
0
;
var
offsetInc
=
componentType
===
WEBGL_CONSTANTS
.
UNSIGNED_SHORT
?
2
:
4
;
var
dataView
=
new
DataView
(
new
ArrayBuffer
(
byteLength
)
);
for
(
var
i
=
0
;
i
<
attribute
.
count
;
i
++
)
{
for
(
var
i
=
start
;
i
<
start
+
count
;
i
++
)
{
for
(
var
a
=
0
;
a
<
attribute
.
itemSize
;
a
++
)
{
...
...
@@ -175,7 +178,7 @@ THREE.GLTFExporter.prototype = {
}
offset
+=
offsetInc
;
offset
+=
componentSize
;
}
...
...
@@ -193,7 +196,7 @@ THREE.GLTFExporter.prototype = {
* @param {[type]} data [description]
* @return {[type]} [description]
*/
function
processBufferView
(
data
,
componentType
)
{
function
processBufferView
(
data
,
componentType
,
start
,
count
)
{
var
isVertexAttributes
=
componentType
===
WEBGL_CONSTANTS
.
FLOAT
;
...
...
@@ -203,17 +206,22 @@ THREE.GLTFExporter.prototype = {
}
var
componentSize
=
componentType
===
WEBGL_CONSTANTS
.
UNSIGNED_SHORT
?
2
:
4
;
// Create a new dataview and dump the attribute's array into it
var
byteLength
=
count
*
data
.
itemSize
*
componentSize
;
var
gltfBufferView
=
{
buffer
:
processBuffer
(
data
,
componentType
),
buffer
:
processBuffer
(
data
,
componentType
,
start
,
count
),
byteOffset
:
byteOffset
,
byteLength
:
data
.
array
.
byteLength
,
byteStride
:
data
.
itemSize
*
(
componentType
===
WEBGL_CONSTANTS
.
UNSIGNED_SHORT
?
2
:
4
)
,
byteLength
:
byteLength
,
byteStride
:
data
.
itemSize
*
componentSize
,
target
:
isVertexAttributes
?
WEBGL_CONSTANTS
.
ARRAY_BUFFER
:
WEBGL_CONSTANTS
.
ELEMENT_ARRAY_BUFFER
};
byteOffset
+=
data
.
array
.
byteLength
;
byteOffset
+=
byteLength
;
outputJSON
.
bufferViews
.
push
(
gltfBufferView
);
...
...
@@ -234,7 +242,7 @@ THREE.GLTFExporter.prototype = {
* @param {THREE.WebGLAttribute} attribute Attribute to process
* @return {Integer} Index of the processed accessor on the "accessors" array
*/
function
processAccessor
(
attribute
)
{
function
processAccessor
(
attribute
,
geometry
)
{
if
(
!
outputJSON
.
accessors
)
{
...
...
@@ -273,14 +281,24 @@ THREE.GLTFExporter.prototype = {
}
var
minMax
=
getMinMax
(
attribute
);
var
bufferView
=
processBufferView
(
attribute
,
componentType
);
var
start
=
0
;
var
count
=
attribute
.
count
;
// @TODO Indexed buffer geometry with drawRange not supported yet
if
(
options
.
truncateDrawRange
&&
geometry
.
index
===
null
)
{
start
=
geometry
.
drawRange
.
start
;
count
=
geometry
.
drawRange
.
count
!==
Infinity
?
geometry
.
drawRange
.
count
:
attribute
.
count
;
}
var
bufferView
=
processBufferView
(
attribute
,
componentType
,
start
,
count
);
var
gltfAccessor
=
{
bufferView
:
bufferView
.
id
,
byteOffset
:
bufferView
.
byteOffset
,
componentType
:
componentType
,
count
:
attribute
.
count
,
count
:
count
,
max
:
minMax
.
max
,
min
:
minMax
.
min
,
type
:
types
[
attribute
.
itemSize
-
1
]
...
...
@@ -559,7 +577,7 @@ THREE.GLTFExporter.prototype = {
}
else
{
if
(
!
(
geometry
instanceof
THREE
.
BufferGeometry
)
)
{
if
(
!
geometry
.
isBufferGeometry
)
{
var
geometryTemp
=
new
THREE
.
BufferGeometry
();
geometryTemp
.
fromGeometry
(
geometry
);
...
...
@@ -603,7 +621,7 @@ THREE.GLTFExporter.prototype = {
if
(
geometry
.
index
)
{
gltfMesh
.
primitives
[
0
].
indices
=
processAccessor
(
geometry
.
index
);
gltfMesh
.
primitives
[
0
].
indices
=
processAccessor
(
geometry
.
index
,
geometry
);
}
...
...
@@ -628,7 +646,7 @@ THREE.GLTFExporter.prototype = {
var
attribute
=
geometry
.
attributes
[
attributeName
];
attributeName
=
nameConversion
[
attributeName
]
||
attributeName
.
toUpperCase
();
gltfAttributes
[
attributeName
]
=
processAccessor
(
attribute
);
gltfAttributes
[
attributeName
]
=
processAccessor
(
attribute
,
geometry
);
}
...
...
examples/misc_exporter_gltf.html
浏览文件 @
f64fac67
...
...
@@ -31,6 +31,7 @@
<br/>
<label><input
id=
"option_trs"
name=
"trs"
type=
"checkbox"
/>
TRS
</label>
<label><input
id=
"option_visible"
name=
"visible"
type=
"checkbox"
checked=
"checked"
/>
Only Visible
</label>
<label><input
id=
"option_drawrange"
name=
"visible"
type=
"checkbox"
checked=
"checked"
/>
Truncate drawRange
</label>
</div>
<script
src=
"../build/three.js"
></script>
...
...
@@ -47,6 +48,7 @@
var
options
=
{
trs
:
document
.
getElementById
(
'
option_trs
'
).
checked
,
onlyVisible
:
document
.
getElementById
(
'
option_visible
'
).
checked
,
truncateDrawRange
:
document
.
getElementById
(
'
option_drawrange
'
).
checked
}
gltfExporter
.
parse
(
input
,
function
(
result
)
{
...
...
@@ -345,6 +347,44 @@
scene1
.
add
(
object
);
// ---------------------------------------------------------------------
// Buffer geometry truncated (DrawRange)
// ---------------------------------------------------------------------
var
geometry
=
new
THREE
.
BufferGeometry
();
var
numElements
=
6
;
var
outOfRange
=
3
;
var
positions
=
new
Float32Array
(
(
numElements
+
outOfRange
)
*
3
);
var
colors
=
new
Float32Array
(
(
numElements
+
outOfRange
)
*
3
);
positions
.
set
([
0
,
0
,
0
,
0
,
80
,
0
,
80
,
0
,
0
,
80
,
0
,
0
,
0
,
80
,
0
,
80
,
80
,
0
]);
colors
.
set
([
1
,
0
,
0
,
1
,
0
,
0
,
1
,
1
,
0
,
1
,
1
,
0
,
0
,
0
,
1
,
0
,
0
,
1
,
]);
geometry
.
addAttribute
(
'
position
'
,
new
THREE
.
BufferAttribute
(
positions
,
3
)
);
geometry
.
addAttribute
(
'
color
'
,
new
THREE
.
BufferAttribute
(
colors
,
3
)
);
geometry
.
setDrawRange
(
0
,
numElements
);
object
=
new
THREE
.
Mesh
(
geometry
,
new
THREE
.
MeshBasicMaterial
(
{
side
:
THREE
.
DoubleSide
,
vertexColors
:
THREE
.
VertexColors
}
)
);
object
.
name
=
'
Custom buffered truncated
'
;
object
.
position
.
set
(
340
,
-
40
,
-
200
);
scene1
.
add
(
object
);
// ---------------------------------------------------------------------
// Points
// ---------------------------------------------------------------------
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录