Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for KHR_texture_transform #7549

Merged
merged 7 commits into from
Apr 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ Change Log

### 1.57 - 2019-05-01

##### Fixes :wrench:
##### Additions :tada:
* Added support for the `KHR_texture_transform` glTF extension. [#7549](https://github.com/AnalyticalGraphicsInc/cesium/pull/7549)

##### Fixes :wrench:
* Fixed an error where `clampToHeightMostDetailed` or `sampleHeightMostDetailed` would crash if entities were created when the promise resolved. [#7690](https://github.com/AnalyticalGraphicsInc/cesium/pull/7690)

### 1.56.1 - 2019-04-02
Expand Down
71 changes: 59 additions & 12 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ define([
* {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit/README.md|KHR_materials_unlit}
* </li><li>
* {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/README.md|KHR_materials_pbrSpecularGlossiness}
* </li><li>
* {@link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md|KHR_texture_transform}
* </li>
* </ul>
* </p>
Expand Down Expand Up @@ -1296,6 +1298,8 @@ define([
* {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit/README.md|KHR_materials_unlit}
* </li><li>
* {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/README.md|KHR_materials_pbrSpecularGlossiness}
* </li><li>
* {@link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md|KHR_texture_transform}
* </li>
* </ul>
* </p>
Expand Down Expand Up @@ -2379,24 +2383,67 @@ define([

var rendererSamplers = model._rendererResources.samplers;
var sampler = rendererSamplers[texture.sampler];
sampler = defaultValue(sampler, new Sampler({
wrapS : TextureWrap.REPEAT,
wrapT : TextureWrap.REPEAT
}));
if (!defined(sampler)) {
sampler = new Sampler({
wrapS : TextureWrap.REPEAT,
wrapT : TextureWrap.REPEAT
});
}

var usesTextureTransform = false;
var materials = model.gltf.materials;
var materialsLength = materials.length;
for (var i = 0; i < materialsLength; ++i) {
var material = materials[i];
if (defined(material.extensions) && defined(material.extensions.KHR_techniques_webgl)) {
var values = material.extensions.KHR_techniques_webgl.values;
for (var valueName in values) {
if (values.hasOwnProperty(valueName) && valueName.indexOf('Texture') !== -1) {
var value = values[valueName];
if (value.index === gltfTexture.id && defined(value.extensions) && defined(value.extensions.KHR_texture_transform)) {
usesTextureTransform = true;
break;
}
}
}
}
if (usesTextureTransform) {
break;
}
}

var wrapS = sampler.wrapS;
var wrapT = sampler.wrapT;
var minFilter = sampler.minificationFilter;

if (usesTextureTransform && minFilter !== TextureMinificationFilter.LINEAR && minFilter !== TextureMinificationFilter.NEAREST) {
if (minFilter === TextureMinificationFilter.NEAREST_MIPMAP_NEAREST || minFilter === TextureMinificationFilter.NEAREST_MIPMAP_LINEAR) {
minFilter = TextureMinificationFilter.NEAREST;
} else {
minFilter = TextureMinificationFilter.LINEAR;
}

sampler = new Sampler({
wrapS : sampler.wrapS,
wrapT : sampler.wrapT,
textureMinificationFilter : minFilter,
textureMagnificationFilter : sampler.magnificationFilter
});
}

var internalFormat = gltfTexture.internalFormat;

var mipmap =
(!(defined(internalFormat) && PixelFormat.isCompressedFormat(internalFormat))) &&
((sampler.minificationFilter === TextureMinificationFilter.NEAREST_MIPMAP_NEAREST) ||
(sampler.minificationFilter === TextureMinificationFilter.NEAREST_MIPMAP_LINEAR) ||
(sampler.minificationFilter === TextureMinificationFilter.LINEAR_MIPMAP_NEAREST) ||
(sampler.minificationFilter === TextureMinificationFilter.LINEAR_MIPMAP_LINEAR));
((minFilter === TextureMinificationFilter.NEAREST_MIPMAP_NEAREST) ||
(minFilter === TextureMinificationFilter.NEAREST_MIPMAP_LINEAR) ||
(minFilter === TextureMinificationFilter.LINEAR_MIPMAP_NEAREST) ||
(minFilter === TextureMinificationFilter.LINEAR_MIPMAP_LINEAR));
var requiresNpot = mipmap ||
(sampler.wrapS === TextureWrap.REPEAT) ||
(sampler.wrapS === TextureWrap.MIRRORED_REPEAT) ||
(sampler.wrapT === TextureWrap.REPEAT) ||
(sampler.wrapT === TextureWrap.MIRRORED_REPEAT);
(wrapS === TextureWrap.REPEAT) ||
(wrapS === TextureWrap.MIRRORED_REPEAT) ||
(wrapT === TextureWrap.REPEAT) ||
(wrapT === TextureWrap.MIRRORED_REPEAT);

var tx;
var source = gltfTexture.image;
Expand Down
1 change: 1 addition & 0 deletions Source/Scene/ModelUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ define([
'KHR_techniques_webgl' : true,
'KHR_materials_unlit' : true,
'KHR_materials_pbrSpecularGlossiness' : true,
'KHR_texture_transform' : true,
'WEB3D_quantized_attributes' : true,
'EXT_texture_webp' : true
};
Expand Down
Loading