Sebastien Vandenberghe 7 lat temu
rodzic
commit
ed1f2a91e8

Plik diff jest za duży
+ 9072 - 9071
Playground/babylon.d.txt


Plik diff jest za duży
+ 8753 - 8752
dist/preview release/babylon.d.ts


Plik diff jest za duży
+ 6 - 6
dist/preview release/babylon.js


+ 27 - 7
dist/preview release/babylon.max.js

@@ -64734,6 +64734,11 @@ var BABYLON;
             _this._stillImageCaptured = false;
             _this._createInternalTexture = function () {
                 if (_this._texture != null) {
+                    if (!_this.isReady) {
+                        _this._texture.isReady = true;
+                        _this._updateInternalTexture();
+                        _this._createInternalTexture();
+                    }
                     return;
                 }
                 if (!_this._engine.needPOTTextures ||
@@ -64747,8 +64752,11 @@ var BABYLON;
                     _this._generateMipMaps = false;
                 }
                 _this._texture = _this._engine.createDynamicTexture(_this.video.videoWidth, _this.video.videoHeight, _this._generateMipMaps, _this._samplingMode);
-                _this._texture.isReady = true;
-                _this._updateInternalTexture();
+                if (_this.video.readyState >= _this.video.HAVE_CURRENT_DATA) {
+                    _this._texture.isReady = true;
+                    _this._updateInternalTexture();
+                    _this._createInternalTexture();
+                }
                 if (_this._onLoadObservable && _this._onLoadObservable.hasObservers()) {
                     _this.onLoadObservable.notifyObservers(_this);
                 }
@@ -64781,6 +64789,7 @@ var BABYLON;
             if (settings.loop !== undefined) {
                 _this.video.loop = settings.loop;
             }
+            _this.video.addEventListener("canplay", _this._createInternalTexture);
             _this.video.addEventListener("canplaythrough", _this._createInternalTexture);
             _this.video.addEventListener("paused", _this._updateInternalTexture);
             _this.video.addEventListener("seeked", _this._updateInternalTexture);
@@ -64860,6 +64869,7 @@ var BABYLON;
         };
         VideoTexture.prototype.dispose = function () {
             _super.prototype.dispose.call(this);
+            this.video.removeEventListener("canplay", this._createInternalTexture);
             this.video.removeEventListener("canplaythrough", this._createInternalTexture);
             this.video.removeEventListener("paused", this._updateInternalTexture);
             this.video.removeEventListener("seeked", this._updateInternalTexture);
@@ -89140,14 +89150,14 @@ var BABYLON;
             });
             this._scene.beginAnimation(this.currentVRCamera, 0, 6, false, 1);
         };
-        VRExperienceHelper.prototype._moveTeleportationSelectorTo = function (hit, gazer) {
+        VRExperienceHelper.prototype._moveTeleportationSelectorTo = function (hit, gazer, ray) {
             if (hit.pickedPoint) {
                 if (gazer._teleportationRequestInitiated) {
                     this._displayTeleportationTarget();
                     this._haloCenter.copyFrom(hit.pickedPoint);
                     this._teleportationTarget.position.copyFrom(hit.pickedPoint);
                 }
-                var pickNormal = hit.getNormal(true, false);
+                var pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(true, false), ray);
                 if (pickNormal) {
                     var axis1 = BABYLON.Vector3.Cross(BABYLON.Axis.Y, pickNormal);
                     var axis2 = BABYLON.Vector3.Cross(pickNormal, axis1);
@@ -89238,11 +89248,21 @@ var BABYLON;
             });
             this._hideTeleportationTarget();
         };
+        VRExperienceHelper.prototype._convertNormalToDirectionOfRay = function (normal, ray) {
+            if (normal) {
+                var angle = Math.acos(BABYLON.Vector3.Dot(normal, ray.direction));
+                if (angle < Math.PI / 2) {
+                    normal.scaleInPlace(-1);
+                }
+            }
+            return normal;
+        };
         VRExperienceHelper.prototype._castRayAndSelectObject = function (gazer) {
             if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
                 return;
             }
-            var hit = this._scene.pickWithRay(gazer._getForwardRay(this._rayLength), this._raySelectionPredicate);
+            var ray = gazer._getForwardRay(this._rayLength);
+            var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
             // Moving the gazeTracker on the mesh face targetted
             if (hit && hit.pickedPoint) {
                 if (this._displayGaze) {
@@ -89254,7 +89274,7 @@ var BABYLON;
                     gazer._gazeTracker.scaling.x = hit.distance * multiplier;
                     gazer._gazeTracker.scaling.y = hit.distance * multiplier;
                     gazer._gazeTracker.scaling.z = hit.distance * multiplier;
-                    var pickNormal = hit.getNormal();
+                    var pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(), ray);
                     // To avoid z-fighting
                     var deltaFighting = 0.002;
                     if (pickNormal) {
@@ -89302,7 +89322,7 @@ var BABYLON;
                     }
                     gazer._currentMeshSelected = null;
                     if (gazer._teleportationRequestInitiated) {
-                        this._moveTeleportationSelectorTo(hit, gazer);
+                        this._moveTeleportationSelectorTo(hit, gazer, ray);
                     }
                     return;
                 }

+ 27 - 7
dist/preview release/babylon.no-module.max.js

@@ -64701,6 +64701,11 @@ var BABYLON;
             _this._stillImageCaptured = false;
             _this._createInternalTexture = function () {
                 if (_this._texture != null) {
+                    if (!_this.isReady) {
+                        _this._texture.isReady = true;
+                        _this._updateInternalTexture();
+                        _this._createInternalTexture();
+                    }
                     return;
                 }
                 if (!_this._engine.needPOTTextures ||
@@ -64714,8 +64719,11 @@ var BABYLON;
                     _this._generateMipMaps = false;
                 }
                 _this._texture = _this._engine.createDynamicTexture(_this.video.videoWidth, _this.video.videoHeight, _this._generateMipMaps, _this._samplingMode);
-                _this._texture.isReady = true;
-                _this._updateInternalTexture();
+                if (_this.video.readyState >= _this.video.HAVE_CURRENT_DATA) {
+                    _this._texture.isReady = true;
+                    _this._updateInternalTexture();
+                    _this._createInternalTexture();
+                }
                 if (_this._onLoadObservable && _this._onLoadObservable.hasObservers()) {
                     _this.onLoadObservable.notifyObservers(_this);
                 }
@@ -64748,6 +64756,7 @@ var BABYLON;
             if (settings.loop !== undefined) {
                 _this.video.loop = settings.loop;
             }
+            _this.video.addEventListener("canplay", _this._createInternalTexture);
             _this.video.addEventListener("canplaythrough", _this._createInternalTexture);
             _this.video.addEventListener("paused", _this._updateInternalTexture);
             _this.video.addEventListener("seeked", _this._updateInternalTexture);
@@ -64827,6 +64836,7 @@ var BABYLON;
         };
         VideoTexture.prototype.dispose = function () {
             _super.prototype.dispose.call(this);
+            this.video.removeEventListener("canplay", this._createInternalTexture);
             this.video.removeEventListener("canplaythrough", this._createInternalTexture);
             this.video.removeEventListener("paused", this._updateInternalTexture);
             this.video.removeEventListener("seeked", this._updateInternalTexture);
@@ -89107,14 +89117,14 @@ var BABYLON;
             });
             this._scene.beginAnimation(this.currentVRCamera, 0, 6, false, 1);
         };
-        VRExperienceHelper.prototype._moveTeleportationSelectorTo = function (hit, gazer) {
+        VRExperienceHelper.prototype._moveTeleportationSelectorTo = function (hit, gazer, ray) {
             if (hit.pickedPoint) {
                 if (gazer._teleportationRequestInitiated) {
                     this._displayTeleportationTarget();
                     this._haloCenter.copyFrom(hit.pickedPoint);
                     this._teleportationTarget.position.copyFrom(hit.pickedPoint);
                 }
-                var pickNormal = hit.getNormal(true, false);
+                var pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(true, false), ray);
                 if (pickNormal) {
                     var axis1 = BABYLON.Vector3.Cross(BABYLON.Axis.Y, pickNormal);
                     var axis2 = BABYLON.Vector3.Cross(pickNormal, axis1);
@@ -89205,11 +89215,21 @@ var BABYLON;
             });
             this._hideTeleportationTarget();
         };
+        VRExperienceHelper.prototype._convertNormalToDirectionOfRay = function (normal, ray) {
+            if (normal) {
+                var angle = Math.acos(BABYLON.Vector3.Dot(normal, ray.direction));
+                if (angle < Math.PI / 2) {
+                    normal.scaleInPlace(-1);
+                }
+            }
+            return normal;
+        };
         VRExperienceHelper.prototype._castRayAndSelectObject = function (gazer) {
             if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
                 return;
             }
-            var hit = this._scene.pickWithRay(gazer._getForwardRay(this._rayLength), this._raySelectionPredicate);
+            var ray = gazer._getForwardRay(this._rayLength);
+            var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
             // Moving the gazeTracker on the mesh face targetted
             if (hit && hit.pickedPoint) {
                 if (this._displayGaze) {
@@ -89221,7 +89241,7 @@ var BABYLON;
                     gazer._gazeTracker.scaling.x = hit.distance * multiplier;
                     gazer._gazeTracker.scaling.y = hit.distance * multiplier;
                     gazer._gazeTracker.scaling.z = hit.distance * multiplier;
-                    var pickNormal = hit.getNormal();
+                    var pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(), ray);
                     // To avoid z-fighting
                     var deltaFighting = 0.002;
                     if (pickNormal) {
@@ -89269,7 +89289,7 @@ var BABYLON;
                     }
                     gazer._currentMeshSelected = null;
                     if (gazer._teleportationRequestInitiated) {
-                        this._moveTeleportationSelectorTo(hit, gazer);
+                        this._moveTeleportationSelectorTo(hit, gazer, ray);
                     }
                     return;
                 }

Plik diff jest za duży
+ 6 - 6
dist/preview release/babylon.worker.js


+ 27 - 7
dist/preview release/es6.js

@@ -64701,6 +64701,11 @@ var BABYLON;
             _this._stillImageCaptured = false;
             _this._createInternalTexture = function () {
                 if (_this._texture != null) {
+                    if (!_this.isReady) {
+                        _this._texture.isReady = true;
+                        _this._updateInternalTexture();
+                        _this._createInternalTexture();
+                    }
                     return;
                 }
                 if (!_this._engine.needPOTTextures ||
@@ -64714,8 +64719,11 @@ var BABYLON;
                     _this._generateMipMaps = false;
                 }
                 _this._texture = _this._engine.createDynamicTexture(_this.video.videoWidth, _this.video.videoHeight, _this._generateMipMaps, _this._samplingMode);
-                _this._texture.isReady = true;
-                _this._updateInternalTexture();
+                if (_this.video.readyState >= _this.video.HAVE_CURRENT_DATA) {
+                    _this._texture.isReady = true;
+                    _this._updateInternalTexture();
+                    _this._createInternalTexture();
+                }
                 if (_this._onLoadObservable && _this._onLoadObservable.hasObservers()) {
                     _this.onLoadObservable.notifyObservers(_this);
                 }
@@ -64748,6 +64756,7 @@ var BABYLON;
             if (settings.loop !== undefined) {
                 _this.video.loop = settings.loop;
             }
+            _this.video.addEventListener("canplay", _this._createInternalTexture);
             _this.video.addEventListener("canplaythrough", _this._createInternalTexture);
             _this.video.addEventListener("paused", _this._updateInternalTexture);
             _this.video.addEventListener("seeked", _this._updateInternalTexture);
@@ -64827,6 +64836,7 @@ var BABYLON;
         };
         VideoTexture.prototype.dispose = function () {
             _super.prototype.dispose.call(this);
+            this.video.removeEventListener("canplay", this._createInternalTexture);
             this.video.removeEventListener("canplaythrough", this._createInternalTexture);
             this.video.removeEventListener("paused", this._updateInternalTexture);
             this.video.removeEventListener("seeked", this._updateInternalTexture);
@@ -89107,14 +89117,14 @@ var BABYLON;
             });
             this._scene.beginAnimation(this.currentVRCamera, 0, 6, false, 1);
         };
-        VRExperienceHelper.prototype._moveTeleportationSelectorTo = function (hit, gazer) {
+        VRExperienceHelper.prototype._moveTeleportationSelectorTo = function (hit, gazer, ray) {
             if (hit.pickedPoint) {
                 if (gazer._teleportationRequestInitiated) {
                     this._displayTeleportationTarget();
                     this._haloCenter.copyFrom(hit.pickedPoint);
                     this._teleportationTarget.position.copyFrom(hit.pickedPoint);
                 }
-                var pickNormal = hit.getNormal(true, false);
+                var pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(true, false), ray);
                 if (pickNormal) {
                     var axis1 = BABYLON.Vector3.Cross(BABYLON.Axis.Y, pickNormal);
                     var axis2 = BABYLON.Vector3.Cross(pickNormal, axis1);
@@ -89205,11 +89215,21 @@ var BABYLON;
             });
             this._hideTeleportationTarget();
         };
+        VRExperienceHelper.prototype._convertNormalToDirectionOfRay = function (normal, ray) {
+            if (normal) {
+                var angle = Math.acos(BABYLON.Vector3.Dot(normal, ray.direction));
+                if (angle < Math.PI / 2) {
+                    normal.scaleInPlace(-1);
+                }
+            }
+            return normal;
+        };
         VRExperienceHelper.prototype._castRayAndSelectObject = function (gazer) {
             if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
                 return;
             }
-            var hit = this._scene.pickWithRay(gazer._getForwardRay(this._rayLength), this._raySelectionPredicate);
+            var ray = gazer._getForwardRay(this._rayLength);
+            var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
             // Moving the gazeTracker on the mesh face targetted
             if (hit && hit.pickedPoint) {
                 if (this._displayGaze) {
@@ -89221,7 +89241,7 @@ var BABYLON;
                     gazer._gazeTracker.scaling.x = hit.distance * multiplier;
                     gazer._gazeTracker.scaling.y = hit.distance * multiplier;
                     gazer._gazeTracker.scaling.z = hit.distance * multiplier;
-                    var pickNormal = hit.getNormal();
+                    var pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(), ray);
                     // To avoid z-fighting
                     var deltaFighting = 0.002;
                     if (pickNormal) {
@@ -89269,7 +89289,7 @@ var BABYLON;
                     }
                     gazer._currentMeshSelected = null;
                     if (gazer._teleportationRequestInitiated) {
-                        this._moveTeleportationSelectorTo(hit, gazer);
+                        this._moveTeleportationSelectorTo(hit, gazer, ray);
                     }
                     return;
                 }

Plik diff jest za duży
+ 6 - 6
dist/preview release/viewer/babylon.viewer.js


+ 27 - 7
dist/preview release/viewer/babylon.viewer.max.js

@@ -64822,6 +64822,11 @@ var BABYLON;
             _this._stillImageCaptured = false;
             _this._createInternalTexture = function () {
                 if (_this._texture != null) {
+                    if (!_this.isReady) {
+                        _this._texture.isReady = true;
+                        _this._updateInternalTexture();
+                        _this._createInternalTexture();
+                    }
                     return;
                 }
                 if (!_this._engine.needPOTTextures ||
@@ -64835,8 +64840,11 @@ var BABYLON;
                     _this._generateMipMaps = false;
                 }
                 _this._texture = _this._engine.createDynamicTexture(_this.video.videoWidth, _this.video.videoHeight, _this._generateMipMaps, _this._samplingMode);
-                _this._texture.isReady = true;
-                _this._updateInternalTexture();
+                if (_this.video.readyState >= _this.video.HAVE_CURRENT_DATA) {
+                    _this._texture.isReady = true;
+                    _this._updateInternalTexture();
+                    _this._createInternalTexture();
+                }
                 if (_this._onLoadObservable && _this._onLoadObservable.hasObservers()) {
                     _this.onLoadObservable.notifyObservers(_this);
                 }
@@ -64869,6 +64877,7 @@ var BABYLON;
             if (settings.loop !== undefined) {
                 _this.video.loop = settings.loop;
             }
+            _this.video.addEventListener("canplay", _this._createInternalTexture);
             _this.video.addEventListener("canplaythrough", _this._createInternalTexture);
             _this.video.addEventListener("paused", _this._updateInternalTexture);
             _this.video.addEventListener("seeked", _this._updateInternalTexture);
@@ -64948,6 +64957,7 @@ var BABYLON;
         };
         VideoTexture.prototype.dispose = function () {
             _super.prototype.dispose.call(this);
+            this.video.removeEventListener("canplay", this._createInternalTexture);
             this.video.removeEventListener("canplaythrough", this._createInternalTexture);
             this.video.removeEventListener("paused", this._updateInternalTexture);
             this.video.removeEventListener("seeked", this._updateInternalTexture);
@@ -89228,14 +89238,14 @@ var BABYLON;
             });
             this._scene.beginAnimation(this.currentVRCamera, 0, 6, false, 1);
         };
-        VRExperienceHelper.prototype._moveTeleportationSelectorTo = function (hit, gazer) {
+        VRExperienceHelper.prototype._moveTeleportationSelectorTo = function (hit, gazer, ray) {
             if (hit.pickedPoint) {
                 if (gazer._teleportationRequestInitiated) {
                     this._displayTeleportationTarget();
                     this._haloCenter.copyFrom(hit.pickedPoint);
                     this._teleportationTarget.position.copyFrom(hit.pickedPoint);
                 }
-                var pickNormal = hit.getNormal(true, false);
+                var pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(true, false), ray);
                 if (pickNormal) {
                     var axis1 = BABYLON.Vector3.Cross(BABYLON.Axis.Y, pickNormal);
                     var axis2 = BABYLON.Vector3.Cross(pickNormal, axis1);
@@ -89326,11 +89336,21 @@ var BABYLON;
             });
             this._hideTeleportationTarget();
         };
+        VRExperienceHelper.prototype._convertNormalToDirectionOfRay = function (normal, ray) {
+            if (normal) {
+                var angle = Math.acos(BABYLON.Vector3.Dot(normal, ray.direction));
+                if (angle < Math.PI / 2) {
+                    normal.scaleInPlace(-1);
+                }
+            }
+            return normal;
+        };
         VRExperienceHelper.prototype._castRayAndSelectObject = function (gazer) {
             if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
                 return;
             }
-            var hit = this._scene.pickWithRay(gazer._getForwardRay(this._rayLength), this._raySelectionPredicate);
+            var ray = gazer._getForwardRay(this._rayLength);
+            var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
             // Moving the gazeTracker on the mesh face targetted
             if (hit && hit.pickedPoint) {
                 if (this._displayGaze) {
@@ -89342,7 +89362,7 @@ var BABYLON;
                     gazer._gazeTracker.scaling.x = hit.distance * multiplier;
                     gazer._gazeTracker.scaling.y = hit.distance * multiplier;
                     gazer._gazeTracker.scaling.z = hit.distance * multiplier;
-                    var pickNormal = hit.getNormal();
+                    var pickNormal = this._convertNormalToDirectionOfRay(hit.getNormal(), ray);
                     // To avoid z-fighting
                     var deltaFighting = 0.002;
                     if (pickNormal) {
@@ -89390,7 +89410,7 @@ var BABYLON;
                     }
                     gazer._currentMeshSelected = null;
                     if (gazer._teleportationRequestInitiated) {
-                        this._moveTeleportationSelectorTo(hit, gazer);
+                        this._moveTeleportationSelectorTo(hit, gazer, ray);
                     }
                     return;
                 }

+ 14 - 3
src/Materials/Textures/babylon.videoTexture.ts

@@ -75,6 +75,7 @@
                 this.video.loop = settings.loop;
             }
 
+            this.video.addEventListener("canplay", this._createInternalTexture);
             this.video.addEventListener("canplaythrough", this._createInternalTexture);
             this.video.addEventListener("paused", this._updateInternalTexture);
             this.video.addEventListener("seeked", this._updateInternalTexture);
@@ -119,6 +120,12 @@
 
         private _createInternalTexture = (): void => {
             if (this._texture != null) {
+                if (!this.isReady) {
+                    this._texture.isReady = true;
+                    this._updateInternalTexture();
+                    this._createInternalTexture();
+                }
+                
                 return;
             }
 
@@ -141,9 +148,12 @@
                 this._samplingMode
             );
 
-            this._texture.isReady = true;
+            if (this.video.readyState >= this.video.HAVE_CURRENT_DATA) {
+                this._texture.isReady = true;
+                this._updateInternalTexture();
+                this._createInternalTexture();
+            }
 
-            this._updateInternalTexture();
             if (this._onLoadObservable && this._onLoadObservable.hasObservers()) {
                 this.onLoadObservable.notifyObservers(this);
             }
@@ -211,7 +221,8 @@
         }
 
         public dispose(): void {
-            super.dispose();            
+            super.dispose();
+            this.video.removeEventListener("canplay", this._createInternalTexture);
             this.video.removeEventListener("canplaythrough", this._createInternalTexture);
             this.video.removeEventListener("paused", this._updateInternalTexture);
             this.video.removeEventListener("seeked", this._updateInternalTexture);