Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
5ff4d48d
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,发现更多精彩内容 >>
提交
5ff4d48d
编写于
8月 11, 2017
作者:
D
Don McCurdy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[glTF] Implement loadTexture(texIndex).
上级
c773acec
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
201 addition
and
127 deletion
+201
-127
examples/js/loaders/GLTF2Loader.js
examples/js/loaders/GLTF2Loader.js
+201
-127
未找到文件。
examples/js/loaders/GLTF2Loader.js
浏览文件 @
5ff4d48d
...
...
@@ -316,10 +316,12 @@ THREE.GLTF2Loader = ( function () {
};
GLTFMaterialsCommonExtension
.
prototype
.
extendParams
=
function
(
materialParams
,
material
,
dependencies
)
{
GLTFMaterialsCommonExtension
.
prototype
.
extendParams
=
function
(
materialParams
,
material
,
parser
)
{
var
khrMaterial
=
material
.
extensions
[
this
.
name
];
var
pending
=
[];
var
keys
=
[];
// TODO: Currently ignored: 'ambientFactor', 'ambientTexture'
...
...
@@ -357,7 +359,7 @@ THREE.GLTF2Loader = ( function () {
if
(
materialValues
.
diffuseTexture
!==
undefined
)
{
materialParams
.
map
=
dependencies
.
textures
[
materialValues
.
diffuseTexture
.
index
]
;
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
map
'
,
materialValues
.
diffuseTexture
.
index
)
)
;
}
...
...
@@ -369,7 +371,7 @@ THREE.GLTF2Loader = ( function () {
if
(
materialValues
.
specularTexture
!==
undefined
)
{
materialParams
.
specularMap
=
dependencies
.
textures
[
materialValues
.
specularTexture
.
index
]
;
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
specularMap
'
,
materialValues
.
specularTexture
.
index
)
)
;
}
...
...
@@ -379,6 +381,8 @@ THREE.GLTF2Loader = ( function () {
}
return
Promise
.
all
(
pending
);
};
/* BINARY EXTENSION */
...
...
@@ -466,10 +470,7 @@ THREE.GLTF2Loader = ( function () {
},
extendParams
:
function
(
params
,
material
,
dependencies
)
{
// specification
// https://github.com/sbtron/glTF/tree/KHRpbrSpecGloss/extensions/Khronos/KHR_materials_pbrSpecularGlossiness
extendParams
:
function
(
params
,
material
,
parser
)
{
var
pbrSpecularGlossiness
=
material
.
extensions
[
this
.
name
];
...
...
@@ -542,6 +543,8 @@ THREE.GLTF2Loader = ( function () {
params
.
color
=
new
THREE
.
Color
(
1.0
,
1.0
,
1.0
);
params
.
opacity
=
1.0
;
var
pending
=
[];
if
(
Array
.
isArray
(
pbrSpecularGlossiness
.
diffuseFactor
)
)
{
var
array
=
pbrSpecularGlossiness
.
diffuseFactor
;
...
...
@@ -553,7 +556,7 @@ THREE.GLTF2Loader = ( function () {
if
(
pbrSpecularGlossiness
.
diffuseTexture
!==
undefined
)
{
p
arams
.
map
=
dependencies
.
textures
[
pbrSpecularGlossiness
.
diffuseTexture
.
index
]
;
p
ending
.
push
(
parser
.
assignTexture
(
params
,
'
map
'
,
pbrSpecularGlossiness
.
diffuseTexture
.
index
)
)
;
}
...
...
@@ -569,11 +572,14 @@ THREE.GLTF2Loader = ( function () {
if
(
pbrSpecularGlossiness
.
specularGlossinessTexture
!==
undefined
)
{
params
.
glossinessMap
=
dependencies
.
textures
[
pbrSpecularGlossiness
.
specularGlossinessTexture
.
index
];
params
.
specularMap
=
dependencies
.
textures
[
pbrSpecularGlossiness
.
specularGlossinessTexture
.
index
];
var
specGlossIndex
=
pbrSpecularGlossiness
.
specularGlossinessTexture
.
index
;
pending
.
push
(
parser
.
assignTexture
(
params
,
'
glossinessMap
'
,
specGlossIndex
)
);
pending
.
push
(
parser
.
assignTexture
(
params
,
'
specularMap
'
,
specGlossIndex
)
);
}
return
Promise
.
all
(
pending
);
},
createMaterial
:
function
(
params
)
{
...
...
@@ -1290,6 +1296,29 @@ THREE.GLTF2Loader = ( function () {
};
/**
* Requests the specified dependency asynchronously, with caching.
* @param {string} type
* @param {number} index
* @return {Promise<Object>}
*/
GLTFParser
.
prototype
.
getDependency
=
function
(
type
,
index
)
{
var
cacheKey
=
type
+
'
:
'
+
index
;
var
dependency
=
this
.
cache
.
get
(
cacheKey
);
if
(
!
dependency
)
{
var
fnName
=
'
load
'
+
type
.
charAt
(
0
).
toUpperCase
()
+
type
.
slice
(
1
);
dependency
=
this
[
fnName
](
index
);
this
.
cache
.
add
(
cacheKey
,
dependency
);
}
return
dependency
;
};
GLTFParser
.
prototype
.
loadBuffers
=
function
()
{
var
json
=
this
.
json
;
...
...
@@ -1329,6 +1358,26 @@ THREE.GLTF2Loader = ( function () {
};
/**
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
* @param {number} bufferViewIndex
* @return {Promise<ArrayBuffer>}
*/
GLTFParser
.
prototype
.
loadBufferView
=
function
(
bufferViewIndex
)
{
return
this
.
_withDependencies
(
[
'
bufferViews
'
]
).
then
(
function
(
dependencies
)
{
return
dependencies
.
bufferViews
[
bufferViewIndex
];
}
);
};
/** @deprecated */
GLTFParser
.
prototype
.
loadBufferViews
=
function
()
{
var
json
=
this
.
json
;
...
...
@@ -1401,122 +1450,145 @@ THREE.GLTF2Loader = ( function () {
};
GLTFParser
.
prototype
.
loadTextures
=
function
()
{
var
URL
=
window
.
URL
||
window
.
webkitURL
;
/**
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
* @param {number} textureIndex
* @return {Promise<THREE.Texture>}
*/
GLTFParser
.
prototype
.
loadTexture
=
function
(
textureIndex
)
{
var
parser
=
this
;
var
json
=
this
.
json
;
var
options
=
this
.
options
;
return
this
.
_withDependencies
(
[
var
textureDef
=
this
.
json
.
textures
[
textureIndex
];
'
bufferViews
'
if
(
textureDef
.
source
===
undefined
)
{
]
).
then
(
function
(
dependencies
)
{
throw
new
Error
(
'
THREE.GLTF2Loader: Unknown texture for index
'
+
textureIndex
);
return
_each
(
json
.
textures
,
function
(
texture
)
{
}
if
(
texture
.
source
!==
undefined
)
{
var
source
=
json
.
images
[
textureDef
.
source
];
var
sourceURI
=
source
.
uri
;
var
isObjectURL
=
false
;
return
new
Promise
(
function
(
resolve
)
{
var
source
=
json
.
images
[
texture
.
source
];
var
sourceUri
=
source
.
uri
;
if
(
source
.
bufferView
!==
undefined
)
{
var
urlCreator
;
// Load binary image data from bufferView, if provided.
if
(
source
.
bufferView
!==
undefined
)
{
sourceURI
=
parser
.
loadBufferView
(
source
.
bufferView
)
.
then
(
function
(
bufferView
)
{
var
bufferView
=
dependencies
.
bufferViews
[
source
.
bufferView
]
;
isObjectURL
=
true
;
var
blob
=
new
Blob
(
[
bufferView
],
{
type
:
source
.
mimeType
}
);
urlCreator
=
window
.
URL
||
window
.
webkitURL
;
sourceUri
=
urlCreator
.
createObjectURL
(
blob
);
sourceURI
=
URL
.
createObjectURL
(
blob
);
return
sourceURI
;
}
);
}
var
textureLoader
=
THREE
.
Loader
.
Handlers
.
get
(
sourceUri
);
return
Promise
.
resolve
(
sourceURI
).
then
(
function
(
sourceURI
)
{
if
(
textureLoader
===
null
)
{
// Load Texture resource.
textureLoader
=
new
THREE
.
TextureLoader
();
var
textureLoader
=
THREE
.
Loader
.
Handlers
.
get
(
sourceURI
)
||
new
THREE
.
TextureLoader
();
textureLoader
.
setCrossOrigin
(
options
.
crossOrigin
);
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
textureLoader
.
setCrossOrigin
(
options
.
crossOrigin
);
textureLoader
.
load
(
resolveURL
(
sourceURI
,
options
.
path
),
resolve
,
undefined
,
reject
);
textureLoader
.
load
(
resolveURL
(
sourceUri
,
options
.
path
),
function
(
_texture
)
{
}
);
}
).
then
(
function
(
texture
)
{
if
(
urlCreator
!==
undefined
)
{
// Clean up resources and configure Texture.
urlCreator
.
revokeObjectURL
(
sourceUri
);
if
(
isObjectURL
!==
undefined
)
{
URL
.
revokeObjectURL
(
sourceURI
);
}
_
texture
.
flipY
=
false
;
texture
.
flipY
=
false
;
if
(
texture
.
name
!==
undefined
)
_texture
.
name
=
texture
.
name
;
if
(
textureDef
.
name
!==
undefined
)
texture
.
name
=
textureDef
.
name
;
_texture
.
format
=
texture
.
format
!==
undefined
?
WEBGL_TEXTURE_FORMATS
[
texture
.
format
]
:
THREE
.
RGBAFormat
;
texture
.
format
=
textureDef
.
format
!==
undefined
?
WEBGL_TEXTURE_FORMATS
[
textureDef
.
format
]
:
THREE
.
RGBAFormat
;
if
(
texture
.
internalFormat
!==
undefined
&&
_texture
.
format
!==
WEBGL_TEXTURE_FORMATS
[
texture
.
internalFormat
]
)
{
if
(
textureDef
.
internalFormat
!==
undefined
&&
texture
.
format
!==
WEBGL_TEXTURE_FORMATS
[
textureDef
.
internalFormat
]
)
{
console
.
warn
(
'
THREE.GLTF2Loader: Three.js does not support texture internalFormat which is different from texture format.
'
+
'
internalFormat will be forced to be the same value as format.
'
);
}
_texture
.
type
=
texture
.
type
!==
undefined
?
WEBGL_TEXTURE_DATATYPES
[
texture
.
type
]
:
THREE
.
UnsignedByteType
;
texture
.
type
=
textureDef
.
type
!==
undefined
?
WEBGL_TEXTURE_DATATYPES
[
textureDef
.
type
]
:
THREE
.
UnsignedByteType
;
var
samplers
=
json
.
samplers
||
{};
var
sampler
=
samplers
[
texture
.
sampler
]
||
{};
_texture
.
magFilter
=
WEBGL_FILTERS
[
sampler
.
magFilter
]
||
THREE
.
LinearFilter
;
_texture
.
minFilter
=
WEBGL_FILTERS
[
sampler
.
minFilter
]
||
THREE
.
LinearMipMapLinearFilter
;
_texture
.
wrapS
=
WEBGL_WRAPPINGS
[
sampler
.
wrapS
]
||
THREE
.
RepeatWrapping
;
_texture
.
wrapT
=
WEBGL_WRAPPINGS
[
sampler
.
wrapT
]
||
THREE
.
RepeatWrapping
;
var
sampler
=
samplers
[
textureDef
.
sampler
]
||
{};
resolve
(
_texture
);
texture
.
magFilter
=
WEBGL_FILTERS
[
sampler
.
magFilter
]
||
THREE
.
LinearFilter
;
texture
.
minFilter
=
WEBGL_FILTERS
[
sampler
.
minFilter
]
||
THREE
.
LinearMipMapLinearFilter
;
texture
.
wrapS
=
WEBGL_WRAPPINGS
[
sampler
.
wrapS
]
||
THREE
.
RepeatWrapping
;
texture
.
wrapT
=
WEBGL_WRAPPINGS
[
sampler
.
wrapT
]
||
THREE
.
RepeatWrapping
;
},
undefined
,
function
()
{
resolve
();
return
texture
;
}
);
}
)
;
}
;
}
/**
* Asynchronously assigns a texture to the given material parameters.
* @param {Object} materialParams
* @param {string} textureName
* @param {number} textureIndex
* @return {Promise}
*/
GLTFParser
.
prototype
.
assignTexture
=
function
(
materialParams
,
textureName
,
textureIndex
)
{
}
);
return
this
.
getDependency
(
'
texture
'
,
textureIndex
).
then
(
function
(
texture
)
{
materialParams
[
textureName
]
=
texture
;
}
);
};
/**
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
* @return {Promise<Array<THREE.Material>>}
*/
GLTFParser
.
prototype
.
loadMaterials
=
function
()
{
var
parser
=
this
;
var
json
=
this
.
json
;
var
extensions
=
this
.
extensions
;
return
this
.
_withDependencies
(
[
'
textures
'
]
).
then
(
function
(
dependencies
)
{
return
_each
(
json
.
materials
,
function
(
material
)
{
var
materialType
;
var
materialParams
=
{};
var
materialExtensions
=
material
.
extensions
||
{};
var
pending
=
[];
if
(
materialExtensions
[
EXTENSIONS
.
KHR_MATERIALS_COMMON
]
)
{
materialType
=
extensions
[
EXTENSIONS
.
KHR_MATERIALS_COMMON
].
getMaterialType
(
material
);
extensions
[
EXTENSIONS
.
KHR_MATERIALS_COMMON
].
extendParams
(
materialParams
,
material
,
dependencies
);
var
khcExtension
=
extensions
[
EXTENSIONS
.
KHR_MATERIALS_COMMON
];
materialType
=
khcExtension
.
getMaterialType
(
material
);
pending
.
push
(
khcExtension
.
extendParams
(
materialParams
,
material
,
parser
)
);
}
else
if
(
materialExtensions
[
EXTENSIONS
.
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS
]
)
{
materialType
=
extensions
[
EXTENSIONS
.
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS
].
getMaterialType
(
material
);
extensions
[
EXTENSIONS
.
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS
].
extendParams
(
materialParams
,
material
,
dependencies
);
var
sgExtension
=
extensions
[
EXTENSIONS
.
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS
];
materialType
=
sgExtension
.
getMaterialType
(
material
);
pending
.
push
(
sgExtension
.
extendParams
(
materialParams
,
material
,
parser
)
);
}
else
if
(
materialExtensions
[
EXTENSIONS
.
KHR_TECHNIQUE_WEBGL
]
)
{
...
...
@@ -1546,7 +1618,7 @@ THREE.GLTF2Loader = ( function () {
if
(
metallicRoughness
.
baseColorTexture
!==
undefined
)
{
materialParams
.
map
=
dependencies
.
textures
[
metallicRoughness
.
baseColorTexture
.
index
]
;
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
map
'
,
metallicRoughness
.
baseColorTexture
.
index
)
)
;
}
...
...
@@ -1556,8 +1628,8 @@ THREE.GLTF2Loader = ( function () {
if
(
metallicRoughness
.
metallicRoughnessTexture
!==
undefined
)
{
var
textureIndex
=
metallicRoughness
.
metallicRoughnessTexture
.
index
;
materialParams
.
metalnessMap
=
dependencies
.
textures
[
textureIndex
]
;
materialParams
.
roughnessMap
=
dependencies
.
textures
[
textureIndex
]
;
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
metalnessMap
'
,
textureIndex
)
)
;
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
roughnessMap
'
,
textureIndex
)
)
;
}
...
...
@@ -1587,13 +1659,13 @@ THREE.GLTF2Loader = ( function () {
if
(
material
.
normalTexture
!==
undefined
)
{
materialParams
.
normalMap
=
dependencies
.
textures
[
material
.
normalTexture
.
index
]
;
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
normalMap
'
,
material
.
normalTexture
.
index
)
)
;
}
if
(
material
.
occlusionTexture
!==
undefined
)
{
materialParams
.
aoMap
=
dependencies
.
textures
[
material
.
occlusionTexture
.
index
]
;
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
aoMap
'
,
material
.
occlusionTexture
.
index
)
)
;
}
...
...
@@ -1615,16 +1687,18 @@ THREE.GLTF2Loader = ( function () {
if
(
materialType
===
THREE
.
MeshBasicMaterial
)
{
materialParams
.
map
=
dependencies
.
textures
[
material
.
emissiveTexture
.
index
]
;
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
map
'
,
material
.
emissiveTexture
.
index
)
)
;
}
else
{
materialParams
.
emissiveMap
=
dependencies
.
textures
[
material
.
emissiveTexture
.
index
]
;
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
emissiveMap
'
,
material
.
emissiveTexture
.
index
)
)
;
}
}
return
Promise
.
all
(
pending
).
then
(
function
()
{
var
_material
;
if
(
materialType
===
THREE
.
ShaderMaterial
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录