Skip to content

Commit

Permalink
remove src from ModelScene
Browse files Browse the repository at this point in the history
  • Loading branch information
samaneh-kazemi committed Nov 15, 2024
1 parent ca5ee9f commit d190c4a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/model-viewer/src/model-viewer-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export default class ModelViewerElementBase extends ReactiveElement {
this[$loaded] = false;
this[$loadedTime] = 0;
this[$scene].reset();
} else if (this.src !== this[$scene].url) {
} else if (this.src !== this[$scene].modelData.url) {
this[$loaded] = false;
this[$loadedTime] = 0;
this[$updateSource]();
Expand Down Expand Up @@ -594,7 +594,7 @@ export default class ModelViewerElementBase extends ReactiveElement {
async[$updateSource]() {
const scene = this[$scene];
if (this.loaded || !this[$shouldAttemptPreload]() ||
this.src === scene.url) {
this.src === scene.modelData.url) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/model-viewer/src/test/model-viewer-base-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* you may not use this file except in iance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
Expand Down Expand Up @@ -92,7 +92,7 @@ suite('ModelViewerElementBase', () => {
element.src = assetPath('models/Horse.glb');
await waitForEvent(element, 'load');

expect(element[$scene].url)
expect(element[$scene].modelData.url)
.to.be.equal(assetPath('models/Horse.glb'));
});

Expand All @@ -102,7 +102,7 @@ suite('ModelViewerElementBase', () => {
element.src = assetPath('models/Horse.glb');
await waitForEvent(element, 'load');

expect(element[$scene].url)
expect(element[$scene].modelData.url)
.to.be.equal(assetPath('models/Horse.glb'));
});
});
Expand Down
18 changes: 13 additions & 5 deletions packages/model-viewer/src/three-components/ModelScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class ModelScene extends Scene {
public camera = new PerspectiveCamera(45, 1, 0.1, 100);
public xrCamera: Camera|null = null;

public url: string|null = null;

public pivot = new Object3D();
public target = new Object3D();
public animationNames: Array<string> = [];
Expand Down Expand Up @@ -205,14 +205,17 @@ export class ModelScene extends Scene {
async setSource(
url: string|null,
progressCallback: (progress: number) => void = () => {}) {
if (!url || url === this.url) {
console.log("SK: ModelScene:SetSource Started");
if (!url || url === this.modelData.url) {
console.log("SK: ModelScene:SetSource no change");
progressCallback(1);
return;
}
this.reset();
this.url = url;
this.modelData.url = url;

if (this.externalRenderer != null) {
console.log("SK: ModelScene:SetSource externalRendere.load");
const framingInfo = await this.externalRenderer.load(progressCallback);

this.boundingSphere.radius = framingInfo.framedRadius;
Expand All @@ -223,6 +226,7 @@ export class ModelScene extends Scene {
// If we have pending work due to a previous source change in progress,
// cancel it so that we do not incur a race condition:
if (this.cancelPendingSourceChange != null) {
console.log("SK: ModelScene:SetSource cancelPendingSourceChange");
this.cancelPendingSourceChange!();
this.cancelPendingSourceChange = null;
}
Expand All @@ -233,6 +237,7 @@ export class ModelScene extends Scene {
gltf = await new Promise<ModelViewerGLTFInstance>(
async (resolve, reject) => {
this.cancelPendingSourceChange = () => reject();
console.log("SK: ModelScene:SetSource load gltf");
try {
const result = await this.element[$renderer].loader.load(
url, this.element, progressCallback);
Expand All @@ -246,13 +251,16 @@ export class ModelScene extends Scene {
// Loading was cancelled, so silently return
return;
}
console.log("SK: ModelScene:SetSource failed load gltf");

throw error;
}

this.cancelPendingSourceChange = null;
this.reset();
this.url = url;
this.modelData.url = url;
console.log("SK: ModelScene:SetSource gltf value", gltf);

this._currentGLTF = gltf;

if (gltf != null) {
Expand Down Expand Up @@ -289,7 +297,7 @@ export class ModelScene extends Scene {
}

reset() {
this.url = null;
this.modelData.url = null;
this.renderCount = 0;
this.queueRender();
if (this.shadow != null) {
Expand Down

0 comments on commit d190c4a

Please sign in to comment.