No longer need mitredExtrude
This commit is contained in:
parent
cd623194d2
commit
3c1ddce07b
|
@ -287,61 +287,3 @@ export const TurtlePrimitives: Cat.Environment<TurtleVM> = Object.assign({}, Cat
|
|||
return [];
|
||||
},
|
||||
} satisfies Cat.Environment<TurtleVM>);
|
||||
|
||||
function mitredExtrude(
|
||||
name: string,
|
||||
options: { shape: Vector3[], path: Vector3[], close?: boolean },
|
||||
scene: Scene,
|
||||
): Mesh {
|
||||
const shape = options.shape;
|
||||
const path = options.path;
|
||||
const closed = options.close ?? false;
|
||||
|
||||
function miterNormal(v1: Vector3, v2: Vector3): Vector3 {
|
||||
return Vector3.Cross(Vector3.Cross(v2, v1), v2.subtract(v1));
|
||||
}
|
||||
|
||||
var allPaths = [];
|
||||
|
||||
for (var s = 0; s < shape.length; s++) {
|
||||
let axisZ = path[1].subtract(path[0]).normalize();
|
||||
const axisX = Vector3.Cross(scene.activeCamera!.position, axisZ).normalize();
|
||||
const axisY = Vector3.Cross(axisZ, axisX);
|
||||
let startPoint = path[0].add(axisX.scale(shape[s].x)).add(axisY.scale(shape[s].y));
|
||||
const ribbonPath = [startPoint];
|
||||
for (var p = 0; p < path.length - 2; p++) {
|
||||
const nextAxisZ = path[p + 2].subtract(path[p + 1]).normalize();
|
||||
|
||||
startPoint = startPoint.add(axisZ.scale(new Ray(startPoint, axisZ).intersectsPlane(Plane.FromPositionAndNormal(path[p + 1], miterNormal(axisZ, nextAxisZ)))!));
|
||||
|
||||
ribbonPath.push(startPoint);
|
||||
axisZ = nextAxisZ;
|
||||
}
|
||||
// Last Point
|
||||
if (closed) {
|
||||
let nextAxisZ = path[0].subtract(path[path.length - 1]).normalize();
|
||||
startPoint = startPoint.add(axisZ.scale(new Ray(startPoint, axisZ).intersectsPlane(Plane.FromPositionAndNormal(path[path.length - 1], miterNormal(axisZ, nextAxisZ)))!));
|
||||
|
||||
ribbonPath.push(startPoint);
|
||||
axisZ = nextAxisZ;
|
||||
|
||||
nextAxisZ = path[1].subtract(path[0]).normalize();
|
||||
startPoint = startPoint.add(axisZ.scale(new Ray(startPoint, axisZ).intersectsPlane(Plane.FromPositionAndNormal(path[0], miterNormal(axisZ, nextAxisZ)))!));
|
||||
|
||||
ribbonPath.shift();
|
||||
ribbonPath.unshift(startPoint);
|
||||
} else {
|
||||
startPoint = startPoint.add(axisZ.scale(new Ray(startPoint, axisZ).intersectsPlane(Plane.FromPositionAndNormal(path[path.length - 1], axisZ))!));
|
||||
|
||||
ribbonPath.push(startPoint);
|
||||
}
|
||||
allPaths.push(ribbonPath);
|
||||
}
|
||||
|
||||
return MeshBuilder.CreateRibbon(name, {
|
||||
pathArray: allPaths,
|
||||
sideOrientation: Mesh.DOUBLESIDE,
|
||||
closeArray: true,
|
||||
closePath: closed,
|
||||
}, scene);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue