P4: add expressions dependency recompute and topology signatures
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { BitByBitOCCT, OccStateEnum } from '@bitbybit-dev/occt-worker'
|
||||
import type { Inputs } from '@bitbybit-dev/occt'
|
||||
import type { ApplyPlacementInput, BooleanCutInput, BooleanIntersectionInput, BooleanUnionInput, CreateBoxInput, CreateConeInput, CreateCylinderInput, CreateSphereInput, GeometryCapabilities, GeometryDocumentContext, LinearFeatureParameters, MeshAsset, PadInput, PlanarProfile, PocketInput, Point3, RevolutionInput, ShapeHandle } from './types'
|
||||
import type { ApplyPlacementInput, BooleanCutInput, BooleanIntersectionInput, BooleanUnionInput, CreateBoxInput, CreateConeInput, CreateCylinderInput, CreateSphereInput, GeometryCapabilities, GeometryDocumentContext, LinearFeatureParameters, MeshAsset, PadInput, PlanarProfile, PocketInput, Point3, RevolutionInput, ShapeHandle, SubshapeRef } from './types'
|
||||
import { createSubshapeRefs } from './topologyNaming'
|
||||
|
||||
type KernelShapeReference = Inputs.OCCT.TopoDSShapePointer
|
||||
type KernelMesh = Inputs.OCCT.DecomposedMeshDto
|
||||
@@ -176,7 +177,7 @@ const appendFace = (face: Inputs.OCCT.DecomposedFaceDto, positions: number[], no
|
||||
for (const index of face.triIndexes) indices.push(vertexOffset + index)
|
||||
}
|
||||
|
||||
export const normalizeBitbybitMesh = (shape: ShapeHandle, mesh: KernelMesh): MeshAsset => {
|
||||
export const normalizeBitbybitMesh = (shape: ShapeHandle, mesh: KernelMesh, tolerance = 1e-5): MeshAsset => {
|
||||
const positions: number[] = []
|
||||
const normals: number[] = []
|
||||
const indices: number[] = []
|
||||
@@ -191,12 +192,14 @@ export const normalizeBitbybitMesh = (shape: ShapeHandle, mesh: KernelMesh): Mes
|
||||
max[axis] = Math.max(max[axis], positions[index + axis])
|
||||
}
|
||||
}
|
||||
const subshapes: SubshapeRef[] = createSubshapeRefs(shape.id, shape.documentVersion, mesh.faceList.map((face) => ({ vertexCoord: face.vertexCoord, normalCoord: face.normalCoord, triIndexes: face.triIndexes })), tolerance).refs
|
||||
return {
|
||||
shapeId: shape.id,
|
||||
topologyVersion: shape.documentVersion,
|
||||
positions: new Float32Array(positions),
|
||||
normals: new Float32Array(normals),
|
||||
indices: new Uint32Array(indices),
|
||||
subshapes,
|
||||
bounds: { min, max },
|
||||
}
|
||||
}
|
||||
@@ -385,7 +388,11 @@ export class BitbybitGeometryRuntime {
|
||||
const entry = this.resolveShape(shape)
|
||||
const client = await this.readyClient()
|
||||
const mesh = await client.occt.shapeToMesh({ shape: entry.reference, precision, adjustYtoZ: false })
|
||||
return normalizeBitbybitMesh(entry.handle, mesh)
|
||||
return normalizeBitbybitMesh(entry.handle, mesh, Math.max(1e-5, precision * 0.1))
|
||||
}
|
||||
|
||||
async subshapes(shape: ShapeHandle, precision = 0.05): Promise<SubshapeRef[]> {
|
||||
return (await this.mesh(shape, precision)).subshapes ?? []
|
||||
}
|
||||
|
||||
async release(shape: ShapeHandle): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user