!2996 修复:拉伸实体的UV贴图构造器

pull/2997/head
林三 1 month ago committed by ChenX
parent 0441166520
commit 6d232eeae4

@ -6,12 +6,12 @@ import { ColorMaterial } from "../../Common/ColorPalette";
import { DisposeThreeObj, Object3DRemoveAll } from "../../Common/Dispose"; import { DisposeThreeObj, Object3DRemoveAll } from "../../Common/Dispose";
import { Vector2ApplyMatrix4 } from "../../Common/Matrix4Utils"; import { Vector2ApplyMatrix4 } from "../../Common/Matrix4Utils";
import { ObjectSnapMode } from "../../Editor/ObjectSnapMode"; import { ObjectSnapMode } from "../../Editor/ObjectSnapMode";
import { boardUVGenerator } from "../../Geometry/BoardUVGenerator";
import { Box3Ext } from "../../Geometry/Box"; import { Box3Ext } from "../../Geometry/Box";
import { FastWireframe2 } from "../../Geometry/CreateWireframe"; import { FastWireframe2 } from "../../Geometry/CreateWireframe";
import { AsVector3, ZeroVec, equaln, equalv2, equalv3 } from "../../Geometry/GeUtils"; import { AsVector3, ZeroVec, equaln, equalv2, equalv3 } from "../../Geometry/GeUtils";
import { GenerateExtrudeEdgeGeometry } from "../../Geometry/SimpleExtrudeEdgeGeometry"; import { GenerateExtrudeEdgeGeometry } from "../../Geometry/SimpleExtrudeEdgeGeometry";
import { ScaleUV } from "../../Geometry/UVUtils"; import { ScaleUV } from "../../Geometry/UVUtils";
import { worldUVGenerator } from "../../Geometry/WordUVGenerator";
import { RenderType } from "../../GraphicsSystem/RenderType"; import { RenderType } from "../../GraphicsSystem/RenderType";
import { AutoRecord } from "../AutoRecord"; import { AutoRecord } from "../AutoRecord";
import { Factory } from "../CADFactory"; import { Factory } from "../CADFactory";
@ -233,7 +233,7 @@ export class ExtrudeHole extends Hole
steps: 1, steps: 1,
bevelEnabled: false, bevelEnabled: false,
depth: this.Height, depth: this.Height,
UVGenerator: boardUVGenerator, UVGenerator: worldUVGenerator,
}; };
let geo = new ExtrudeGeometry(this.ContourCurve.Shape, extrudeSettings); let geo = new ExtrudeGeometry(this.ContourCurve.Shape, extrudeSettings);
geo.applyMatrix4(this._contourCurve.OCSNoClone); geo.applyMatrix4(this._contourCurve.OCSNoClone);

@ -0,0 +1,58 @@
import { ExtrudeBufferGeometry, UVGenerator, Vector2 } from "three";
//https://github.com/mrdoob/three.js/blob/master/src/geometries/ExtrudeGeometry.js#L727
class WorldUVGenerator implements UVGenerator
{
generateTopUV(geometry: ExtrudeBufferGeometry, vertices: number[], indexA: number, indexB: number, indexC: number)
{
const a_x = vertices[indexA * 3];
const a_y = vertices[indexA * 3 + 1];
const b_x = vertices[indexB * 3];
const b_y = vertices[indexB * 3 + 1];
const c_x = vertices[indexC * 3];
const c_y = vertices[indexC * 3 + 1];
return [
new Vector2(a_x, a_y),
new Vector2(b_x, b_y),
new Vector2(c_x, c_y)
];
}
generateSideWallUV(geometry: ExtrudeBufferGeometry, vertices: number[], indexA: number, indexB: number, indexC: number, indexD: number)
{
const a_x = vertices[indexA * 3];
const a_y = vertices[indexA * 3 + 1];
const a_z = vertices[indexA * 3 + 2];
const b_x = vertices[indexB * 3];
const b_y = vertices[indexB * 3 + 1];
const b_z = vertices[indexB * 3 + 2];
const c_x = vertices[indexC * 3];
const c_y = vertices[indexC * 3 + 1];
const c_z = vertices[indexC * 3 + 2];
const d_x = vertices[indexD * 3];
const d_y = vertices[indexD * 3 + 1];
const d_z = vertices[indexD * 3 + 2];
if (Math.abs(a_y - b_y) < Math.abs(a_x - b_x))
{
return [
new Vector2(a_x, 1 - a_z),
new Vector2(b_x, 1 - b_z),
new Vector2(c_x, 1 - c_z),
new Vector2(d_x, 1 - d_z)
];
}
else
{
return [
new Vector2(a_y, 1 - a_z),
new Vector2(b_y, 1 - b_z),
new Vector2(c_y, 1 - c_z),
new Vector2(d_y, 1 - d_z)
];
}
}
}
export const worldUVGenerator = new WorldUVGenerator();
Loading…
Cancel
Save