Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
951ab07d
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,发现更多精彩内容 >>
提交
951ab07d
编写于
2月 22, 2018
作者:
D
Don McCurdy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
GLTFLoader: Implement KHR_texture_transform.
上级
80cd24c0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
91 addition
and
26 deletion
+91
-26
docs/examples/loaders/GLTFLoader.html
docs/examples/loaders/GLTFLoader.html
+16
-6
examples/js/loaders/GLTFLoader.js
examples/js/loaders/GLTFLoader.js
+75
-20
未找到文件。
docs/examples/loaders/GLTFLoader.html
浏览文件 @
951ab07d
...
...
@@ -32,8 +32,18 @@
<li>
KHR_materials_pbrSpecularGlossiness
</li>
<li>
KHR_materials_unlit
</li>
<li>
KHR_lights_punctual (experimental)
</li>
<li>
KHR_texture_transform
<sup>
*
</sup></li>
<li>
MSFT_texture_dds
</li>
</ul>
<p><i>
<sup>
*
</sup>
UV transforms are supported, with several key limitations in comparison to the
glTF specification. A transform is applied to all textures using that UV set on the current
material, and no more than one transform may be used per material. Each transform will result
in an additional GPU texture upload. See #[link:https://github.com/mrdoob/three.js/pull/13831 13831]
and #[link:https://github.com/mrdoob/three.js/issues/12788 12788].
</i></p>
<h2>
Example
</h2>
<code>
...
...
@@ -85,30 +95,30 @@
providing a Promise replacement.
</p>
<h2>
Textures
</h2>
<p>
Textures containing color information (.map, .emissiveMap, and .specularMap) always use sRGB colorspace in
glTF, while vertex colors and material properties (.color, .emissive, .specular) use linear colorspace. In a
typical rendering workflow, textures are converted to linear colorspace by the renderer, lighting calculations
are made, then final output is converted back to sRGB and displayed on screen. Unless you need post-processing
in linear colorspace, always configure [page:WebGLRenderer] as follows when using glTF:
</p>
<code>
renderer.gammaOutput = true;
renderer.gammaFactor = 2.2;
</code>
<p>
GLTFLoader will automatically configure textures referenced from a .gltf or .glb file correctly, with the
assumption that the renderer is set up as shown above. When loading textures externally (e.g., using
[page:TextureLoader]) and applying them to a glTF model, colorspace and orientation must be given:
</p>
<code>
// If texture is used for color information, set colorspace.
texture.encoding = THREE.sRGBEncoding;
// UVs use the convention that (0, 0) corresponds to the upper left corner of a texture.
texture.flipY = false;
</code>
</code>
<h2>
Custom extensions
</h2>
<p>
...
...
examples/js/loaders/GLTFLoader.js
浏览文件 @
951ab07d
...
...
@@ -181,7 +181,7 @@ THREE.GLTFLoader = ( function () {
break
;
case
EXTENSIONS
.
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS
:
extensions
[
extensionName
]
=
new
GLTFMaterialsPbrSpecularGlossinessExtension
();
extensions
[
extensionName
]
=
new
GLTFMaterialsPbrSpecularGlossinessExtension
(
json
);
break
;
case
EXTENSIONS
.
KHR_DRACO_MESH_COMPRESSION
:
...
...
@@ -189,7 +189,11 @@ THREE.GLTFLoader = ( function () {
break
;
case
EXTENSIONS
.
MSFT_TEXTURE_DDS
:
extensions
[
EXTENSIONS
.
MSFT_TEXTURE_DDS
]
=
new
GLTFTextureDDSExtension
();
extensions
[
EXTENSIONS
.
MSFT_TEXTURE_DDS
]
=
new
GLTFTextureDDSExtension
(
json
);
break
;
case
EXTENSIONS
.
KHR_TEXTURE_TRANSFORM
:
extensions
[
EXTENSIONS
.
KHR_TEXTURE_TRANSFORM
]
=
new
GLTFTextureTransformExtension
(
json
);
break
;
default
:
...
...
@@ -282,6 +286,7 @@ THREE.GLTFLoader = ( function () {
KHR_LIGHTS_PUNCTUAL
:
'
KHR_lights_punctual
'
,
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS
:
'
KHR_materials_pbrSpecularGlossiness
'
,
KHR_MATERIALS_UNLIT
:
'
KHR_materials_unlit
'
,
KHR_TEXTURE_TRANSFORM
:
'
KHR_texture_transform
'
,
MSFT_TEXTURE_DDS
:
'
MSFT_texture_dds
'
};
...
...
@@ -409,7 +414,7 @@ THREE.GLTFLoader = ( function () {
if
(
metallicRoughness
.
baseColorTexture
!==
undefined
)
{
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
map
'
,
metallicRoughness
.
baseColorTexture
.
index
)
);
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
map
'
,
metallicRoughness
.
baseColorTexture
)
);
}
...
...
@@ -563,6 +568,49 @@ THREE.GLTFLoader = ( function () {
};
/**
* Texture Transform Extension
*
* Specification:
*/
function
GLTFTextureTransformExtension
(
json
)
{
this
.
name
=
EXTENSIONS
.
KHR_TEXTURE_TRANSFORM
;
}
GLTFTextureTransformExtension
.
prototype
.
extendTexture
=
function
(
texture
,
mapDef
)
{
var
transform
=
mapDef
.
extensions
!==
undefined
?
mapDef
.
extensions
[
this
.
name
]
:
undefined
;
if
(
transform
===
undefined
)
return
texture
;
texture
=
texture
.
clone
();
if
(
transform
.
offset
!==
undefined
)
{
texture
.
offset
.
fromArray
(
transform
.
offset
);
}
if
(
transform
.
rotation
!==
undefined
)
{
texture
.
rotation
=
transform
.
rotation
;
}
if
(
transform
.
scale
!==
undefined
)
{
texture
.
repeat
.
fromArray
(
transform
.
scale
);
}
texture
.
needsUpdate
=
true
;
return
texture
;
};
/**
* Specular-Glossiness Extension
*
...
...
@@ -692,7 +740,7 @@ THREE.GLTFLoader = ( function () {
if
(
pbrSpecularGlossiness
.
diffuseTexture
!==
undefined
)
{
pending
.
push
(
parser
.
assignTexture
(
params
,
'
map
'
,
pbrSpecularGlossiness
.
diffuseTexture
.
index
)
);
pending
.
push
(
parser
.
assignTexture
(
params
,
'
map
'
,
pbrSpecularGlossiness
.
diffuseTexture
)
);
}
...
...
@@ -708,9 +756,9 @@ THREE.GLTFLoader = ( function () {
if
(
pbrSpecularGlossiness
.
specularGlossinessTexture
!==
undefined
)
{
var
specGloss
Index
=
pbrSpecularGlossiness
.
specularGlossinessTexture
.
index
;
pending
.
push
(
parser
.
assignTexture
(
params
,
'
glossinessMap
'
,
specGloss
Index
)
);
pending
.
push
(
parser
.
assignTexture
(
params
,
'
specularMap
'
,
specGloss
Index
)
);
var
specGloss
MapDef
=
pbrSpecularGlossiness
.
specularGlossinessTexture
;
pending
.
push
(
parser
.
assignTexture
(
params
,
'
glossinessMap
'
,
specGloss
MapDef
)
);
pending
.
push
(
parser
.
assignTexture
(
params
,
'
specularMap
'
,
specGloss
MapDef
)
);
}
...
...
@@ -2146,15 +2194,23 @@ THREE.GLTFLoader = ( function () {
/**
* Asynchronously assigns a texture to the given material parameters.
* @param {Object} materialParams
* @param {string}
texture
Name
* @param {
number} textureIndex
* @return {Promise
<THREE.Texture>
}
* @param {string}
map
Name
* @param {
Object} mapDef
* @return {Promise}
*/
GLTFParser
.
prototype
.
assignTexture
=
function
(
materialParams
,
textureName
,
textureIndex
)
{
GLTFParser
.
prototype
.
assignTexture
=
function
(
materialParams
,
mapName
,
mapDef
)
{
var
parser
=
this
;
return
this
.
getDependency
(
'
texture
'
,
textureIndex
).
then
(
function
(
texture
)
{
return
this
.
getDependency
(
'
texture
'
,
mapDef
.
index
).
then
(
function
(
texture
)
{
if
(
parser
.
extensions
[
EXTENSIONS
.
KHR_TEXTURE_TRANSFORM
]
)
{
texture
=
parser
.
extensions
[
EXTENSIONS
.
KHR_TEXTURE_TRANSFORM
].
extendTexture
(
texture
,
mapDef
);
}
materialParams
[
texture
Name
]
=
texture
;
materialParams
[
map
Name
]
=
texture
;
}
);
...
...
@@ -2213,7 +2269,7 @@ THREE.GLTFLoader = ( function () {
if
(
metallicRoughness
.
baseColorTexture
!==
undefined
)
{
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
map
'
,
metallicRoughness
.
baseColorTexture
.
index
)
);
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
map
'
,
metallicRoughness
.
baseColorTexture
)
);
}
...
...
@@ -2222,9 +2278,8 @@ THREE.GLTFLoader = ( function () {
if
(
metallicRoughness
.
metallicRoughnessTexture
!==
undefined
)
{
var
textureIndex
=
metallicRoughness
.
metallicRoughnessTexture
.
index
;
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
metalnessMap
'
,
textureIndex
)
);
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
roughnessMap
'
,
textureIndex
)
);
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
metalnessMap
'
,
metallicRoughness
.
metallicRoughnessTexture
)
);
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
roughnessMap
'
,
metallicRoughness
.
metallicRoughnessTexture
)
);
}
...
...
@@ -2256,7 +2311,7 @@ THREE.GLTFLoader = ( function () {
if
(
materialDef
.
normalTexture
!==
undefined
&&
materialType
!==
THREE
.
MeshBasicMaterial
)
{
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
normalMap
'
,
materialDef
.
normalTexture
.
index
)
);
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
normalMap
'
,
materialDef
.
normalTexture
)
);
materialParams
.
normalScale
=
new
THREE
.
Vector2
(
1
,
1
);
...
...
@@ -2270,7 +2325,7 @@ THREE.GLTFLoader = ( function () {
if
(
materialDef
.
occlusionTexture
!==
undefined
&&
materialType
!==
THREE
.
MeshBasicMaterial
)
{
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
aoMap
'
,
materialDef
.
occlusionTexture
.
index
)
);
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
aoMap
'
,
materialDef
.
occlusionTexture
)
);
if
(
materialDef
.
occlusionTexture
.
strength
!==
undefined
)
{
...
...
@@ -2288,7 +2343,7 @@ THREE.GLTFLoader = ( function () {
if
(
materialDef
.
emissiveTexture
!==
undefined
&&
materialType
!==
THREE
.
MeshBasicMaterial
)
{
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
emissiveMap
'
,
materialDef
.
emissiveTexture
.
index
)
);
pending
.
push
(
parser
.
assignTexture
(
materialParams
,
'
emissiveMap
'
,
materialDef
.
emissiveTexture
)
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录