|
16 | 16 | import {AnimationAction, AnimationClip, AnimationMixer, Box3, Camera, Euler, Event as ThreeEvent, LoopPingPong, LoopRepeat, Material, Matrix3, Mesh, Object3D, PerspectiveCamera, Raycaster, Scene, Sphere, Texture, Vector2, Vector3, WebGLRenderer} from 'three'; |
17 | 17 | import {CSS2DRenderer} from 'three/examples/jsm/renderers/CSS2DRenderer.js'; |
18 | 18 |
|
| 19 | +import {$currentGLTF, $model, $originalGltfJson} from '../features/scene-graph.js'; |
19 | 20 | import ModelViewerElementBase, {$renderer, RendererInterface} from '../model-viewer-base.js'; |
20 | 21 | import {ModelViewerElement} from '../model-viewer.js'; |
21 | 22 | import {normalizeUnit} from '../styles/conversions.js'; |
@@ -64,7 +65,6 @@ const ndc = new Vector2(); |
64 | 65 | export class ModelScene extends Scene { |
65 | 66 | public element: ModelViewerElement; |
66 | 67 | public canvas: HTMLCanvasElement; |
67 | | - public context: CanvasRenderingContext2D|null = null; |
68 | 68 | public annotationRenderer = new CSS2DRenderer(); |
69 | 69 | public schemaElement = document.createElement('script'); |
70 | 70 | public width = 1; |
@@ -148,8 +148,8 @@ export class ModelScene extends Scene { |
148 | 148 | * directly. This extra context is necessary to copy the renderings into when |
149 | 149 | * there are more than one. |
150 | 150 | */ |
151 | | - createContext() { |
152 | | - this.context = this.canvas.getContext('2d'); |
| 151 | + get context() { |
| 152 | + return this.canvas.getContext('2d'); |
153 | 153 | } |
154 | 154 |
|
155 | 155 | getCamera(): Camera { |
@@ -236,6 +236,7 @@ export class ModelScene extends Scene { |
236 | 236 | throw error; |
237 | 237 | } |
238 | 238 |
|
| 239 | + this.cancelPendingSourceChange = null; |
239 | 240 | this.reset(); |
240 | 241 | this.url = url; |
241 | 242 | this._currentGLTF = gltf; |
@@ -300,6 +301,17 @@ export class ModelScene extends Scene { |
300 | 301 | this.mixer.uncacheRoot(this); |
301 | 302 | } |
302 | 303 |
|
| 304 | + dispose() { |
| 305 | + this.reset(); |
| 306 | + if (this.shadow != null) { |
| 307 | + this.shadow.dispose(); |
| 308 | + this.shadow = null; |
| 309 | + } |
| 310 | + (this.element as any)[$currentGLTF] = null; |
| 311 | + (this.element as any)[$originalGltfJson] = null; |
| 312 | + (this.element as any)[$model] = null; |
| 313 | + } |
| 314 | + |
303 | 315 | get currentGLTF() { |
304 | 316 | return this._currentGLTF; |
305 | 317 | } |
|
0 commit comments