Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
b4e7fa62
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,发现更多精彩内容 >>
提交
b4e7fa62
编写于
6月 24, 2019
作者:
K
Kai Salmen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implemented review suggestions and added additional code doc
上级
05a07fbb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
72 addition
and
43 deletion
+72
-43
examples/jsm/loaders/OBJLoader2Parallel.js
examples/jsm/loaders/OBJLoader2Parallel.js
+1
-6
examples/jsm/loaders/obj2/shared/MeshReceiver.js
examples/jsm/loaders/obj2/shared/MeshReceiver.js
+0
-2
examples/jsm/loaders/obj2/worker/main/WorkerExecutionSupport.js
...es/jsm/loaders/obj2/worker/main/WorkerExecutionSupport.js
+71
-35
未找到文件。
examples/jsm/loaders/OBJLoader2Parallel.js
浏览文件 @
b4e7fa62
...
...
@@ -56,11 +56,6 @@ OBJLoader2Parallel.prototype.setCallbackOnParseComplete = function ( onParseComp
if
(
onParseComplete
!==
undefined
&&
onParseComplete
!==
null
)
{
this
.
callbacks
.
onParseComplete
=
onParseComplete
;
}
else
{
throw
"
No callbackOnLoad was provided! Aborting!
"
;
}
return
this
;
};
...
...
@@ -121,7 +116,7 @@ OBJLoader2Parallel.prototype.buildWorkerCode = function () {
*/
OBJLoader2Parallel
.
prototype
.
_configure
=
function
()
{
if
(
this
.
callbacks
.
onParseComplete
===
null
)
{
"
No callbackOnLoad was provided! Aborting!
"
throw
"
No callbackOnLoad was provided! Aborting!
"
;
}
// check if worker is already available and if so, then fast-fail
if
(
this
.
workerExecutionSupport
.
isWorkerLoaded
(
this
.
preferJsmWorker
)
)
return
;
...
...
examples/jsm/loaders/obj2/shared/MeshReceiver.js
浏览文件 @
b4e7fa62
...
...
@@ -11,8 +11,6 @@ import {
Points
}
from
"
../../../../../build/three.module.js
"
;
import
{
MaterialHandler
}
from
"
./MaterialHandler.js
"
;
/**
*
...
...
examples/jsm/loaders/obj2/worker/main/WorkerExecutionSupport.js
浏览文件 @
b4e7fa62
...
...
@@ -18,7 +18,7 @@ const CodeBuilderInstructions = function ( supportsStandardWorker, supportsJsmWo
this
.
codeFragments
=
[];
this
.
importStatements
=
[];
this
.
jsmWorkerFile
;
this
.
jsmWorkerFile
=
null
;
this
.
defaultGeometryType
=
0
;
};
...
...
@@ -38,18 +38,37 @@ CodeBuilderInstructions.prototype = {
return
this
.
preferJsmWorker
;
},
/**
* Set the full path to the module that contains the worker code.
*
* @param {String} jsmWorkerFile
*/
setJsmWorkerFile
:
function
(
jsmWorkerFile
)
{
this
.
jsmWorkerFile
=
jsmWorkerFile
;
if
(
jsmWorkerFile
!==
undefined
&&
jsmWorkerFile
!==
null
)
{
this
.
jsmWorkerFile
=
jsmWorkerFile
;
}
},
/**
* Add code that is contained in addition to fragments and libraries
* @param {String} startCode
*/
addStartCode
:
function
(
startCode
)
{
this
.
startCode
=
startCode
;
},
/**
* Add code fragment that is included in the provided order
* @param {String} code
*/
addCodeFragment
:
function
(
code
)
{
this
.
codeFragments
.
push
(
code
);
},
/**
* Add full path to a library that is contained at the start of the worker via "importScripts"
* @param {String} libraryPath
*/
addLibraryImport
:
function
(
libraryPath
)
{
let
libraryUrl
=
new
URL
(
libraryPath
,
window
.
location
.
href
).
href
;
let
code
=
'
importScripts( "
'
+
libraryUrl
+
'
" );
'
;
...
...
@@ -82,7 +101,7 @@ const WorkerExecutionSupport = function () {
this
.
_reset
();
};
WorkerExecutionSupport
.
WORKER_SUPPORT_VERSION
=
'
3.0.0-
preview
'
;
WorkerExecutionSupport
.
WORKER_SUPPORT_VERSION
=
'
3.0.0-
beta2
'
;
console
.
info
(
'
Using WorkerSupport version:
'
+
WorkerExecutionSupport
.
WORKER_SUPPORT_VERSION
);
...
...
@@ -221,24 +240,30 @@ WorkerExecutionSupport.prototype = {
*/
_buildWorkerJsm
:
function
(
codeBuilderInstructions
)
{
let
jsmSuccess
=
true
;
this
.
_buildWorkerCheckPreconditions
(
true
,
'
buildWorkerJsm
'
);
let
timeLabel
=
'
buildWorkerJsm
'
;
let
workerAvailable
=
this
.
_buildWorkerCheckPreconditions
(
true
,
timeLabel
);
if
(
!
workerAvailable
)
{
let
workerFileUrl
=
new
URL
(
codeBuilderInstructions
.
jsmWorkerFile
,
window
.
location
.
href
).
href
;
try
{
let
workerFileUrl
=
new
URL
(
codeBuilderInstructions
.
jsmWorkerFile
,
window
.
location
.
href
).
href
;
try
{
let
worker
=
new
Worker
(
workerFileUrl
,
{
type
:
"
module
"
}
);
this
.
_configureWorkerCommunication
(
worker
,
true
,
codeBuilderInstructions
.
defaultGeometryType
,
'
buildWorkerJsm
'
);
let
worker
=
new
Worker
(
workerFileUrl
,
{
type
:
"
module
"
}
);
this
.
_configureWorkerCommunication
(
worker
,
true
,
codeBuilderInstructions
.
defaultGeometryType
,
timeLabel
);
}
catch
(
e
)
{
}
catch
(
e
)
{
jsmSuccess
=
false
;
if
(
e
instanceof
TypeError
||
e
instanceof
SyntaxError
)
{
jsmSuccess
=
false
;
// Chrome throws this exception, but Firefox currently does not complain, but can't execute the worker afterwards
if
(
e
instanceof
TypeError
||
e
instanceof
SyntaxError
)
{
console
.
error
(
"
Modules are not supported in workers.
"
);
console
.
error
(
"
Modules are not supported in workers.
"
);
}
}
}
return
jsmSuccess
;
},
...
...
@@ -254,34 +279,45 @@ WorkerExecutionSupport.prototype = {
* @private
*/
_buildWorkerStandard
:
function
(
codeBuilderInstructions
)
{
this
.
_buildWorkerCheckPreconditions
(
false
,
'
buildWorkerStandard
'
);
let
concatenateCode
=
''
;
codeBuilderInstructions
.
getImportStatements
().
forEach
(
function
(
element
)
{
concatenateCode
+=
element
+
'
\n
'
;
}
);
concatenateCode
+=
'
\n
'
;
codeBuilderInstructions
.
getCodeFragments
().
forEach
(
function
(
element
)
{
concatenateCode
+=
element
+
'
\n
'
;
}
);
concatenateCode
+=
'
\n
'
;
concatenateCode
+=
codeBuilderInstructions
.
getStartCode
();
let
blob
=
new
Blob
(
[
concatenateCode
],
{
type
:
'
application/javascript
'
}
);
let
worker
=
new
Worker
(
window
.
URL
.
createObjectURL
(
blob
)
);
this
.
_configureWorkerCommunication
(
worker
,
false
,
codeBuilderInstructions
.
defaultGeometryType
,
'
buildWorkerStandard
'
);
let
timeLabel
=
'
buildWorkerStandard
'
;
let
workerAvailable
=
this
.
_buildWorkerCheckPreconditions
(
false
,
timeLabel
);
if
(
!
workerAvailable
)
{
let
concatenateCode
=
''
;
codeBuilderInstructions
.
getImportStatements
().
forEach
(
function
(
element
)
{
concatenateCode
+=
element
+
'
\n
'
;
}
);
concatenateCode
+=
'
\n
'
;
codeBuilderInstructions
.
getCodeFragments
().
forEach
(
function
(
element
)
{
concatenateCode
+=
element
+
'
\n
'
;
}
);
concatenateCode
+=
'
\n
'
;
concatenateCode
+=
codeBuilderInstructions
.
getStartCode
();
let
blob
=
new
Blob
(
[
concatenateCode
],
{
type
:
'
application/javascript
'
}
);
let
worker
=
new
Worker
(
window
.
URL
.
createObjectURL
(
blob
)
);
this
.
_configureWorkerCommunication
(
worker
,
false
,
codeBuilderInstructions
.
defaultGeometryType
,
timeLabel
);
}
},
_buildWorkerCheckPreconditions
:
function
(
requireJsmWorker
,
timeLabel
)
{
if
(
this
.
isWorkerLoaded
(
requireJsmWorker
)
)
return
;
let
workerAvailable
=
false
;
if
(
this
.
isWorkerLoaded
(
requireJsmWorker
)
)
{
if
(
this
.
logging
.
enabled
)
{
workerAvailable
=
true
;
console
.
info
(
'
WorkerExecutionSupport: Building
'
+
(
requireJsmWorker
?
'
jsm
'
:
'
standard
'
)
+
'
worker code...
'
);
console
.
time
(
timeLabel
);
}
else
{
if
(
this
.
logging
.
enabled
)
{
console
.
info
(
'
WorkerExecutionSupport: Building
'
+
(
requireJsmWorker
?
'
jsm
'
:
'
standard
'
)
+
'
worker code...
'
);
console
.
time
(
timeLabel
);
}
}
return
workerAvailable
;
},
_configureWorkerCommunication
:
function
(
worker
,
haveJsmWorker
,
defaultGeometryType
,
timeLabel
)
{
...
...
@@ -402,7 +438,7 @@ WorkerExecutionSupport.prototype = {
},
_postMessage
:
function
()
{
if
(
this
.
worker
.
queuedMessage
!==
null
&&
this
.
isWorkerLoaded
(
this
.
worker
.
jsmWorker
)
)
{
if
(
this
.
worker
.
queuedMessage
!==
null
)
{
if
(
this
.
worker
.
queuedMessage
.
payload
.
data
.
input
instanceof
ArrayBuffer
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录