Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
c618c955
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,发现更多精彩内容 >>
未验证
提交
c618c955
编写于
12月 12, 2019
作者:
M
Mr.doob
提交者:
GitHub
12月 12, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18136 from donmccurdy/feat-dracoloader-taskcache
DRACOLoader: Support repeated loading of same geometry
上级
3ff792c4
81a64259
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
94 addition
and
8 deletion
+94
-8
examples/js/loaders/DRACOLoader.js
examples/js/loaders/DRACOLoader.js
+47
-4
examples/jsm/loaders/DRACOLoader.js
examples/jsm/loaders/DRACOLoader.js
+47
-4
未找到文件。
examples/js/loaders/DRACOLoader.js
浏览文件 @
c618c955
...
...
@@ -124,10 +124,6 @@ THREE.DRACOLoader.prototype = Object.assign( Object.create( THREE.Loader.prototy
decodeGeometry
:
function
(
buffer
,
taskConfig
)
{
var
worker
;
var
taskID
=
this
.
workerNextTaskID
++
;
var
taskCost
=
buffer
.
byteLength
;
// TODO: For backward-compatibility, support 'attributeTypes' objects containing
// references (rather than names) to typed array constructors. These must be
// serialized before sending them to the worker.
...
...
@@ -143,6 +139,43 @@ THREE.DRACOLoader.prototype = Object.assign( Object.create( THREE.Loader.prototy
}
//
var
taskKey
=
JSON
.
stringify
(
taskConfig
);
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
// again from this thread.
if
(
THREE
.
DRACOLoader
.
taskCache
.
has
(
buffer
)
)
{
var
cachedTask
=
THREE
.
DRACOLoader
.
taskCache
.
get
(
buffer
);
if
(
cachedTask
.
key
===
taskKey
)
{
return
cachedTask
.
promise
;
}
else
if
(
buffer
.
byteLength
===
0
)
{
// Technically, it would be possible to wait for the previous task to complete,
// transfer the buffer back, and decode again with the second configuration. That
// is complex, and I don't know of any reason to decode a Draco buffer twice in
// different ways, so this is left unimplemented.
throw
new
Error
(
'
THREE.DRACOLoader: Unable to re-decode a buffer with different
'
+
'
settings. Buffer has already been transferred.
'
);
}
}
//
var
worker
;
var
taskID
=
this
.
workerNextTaskID
++
;
var
taskCost
=
buffer
.
byteLength
;
// Obtain a worker and assign a task, and construct a geometry instance
// when the task completes.
var
geometryPending
=
this
.
_getWorker
(
taskID
,
taskCost
)
...
...
@@ -177,6 +210,14 @@ THREE.DRACOLoader.prototype = Object.assign( Object.create( THREE.Loader.prototy
}
);
// Cache the task result.
THREE
.
DRACOLoader
.
taskCache
.
set
(
buffer
,
{
key
:
taskKey
,
promise
:
geometryPending
}
);
return
geometryPending
;
},
...
...
@@ -604,6 +645,8 @@ THREE.DRACOLoader.DRACOWorker = function () {
};
THREE
.
DRACOLoader
.
taskCache
=
new
WeakMap
();
/** Deprecated static methods */
/** @deprecated */
...
...
examples/jsm/loaders/DRACOLoader.js
浏览文件 @
c618c955
...
...
@@ -131,10 +131,6 @@ DRACOLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
decodeGeometry
:
function
(
buffer
,
taskConfig
)
{
var
worker
;
var
taskID
=
this
.
workerNextTaskID
++
;
var
taskCost
=
buffer
.
byteLength
;
// TODO: For backward-compatibility, support 'attributeTypes' objects containing
// references (rather than names) to typed array constructors. These must be
// serialized before sending them to the worker.
...
...
@@ -150,6 +146,43 @@ DRACOLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
}
//
var
taskKey
=
JSON
.
stringify
(
taskConfig
);
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
// again from this thread.
if
(
DRACOLoader
.
taskCache
.
has
(
buffer
)
)
{
var
cachedTask
=
DRACOLoader
.
taskCache
.
get
(
buffer
);
if
(
cachedTask
.
key
===
taskKey
)
{
return
cachedTask
.
promise
;
}
else
if
(
buffer
.
byteLength
===
0
)
{
// Technically, it would be possible to wait for the previous task to complete,
// transfer the buffer back, and decode again with the second configuration. That
// is complex, and I don't know of any reason to decode a Draco buffer twice in
// different ways, so this is left unimplemented.
throw
new
Error
(
'
THREE.DRACOLoader: Unable to re-decode a buffer with different
'
+
'
settings. Buffer has already been transferred.
'
);
}
}
//
var
worker
;
var
taskID
=
this
.
workerNextTaskID
++
;
var
taskCost
=
buffer
.
byteLength
;
// Obtain a worker and assign a task, and construct a geometry instance
// when the task completes.
var
geometryPending
=
this
.
_getWorker
(
taskID
,
taskCost
)
...
...
@@ -184,6 +217,14 @@ DRACOLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
}
);
// Cache the task result.
DRACOLoader
.
taskCache
.
set
(
buffer
,
{
key
:
taskKey
,
promise
:
geometryPending
}
);
return
geometryPending
;
},
...
...
@@ -611,6 +652,8 @@ DRACOLoader.DRACOWorker = function () {
};
DRACOLoader
.
taskCache
=
new
WeakMap
();
/** Deprecated static methods */
/** @deprecated */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录