ddg.blender package

Submodules

Module contents

ddg.blender.convert(convertible, name, /, material=None, collection=None, bounding_box=(inf, inf, inf), curve_sampling=(100, 0.1), surface_sampling=(30, 0.1), subspace_size=100, curve_radius=0.015, point_radius=0.05, icosphere_subdivision_steps=3)[source]

Convert pyddg objects, points, curves and meshes to Blender objects.

Parameters:
convertible

This must be an instance of:

- `ddg.geometry.Subspace` of dimension <= 2
- `ddg.geometry.Quadric` of dimension <= 2
- `ddg.geometry.QuadricIntersection` of dimension_complex == 1
- `ddg.geometry.spheres.QuadricSphere` of dimension <= 2
- `ddg.indexedfaceset.IndexedFaceSet` with coordinate attribute "co"
- `ddg.halfedge.Surface` with coordinate attribute "co"
- `ddg.nets.SmoothCurve`
- `ddg.nets.SmoothNet`
- `ddg.nets.DiscreteCurve`
- `ddg.nets.DiscreteNet`
- `ddg.nets.PointNet`
- `ddg.nets.EmptyNet`
- `ddg.nets.NetCollection` of smooth or discrete nets of the same dimension
- `ddg.arrays.Points`
- `ddg.arrays.Curve`
- `ddg.arrays.CurveList`
- `ddg.arrays.Mesh`
namestr

Sets bobj.name and bobj.data.name to this value.

materialstr or bpy.types.Material (default=None)

The resulting Blender object is assigned this material if it isn’t None.

collectionbpy.types.Collection (default=None)

The resulting Blender object is linked to this collection if it isn’t None.

bounding_boxarray_like of shape (3,) of type float

(default=(np.inf, np.inf, np.inf)) Bounding box of the resulting blender object.

curve_samplingtuple of an int and a float

(default=_default_curve_sampling) Determines the sample number and stepsize for curves

surface_samplingtuple of an int and a float

(default=_default_surface_sampling) Determines the sample number and stepsize for surfaces

subspace_sizefloat

(default=_default_subspace_size) Determines the size of subspaces

curve_radiusfloat (default=_default_curve_radius)

Radius for curves, set as bobj.data.bevel_depth

point_radiusfloat (default=_default_point_radius)

Radius of the sphere representing points

icosphere_subdivision_stepsint (default=_default_icosphere_subdivision_steps)

Number of subdivision steps for the icosphere representing points

Returns:
bpy.types.Object

The data attribute is of type bpy.types.Curve if convertible represents a curve curve and bpy.types.Mesh represents a point, points or a mesh.

Examples

>>> import bpy
>>> import numpy as np
>>> import ddg

To display a 2-dimensional subspace

>>> plane = ddg.geometry.subspace_from_affine_points(
...     (0, 0, 0), (1, 0, 0), (0, 1, 0)
... )
>>> ddg.blender.convert(plane, "plane")
bpy.data.objects['plane']

To display a quadric

>>> two_sheeted_hyperboloid = ddg.geometry.Quadric(np.diag([1, 1, -1, 1]))
>>> ddg.blender.convert(two_sheeted_hyperboloid, "two sheeted hyperboloid")
bpy.data.objects['two sheeted hyperboloid']

To display a curve represented by a discrete curve

>>> discrete_curve = ddg.nets.DiscreteCurve(
...     lambda t: (np.cos(t), np.sin(t), t), (-10, 10)
... )
>>> ddg.blender.convert(discrete_curve, "discrete_curve")
bpy.data.objects['discrete_curve']

To display a surface represented by a discrete net

>>> discrete_net = ddg.nets.DiscreteNet(
...     lambda u, v: (u, v, np.cos(v)), ((-10, 10), (-10, 10))
... )
>>> ddg.blender.convert(discrete_net, "discrete_net")
bpy.data.objects['discrete_net']

To create a curve object manually

>>> curve = ddg.arrays.Curve([(0, 0, 0), (1, 0, 0)], False)
>>> curve_object = ddg.blender.convert(curve, "Curve")
>>> type(curve_object.data)
<class 'bpy.types.Curve'>
>>> curve_object.data.name
'Curve'
>>> curve_object.name
'Curve'

To create a mesh object manually

>>> mesh = ddg.arrays.Mesh([(0, 0, 0), (1, 0, 0), (0, 1, 0)], [(0, 1, 2)])
>>> mesh_object = ddg.blender.convert(mesh, "Triangle")
>>> type(mesh_object.data)
<class 'bpy_types.Mesh'>
>>> mesh_object.data.name
'Triangle'
>>> mesh_object.name
'Triangle'

To create non-manifold meshes manually

>>> non_manifold_edges = np.array([(0, 3)])
>>> non_manifold_mesh = ddg.arrays.Mesh(
...     [(0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0)],
...     [(0, 1, 2)],
...     non_manifold_edges,
... )
>>> non_manifold_mesh_object = ddg.blender.convert(
...     non_manifold_mesh, "Triangle with extra edge"
... )
>>> [tuple(e.vertices) for e in non_manifold_mesh_object.data.edges]
[(1, 2), (0, 1), (0, 2), (0, 3)]

It is usually unnecessary to create the input arrays manually. The functions in ddg.arrays convert most ddg objects into suitable input for ddg.blender.convert.

ddg.blender.convert_qsic(intersection_object, name, material=None, collection=None, bounding_box=(inf, inf, inf), sampling=(100, 0.1), subspace_size=100, curve_radius=0.015, point_radius=0.05, icosphere_subdivision_steps=3)[source]

Converts a ddg.geometry.QuadricIntersection object into a blender object containing the intersection curve of the two quadrics

Parameters:
intersection_objectddg.geometry.QuadricIntersection

The intersection to depict with attributes Q1, Q2 representing the quadrics that span it

namestr

Sets bobj.name and bobj.data.name to this value.

materialstr or bpy.types.Material (default=None)

The resulting Blender object is assigned this material if it isn’t None.

collectionbpy.types.Collection (default=None)

The resulting Blender object is linked to this collection if it isn’t None.

bounding_boxarray_like of shape (3,) of type float

(default=(np.inf, np.inf, np.inf)) Bounding box of the resulting blender object.

samplingtuple of an int and a float

(default=_default_curve_sampling) Determines the sample number and stepsize for quadrics used to intersect

subspace_sizefloat

(default=_default_subspace_size) Determines the size of subspaces

curve_radiusfloat (default=_default_curve_radius)

Sets the bevel depth of the intersection curve to this value

point_radiusfloat (default=_default_point_radius)

Radius of the sphere representing points

icosphere_subdivision_stepsint (default=_default_icosphere_subdivision_steps)

Number of subdivision steps for the icosphere representing points

Returns:
bpy.types.Object
ddg.blender.edges(convertible, name, /, radius=0.015, material=None, collection=None, curve_sampling=(100, 0.1), surface_sampling=(30, 0.1), subspace_size=100)[source]

Convert mesh to edges as Blender objects.

Parameters:
convertible

Object convertible to a ddg.array.Mesh

namestr

Sets bobj.name and bobj.data.name to this value.

radiusfloat (default=_default_curve_radius)

Sets the radius of the edges as bobj.data.bevel_depth

materialstr or bpy.types.Material (default=None)

The resulting Blender object is assigned this material if it isn’t None.

collectionbpy.types.Collection (default=None)

The resulting Blender object is linked to this collection if it isn’t None.

curve_samplingtuple of an int and a float

(default=_default_curve_sampling) Determines the sample number and stepsize for curves

surface_samplingtuple of an int and a float

(default=_default_surface_sampling) Determines the sample number and stepsize for surfaces

subspace_sizefloat

(default=_default_subspace_size) Determines the size of subspaces

Returns:
bpy.types.Object

The data attribute is of type bpy.types.Mesh` represents the edges.

Examples

>>> import bpy
>>> import numpy as np
>>> import ddg
>>> mesh = ddg.arrays.convert(ddg.halfedge.dodecahedron())
>>> bobj = ddg.blender.edges(mesh, "Edges of Dodecahedron", radius=0.1)
>>> bobj.data.bevel_depth
0.1...
ddg.blender.scatter(convertible, point_mesh, name, /, material=None, collection=None, curve_sampling=(100, 0.1), surface_sampling=(30, 0.1), subspace_size=100)[source]

Put a mesh at each vertex position of convertible.

Parameters:
convertible

This must be an instance of:

- `ddg.geometry.Subspace` of dimension <= 2
- `ddg.geometry.Quadric` of dimension <= 2
- `ddg.geometry.spheres.QuadricSphere` of dimension <= 2
- `ddg.indexedfaceset.IndexedFaceSet` with coordinate attribute "co"
- `ddg.halfedge.Surface` with coordinate attribute "co"
- `ddg.nets.SmoothCurve`
- `ddg.nets.SmoothNet`
- `ddg.nets.DiscreteCurve`
- `ddg.nets.DiscreteNet`
- `ddg.nets.PointNet`
- `ddg.nets.EmptyNet`
- `ddg.nets.NetCollection` of smooth or discrete nets of the same dimension
- `ddg.arrays.Points`
- `ddg.arrays.Curve`
- `ddg.arrays.CurveList`
- `ddg.arrays.Mesh`
point_mesh: ddg.arrays.Mesh

A mesh that will be used for each point.

namestr

Sets bobj.name and bobj.data.name to this value.

materialstr or bpy.types.Material (default=None)

The resulting Blender object is assigned this material if it isn’t None.

collectionbpy.types.Collection (default=None)

The resulting Blender object is linked to this collection if it isn’t None.

curve_samplingtuple of an int and a float

(default=_default_curve_sampling) Determines the sample number and stepsize for curves

surface_samplingtuple of an int and a float

(default=_default_surface_sampling) Determines the sample number and stepsize for surfaces

subspace_sizefloat

(default=_default_subspace_size) Determines the size of subspaces

Returns:
bpy.types.Object

The data attribute is of type bpy.types.Mesh` represents a point or points.

Raises:
TypeError

If convertible has the wrong type

ValueError

If convertible cannot be converted to point/points.

Examples

>>> import bpy
>>> import numpy as np
>>> import ddg
>>> points = ddg.arrays.Points([(1, 2, 3), (3, 4, 5)])
>>> cube = ddg.arrays.Mesh(
...     [
...         (0, 0, 0),
...         (0, 0, 1),
...         (0, 1, 0),
...         (0, 1, 1),
...         (1, 0, 0),
...         (1, 0, 1),
...         (1, 1, 0),
...         (1, 1, 1),
...     ],
...     [
...         (0, 1, 2, 3),
...         (4, 5, 6, 7),
...         (0, 1, 4, 5),
...         (2, 3, 6, 7),
...         (0, 2, 4, 6),
...         (1, 3, 5, 7),
...     ],
... )
>>> ddg.blender.scatter(points, cube, "cube_points")
bpy.data.objects['cube_points']
ddg.blender.vertices(convertible, name, /, radius=0.05, icosphere_subdivision_steps=3, material=None, collection=None, curve_sampling=(100, 0.1), surface_sampling=(30, 0.1), subspace_size=100)[source]

Convert pyddg objects and points to points as Blender objects.

Parameters:
convertible

This must be an instance of:

- `ddg.geometry.Subspace` of dimension <= 2
- `ddg.geometry.Quadric` of dimension <= 2
- `ddg.geometry.spheres.QuadricSphere` of dimension <= 2
- `ddg.indexedfaceset.IndexedFaceSet` with coordinate attribute "co"
- `ddg.halfedge.Surface` with coordinate attribute "co"
- `ddg.nets.SmoothCurve`
- `ddg.nets.SmoothNet`
- `ddg.nets.DiscreteCurve`
- `ddg.nets.DiscreteNet`
- `ddg.nets.PointNet`
- `ddg.nets.EmptyNet`
- `ddg.nets.NetCollection` of smooth or discrete nets of the same dimension
- `ddg.arrays.Points`
- `ddg.arrays.Curve`
- `ddg.arrays.CurveList`
- `ddg.arrays.Mesh`
namestr

Sets bobj.name and bobj.data.name to this value.

radius: float (default=_default_point_radius)

Radius of the icosphere mesh.

icosphere_subdivision_steps: int (default=_default_icosphere_subdivision_steps)

Subdivision steps for the icosphere mesh.

materialstr or bpy.types.Material (default=None)

The resulting Blender object is assigned this material if it isn’t None.

collectionbpy.types.Collection (default=None)

The resulting Blender object is linked to this collection if it isn’t None.

curve_samplingtuple of an int and a float

(default=_default_curve_sampling) Determines the sample number and stepsize for curves

surface_samplingtuple of an int and a float

(default=_default_surface_sampling) Determines the sample number and stepsize for surfaces

subspace_sizefloat

(default=_default_subspace_size) Determines the size of subspaces

Returns:
bpy.types.Object

The data attribute is of type bpy.types.Mesh` represents a point or points.

Raises:
TypeError

If convertible has the wrong type

ValueError

If convertible cannot be converted to point/points.

Examples

>>> import bpy
>>> import numpy as np
>>> import ddg
>>> point = ddg.arrays.Points((1, 2, 3))
>>> ddg.blender.vertices(point, "one_point")
bpy.data.objects['one_point']
>>> points = ddg.arrays.Points([(1, 2, 3), (3, 4, 5)])
>>> ddg.blender.vertices(points, "two_points")
bpy.data.objects['two_points']

To change the radius of the visualized points

>>> ddg.blender.vertices(points, "radius_points", radius=1.0)
bpy.data.objects['radius_points']