I am trying to make random 3d blob objects using pyvista. First, I wrote a code as following ,
import os
import sys
import numpy as np
import cv2
import pyvista as pv
import trimesh as tm
import math
import random as rnd
smooth_iter = rnd.randint(50,200)
num_blob = rnd.randint(5,20)
xyz_list = []
rad_list=[]
rad_list2=[]
p = pv.Plotter(shape=(1,1))
g = pv.PolyData()
pi = 3.141592
for i in range(num_blob):
x= rnd.uniform(-1.5,1.5)
y= rnd.uniform(-1.5,1.5)
z= rnd.uniform(-1.5,1.5)
r1= rnd.uniform(0.3,2.5)
r2= rnd.uniform(r1-0.2,r1+0.2)
r3= rnd.uniform(r1-0.2,r1+0.2)
th= rnd.uniform(-pi,pi)
ps= rnd.uniform(-pi,pi)
py= rnd.uniform(-pi,pi)
xyz_list.append((x,y,z))
rad_list.append((r1,r2,r3))
ell = pv.PolyData(pv.ParametricEllipsoid(r1, r2, r3))
ell.translate([x,y,z])
ell.rotate_x(th)
ell.rotate_y(ps)
ell.rotate_z(py)
p.add_mesh(ell)
print(xyz_list)
print(rad_list)
p.show()
This code showed me the plotted result of overlapped random ellipsoids. But since the resulting p is pv.Plotter, not pv.Polydata, so I could not save/smoothing/edit the result. And I could not yet find what to do to generate custom edittable 3d object in pv.Polydata. Which function should I use or is there any other way to achieve my goal, such as using trimesh?