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

Ensure spec parity between Model and ModelExperimental #10600

Merged
merged 10 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 4 additions & 4 deletions Source/Scene/ModelExperimental/ModelExperimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import SplitDirection from "../SplitDirection.js";
* @param {HeightReference} [options.heightReference=HeightReference.NONE] Determines how the model is drawn relative to terrain.
* @param {Scene} [options.scene] Must be passed in for models that use the height reference property.
* @param {DistanceDisplayCondition} [options.distanceDisplayCondition] The condition specifying at what distance from the camera that this model will be displayed.
* @param {Color} [options.color] A color that blends with the model's rendered color.
* @param {Color} [options.color=Color.WHITE] A color that blends with the model's rendered color.
* @param {ColorBlendMode} [options.colorBlendMode=ColorBlendMode.HIGHLIGHT] Defines how the color blends with the model.
* @param {Number} [options.colorBlendAmount=0.5] Value used to determine the color strength when the <code>colorBlendMode</code> is <code>MIX</code>. A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with any value in-between resulting in a mix of the two.
* @param {Color} [options.silhouetteColor=Color.RED] The silhouette color. If more than 256 models have silhouettes enabled, there is a small chance that overlapping models will have minor artifacts.
Expand Down Expand Up @@ -195,8 +195,8 @@ export default function ModelExperimental(options) {
this._id = options.id;
this._idDirty = false;

const color = options.color;
this._color = defined(color) ? Color.clone(color) : undefined;
const color = defaultValue(options.color, Color.WHITE);
j9liu marked this conversation as resolved.
Show resolved Hide resolved
this._color = Color.clone(color);
this._colorBlendMode = defaultValue(
options.colorBlendMode,
ColorBlendMode.HIGHLIGHT
Expand Down Expand Up @@ -2359,7 +2359,7 @@ ModelExperimental.prototype.destroyModelResources = function () {
* @param {HeightReference} [options.heightReference=HeightReference.NONE] Determines how the model is drawn relative to terrain.
* @param {Scene} [options.scene] Must be passed in for models that use the height reference property.
* @param {DistanceDisplayCondition} [options.distanceDisplayCondition] The condition specifying at what distance from the camera that this model will be displayed.
* @param {Color} [options.color] A color that blends with the model's rendered color.
* @param {Color} [options.color=Color.WHITE] A color that blends with the model's rendered color.
* @param {ColorBlendMode} [options.colorBlendMode=ColorBlendMode.HIGHLIGHT] Defines how the color blends with the model.
* @param {Number} [options.colorBlendAmount=0.5] Value used to determine the color strength when the <code>colorBlendMode</code> is <code>MIX</code>. A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with any value in-between resulting in a mix of the two.
* @param {Color} [options.silhouetteColor=Color.RED] The silhouette color. If more than 256 models have silhouettes enabled, there is a small chance that overlapping models will have minor artifacts.
Expand Down
46 changes: 46 additions & 0 deletions Specs/Scene/GltfLoaderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ describe(
"./Data/Models/GltfLoader/BoxWithPrimitiveOutline/glTF/BoxWithPrimitiveOutline.gltf";
const boxWithPrimitiveOutlineSharedVertices =
"./Data/Models/GltfLoader/BoxWithPrimitiveOutlineSharedVertices/glTF/BoxWithPrimitiveOutlineSharedVertices.gltf";
const multiUvTest = "./Data/Models/MultiUVTest/MultiUVTest.glb";

let scene;
let sceneWithWebgl2;
Expand Down Expand Up @@ -1068,6 +1069,51 @@ describe(
});
});

it("loads MultiUVTest", function () {
return loadGltf(multiUvTest).then(function (gltfLoader) {
const components = gltfLoader.components;
const scene = components.scene;
const rootNode = scene.nodes[0];
const primitive = rootNode.primitives[0];
const material = primitive.material;
const baseColorTexture = material.metallicRoughness.baseColorTexture;
const emissiveTexture = material.emissiveTexture;

const attributes = primitive.attributes;
const positionAttribute = getAttribute(
attributes,
VertexAttributeSemantic.POSITION
);
const normalAttribute = getAttribute(
attributes,
VertexAttributeSemantic.NORMAL
);
const tangentAttribute = getAttribute(
attributes,
VertexAttributeSemantic.TANGENT
);
const texcoordAttribute0 = getAttribute(
attributes,
VertexAttributeSemantic.TEXCOORD,
0
);
const texcoordAttribute1 = getAttribute(
attributes,
VertexAttributeSemantic.TEXCOORD,
1
);

expect(positionAttribute).toBeDefined();
expect(normalAttribute).toBeDefined();
expect(tangentAttribute).toBeDefined();
expect(texcoordAttribute0).toBeDefined();
expect(texcoordAttribute1).toBeDefined();

expect(baseColorTexture.texCoord).toBe(0);
expect(emissiveTexture.texCoord).toBe(1);
});
});

it("loads Microcosm", function () {
return loadGltf(microcosm).then(function (gltfLoader) {
const components = gltfLoader.components;
Expand Down
2 changes: 1 addition & 1 deletion Specs/Scene/ModelExperimental/ModelAnimationChannelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ describe("Scene/ModelExperimental/ModelAnimationChannel", function () {

const wrappedRuntimeAnimation = {
model: {
clampedAnimations: false,
clampAnimations: false,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationCollection", functio
const interpolationTestUrl =
"./Data/Models/InterpolationTest/InterpolationTest.glb";

const defaultDate = JulianDate.fromDate(
new Date("January 1, 2014 12:00:00 UTC")
);
const scratchJulianDate = new JulianDate();
let scene;

Expand Down Expand Up @@ -475,7 +478,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationCollection", functio
},
scene
).then(function (model) {
let time = JulianDate.fromDate(new Date("January 1, 2014 12:00:00 UTC"));
let time = defaultDate;
const animations = model.activeAnimations;
const animation = animations.add({
index: 0,
Expand Down Expand Up @@ -520,17 +523,42 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationCollection", functio
});
});

it("animates with a delay", function () {
it("finishes animation when it reaches its end", function () {
return loadAndZoomToModelExperimental(
{
gltf: animatedTriangleUrl,
},
scene
).then(function (model) {
const time = JulianDate.fromDate(
new Date("January 1, 2014 12:00:00 UTC")
);
const time = defaultDate;
const animationCollection = model.activeAnimations;
const animation = animationCollection.add({
index: 0,
});

const spyUpdate = jasmine.createSpy("listener");
animation.update.addEventListener(spyUpdate);

scene.renderForSpecs(time);
scene.renderForSpecs(JulianDate.addSeconds(time, 1.0, scratchJulianDate));
scene.renderForSpecs(JulianDate.addSeconds(time, 2.0, scratchJulianDate));

expect(spyUpdate.calls.count()).toEqual(3);
expect(spyUpdate.calls.argsFor(0)[2]).toEqual(0.0);
expect(spyUpdate.calls.argsFor(1)[2]).toEqual(1.0);
// Animation has reached its final time value.
expect(spyUpdate.calls.argsFor(2)[2]).toEqual(1.0);
});
});

it("animates with a delay", function () {
return loadAndZoomToModelExperimental(
{
gltf: animatedTriangleUrl,
},
scene
).then(function (model) {
const time = defaultDate;
const animationCollection = model.activeAnimations;
const animation = animationCollection.add({
index: 0,
Expand All @@ -555,10 +583,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationCollection", functio
},
scene
).then(function (model) {
const time = JulianDate.fromDate(
new Date("January 1, 2014 12:00:00 UTC")
);

const time = defaultDate;
const animationCollection = model.activeAnimations;
const animation = animationCollection.add({
index: 0,
Expand Down Expand Up @@ -623,9 +648,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationCollection", functio
},
scene
).then(function (model) {
const time = JulianDate.fromDate(
new Date("January 1, 2014 12:00:00 UTC")
);
const time = defaultDate;
const animationCollection = model.activeAnimations;
let animationTime = 0;
const animation = animationCollection.add({
Expand Down Expand Up @@ -672,9 +695,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationCollection", functio
},
scene
).then(function (model) {
const time = JulianDate.fromDate(
new Date("January 1, 2014 12:00:00 UTC")
);
const time = defaultDate;
const animationCollection = model.activeAnimations;
animationCollection.animateWhilePaused = true;
let animationTime = 0;
Expand Down Expand Up @@ -719,9 +740,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationCollection", functio
},
scene
).then(function (model) {
const time = JulianDate.fromDate(
new Date("January 1, 2014 12:00:00 UTC")
);
const time = defaultDate;
const animationCollection = model.activeAnimations;
const animation = animationCollection.add({
index: 0,
Expand Down Expand Up @@ -750,9 +769,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationCollection", functio
},
scene
).then(function (model) {
const time = JulianDate.fromDate(
new Date("January 1, 2014 12:00:00 UTC")
);
const time = defaultDate;
const animationCollection = model.activeAnimations;
const animation = animationCollection.add({
index: 0,
Expand Down Expand Up @@ -781,9 +798,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationCollection", functio
},
scene
).then(function (model) {
const time = JulianDate.fromDate(
new Date("January 1, 2014 12:00:00 UTC")
);
const time = defaultDate;
const animationCollection = model.activeAnimations;
const animation = animationCollection.add({
index: 0,
Expand Down Expand Up @@ -814,9 +829,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationCollection", functio
},
scene
).then(function (model) {
const time = JulianDate.fromDate(
new Date("January 1, 2014 12:00:00 UTC")
);
const time = defaultDate;
const animationCollection = model.activeAnimations;
const animation = animationCollection.add({
index: 0,
Expand Down
Loading