Skip to main content

OCP-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 OCP TopoDS_* shapes, 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.

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 ocp_tessellate.convert:

  • export_three_cad_viewer_js(var, *objs, names=None, colors=None, alphas=None, modes=None, filename=None, keep_instances=False) — runs the full pipeline (to_ocpgroup → tessellate_group → JSON encode) and writes a var <name> = {...}; JS file. The direct integration point with three-cad-viewer.
  • to_ocpgroup(*objs, names=None, colors=None, alphas=None, modes=None, ...) — converts CAD objects (build123d / CadQuery / OCP / nested dicts and lists) into an OcpGroup hierarchy plus an instance list. Accepts per-object names, colors, alphas, materials, modes ((state_faces, state_edges) 2-tuples), and a default_color. Renderer-control flags include helper_scale, render_joints, render_mates, show_parent, show_locals.
  • tessellate_group(group, instances, kwargs=None, progress=None, timeit=False) — meshes the instances and returns the structures consumed by three-cad-viewer. kwargs can carry tessellation parameters like deviation, angular_tolerance, edge_accuracy, and render_normals.

For lower-level use, OcpConverter exposes to_ocp(...), which is what to_ocpgroup calls internally.

What gets shown

Inputs are walked recursively. The resulting tree mirrors the input structure:

input result
build123d / CadQuery / OCP shape a single OcpObject
dict a Dict group with one named child per key
list / tuple a List group with default-named children
ShapeList a ShapeList group exposing each item individually
Compound(children=[...]) (assembly) a group preserving the assembly hierarchy
Compound(...) (standard, no children) unwrapped to its inner shape
BuildPart / BuildSheet / BuildSketch / BuildLine a single OcpObject for the builder result, plus a part_local / sheet_local / sketch_local / line_local sibling unless disabled

Compatibility

  • Python 3.10+
  • OCP 7.8, 7.9 and 8.0
  • build123d (current)
  • CadQuery 2.x

License

Apache 2.0. See LICENSE.

Changelog

See CHANGELOG.md.

Metadata

Release files for ocp-tessellate 3.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ocp-tessellate 3.5.1
File Size Uploaded
ocp_tessellate-3.5.1.tar.gz 71.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ocp-tessellate 3.5.1
File Interpreter ABI Platform
ocp_tessellate-3.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 132.4 kB

Release files / ocp_tessellate-3.5.1.tar.gz

Download URL ocp_tessellate-3.5.1.tar.gz
Size 71.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6c695d47190f5c12c90b5bf1559c29fc48ce24eed35cd2b92c2bd01c2b527991
BLAKE2b-256 checksum
How to use checksums
7e1688b4153c93e5006b1e893670fea581f038f9fd1f5b8ae925eaeb84b2bd0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release files / ocp_tessellate-3.5.1-py3-none-any.whl

Download URL ocp_tessellate-3.5.1-py3-none-any.whl
Size 61.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40b3abcb14c733fcf4d37181de6d687c9cd6b36061b3957e84701db683709b5f
BLAKE2b-256 checksum
How to use checksums
d13ee529123b8b7e70d21f16fee2bfe51f29ac57b554e02fc7dad0788c5290cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release history Release notifications | RSS feed

3.5.3

2 release files

3.5.2

2 release files

This release

3.5.1 This release

2 release files

3.5.0

2 release files

3.4.2

2 release files

3.4.1

2 release files

3.3.0

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.16

2 release files

3.0.15

2 release files

3.0.14

2 release files

3.0.13

2 release files

3.0.11

2 release files

3.0.9

2 release files

3.0.8

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

2.3.3

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page