Read mesh
In [1]:
Copied!
from imodmodel import ImodModel
from imodmodel import ImodModel
In [2]:
Copied!
model = ImodModel.from_file("../../tests/test_data/meshed_contour_example.mod")
model = ImodModel.from_file("../../tests/test_data/meshed_contour_example.mod")
Render with trimesh¶
In [3]:
Copied!
import trimesh
scene = trimesh.Scene()
for mesh in model.objects[0].meshes:
scene.add_geometry(trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.indices))
scene.show()
import trimesh
scene = trimesh.Scene()
for mesh in model.objects[0].meshes:
scene.add_geometry(trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.indices))
scene.show()
Out[3]:
In [11]:
Copied!
model.objects[0].meshes[0].vertices[1]
model.objects[0].meshes[0].vertices[1]
Out[11]:
array([525.01641846, 968.3092041 , -4.66856098])
In [10]:
Copied!
model.objects[0].meshes[0].normals[0]
model.objects[0].meshes[0].normals[0]
Out[10]:
array([-2.15655327, -0.33435941, -4.25762367])
Render using Blender/MolecularNodes¶
In [ ]:
Copied!
import molecularnodes as mn
import databpy
import bpy
mn.register()
mn.template.install()
can = mn.Canvas()
can.scene_reset()
obj = databpy.create_object(vertices=model.objects[0].meshes[0].vertices/10,faces=model.objects[0].meshes[0].indices)
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.shade_smooth()
can.frame_object(obj)
can.render_engine = "EEVEE"
can.resolution = (960, 540)
can.snapshot()
import molecularnodes as mn
import databpy
import bpy
mn.register()
mn.template.install()
can = mn.Canvas()
can.scene_reset()
obj = databpy.create_object(vertices=model.objects[0].meshes[0].vertices/10,faces=model.objects[0].meshes[0].indices)
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.shade_smooth()
can.frame_object(obj)
can.render_engine = "EEVEE"
can.resolution = (960, 540)
can.snapshot()
/home/elferich/Documents/imodmodel/.venv/lib64/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm
Fra:1 Mem:61.75M (Peak 70.29M) | Time:00:01.37 | Rendering 1 / 64 samples Fra:1 Mem:61.75M (Peak 70.29M) | Time:00:06.23 | Rendering 25 / 64 samples Fra:1 Mem:61.75M (Peak 70.29M) | Time:00:11.66 | Rendering 50 / 64 samples Fra:1 Mem:61.75M (Peak 70.29M) | Time:00:14.72 | Rendering 64 / 64 samples Saved: '/tmp/tmpr0kdw5w1/snapshot.png' Time: 00:14.91 (Saving: 00:00.17)
In [ ]:
Copied!