|
@@ -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();
|
|
|
}
|