Parcourir la source

Fix linter errors and add documentation

Scott Nagy il y a 4 ans
Parent
commit
4310de6606
2 fichiers modifiés avec 17 ajouts et 15 suppressions
  1. 1 0
      dist/preview release/what's new.md
  2. 16 15
      src/Meshes/polygonMesh.ts

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

@@ -8,6 +8,7 @@
 
 - Added static CenterToRef for vectors 2/3/4  ([aWeirdo](https://github.com/aWeirdo))
 - Added ability to view images (ktx2, png, jpg) to the sandbox. ([bghgary](https://github.com/bghgary))
+- Added optional smoothed normals for extruded procedural polygons. ([snagy](https://github.com/snagy))
 
 ### Loaders
 

+ 16 - 15
src/Meshes/polygonMesh.ts

@@ -222,6 +222,7 @@ export class PolygonMeshBuilder {
      * Creates the polygon
      * @param updatable If the mesh should be updatable
      * @param depth The depth of the mesh created
+     * @param smoothingThreshold Dot product threshold for smoothed normals
      * @returns the created mesh
      */
     build(updatable: boolean = false, depth: number = 0, smoothingThreshold: number = 2): Mesh {
@@ -240,6 +241,7 @@ export class PolygonMeshBuilder {
     /**
      * Creates the polygon
      * @param depth The depth of the mesh created
+     * @param smoothingThreshold Dot product threshold for smoothed normals
      * @returns the created VertexData
      */
     buildVertexData(depth: number = 0, smoothingThreshold: number = 2): VertexData {
@@ -316,36 +318,35 @@ export class PolygonMeshBuilder {
         var ulength: number = 0;
         for (var i: number = 0; i < points.elements.length; i++) {
             var p: IndexedVector2 = points.elements[i];
-            var p1: IndexedVector2 = points.elements[(i + 1)%points.elements.length];
+            var p1: IndexedVector2 = points.elements[(i + 1) % points.elements.length];
 
             positions.push(p.x, 0, p.y);
             positions.push(p.x, -depth, p.y);
             positions.push(p1.x, 0, p1.y);
             positions.push(p1.x, -depth, p1.y);
 
-            let vc = new Vector3(-(p1.y-p.y), 0, p1.x-p.x);
+            let vc = new Vector3(-(p1.y - p.y), 0, p1.x - p.x);
             const vc_len = vc.length();
             vc = vc.normalizeFromLength(vc_len);
 
-            
-            const p0: IndexedVector2 = points.elements[(i + points.elements.length - 1)%points.elements.length];
-            const p2: IndexedVector2 = points.elements[(i + 2)%points.elements.length];
-            let vp = new Vector3(-( p.y-p0.y), 0,  p.x-p0.x);
+            const p0: IndexedVector2 = points.elements[(i + points.elements.length - 1) % points.elements.length];
+            const p2: IndexedVector2 = points.elements[(i + 2) % points.elements.length];
+            let vp = new Vector3(-(p.y - p0.y), 0,  p.x - p0.x);
             const vp_len = vp.length();
             vp = vp.normalizeFromLength(vp_len);
-            let vn = new Vector3(-(p2.y-p1.y), 0, p2.x-p1.x);
+            let vn = new Vector3(-(p2.y - p1.y), 0, p2.x - p1.x);
             const vn_len = vn.length();
             vn = vn.normalizeFromLength(vn_len);
-            
-            if(!flip) {
+
+            if (!flip) {
                 vp = vp.scale(-1);
                 vn = vn.scale(-1);
                 vc = vc.scale(-1);
             }
-            
+
             const dotp = Vector3.Dot(vp, vc);
-            if(dotp > smoothingThreshold) {
-                if( dotp < Epsilon-1) {
+            if (dotp > smoothingThreshold) {
+                if (dotp < Epsilon - 1) {
                     vp = (new Vector3(p.x, 0, p.y)).subtract(new Vector3(p1.x, 0, p1.y)).normalize();
                 }
                 else {
@@ -357,9 +358,9 @@ export class PolygonMeshBuilder {
                 vp = vc;
             }
 
-            const dotn = Vector3.Dot(vn, vc)
-            if(dotn > smoothingThreshold) {
-                if( dotn < Epsilon-1) {
+            const dotn = Vector3.Dot(vn, vc);
+            if (dotn > smoothingThreshold) {
+                if (dotn < Epsilon - 1) {
                     // back to back
                     vn = (new Vector3(p1.x, 0, p1.y)).subtract(new Vector3(p.x, 0, p.y)).normalize();
                 }