API

A few utility functions are re-exported at PCV module level to aid with general script or addon development. If there is problem with function input, error will be logged to console, but all exceptions will be handled to not interrupt main script from running.

API Lorenz
Display results of a simple script executed from Text Editor
draw(data=None, *, name=None, matrix=None, is_debug=False, )
  • Draw data with pcv
    • data: dict with vs, ns, cs and scalars keys (all optional except vs) with numpy arrays as values, all of them must have the same length, shapes of arrays must be: vs and ns (n, 3), cs (n, 4) or (n, 3) and scalars must be a structured array (n, ). if None is passed instead of a dict, empty arrays will be used, nothing will be drawn, but pcv will be initialized
    • name: string, assumes object is in scene, if not raises error, if None is passed, pcv_debug object will be created if needed and drawing mode is set to debug (is_debug=True) (i.e. bigger points, drawn on top, normals visible if exists, fast nav disabled..)
    • matrix: if not None, target object will get assigned this matrix to matrix_world, if not instance of Matrix, it will be converted (if possible, if not, will be ignored)
    • is_debug: if True, some for-better-visibility properties will be adjusted, see source for details, also set to True when no object name is passed (and pcv_debug is used instead)
properties(*, name=None, )
  • Get property group with pcv properties
    • it is the same as bpy.context.scene.objects[name].point_cloud_visualizer
    • name: string, assumes object is in scene, if not raises error. if None is passed, pcv_debug name will be used
erase(*, name=None, )
  • Stop drawing and unload data
    • if name is None, pcv_debug name will be used, if such object is found and is EMPTY type, will be removed
    • name: string, assumes object is in scene, if not raises error. if None is passed, pcv_debug name will be used

Basic Example

import numpy as np
import point_cloud_visualizer as pcv
# will create `pcv_debug` empty object in scene, to use existing object pass `name="OBJECT_NAME"`
pcv.draw(data={
    'vs': np.array([(0, 0, 0), (0.1, 0, 0), (0.2, 0, 0)], dtype=np.float32, ),
}, )

Full Example

import bpy
import numpy as np
import point_cloud_visualizer as pcv
from mathutils import Matrix
# add an empty object
o = bpy.data.objects.new("points", None)
bpy.context.view_layer.active_layer_collection.collection.objects.link(o)
# craft some object level transformation
m = Matrix.LocRotScale((0.1, 0.2, 0.3), Matrix.Rotation(np.pi / 4, 3, 'X'), (1, 1, 1))
# scalars got to be a structured array with named fields
sc = np.empty(3, dtype=[('intensity', np.float32, ), ])
sc['intensity'] = np.linspace(0, 1.0, 3)
pcv.draw(name='points', data={
    'vs': np.array([(0, 0, 0), (0.1, 0, 0), (0.2, 0, 0)], dtype=np.float32, ),
    'ns': np.array([(-1, 0, 0), (0, 1, 0), (0, 0, 1)], dtype=np.float32, ),
    'cs': np.array([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)], dtype=np.float32, ),
    'scalars': sc,
}, matrix=m, is_debug=True, )
API Frustum
Interactive drawing of results from running modal operator

Context Manager

Context manager for running PCV operators from custom scripts

Will make sure that name object exists, has loaded points in cache and drawn on screen (if not, tries to load linked file if possible), object is selected and active and operators are called with proper context.temp_override (i.e. 3d viewport exists, if not it will swap area, this is especially important when running render operator). On exit it will restore selection and original area (if has been swapped before).

Example (assuming there is an object named points in scene with linked file and (maybe) loaded points):

import bpy
import point_cloud_visualizer as pcv
with pcv.common.PCVOperatorContextManager('points'):
    bpy.ops.point_cloud_visualizer.render()