Skip to content

Commit

Permalink
fix shadow lazy creation (google#1055)
Browse files Browse the repository at this point in the history
* fix shadow lazy creation

* added test
  • Loading branch information
elalish authored Feb 27, 2020
1 parent 201cf41 commit c07a0b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ suite('ModelScene', () => {
scene.setShadowIntensity(0);
expect(scene.shadow!.getIntensity()).to.be.equal(0);
});

test('shadow is only created when intensity is greater than zero', () => {
expect(scene.shadow).to.be.not.ok;
scene.setShadowIntensity(1);
expect(scene.shadow).to.be.ok;
});
});
});

Expand Down
6 changes: 4 additions & 2 deletions packages/model-viewer/src/three-components/ModelScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,14 @@ export class ModelScene extends Scene {
shadowIntensity = Math.max(shadowIntensity, 0);
this.shadowIntensity = shadowIntensity;
if (this.model.hasModel()) {
if (this.shadow == null) {
if (this.shadow == null && shadowIntensity > 0) {
this.shadow = new Shadow(this.model, this.pivot, this.shadowSoftness);
this.pivot.add(this.shadow);
// showShadowHelper(this);
}
this.shadow.setIntensity(shadowIntensity);
if (this.shadow != null) {
this.shadow.setIntensity(shadowIntensity);
}
}
}

Expand Down

0 comments on commit c07a0b8

Please sign in to comment.