|
|
|
@ -42,9 +42,11 @@ export class SweepBufferGeometry extends BufferGeometry
|
|
|
|
|
|
|
|
|
|
//轮廓点表
|
|
|
|
|
let shapePts = contour.Shape.getPoints(4).map(Vec2DTo3D);
|
|
|
|
|
shapePts.forEach(p => p.applyMatrix4(contour.OCS));
|
|
|
|
|
if (!ShapeUtils.isClockWise(shapePts))
|
|
|
|
|
shapePts.reverse();
|
|
|
|
|
//轮廓三角网格索引
|
|
|
|
|
let faces = ShapeUtils.triangulateShape(shapePts, []);
|
|
|
|
|
shapePts.forEach(p => p.applyMatrix4(contour.OCS));
|
|
|
|
|
|
|
|
|
|
const shapePtsCount = shapePts.length;
|
|
|
|
|
const isClosePath = path.IsClose;
|
|
|
|
@ -71,7 +73,6 @@ export class SweepBufferGeometry extends BufferGeometry
|
|
|
|
|
needVers.push(...ProjectionToPlane(shapePts, path.Normal, pathPts[i], pathPts[i - 1], pathPts[i + 1]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let alluv: Vector2[] = [];
|
|
|
|
|
const f4 = (a, b, c, d) =>
|
|
|
|
|
{
|
|
|
|
@ -88,15 +89,13 @@ export class SweepBufferGeometry extends BufferGeometry
|
|
|
|
|
uvs.push(...alluv[c].toArray());
|
|
|
|
|
|
|
|
|
|
uvs.push(...alluv[b].toArray());
|
|
|
|
|
uvs.push(...alluv[d].toArray());
|
|
|
|
|
uvs.push(...alluv[c].toArray());
|
|
|
|
|
uvs.push(...alluv[a].toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//盖子,顶面底面.
|
|
|
|
|
if (!isClosePath)
|
|
|
|
|
{
|
|
|
|
|
//轮廓三角网格索引
|
|
|
|
|
let faces = ShapeUtils.triangulateShape(shapePts, []);
|
|
|
|
|
let shapeUvs = shapePts.map(p => Vec3DTo2D(p).multiplyScalar(1e-3));
|
|
|
|
|
const f3 = (a, b, c) =>
|
|
|
|
|
{
|
|
|
|
@ -123,11 +122,10 @@ export class SweepBufferGeometry extends BufferGeometry
|
|
|
|
|
|
|
|
|
|
//侧面uv
|
|
|
|
|
let uvYs: number[] = [0];
|
|
|
|
|
for (let i = 1; i < shapePts.length; i++)
|
|
|
|
|
for (let i = 1; i < shapePtsCount; i++)
|
|
|
|
|
{
|
|
|
|
|
uvYs.push(shapePts[i].distanceTo(shapePts[i - 1]));
|
|
|
|
|
uvYs.push((uvYs[i - 1] + shapePts[i].distanceTo(shapePts[i - 1]) * 1e-3) % 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uvYs.forEach(y =>
|
|
|
|
|
{
|
|
|
|
|
alluv.push(new Vector2(0, y));
|
|
|
|
@ -139,14 +137,17 @@ export class SweepBufferGeometry extends BufferGeometry
|
|
|
|
|
{
|
|
|
|
|
let count = shapePtsCount;
|
|
|
|
|
|
|
|
|
|
x += pathPts[i].distanceTo(pathPts[i - 1]) * 1e-3;
|
|
|
|
|
uvYs.forEach(y =>
|
|
|
|
|
{
|
|
|
|
|
alluv.push(new Vector2(x, y));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let c0 = count * (i - 1);
|
|
|
|
|
let c1 = count * i;
|
|
|
|
|
|
|
|
|
|
for (let j = 0; j < count; j++)
|
|
|
|
|
{
|
|
|
|
|
let c0j = c0 + j;
|
|
|
|
|
let c1j = c1 + j;
|
|
|
|
|
|
|
|
|
|
let newx = alluv[c0j].x + needVers[c1j].distanceTo(needVers[c0j]) * 1e-3;
|
|
|
|
|
alluv.push(new Vector2(newx, uvYs[j]));
|
|
|
|
|
}
|
|
|
|
|
for (let j = 0; j < count; j++)
|
|
|
|
|
{
|
|
|
|
|
let jn = FixIndex(j + 1, count);
|
|
|
|
|