kzhsw
November 21, 2024, 12:42am
1
Version: 7.34.4
Background
Currently CSG2.FromMesh
and other CSG2 methods return any
type, makes it harder to inference type of returned value, and make it harder for devs to get type hints compared to the old CSG.
The CSG2.FromMesh
:
return this._Construct(vertexData, null);
}
/**
* Create a new Constructive Solid Geometry from a mesh
* @param mesh defines the mesh to use to create the CSG
* @param ignoreWorldMatrix defines if the world matrix should be ignored
* @returns a new CSG2 class
*/
public static FromMesh(mesh: Mesh, ignoreWorldMatrix = false): any {
const sourceVertices = mesh.getVerticesData(VertexBuffer.PositionKind);
const sourceIndices = mesh.getIndices();
const worldMatrix = mesh.computeWorldMatrix(true);
if (!sourceVertices || !sourceIndices) {
throw new Error("The mesh must at least have positions and indices");
}
// Create a triangle run for each submesh (material)
const starts = [...Array(mesh.subMeshes.length)].map((_, idx) => mesh.subMeshes[idx].indexStart);
The CSG.FromMesh
:
return csg;
}
/**
* Convert the Mesh to CSG
* @param mesh The Mesh to convert to CSG
* @param absolute If true, the final (local) matrix transformation is set to the identity and not to that of `mesh`. It can help when dealing with right-handed meshes (default: false)
* @returns A new CSG from the Mesh
*/
public static FromMesh(mesh: Mesh, absolute = false): CSG {
let vertex: Vertex,
normal: Vector3,
uv: Vector2 | undefined = undefined,
position: Vector3,
vertColor: Color4 | undefined = undefined,
polygon: CSGPolygon,
vertices: Vertex[];
const polygons: CSGPolygon[] = [];
let matrix: Matrix,
meshPosition: Vector3,
Proposal
Make user-facing CSG2 methods return CSG2 type instead of any
.
Risks
Since CSG2 is already released with any
type, narrowing the type to CSG2
could be breaking for typescript users.
RaananW
November 21, 2024, 10:48am
2
CC @Deltakosh , I don’t see why it would be a problem doing that, but he would probably know better, as he built it
No problem at all and probably an oversight on my side
Please do a PR @kzhsw
1 Like