Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
8d8ff4d3
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,发现更多精彩内容 >>
未验证
提交
8d8ff4d3
编写于
6月 16, 2019
作者:
M
Michael Herzog
提交者:
GitHub
6月 16, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16797 from Mugen87/dev34
JSM: Added module and TS file for CTMLoader.
上级
495f4c2c
c92d01b7
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
362 addition
and
40 deletion
+362
-40
docs/manual/en/introduction/Import-via-modules.html
docs/manual/en/introduction/Import-via-modules.html
+5
-0
examples/js/loaders/ctm/CTMLoader.js
examples/js/loaders/ctm/CTMLoader.js
+38
-39
examples/jsm/loaders/ctm/CTMLoader.d.ts
examples/jsm/loaders/ctm/CTMLoader.d.ts
+20
-0
examples/jsm/loaders/ctm/CTMLoader.js
examples/jsm/loaders/ctm/CTMLoader.js
+288
-0
examples/webgl_loader_ctm.html
examples/webgl_loader_ctm.html
+7
-0
examples/webgl_loader_ctm_materials.html
examples/webgl_loader_ctm_materials.html
+3
-1
utils/modularize.js
utils/modularize.js
+1
-0
未找到文件。
docs/manual/en/introduction/Import-via-modules.html
浏览文件 @
8d8ff4d3
...
...
@@ -169,6 +169,11 @@
</li>
<li>
loaders
<ul>
<li>
ctm
<ul>
<li>
CTMLoader
</li>
</ul>
</li>
<li>
deprecated
<ul>
<li>
LegacyGLTFLoader
</li>
...
...
examples/js/loaders/ctm/CTMLoader.js
浏览文件 @
8d8ff4d3
...
...
@@ -32,12 +32,22 @@
*
*/
/* global CTM */
THREE
.
CTMLoader
=
function
()
{
this
.
workerPath
=
null
;
};
THREE
.
CTMLoader
.
prototype
.
constructor
=
THREE
.
CTMLoader
;
THREE
.
CTMLoader
.
prototype
.
setWorkerPath
=
function
(
workerPath
)
{
this
.
workerPath
=
workerPath
;
};
// Load multiple CTM parts defined in JSON
THREE
.
CTMLoader
.
prototype
.
loadParts
=
function
(
url
,
callback
,
parameters
)
{
...
...
@@ -131,7 +141,7 @@ THREE.CTMLoader.prototype.load = function ( url, callback, parameters ) {
if
(
parameters
.
useWorker
)
{
var
worker
=
parameters
.
worker
||
new
Worker
(
'
js/loaders/ctm/CTMWorker.js
'
);
var
worker
=
parameters
.
worker
||
new
Worker
(
scope
.
workerPath
);
worker
.
onmessage
=
function
(
event
)
{
...
...
@@ -144,7 +154,7 @@ THREE.CTMLoader.prototype.load = function ( url, callback, parameters ) {
var
e1
=
Date
.
now
();
// console.log( "CTM data parse time [worker]: " + (e1-s) + " ms" );
scope
.
createModel
(
ctmFile
,
callback
);
scope
.
_createGeometry
(
ctmFile
,
callback
);
var
e
=
Date
.
now
();
console
.
log
(
"
model load time [worker]:
"
+
(
e
-
e1
)
+
"
ms, total:
"
+
(
e
-
s
)
);
...
...
@@ -165,7 +175,7 @@ THREE.CTMLoader.prototype.load = function ( url, callback, parameters ) {
var
ctmFile
=
new
CTM
.
File
(
stream
);
scope
.
createModel
(
ctmFile
,
callback
);
scope
.
_createGeometry
(
ctmFile
,
callback
);
}
...
...
@@ -210,63 +220,52 @@ THREE.CTMLoader.prototype.load = function ( url, callback, parameters ) {
};
THREE
.
CTMLoader
.
prototype
.
createModel
=
function
(
file
,
callback
)
{
var
Model
=
function
()
{
THREE
.
BufferGeometry
.
call
(
this
);
this
.
materials
=
[];
var
indices
=
file
.
body
.
indices
;
var
positions
=
file
.
body
.
vertices
;
var
normals
=
file
.
body
.
normals
;
var
uvs
,
colors
;
THREE
.
CTMLoader
.
prototype
.
_createGeometry
=
function
(
file
,
callback
)
{
var
uvMaps
=
file
.
body
.
uvMaps
;
var
geometry
=
new
THREE
.
BufferGeometry
()
;
if
(
uvMaps
!==
undefined
&&
uvMaps
.
length
>
0
)
{
var
indices
=
file
.
body
.
indices
;
var
positions
=
file
.
body
.
vertices
;
var
normals
=
file
.
body
.
normals
;
uvs
=
uvMaps
[
0
].
uv
;
var
uvs
,
colors
;
}
var
uvMaps
=
file
.
body
.
uvMaps
;
var
attrMaps
=
file
.
body
.
attrMaps
;
if
(
uvMaps
!==
undefined
&&
uvMaps
.
length
>
0
)
{
if
(
attrMaps
!==
undefined
&&
attrMaps
.
length
>
0
&&
attrMaps
[
0
].
name
===
'
Color
'
)
{
uvs
=
uvMaps
[
0
].
uv
;
colors
=
attrMaps
[
0
].
attr
;
}
}
var
attrMaps
=
file
.
body
.
attrMaps
;
this
.
setIndex
(
new
THREE
.
BufferAttribute
(
indices
,
1
)
);
this
.
addAttribute
(
'
position
'
,
new
THREE
.
BufferAttribute
(
positions
,
3
)
);
if
(
attrMaps
!==
undefined
&&
attrMaps
.
length
>
0
&&
attrMaps
[
0
].
name
===
'
Color
'
)
{
if
(
normals
!==
undefined
)
{
colors
=
attrMaps
[
0
].
attr
;
this
.
addAttribute
(
'
normal
'
,
new
THREE
.
BufferAttribute
(
normals
,
3
)
);
}
}
geometry
.
setIndex
(
new
THREE
.
BufferAttribute
(
indices
,
1
)
);
geometry
.
addAttribute
(
'
position
'
,
new
THREE
.
BufferAttribute
(
positions
,
3
)
);
if
(
uv
s
!==
undefined
)
{
if
(
normal
s
!==
undefined
)
{
this
.
addAttribute
(
'
uv
'
,
new
THREE
.
BufferAttribute
(
uvs
,
2
)
);
geometry
.
addAttribute
(
'
normal
'
,
new
THREE
.
BufferAttribute
(
normals
,
3
)
);
}
}
if
(
color
s
!==
undefined
)
{
if
(
uv
s
!==
undefined
)
{
this
.
addAttribute
(
'
color
'
,
new
THREE
.
BufferAttribute
(
colors
,
4
)
);
geometry
.
addAttribute
(
'
uv
'
,
new
THREE
.
BufferAttribute
(
uvs
,
2
)
);
}
}
};
if
(
colors
!==
undefined
)
{
Model
.
prototype
=
Object
.
create
(
THREE
.
BufferGeometry
.
prototype
);
Model
.
prototype
.
constructor
=
Model
;
geometry
.
addAttribute
(
'
color
'
,
new
THREE
.
BufferAttribute
(
colors
,
4
)
);
var
geometry
=
new
Model
();
}
// compute vertex normals if not present in the CTM model
if
(
geometry
.
attributes
.
normal
===
undefined
)
{
...
...
examples/jsm/loaders/ctm/CTMLoader.d.ts
0 → 100644
浏览文件 @
8d8ff4d3
import
{
BufferGeometry
,
Material
}
from
'
../../../../src/Three
'
;
export
interface
CTMLoaderParameters
{
basePath
?:
string
;
offsets
?:
number
[];
useWorker
?:
boolean
;
worker
?:
object
;
}
export
class
CTMLoader
{
constructor
();
workerPath
:
string
;
load
(
url
:
string
,
onLoad
:
(
geometry
:
BufferGeometry
)
=>
void
,
parameters
:
CTMLoaderParameters
):
void
;
loadParts
(
url
:
string
,
onLoad
:
(
geometries
:
BufferGeometry
[],
materials
:
Material
[])
=>
void
,
parameters
:
CTMLoaderParameters
):
void
;
setWorkerPath
(
value
:
string
):
this
;
}
examples/jsm/loaders/ctm/CTMLoader.js
0 → 100644
浏览文件 @
8d8ff4d3
/**
* Loader for CTM encoded models generated by OpenCTM tools:
* http://openctm.sourceforge.net/
*
* Uses js-openctm library by Juan Mellado
* http://code.google.com/p/js-openctm/
*
* @author alteredq / http://alteredqualia.com/
*
* OpenCTM LICENSE:
*
* Copyright (c) 2009-2010 Marcus Geelnard
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*
*/
import
{
BufferAttribute
,
BufferGeometry
,
Loader
,
LoaderUtils
}
from
"
../../../../build/three.module.js
"
;
/* global CTM */
var
CTMLoader
=
function
()
{
this
.
workerPath
=
null
;
};
CTMLoader
.
prototype
.
constructor
=
CTMLoader
;
CTMLoader
.
prototype
.
setWorkerPath
=
function
(
workerPath
)
{
this
.
workerPath
=
workerPath
;
};
// Load multiple CTM parts defined in JSON
CTMLoader
.
prototype
.
loadParts
=
function
(
url
,
callback
,
parameters
)
{
parameters
=
parameters
||
{};
var
scope
=
this
;
var
xhr
=
new
XMLHttpRequest
();
var
basePath
=
parameters
.
basePath
?
parameters
.
basePath
:
LoaderUtils
.
extractUrlBase
(
url
);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
===
4
)
{
if
(
xhr
.
status
===
200
||
xhr
.
status
===
0
)
{
var
jsonObject
=
JSON
.
parse
(
xhr
.
responseText
);
var
materials
=
[],
geometries
=
[],
counter
=
0
;
function
callbackFinal
(
geometry
)
{
counter
+=
1
;
geometries
.
push
(
geometry
);
if
(
counter
===
jsonObject
.
offsets
.
length
)
{
callback
(
geometries
,
materials
);
}
}
// init materials
for
(
var
i
=
0
;
i
<
jsonObject
.
materials
.
length
;
i
++
)
{
materials
[
i
]
=
Loader
.
prototype
.
createMaterial
(
jsonObject
.
materials
[
i
],
basePath
);
}
// load joined CTM file
var
partUrl
=
basePath
+
jsonObject
.
data
;
var
parametersPart
=
{
useWorker
:
parameters
.
useWorker
,
worker
:
parameters
.
worker
,
offsets
:
jsonObject
.
offsets
};
scope
.
load
(
partUrl
,
callbackFinal
,
parametersPart
);
}
}
};
xhr
.
open
(
"
GET
"
,
url
,
true
);
xhr
.
setRequestHeader
(
"
Content-Type
"
,
"
text/plain
"
);
xhr
.
send
(
null
);
};
// Load CTMLoader compressed models
// - parameters
// - url (required)
// - callback (required)
CTMLoader
.
prototype
.
load
=
function
(
url
,
callback
,
parameters
)
{
parameters
=
parameters
||
{};
var
scope
=
this
;
var
offsets
=
parameters
.
offsets
!==
undefined
?
parameters
.
offsets
:
[
0
];
var
xhr
=
new
XMLHttpRequest
(),
callbackProgress
=
null
;
var
length
=
0
;
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
===
4
)
{
if
(
xhr
.
status
===
200
||
xhr
.
status
===
0
)
{
var
binaryData
=
new
Uint8Array
(
xhr
.
response
);
var
s
=
Date
.
now
();
if
(
parameters
.
useWorker
)
{
var
worker
=
parameters
.
worker
||
new
Worker
(
scope
.
workerPath
);
worker
.
onmessage
=
function
(
event
)
{
var
files
=
event
.
data
;
for
(
var
i
=
0
;
i
<
files
.
length
;
i
++
)
{
var
ctmFile
=
files
[
i
];
var
e1
=
Date
.
now
();
// console.log( "CTM data parse time [worker]: " + (e1-s) + " ms" );
scope
.
_createGeometry
(
ctmFile
,
callback
);
var
e
=
Date
.
now
();
console
.
log
(
"
model load time [worker]:
"
+
(
e
-
e1
)
+
"
ms, total:
"
+
(
e
-
s
)
);
}
};
worker
.
postMessage
(
{
"
data
"
:
binaryData
,
"
offsets
"
:
offsets
},
[
binaryData
.
buffer
]
);
}
else
{
for
(
var
i
=
0
;
i
<
offsets
.
length
;
i
++
)
{
var
stream
=
new
CTM
.
Stream
(
binaryData
);
stream
.
offset
=
offsets
[
i
];
var
ctmFile
=
new
CTM
.
File
(
stream
);
scope
.
_createGeometry
(
ctmFile
,
callback
);
}
//var e = Date.now();
//console.log( "CTM data parse time [inline]: " + (e-s) + " ms" );
}
}
else
{
console
.
error
(
"
Couldn't load [
"
+
url
+
"
] [
"
+
xhr
.
status
+
"
]
"
);
}
}
else
if
(
xhr
.
readyState
===
3
)
{
if
(
callbackProgress
)
{
if
(
length
===
0
)
{
length
=
xhr
.
getResponseHeader
(
"
Content-Length
"
);
}
callbackProgress
(
{
total
:
length
,
loaded
:
xhr
.
responseText
.
length
}
);
}
}
else
if
(
xhr
.
readyState
===
2
)
{
length
=
xhr
.
getResponseHeader
(
"
Content-Length
"
);
}
};
xhr
.
open
(
"
GET
"
,
url
,
true
);
xhr
.
responseType
=
"
arraybuffer
"
;
xhr
.
send
(
null
);
};
CTMLoader
.
prototype
.
_createGeometry
=
function
(
file
,
callback
)
{
var
geometry
=
new
BufferGeometry
();
var
indices
=
file
.
body
.
indices
;
var
positions
=
file
.
body
.
vertices
;
var
normals
=
file
.
body
.
normals
;
var
uvs
,
colors
;
var
uvMaps
=
file
.
body
.
uvMaps
;
if
(
uvMaps
!==
undefined
&&
uvMaps
.
length
>
0
)
{
uvs
=
uvMaps
[
0
].
uv
;
}
var
attrMaps
=
file
.
body
.
attrMaps
;
if
(
attrMaps
!==
undefined
&&
attrMaps
.
length
>
0
&&
attrMaps
[
0
].
name
===
'
Color
'
)
{
colors
=
attrMaps
[
0
].
attr
;
}
geometry
.
setIndex
(
new
BufferAttribute
(
indices
,
1
)
);
geometry
.
addAttribute
(
'
position
'
,
new
BufferAttribute
(
positions
,
3
)
);
if
(
normals
!==
undefined
)
{
geometry
.
addAttribute
(
'
normal
'
,
new
BufferAttribute
(
normals
,
3
)
);
}
if
(
uvs
!==
undefined
)
{
geometry
.
addAttribute
(
'
uv
'
,
new
BufferAttribute
(
uvs
,
2
)
);
}
if
(
colors
!==
undefined
)
{
geometry
.
addAttribute
(
'
color
'
,
new
BufferAttribute
(
colors
,
4
)
);
}
// compute vertex normals if not present in the CTM model
if
(
geometry
.
attributes
.
normal
===
undefined
)
{
geometry
.
computeVertexNormals
();
}
callback
(
geometry
);
};
export
{
CTMLoader
};
examples/webgl_loader_ctm.html
浏览文件 @
8d8ff4d3
...
...
@@ -25,6 +25,12 @@
<script>
if
(
WEBGL
.
isWebGLAvailable
()
===
false
)
{
document
.
body
.
appendChild
(
WEBGL
.
getWebGLErrorMessage
()
);
}
var
SCREEN_WIDTH
=
window
.
innerWidth
;
var
SCREEN_HEIGHT
=
window
.
innerHeight
;
...
...
@@ -127,6 +133,7 @@
}
var
loader
=
new
THREE
.
CTMLoader
();
loader
.
setWorkerPath
(
"
js/loaders/ctm/CTMWorker.js
"
);
loader
.
load
(
"
models/ctm/ben.ctm
"
,
function
(
geometry
)
{
...
...
examples/webgl_loader_ctm_materials.html
浏览文件 @
8d8ff4d3
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl -
baked illumination
</title>
<title>
three.js webgl -
CTM loader materials
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
>
<link
type=
"text/css"
rel=
"stylesheet"
href=
"main.css"
>
...
...
@@ -116,6 +116,8 @@
var
scale
=
new
THREE
.
Vector3
(
30
,
30
,
30
);
var
loader
=
new
THREE
.
CTMLoader
();
loader
.
setWorkerPath
(
"
js/loaders/ctm/CTMWorker.js
"
);
loader
.
loadParts
(
"
models/ctm/camaro/camaro.js
"
,
function
(
geometries
,
materials
)
{
hackMaterials
(
materials
);
...
...
utils/modularize.js
浏览文件 @
8d8ff4d3
...
...
@@ -72,6 +72,7 @@ var files = [
{
path
:
'
lines/Wireframe.js
'
,
dependencies
:
[
{
name
:
'
LineSegmentsGeometry
'
,
path
:
'
lines/LineSegmentsGeometry.js
'
},
{
name
:
'
LineMaterial
'
,
path
:
'
lines/LineMaterial.js
'
}
],
ignoreList
:
[]
},
{
path
:
'
lines/WireframeGeometry2.js
'
,
dependencies
:
[
{
name
:
'
LineSegmentsGeometry
'
,
path
:
'
lines/LineSegmentsGeometry.js
'
}
],
ignoreList
:
[]
},
{
path
:
'
loaders/ctm/CTMLoader.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
loaders/deprecated/LegacyGLTFLoader.js
'
,
dependencies
:
[],
ignoreList
:
[
'
AnimationMixer
'
]
},
{
path
:
'
loaders/deprecated/LegacyJSONLoader.js
'
,
dependencies
:
[],
ignoreList
:
[
'
ObjectLoader
'
]
},
{
path
:
'
loaders/3MFLoader.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录