I’m really excited to start learning COMPAS and though the best way to get my head around was to port a couple of sketches I did in Processing.
To get me started I would like to know how to draw some points and lines in Blender, play with it, connect them, etc…
I see COMPAS has different classes named compas_blender.utilities.draw_points, compas_blender.utilities.draw_pointcloud or VolMeshArtist.draw_points. Could someone kindly explain:
if they are appropriate to draw points (in Blender)
how they differ
how to use them
I tried the following (extracting vertices from a .obj and display them as points):
import compas
from compas_blender import utilities
from compas_blender.artists import NetworkArtist
from compas.datastructures import Network
# make a network from sample data
network = Network.from_obj(compas.get("C:/Users/solub/Desktop/rocket.obj"))
xyz = network.get_vertices_attributes(('x', 'y', 'z'))
utilities.draw_points(d)
… but got a AttributeError: 'int' object has no attribute 'get' . Does this mean I have to store the vertices in a dictionnary or convert the list array to another data type ?
If you already have your geometry in a Datastructure like the Network in your example, it would be easiest to draw vertices using the NetworkArtist:
import compas
from compas.datastructures import Network
from compas_blender.artists import NetworkArtist
from compas_blender.utilities import clear_layer
network = Network.from_obj(compas.get('grid_irregular.obj'))
artist = NetworkArtist(network=network, layer='Collection')
clear_layer(layer='Collection')
artist.draw_vertices(radius=0.1)
artist.draw_vertexlabels()
Blender doesnt have a Point type of object, so I plot the closest thing I could find, an Empty object, which you can change its size with the radius argument. The code above would produce the following:
You are on the right track with the draw_points() function, you need to give it a list of point dict data, for example:
import compas
from compas.datastructures import Network
from compas_blender.utilities import clear_layer
from compas_blender.utilities import draw_points
network = Network.from_obj(compas.get('grid_irregular.obj'))
xyz = network.get_vertices_attributes('xyz')
clear_layer(layer='Collection')
points = [{'pos': i, 'radius': 0.1} for i in xyz]
draw_points(points=points)
If you use draw_pointcloud(points=points) instead (without radius which isn’t needed), you will get a bunch of Mesh objects with just one vertex, which will plot quite efficiently even for many thousands of points as Blender renders meshes efficiently. Your points then appear as a single vertex Mesh for each point.