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

GltfLoader updates #9595

Merged
merged 11 commits into from
Jun 16, 2021
10 changes: 5 additions & 5 deletions Source/Scene/FeatureTextureProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ function FeatureTextureProperty(options) {
//>>includeEnd('debug');

var textureInfo = property.texture;
var texture = GltfLoaderUtil.createModelTexture({
var textureReader = GltfLoaderUtil.createModelTexture({
textureInfo: textureInfo,
channels: property.channels,
texture: textures[textureInfo.index],
});

this._texture = texture;
this._textureReader = textureReader;
this._classProperty = classProperty;
this._extras = property.extras;
this._extensions = property.extensions;
Expand All @@ -49,13 +49,13 @@ Object.defineProperties(FeatureTextureProperty.prototype, {
* The texture.
*
* @memberof FeatureTextureProperty.prototype
* @type {ModelComponents.Texture}
* @type {ModelComponents.TextureReader}
* @readonly
* @private
*/
texture: {
textureReader: {
get: function () {
return this._texture;
return this._textureReader;
},
},

Expand Down
12 changes: 6 additions & 6 deletions Source/Scene/GltfLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,21 +613,21 @@ function loadTexture(

loader._textureLoaders.push(textureLoader);

var texture = GltfLoaderUtil.createModelTexture({
var textureReader = GltfLoaderUtil.createModelTexture({
textureInfo: textureInfo,
});

textureLoader.promise.then(function (textureLoader) {
if (loader.isDestroyed()) {
return;
}
texture.texture = textureLoader.texture;
textureReader.texture = textureLoader.texture;
if (defined(samplerOverride)) {
texture.texture.sampler = samplerOverride;
textureReader.texture.sampler = samplerOverride;
}
});

return texture;
return textureReader;
}

function loadMaterial(loader, gltf, gltfMaterial, supportedImageFormats) {
Expand Down Expand Up @@ -758,15 +758,15 @@ function loadFeatureIdTexture(
var textureInfo = featureIds.texture;

featureIdTexture.featureTableId = gltfFeatureIdTexture.featureTable;
featureIdTexture.texture = loadTexture(
featureIdTexture.textureReader = loadTexture(
loader,
gltf,
textureInfo,
supportedImageFormats,
Sampler.NEAREST // Feature ID textures require nearest sampling
);

featureIdTexture.texture.channels = featureIds.channels;
featureIdTexture.textureReader.channels = featureIds.channels;

return featureIdTexture;
}
Expand Down
14 changes: 7 additions & 7 deletions Source/Scene/GltfLoaderUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ var defaultScale = new Cartesian2(1.0, 1.0);
* @param {String} [options.channels] The texture channels to read from.
* @param {Texture} [options.texture] The texture object.
*
* @returns {ModelComponents.Texture} The texture.
* @returns {ModelComponents.TextureReader} The texture.
ptrgags marked this conversation as resolved.
Show resolved Hide resolved
*/
GltfLoaderUtil.createModelTexture = function (options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
Expand Down Expand Up @@ -240,13 +240,13 @@ GltfLoaderUtil.createModelTexture = function (options) {
);
}

var modelTexture = new ModelComponents.Texture();
modelTexture.texture = texture;
modelTexture.texCoord = texCoord;
modelTexture.transform = transform;
modelTexture.channels = channels;
var modelTextureReader = new ModelComponents.TextureReader();
modelTextureReader.texture = texture;
modelTextureReader.texCoord = texCoord;
modelTextureReader.transform = transform;
modelTextureReader.channels = channels;

return modelTexture;
return modelTextureReader;
};

export default GltfLoaderUtil;
28 changes: 14 additions & 14 deletions Source/Scene/ModelComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,10 @@ function FeatureIdTexture() {
/**
* The texture containing feature IDs.
*
* @type {ModelComponents.Texture}
* @type {ModelComponents.TextureReader}
* @private
*/
this.texture = undefined;
this.textureReader = undefined;
}

/**
Expand Down Expand Up @@ -647,21 +647,21 @@ function Components() {
}

/**
* A texture.
* The components for reading a texture.
ptrgags marked this conversation as resolved.
Show resolved Hide resolved
*
* @alias ModelComponents.Texture
* @alias ModelComponents.TextureReader
* @constructor
*
* @private
*/
function Texture() {
function TextureReader() {
/**
* The underlying GPU texture. The {@link Texture} contains the sampler.
*
* @type {Texture}
* @private
*/
this.texture = undefined;
this.textureReader = undefined;

/**
* The texture coordinate set.
Expand Down Expand Up @@ -700,15 +700,15 @@ function MetallicRoughness() {
/**
* The base color texture.
*
* @type {ModelComponents.Texture}
* @type {ModelComponents.TextureReader}
* @private
*/
this.baseColorTexture = undefined;

/**
* The metallic roughness texture.
*
* @type {ModelComponents.Texture}
* @type {ModelComponents.TextureReader}
* @private
*/
this.metallicRoughnessTexture = undefined;
Expand Down Expand Up @@ -775,15 +775,15 @@ function SpecularGlossiness() {
/**
* The diffuse texture.
*
* @type {ModelComponents.Texture}
* @type {ModelComponents.TextureReader}
* @private
*/
this.diffuseTexture = undefined;

/**
* The specular glossiness texture.
*
* @type {ModelComponents.Texture}
* @type {ModelComponents.TextureReader}
* @private
*/
this.specularGlossinessTexture = undefined;
Expand Down Expand Up @@ -863,23 +863,23 @@ function Material() {
/**
* The emissive texture.
*
* @type {ModelComponents.Texture}
* @type {ModelComponents.TextureReader}
* @private
*/
this.emissiveTexture = undefined;

/**
* The normal texture.
*
* @type {ModelComponents.Texture}
* @type {ModelComponents.TextureReader}
* @private
*/
this.normalTexture = undefined;

/**
* The occlusion texture.
*
* @type {ModelComponents.Texture}
* @type {ModelComponents.TextureReader}
* @private
*/
this.occlusionTexture = undefined;
Expand Down Expand Up @@ -947,7 +947,7 @@ ModelComponents.Skin = Skin;
ModelComponents.Node = Node;
ModelComponents.Scene = Scene;
ModelComponents.Components = Components;
ModelComponents.Texture = Texture;
ModelComponents.TextureReader = TextureReader;
ModelComponents.MetallicRoughness = MetallicRoughness;
ModelComponents.SpecularGlossiness = SpecularGlossiness;
ModelComponents.Material = Material;
Expand Down
10 changes: 5 additions & 5 deletions Specs/Scene/FeatureTexturePropertySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ describe("Scene/FeatureTextureProperty", function () {
0.0, 0.0, 1.0
);

var modelTexture = featureTextureProperty.texture;
expect(modelTexture.texture).toBe(texture);
expect(modelTexture.texCoord).toBe(1);
expect(modelTexture.transform).toEqual(expectedTransform);
expect(modelTexture.channels).toBe("rgb");
var modelTextureReader = featureTextureProperty.textureReader;
expect(modelTextureReader.texture).toBe(texture);
expect(modelTextureReader.texCoord).toBe(1);
expect(modelTextureReader.transform).toEqual(expectedTransform);
expect(modelTextureReader.channels).toBe("rgb");
});

it("constructor throws without property", function () {
Expand Down
16 changes: 8 additions & 8 deletions Specs/Scene/GltfFeatureMetadataLoaderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,16 @@ describe(
var intensityProperty = mapTexture.getProperty("intensity");
var vegetationProperty = orthoTexture.getProperty("vegetation");

expect(colorProperty.texture.texture.width).toBe(1);
expect(colorProperty.texture.texture.height).toBe(1);
expect(colorProperty.texture.texture).toBe(
intensityProperty.texture.texture
expect(colorProperty.textureReader.texture.width).toBe(1);
expect(colorProperty.textureReader.texture.height).toBe(1);
expect(colorProperty.textureReader.texture).toBe(
intensityProperty.textureReader.texture
);

expect(vegetationProperty.texture.texture.width).toBe(1);
expect(vegetationProperty.texture.texture.height).toBe(1);
expect(vegetationProperty.texture.texture).not.toBe(
colorProperty.texture.texture
expect(vegetationProperty.textureReader.texture.width).toBe(1);
expect(vegetationProperty.textureReader.texture.height).toBe(1);
expect(vegetationProperty.textureReader.texture).not.toBe(
colorProperty.textureReader.texture
);

expect(Object.keys(featureMetadata.schema.classes).sort()).toEqual([
Expand Down
16 changes: 9 additions & 7 deletions Specs/Scene/GltfLoaderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,13 @@ describe(
expect(primitive.featureTextureIds).toEqual(["vegetationTexture"]);

expect(featureIdTexture.featureTableId).toBe("landCoverTable");
expect(featureIdTexture.texture.channels).toBe("r");
expect(featureIdTexture.texture.texCoord).toBe(0);
expect(featureIdTexture.texture.texture.width).toBe(256);
expect(featureIdTexture.texture.texture.height).toBe(256);
expect(featureIdTexture.texture.texture.sampler).toBe(Sampler.NEAREST);
expect(featureIdTexture.textureReader.channels).toBe("r");
expect(featureIdTexture.textureReader.texCoord).toBe(0);
expect(featureIdTexture.textureReader.texture.width).toBe(256);
expect(featureIdTexture.textureReader.texture.height).toBe(256);
expect(featureIdTexture.textureReader.texture.sampler).toBe(
Sampler.NEAREST
);

var classDefinition = featureMetadata.schema.classes.landCover;
var properties = classDefinition.properties;
Expand Down Expand Up @@ -823,8 +825,8 @@ describe(
"vegetationDensity"
);

expect(vegetationProperty.texture.texture.width).toBe(256);
expect(vegetationProperty.texture.texture.height).toBe(256);
expect(vegetationProperty.textureReader.texture.width).toBe(256);
expect(vegetationProperty.textureReader.texture.height).toBe(256);
});
});

Expand Down