Jelajahi Sumber

Merge pull request #9750 from RaananW/observableForDome

OnLoadObservable for *dome
David Catuhe 4 tahun lalu
induk
melakukan
e79733cec0

+ 4 - 3
dist/preview release/what's new.md

@@ -14,8 +14,10 @@
 - Moving button to shared uI folder.([msDestiny14](https://github.com/msDestiny14))
 - Moving additional components to shared UI folder.([msDestiny14](https://github.com/msDestiny14))
 - Added encapsulate and encapsulateBoundingInfo methods to BoundingInfo. ([Tolo789](https://github.com/Tolo789))
+- Added onLoadObservable to the textureDome class(es) ([RaananW](https://github.com/RaananW))
 
 ### Engine
+
 - Moved all instance data from Geometry to Mesh such that the same Geometry objects can be used by many meshes with instancing. Reduces memory consumption on CPU/GPU. ([breakin](https://github.com/breakin)
 
 ### Loaders
@@ -91,12 +93,11 @@
 - Fix PostProcess sharing between cameras/renderTargets, that would create/destroy a texture on every frame ([CraigFeldspar](https://github.com/CraigFeldspar))
 - Fix for DualSense gamepads being incorrectly read as DualShock gamepads ([PolygonalSun](https://github.com/PolygonalSun))
 
-
 ## Breaking changes
 
 - [List of breaking changes introduced by ou compatibility with WebGPU](https://doc.babylonjs.com/advanced_topics/webGPU/webGPUBreakingChanges)
-    - [ReadPixels and ProceduralTexture.getContent are now async](https://doc.babylonjs.com/advanced_topics/webGPU/webGPUBreakingChanges#readpixels-is-now-asynchronous)
-    - [Shader support differences](https://doc.babylonjs.com/advanced_topics/webGPU/webGPUBreakingChanges#shader-code-differences)
+  - [ReadPixels and ProceduralTexture.getContent are now async](https://doc.babylonjs.com/advanced_topics/webGPU/webGPUBreakingChanges#readpixels-is-now-asynchronous)
+  - [Shader support differences](https://doc.babylonjs.com/advanced_topics/webGPU/webGPUBreakingChanges#shader-code-differences)
 - Use both `mesh.visibility` and `material.alpha` values to compute the global alpha value used by the soft transparent shadow rendering code. Formerly was only using `mesh.visibility` ([Popov72](https://github.com/Popov72))
 - Depth renderer: don't render mesh if `infiniteDistance = true` or if `material.disableDepthWrite = true` ([Popov72](https://github.com/Popov72))
 - Mesh.createInstance no longer make a unique Geometry for the Mesh so updating one Geometry can affect more meshes than before. Use Mesh.makeUniqueGeometry for old behaviour. ([breakin](https://github.com/breakin))

+ 15 - 5
src/Helpers/photoDome.ts

@@ -55,12 +55,22 @@ export class PhotoDome extends TextureDome<Texture> {
     }
 
     protected _initTexture(urlsOrElement: string, scene: Scene, options: any): Texture {
-        return new Texture(urlsOrElement, scene, !options.generateMipMaps, !this._useDirectMapping, undefined, undefined, (message, exception) => {
-            this.onLoadErrorObservable.notifyObservers(message || "Unknown error occured");
+        return new Texture(
+            urlsOrElement,
+            scene,
+            !options.generateMipMaps,
+            !this._useDirectMapping,
+            undefined,
+            () => {
+                this.onLoadObservable.notifyObservers();
+            },
+            (message, exception) => {
+                this.onLoadErrorObservable.notifyObservers(message || "Unknown error occured");
 
-            if (this.onError) {
-                this.onError(message, exception);
+                if (this.onError) {
+                    this.onError(message, exception);
+                }
             }
-        });
+        );
     }
 }

+ 6 - 1
src/Helpers/textureDome.ts

@@ -166,9 +166,13 @@ export abstract class TextureDome<T extends Texture> extends TransformNode {
      */
     private _onBeforeCameraRenderObserver: Nullable<Observer<Camera>> = null;
     /**
-     * Observable raised when an error occured while loading the 360 image
+     * Observable raised when an error occurred while loading the texture
      */
     public onLoadErrorObservable = new Observable<string>();
+    /**
+     * Observable raised when the texture finished loading
+     */
+    public onLoadObservable = new Observable<void>();
 
     /**
      * Create an instance of this class and pass through the parameters to the relevant classes- Texture, StandardMaterial, and Mesh.
@@ -328,6 +332,7 @@ export abstract class TextureDome<T extends Texture> extends TransformNode {
 
         this._scene.onBeforeCameraRenderObservable.remove(this._onBeforeCameraRenderObserver);
         this.onLoadErrorObservable.clear();
+        this.onLoadObservable.clear();
 
         super.dispose(doNotRecurse, disposeMaterialAndTextures);
     }

+ 3 - 0
src/Helpers/videoDome.ts

@@ -54,6 +54,9 @@ export class VideoDome extends TextureDome<VideoTexture> {
                 this._texture.video.play();
             };
         }
+        texture.onLoadObservable.add(() => {
+            this.onLoadObservable.notifyObservers();
+        });
         return texture;
     }
 }