Tessellate OCP (https://github.com/cadquery/OCP) objects to use with threejs
Actively maintained. Last release 10 days ago, commits in 14 of the last 26 weeks. A safe choice.
pip install ocp-tessellateOCP-Tessellate
Tessellate OCP (Python bindings for OpenCascade) shapes into a JSON-friendly format suitable for three-cad-viewer and downstream tooling such as ocp_vscode.
It accepts geometry from CadQuery, build123d, and raw TopoDS_* shapes of OCP or nanocct, walks the structure, computes triangulations / discretized edges, and emits a hierarchical group of meshed instances.
Installation
pip install ocp-tessellate
Requires Python 3.10+ and OCP 7.8, 7.9 or 8.0, or nanocct 8.0.1, or both.
How ocp_tessellate chooses between the two bindings is described under Compatibility.
Quick start
Programmatic pipeline
For embedding in a tool (the path used by ocp_vscode):
from build123d import Box, Sphere, Compound
from ocp_tessellate.convert import to_ocpgroup, tessellate_group
box = Box(1, 2, 3)
sphere = Sphere(0.5)
sphere.label = "ball"
assembly = Compound(label="root", children=[box, sphere])
# Step 1: convert to an OcpGroup hierarchy + instance list
group, instances = to_ocpgroup(assembly)
# Step 2: tessellate the instances
meshed_instances, shapes, mapping = tessellate_group(group, instances)
# `shapes` is a JSON-serializable tree consumable by three-cad-viewer
Direct export to three-cad-viewer
The simplest path — emit a .js file that a three-cad-viewer page can load directly:
from build123d import Box
from ocp_tessellate.convert import export_three_cad_viewer_js
box = Box(1, 2, 3)
export_three_cad_viewer_js("box", box, filename="box.js")
# writes box.js with `var box = {...}` ready for three-cad-viewer/examples
This is the bridge to three-cad-viewer: bundles tessellated instances + scene tree into a single JSON payload assigned to a JS variable.
Public API
Three entry points in :