Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
be1a17dc
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,发现更多精彩内容 >>
未验证
提交
be1a17dc
编写于
7月 08, 2020
作者:
M
Mr.doob
提交者:
GitHub
7月 08, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19791 from zeux/gltf-ktx2
GLTFLoader: Implement KHR_texture_basisu support
上级
6bb324ba
60abaa0e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
184 addition
and
34 deletion
+184
-34
examples/js/loaders/GLTFLoader.js
examples/js/loaders/GLTFLoader.js
+92
-17
examples/jsm/loaders/GLTFLoader.js
examples/jsm/loaders/GLTFLoader.js
+92
-17
未找到文件。
examples/js/loaders/GLTFLoader.js
浏览文件 @
be1a17dc
...
...
@@ -5,6 +5,7 @@ console.warn( "THREE.GLTFLoader: As part of the transition to ES6 Modules, the f
* @author Tony Parisi / http://www.tonyparisi.com/
* @author Takahiro / https://github.com/takahirox
* @author Don McCurdy / https://www.donmccurdy.com
* @author Arseny Kapoulkine / https://github.com/zeux
*/
THREE
.
GLTFLoader
=
(
function
()
{
...
...
@@ -15,6 +16,7 @@ THREE.GLTFLoader = ( function () {
this
.
dracoLoader
=
null
;
this
.
ddsLoader
=
null
;
this
.
ktx2Loader
=
null
;
this
.
pluginCallbacks
=
[];
this
.
register
(
function
(
parser
)
{
...
...
@@ -22,6 +24,11 @@ THREE.GLTFLoader = ( function () {
return
new
GLTFMaterialsClearcoatExtension
(
parser
);
}
);
this
.
register
(
function
(
parser
)
{
return
new
GLTFTextureBasisUExtension
(
parser
);
}
);
}
...
...
@@ -119,6 +126,13 @@ THREE.GLTFLoader = ( function () {
},
setKTX2Loader
:
function
(
ktx2Loader
)
{
this
.
ktx2Loader
=
ktx2Loader
;
return
this
;
},
register
:
function
(
callback
)
{
if
(
this
.
pluginCallbacks
.
indexOf
(
callback
)
===
-
1
)
{
...
...
@@ -193,7 +207,8 @@ THREE.GLTFLoader = ( function () {
path
:
path
||
this
.
resourcePath
||
''
,
crossOrigin
:
this
.
crossOrigin
,
manager
:
this
.
manager
manager
:
this
.
manager
,
ktx2Loader
:
this
.
ktx2Loader
}
);
...
...
@@ -318,6 +333,7 @@ THREE.GLTFLoader = ( function () {
KHR_MATERIALS_CLEARCOAT
:
'
KHR_materials_clearcoat
'
,
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS
:
'
KHR_materials_pbrSpecularGlossiness
'
,
KHR_MATERIALS_UNLIT
:
'
KHR_materials_unlit
'
,
KHR_TEXTURE_BASISU
:
'
KHR_texture_basisu
'
,
KHR_TEXTURE_TRANSFORM
:
'
KHR_texture_transform
'
,
KHR_MESH_QUANTIZATION
:
'
KHR_mesh_quantization
'
,
MSFT_TEXTURE_DDS
:
'
MSFT_texture_dds
'
...
...
@@ -535,6 +551,46 @@ THREE.GLTFLoader = ( function () {
};
/**
* BasisU Texture Extension
*
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
* (draft PR https://github.com/KhronosGroup/glTF/pull/1751)
*/
function
GLTFTextureBasisUExtension
(
parser
)
{
this
.
parser
=
parser
;
this
.
name
=
EXTENSIONS
.
KHR_TEXTURE_BASISU
;
}
GLTFTextureBasisUExtension
.
prototype
.
loadTexture
=
function
(
textureIndex
)
{
var
parser
=
this
.
parser
;
var
json
=
parser
.
json
;
var
textureDef
=
json
.
textures
[
textureIndex
];
if
(
!
textureDef
.
extensions
||
!
textureDef
.
extensions
[
this
.
name
]
)
{
return
null
;
}
var
extension
=
textureDef
.
extensions
[
this
.
name
];
var
source
=
json
.
images
[
extension
.
source
];
var
loader
=
parser
.
options
.
ktx2Loader
;
if
(
!
loader
)
{
throw
new
Error
(
'
THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures
'
);
}
return
parser
.
loadTextureImage
(
textureIndex
,
source
,
loader
);
};
/* BINARY EXTENSION */
var
BINARY_EXTENSION_HEADER_MAGIC
=
'
glTF
'
;
var
BINARY_EXTENSION_HEADER_LENGTH
=
12
;
...
...
@@ -1736,7 +1792,11 @@ THREE.GLTFLoader = ( function () {
break
;
case
'
texture
'
:
dependency
=
this
.
loadTexture
(
index
);
dependency
=
this
.
_invokeOne
(
function
(
ext
)
{
return
ext
.
loadTexture
&&
ext
.
loadTexture
(
index
);
}
);
break
;
case
'
skin
'
:
...
...
@@ -1994,9 +2054,6 @@ THREE.GLTFLoader = ( function () {
var
parser
=
this
;
var
json
=
this
.
json
;
var
options
=
this
.
options
;
var
textureLoader
=
this
.
textureLoader
;
var
URL
=
self
.
URL
||
self
.
webkitURL
;
var
textureDef
=
json
.
textures
[
textureIndex
];
...
...
@@ -2014,6 +2071,36 @@ THREE.GLTFLoader = ( function () {
}
var
loader
;
if
(
source
.
uri
)
{
loader
=
options
.
manager
.
getHandler
(
source
.
uri
);
}
if
(
!
loader
)
{
loader
=
textureExtensions
[
EXTENSIONS
.
MSFT_TEXTURE_DDS
]
?
parser
.
extensions
[
EXTENSIONS
.
MSFT_TEXTURE_DDS
].
ddsLoader
:
this
.
textureLoader
;
}
return
this
.
loadTextureImage
(
textureIndex
,
source
,
loader
);
};
GLTFParser
.
prototype
.
loadTextureImage
=
function
(
textureIndex
,
source
,
loader
)
{
var
parser
=
this
;
var
json
=
this
.
json
;
var
options
=
this
.
options
;
var
textureDef
=
json
.
textures
[
textureIndex
];
var
textureExtensions
=
textureDef
.
extensions
||
{};
var
URL
=
self
.
URL
||
self
.
webkitURL
;
var
sourceURI
=
source
.
uri
;
var
isObjectURL
=
false
;
...
...
@@ -2034,18 +2121,6 @@ THREE.GLTFLoader = ( function () {
return
Promise
.
resolve
(
sourceURI
).
then
(
function
(
sourceURI
)
{
// Load Texture resource.
var
loader
=
options
.
manager
.
getHandler
(
sourceURI
);
if
(
!
loader
)
{
loader
=
textureExtensions
[
EXTENSIONS
.
MSFT_TEXTURE_DDS
]
?
parser
.
extensions
[
EXTENSIONS
.
MSFT_TEXTURE_DDS
].
ddsLoader
:
textureLoader
;
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
onLoad
=
resolve
;
...
...
examples/jsm/loaders/GLTFLoader.js
浏览文件 @
be1a17dc
...
...
@@ -4,6 +4,7 @@
* @author Tony Parisi / http://www.tonyparisi.com/
* @author Takahiro / https://github.com/takahirox
* @author Don McCurdy / https://www.donmccurdy.com
* @author Arseny Kapoulkine / https://github.com/zeux
*/
import
{
...
...
@@ -80,6 +81,7 @@ var GLTFLoader = ( function () {
this
.
dracoLoader
=
null
;
this
.
ddsLoader
=
null
;
this
.
ktx2Loader
=
null
;
this
.
pluginCallbacks
=
[];
this
.
register
(
function
(
parser
)
{
...
...
@@ -87,6 +89,11 @@ var GLTFLoader = ( function () {
return
new
GLTFMaterialsClearcoatExtension
(
parser
);
}
);
this
.
register
(
function
(
parser
)
{
return
new
GLTFTextureBasisUExtension
(
parser
);
}
);
}
...
...
@@ -184,6 +191,13 @@ var GLTFLoader = ( function () {
},
setKTX2Loader
:
function
(
ktx2Loader
)
{
this
.
ktx2Loader
=
ktx2Loader
;
return
this
;
},
register
:
function
(
callback
)
{
if
(
this
.
pluginCallbacks
.
indexOf
(
callback
)
===
-
1
)
{
...
...
@@ -258,7 +272,8 @@ var GLTFLoader = ( function () {
path
:
path
||
this
.
resourcePath
||
''
,
crossOrigin
:
this
.
crossOrigin
,
manager
:
this
.
manager
manager
:
this
.
manager
,
ktx2Loader
:
this
.
ktx2Loader
}
);
...
...
@@ -383,6 +398,7 @@ var GLTFLoader = ( function () {
KHR_MATERIALS_CLEARCOAT
:
'
KHR_materials_clearcoat
'
,
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS
:
'
KHR_materials_pbrSpecularGlossiness
'
,
KHR_MATERIALS_UNLIT
:
'
KHR_materials_unlit
'
,
KHR_TEXTURE_BASISU
:
'
KHR_texture_basisu
'
,
KHR_TEXTURE_TRANSFORM
:
'
KHR_texture_transform
'
,
KHR_MESH_QUANTIZATION
:
'
KHR_mesh_quantization
'
,
MSFT_TEXTURE_DDS
:
'
MSFT_texture_dds
'
...
...
@@ -600,6 +616,46 @@ var GLTFLoader = ( function () {
};
/**
* BasisU Texture Extension
*
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
* (draft PR https://github.com/KhronosGroup/glTF/pull/1751)
*/
function
GLTFTextureBasisUExtension
(
parser
)
{
this
.
parser
=
parser
;
this
.
name
=
EXTENSIONS
.
KHR_TEXTURE_BASISU
;
}
GLTFTextureBasisUExtension
.
prototype
.
loadTexture
=
function
(
textureIndex
)
{
var
parser
=
this
.
parser
;
var
json
=
parser
.
json
;
var
textureDef
=
json
.
textures
[
textureIndex
];
if
(
!
textureDef
.
extensions
||
!
textureDef
.
extensions
[
this
.
name
]
)
{
return
null
;
}
var
extension
=
textureDef
.
extensions
[
this
.
name
];
var
source
=
json
.
images
[
extension
.
source
];
var
loader
=
parser
.
options
.
ktx2Loader
;
if
(
!
loader
)
{
throw
new
Error
(
'
THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures
'
);
}
return
parser
.
loadTextureImage
(
textureIndex
,
source
,
loader
);
};
/* BINARY EXTENSION */
var
BINARY_EXTENSION_HEADER_MAGIC
=
'
glTF
'
;
var
BINARY_EXTENSION_HEADER_LENGTH
=
12
;
...
...
@@ -1801,7 +1857,11 @@ var GLTFLoader = ( function () {
break
;
case
'
texture
'
:
dependency
=
this
.
loadTexture
(
index
);
dependency
=
this
.
_invokeOne
(
function
(
ext
)
{
return
ext
.
loadTexture
&&
ext
.
loadTexture
(
index
);
}
);
break
;
case
'
skin
'
:
...
...
@@ -2059,9 +2119,6 @@ var GLTFLoader = ( function () {
var
parser
=
this
;
var
json
=
this
.
json
;
var
options
=
this
.
options
;
var
textureLoader
=
this
.
textureLoader
;
var
URL
=
self
.
URL
||
self
.
webkitURL
;
var
textureDef
=
json
.
textures
[
textureIndex
];
...
...
@@ -2079,6 +2136,36 @@ var GLTFLoader = ( function () {
}
var
loader
;
if
(
source
.
uri
)
{
loader
=
options
.
manager
.
getHandler
(
source
.
uri
);
}
if
(
!
loader
)
{
loader
=
textureExtensions
[
EXTENSIONS
.
MSFT_TEXTURE_DDS
]
?
parser
.
extensions
[
EXTENSIONS
.
MSFT_TEXTURE_DDS
].
ddsLoader
:
this
.
textureLoader
;
}
return
this
.
loadTextureImage
(
textureIndex
,
source
,
loader
);
};
GLTFParser
.
prototype
.
loadTextureImage
=
function
(
textureIndex
,
source
,
loader
)
{
var
parser
=
this
;
var
json
=
this
.
json
;
var
options
=
this
.
options
;
var
textureDef
=
json
.
textures
[
textureIndex
];
var
textureExtensions
=
textureDef
.
extensions
||
{};
var
URL
=
self
.
URL
||
self
.
webkitURL
;
var
sourceURI
=
source
.
uri
;
var
isObjectURL
=
false
;
...
...
@@ -2099,18 +2186,6 @@ var GLTFLoader = ( function () {
return
Promise
.
resolve
(
sourceURI
).
then
(
function
(
sourceURI
)
{
// Load Texture resource.
var
loader
=
options
.
manager
.
getHandler
(
sourceURI
);
if
(
!
loader
)
{
loader
=
textureExtensions
[
EXTENSIONS
.
MSFT_TEXTURE_DDS
]
?
parser
.
extensions
[
EXTENSIONS
.
MSFT_TEXTURE_DDS
].
ddsLoader
:
textureLoader
;
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
onLoad
=
resolve
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录