I have seen a few posts about rendering gemstones here and here, but I need to replicate this task purely from a python script, without using the GUI at all.
Following this example, I have managed to create a data object and attach to it a mesh built from a list of vertices.
import bpy
def point_cloud(ob_name, coords, edges=[], faces=[]):
# Create new mesh and a new object
me = bpy.data.meshes.new(ob_name + 'Mesh')
ob = bpy.data.objects.new(ob_name, me)
# Make a mesh from a list of vertices/edges/faces
me.from_pydata(coords, edges, faces)
me.validate()
# Display name and update the mesh
ob.show_name = True
me.update()
return ob
Create the object
vertices = [(0,0,0),(1,1,1),(1,-1,1),(-1,1,1),(-1,-1,1)]
edges = [(0,1),(0,2),(0,3),(0,4),(1,2),(1,3),(2,4),(3,4)]
faces = [(0,1,2),(0,1,3),(0,2,4),(0,3,4),(1,2,4,3)]
gemstone = point_cloud('pyramid',vertices,edges,faces)
Link object to the active collection
bpy.context.collection.objects.link(gemstone)
Running this creates a pyramidal object (AKA a simple gemstone) like I intend. However, the object is an opaque and grey shape without any material properties.
Now, I would like to render this object in a transparent material with a specified refractive index. Something like
#Pseudocode - does not actually work
gemstone.set_material(mode='Transparent', refractive_index=1.54)
gemstone.render()
How can I accomplish this in a python script? I see there are a few material operations in the documentation, but there are no guidelines on how to actually use them.
Related: I have never used blender before, but I am trying to learn it because I saw it had a python scripting interface. My intention is to render thousands of gemstone variations in order to identify the optimal design. I need to quickly load and render gem polyhedrons from vertex, edge, and face data (ideally less than 1s of render time per stone). I am not interested in high resolution or photorealistic effects, so I don't need to model dispersion, basic refraction is fine. If there is a package other than blender that is able to do this more effectively, then I'd also appreciate recommendations. Thanks.
