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

Handle changes in metadata types from EXT_mesh_features #9880

Merged
merged 16 commits into from
Oct 22, 2021
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
320 changes: 180 additions & 140 deletions Source/Scene/MetadataClassProperty.js

Large diffs are not rendered by default.

470 changes: 470 additions & 0 deletions Source/Scene/MetadataComponentType.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Source/Scene/MetadataEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ MetadataEntity.getProperty = function (

if (defined(classProperty)) {
value = classProperty.normalize(value);
value = classProperty.unpackVectorTypes(value);
value = classProperty.unpackVectorAndMatrixTypes(value);
}

return value;
Expand Down Expand Up @@ -319,7 +319,7 @@ MetadataEntity.setProperty = function (
if (defined(classDefinition)) {
var classProperty = classDefinition.properties[propertyId];
if (defined(classProperty)) {
value = classProperty.packVectorTypes(value);
value = classProperty.packVectorAndMatrixTypes(value);
value = classProperty.unnormalize(value);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Scene/MetadataEnum.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Check from "../Core/Check.js";
import defaultValue from "../Core/defaultValue.js";
import MetadataEnumValue from "./MetadataEnumValue.js";
import MetadataType from "./MetadataType.js";
import MetadataComponentType from "./MetadataComponentType.js";

/**
* A metadata enum.
Expand Down Expand Up @@ -37,8 +37,8 @@ function MetadataEnum(options) {
});

var valueType = defaultValue(
MetadataType[enumDefinition.valueType],
MetadataType.UINT16
MetadataComponentType[enumDefinition.valueType],
MetadataComponentType.UINT16
);

this._values = values;
Expand Down Expand Up @@ -101,7 +101,7 @@ Object.defineProperties(MetadataEnum.prototype, {
* The enum value type.
*
* @memberof MetadataEnum.prototype
* @type {MetadataType}
* @type {MetadataComponentType}
* @readonly
*
* @private
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/MetadataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function getDefault(classDefinition, propertyId) {
value = value.slice(); // clone
}
value = classProperty.normalize(value);
return classProperty.unpackVectorTypes(value);
return classProperty.unpackVectorAndMatrixTypes(value);
}
}
}
Expand Down
68 changes: 40 additions & 28 deletions Source/Scene/MetadataTableProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import DeveloperError from "../Core/DeveloperError.js";
import FeatureDetection from "../Core/FeatureDetection.js";
import getStringFromTypedArray from "../Core/getStringFromTypedArray.js";
import oneTimeWarning from "../Core/oneTimeWarning.js";
import MetadataComponentType from "./MetadataComponentType.js";
import MetadataType from "./MetadataType.js";

/**
Expand Down Expand Up @@ -40,18 +41,21 @@ function MetadataTableProperty(options) {
Check.typeOf.object("options.bufferViews", bufferViews);
//>>includeEnd('debug');

var isArray = classProperty.type === MetadataType.ARRAY;
var type = classProperty.type;
var isArray = type === MetadataType.ARRAY;
var isVariableSizeArray = isArray && !defined(classProperty.componentCount);
var isVectorOrMatrix =
MetadataType.isVectorType(type) || MetadataType.isMatrixType(type);

var valueType = classProperty.valueType;
var enumType = classProperty.enumType;

var hasStrings = valueType === MetadataType.STRING;
var hasBooleans = valueType === MetadataType.BOOLEAN;
var hasStrings = valueType === MetadataComponentType.STRING;
var hasBooleans = valueType === MetadataComponentType.BOOLEAN;

var offsetType = defaultValue(
MetadataType[property.offsetType],
MetadataType.UINT32
MetadataComponentType[property.offsetType],
MetadataComponentType.UINT32
);

var arrayOffsets;
Expand All @@ -66,7 +70,7 @@ function MetadataTableProperty(options) {
var componentCount;
if (isVariableSizeArray) {
componentCount = arrayOffsets.get(count) - arrayOffsets.get(0);
} else if (isArray) {
} else if (isArray || isVectorOrMatrix) {
componentCount = count * classProperty.componentCount;
} else {
componentCount = count;
Expand All @@ -83,7 +87,7 @@ function MetadataTableProperty(options) {

if (hasStrings || hasBooleans) {
// STRING and BOOLEAN types need to be parsed differently than other types
valueType = MetadataType.UINT8;
valueType = MetadataComponentType.UINT8;
}

var valueCount;
Expand Down Expand Up @@ -192,7 +196,7 @@ MetadataTableProperty.prototype.get = function (index) {

var value = get(this, index);
value = this._classProperty.normalize(value);
return this._classProperty.unpackVectorTypes(value);
return this._classProperty.unpackVectorAndMatrixTypes(value);
};

/**
Expand All @@ -214,7 +218,7 @@ MetadataTableProperty.prototype.set = function (index, value) {
}
//>>includeEnd('debug');

value = classProperty.packVectorTypes(value);
value = classProperty.packVectorAndMatrixTypes(value);
value = classProperty.unnormalize(value);

set(this, index, value);
Expand Down Expand Up @@ -264,7 +268,11 @@ function get(property, index) {
return value;
}

if (classProperty.type !== MetadataType.ARRAY) {
var type = classProperty.type;
var isArray = classProperty.type === MetadataType.ARRAY;
var isVectorOrMatrix =
MetadataType.isVectorType(type) || MetadataType.isMatrixType(type);
if (!isArray && !isVectorOrMatrix) {
return property._getValue(index);
}

Expand Down Expand Up @@ -306,7 +314,11 @@ function set(property, index, value) {
// Values are unpacked if the length of a variable-size array changes or the
// property has strings. No need to handle these cases below.

if (classProperty.type !== MetadataType.ARRAY) {
var type = classProperty.type;
var isArray = classProperty.type === MetadataType.ARRAY;
var isVectorOrMatrix =
MetadataType.isVectorType(type) || MetadataType.isMatrixType(type);
if (!isArray && !isVectorOrMatrix) {
property._setValue(index, value);
return;
}
Expand Down Expand Up @@ -437,23 +449,23 @@ function getUint64BigIntFallback(index, values) {
return value;
}

function getComponentDatatype(type) {
switch (type) {
case MetadataType.INT8:
function getComponentDatatype(componentType) {
switch (componentType) {
case MetadataComponentType.INT8:
return ComponentDatatype.BYTE;
case MetadataType.UINT8:
case MetadataComponentType.UINT8:
return ComponentDatatype.UNSIGNED_BYTE;
case MetadataType.INT16:
case MetadataComponentType.INT16:
return ComponentDatatype.SHORT;
case MetadataType.UINT16:
case MetadataComponentType.UINT16:
return ComponentDatatype.UNSIGNED_SHORT;
case MetadataType.INT32:
case MetadataComponentType.INT32:
return ComponentDatatype.INT;
case MetadataType.UINT32:
case MetadataComponentType.UINT32:
return ComponentDatatype.UNSIGNED_INT;
case MetadataType.FLOAT32:
case MetadataComponentType.FLOAT32:
return ComponentDatatype.FLOAT;
case MetadataType.FLOAT64:
case MetadataComponentType.FLOAT64:
return ComponentDatatype.DOUBLE;
}
}
Expand All @@ -465,21 +477,21 @@ function requiresUnpackForGet(property) {

var valueType = property._classProperty.valueType;

if (valueType === MetadataType.STRING) {
if (valueType === MetadataComponentType.STRING) {
// Unpack since UTF-8 decoding is expensive
return true;
}

if (
valueType === MetadataType.INT64 &&
valueType === MetadataComponentType.INT64 &&
!FeatureDetection.supportsBigInt64Array()
) {
// Unpack since the fallback INT64 getters are expensive
return true;
}

if (
valueType === MetadataType.UINT64 &&
valueType === MetadataComponentType.UINT64 &&
!FeatureDetection.supportsBigUint64Array()
) {
// Unpack since the fallback UINT64 getters are expensive
Expand Down Expand Up @@ -560,14 +572,14 @@ function unpackValues(property) {
return unpackedValues;
}

function BufferView(bufferView, type, length) {
function BufferView(bufferView, componentType, length) {
var that = this;

var typedArray;
var getFunction;
var setFunction;

if (type === MetadataType.INT64) {
if (componentType === MetadataComponentType.INT64) {
if (!FeatureDetection.supportsBigInt()) {
oneTimeWarning(
"INT64 type is not fully supported on this platform. Values greater than 2^53 - 1 or less than -(2^53 - 1) may lose precision when read."
Expand Down Expand Up @@ -601,7 +613,7 @@ function BufferView(bufferView, type, length) {
that.typedArray[index] = BigInt(value); // eslint-disable-line
};
}
} else if (type === MetadataType.UINT64) {
} else if (componentType === MetadataComponentType.UINT64) {
if (!FeatureDetection.supportsBigInt()) {
oneTimeWarning(
"UINT64 type is not fully supported on this platform. Values greater than 2^53 - 1 may lose precision when read."
Expand Down Expand Up @@ -636,7 +648,7 @@ function BufferView(bufferView, type, length) {
};
}
} else {
var componentDatatype = getComponentDatatype(type);
var componentDatatype = getComponentDatatype(componentType);
typedArray = ComponentDatatype.createArrayBufferView(
componentDatatype,
bufferView.buffer,
Expand Down
Loading