Browse Source

Merge pull request #7116 from Poolminer/master

Path3D (bi)normal computation edge case fix
David Catuhe 5 years ago
parent
commit
0ec78365f0
2 changed files with 8 additions and 1 deletions
  1. 1 0
      dist/preview release/what's new.md
  2. 7 1
      src/Maths/math.path.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -218,6 +218,7 @@
 - Fixed missing properties in serialization / parsing of `coneParticleEmitter` ([Popov72](https://github.com/Popov72))
 - Fix a bug with exit VR and Edge ([RaananW](https://github.com/RaananW/))
 - Fixed an issue with size of texture in multiview ([RaananW](https://github.com/RaananW/))
+- Fixed Path3D (bi)normals computation for specific edge cases ([Poolminer](https://github.com/Poolminer/))
 
 ## Breaking changes
 

+ 7 - 1
src/Maths/math.path.ts

@@ -616,6 +616,7 @@ export class Path3D {
         var cur: Vector3;         // current vector (segment)
         var curTang: Vector3;     // current tangent
         // previous normal
+        var prevNor: Vector3;    // previous normal
         var prevBinor: Vector3;   // previous binormal
 
         for (var i = 1; i < l; i++) {
@@ -634,7 +635,12 @@ export class Path3D {
             prevBinor = this._binormals[i - 1];
             this._normals[i] = Vector3.Cross(prevBinor, curTang);
             if (!this._raw) {
-                this._normals[i].normalize();
+                if (this._normals[i].length() === 0) {
+                    prevNor = this._normals[i - 1];
+                    this._normals[i] = prevNor.clone();
+                } else {
+                    this._normals[i].normalize();
+                }
             }
             this._binormals[i] = Vector3.Cross(curTang, this._normals[i]);
             if (!this._raw) {