P3/P4: execute OCCT features and export shapes
This commit is contained in:
@@ -408,7 +408,11 @@ export class BitbybitGeometryRuntime {
|
||||
validatePocketInput(input)
|
||||
const base = this.resolveShape(input.base).reference
|
||||
const client = await this.readyClient()
|
||||
const tool = await this.createExtrusion(client, input)
|
||||
const direction = input.direction ?? [0, 1, 0]
|
||||
const featureInput = input.throughAll
|
||||
? { ...input, length: await this.throughAllLength(client, base, direction), symmetricToPlane: true }
|
||||
: input
|
||||
const tool = await this.createExtrusion(client, featureInput)
|
||||
const kernelShape = await client.occt.booleans.difference({ shape: base, shapes: [tool], keepEdges: false })
|
||||
return this.registerShape(kernelShape, input.documentId, input.documentVersion)
|
||||
}
|
||||
@@ -502,6 +506,25 @@ export class BitbybitGeometryRuntime {
|
||||
return client.occt.operations.extrude({ shape: face, direction: extrusion })
|
||||
}
|
||||
|
||||
private async throughAllLength(client: BitByBitOCCT, shape: KernelShapeReference, direction: Point3) {
|
||||
const mesh = await client.occt.shapeToMesh({ shape, precision: 0.1, adjustYtoZ: false })
|
||||
const directionLength = magnitude(direction)
|
||||
const normalized = direction.map((coordinate) => coordinate / directionLength) as Point3
|
||||
let minimum = Infinity
|
||||
let maximum = -Infinity
|
||||
for (const face of mesh.faceList) {
|
||||
for (let index = 0; index < face.vertexCoord.length; index += 3) {
|
||||
const point: Point3 = [face.vertexCoord[index], face.vertexCoord[index + 1], face.vertexCoord[index + 2]]
|
||||
const projection = dot(point, normalized)
|
||||
minimum = Math.min(minimum, projection)
|
||||
maximum = Math.max(maximum, projection)
|
||||
}
|
||||
}
|
||||
if (!Number.isFinite(minimum) || !Number.isFinite(maximum)) throw new Error('Through-all pocket cannot determine the base Shape extent.')
|
||||
const span = Math.max(maximum - minimum, 1)
|
||||
return span + Math.max(1, span * 0.05)
|
||||
}
|
||||
|
||||
private registerShape(reference: KernelShapeReference, documentId: string, documentVersion: number) {
|
||||
const handle: ShapeHandle = {
|
||||
id: `shape-${Date.now().toString(36)}-${(++this.sequence).toString(36)}`,
|
||||
|
||||
Reference in New Issue
Block a user