mirror of https://gitee.com/cf-fz/WebCAD.git
!2996 修复:拉伸实体的UV贴图构造器
parent
0441166520
commit
6d232eeae4
@ -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…
Reference in new issue