Blender | PY

Convert

Convert between Blender and trueform mesh formats.

The tbpy.convert module provides utilities to convert between Blender mesh data and trueform tf.Mesh objects. Use these for standalone scripts where you don't need caching.

Mesh Conversion

from_blender

Convert a Blender mesh or object to a trueform Mesh:

from trueform import bpy as tbpy

# From object (applies world transform)
mesh = tbpy.convert.from_blender(obj)

# From mesh datablock (no transform)
mesh = tbpy.convert.from_blender(obj.data)

Automatically builds spatial tree, face membership, and manifold edge links required for most operations (e.g., booleans).

Parameters:

ParameterTypeDescription
databpy.types.Mesh or bpy.types.ObjectBlender mesh datablock or mesh object

Returns: tf.Mesh with all required structures built.

to_blender

Create a Blender mesh object from a trueform Mesh:

from trueform import bpy as tbpy

# Create new Blender object in active collection
obj = tbpy.convert.to_blender(mesh, name="Result")

# With smooth shading
obj = tbpy.convert.to_blender(mesh, name="Result", flat_shading=False)

Parameters:

ParameterTypeDefaultDescription
meshtf.MeshTrueform mesh to convert
namestr"Mesh"Name for object and mesh datablock
flat_shadingboolTrueUse flat shading on faces

Returns: bpy.types.Object linked to the active collection.

Curves Conversion

to_blender_curves

Create a Blender curves object from paths and points:

from trueform import bpy as tbpy
import trueform as tf

# Get intersection curves
paths, points = tf.intersection_curves(mesh_a, mesh_b)

# Create Blender curves object
curves_obj = tbpy.convert.to_blender_curves(paths, points, name="Curves")

Parameters:

ParameterTypeDescription
pathsOffsetBlockedArrayPaths as indices into points array
pointsnp.ndarray(N, 3) array of point coordinates
namestrName for object and curve datablock

Returns: bpy.types.Object with curve data, linked to active collection.

Low-Level Functions

These functions provide finer control over the conversion process.

extract_geometry

Extract vertices and triangulated faces from a Blender mesh:

points, faces = tbpy.convert.extract_geometry(mesh_data)
# points: (N, 3) float32 array
# faces: (M, 3) int32 array of triangle indices

make_polygons

Create a Blender mesh datablock from numpy arrays:

mesh_data = tbpy.convert.make_polygons(faces, points, name="Mesh")
# Returns bpy.types.Mesh (not linked to any object)

make_curves

Create a Blender curve datablock from paths and points:

curve_data = tbpy.convert.make_curves(paths, points, name="Curves")
# Returns bpy.types.Curve (not linked to any object)

Example: Boolean Script

Complete example of a standalone boolean script:

import trueform as tf
from trueform import bpy as tbpy
import bpy as blender_bpy

# Get selected objects
selected = blender_bpy.context.selected_objects
if len(selected) != 2:
    raise ValueError("Select exactly 2 mesh objects")

obj_a, obj_b = selected

# Convert to trueform
mesh_a = tbpy.convert.from_blender(obj_a)
mesh_b = tbpy.convert.from_blender(obj_b)

# Compute boolean difference with curves
(faces, points), labels, (paths, curve_points) = tf.boolean_difference(
    mesh_a, mesh_b, return_curves=True
)

# Create result mesh
result = tf.Mesh(faces, points)
result_obj = tbpy.convert.to_blender(result, name="Boolean_Result")

# Create intersection curves
if len(paths) > 0:
    curves_obj = tbpy.convert.to_blender_curves(paths, curve_points, name="Intersection_Curves")
    curves_obj.data.bevel_depth = 0.01  # Make curves visible

# Hide input objects
obj_a.hide_set(True)
obj_b.hide_set(True)
For cached mesh access in add-ons with live preview, see Scene. For boolean operations on tf.Mesh objects, see Cut.