Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def callback(self, dt):
# change camera location
self.scene_widget1._angles[2] += np.deg2rad(1)
self.scene_widget1.scene.set_camera(self.scene_widget1._angles)
# change scene
if len(self.scene_widget2.scene.graph.nodes) < 100:
geom = trimesh.creation.icosphere(radius=0.01)
geom.visual.face_colors = np.random.uniform(0, 1, (3,))
geom.apply_translation(np.random.uniform(-0.3, 0.3, (3,)))
self.scene_widget2.scene.add_geometry(geom)
self.scene_widget2._draw()
# change image
image = np.random.randint(0,
255,
(self.height - 10, self.width // 3 - 10, 3),
dtype=np.uint8)
with io.BytesIO() as f:
PIL.Image.fromarray(image).save(f, format='JPEG')
self.image_widget.image = pyglet.image.load(filename=None, file=f)
parser = argparse.ArgumentParser()
parser.add_argument("--restart", action='store_true', default=False)
parser.add_argument("--ranks", type=int, nargs=3)
args = parser.parse_args()
comm = MPI.COMM_WORLD
ranks = args.ranks
domain = (16, 16, 16)
dt = 0
u = mir.Mirheo(ranks, domain, dt, comm_ptr=MPI._addressof(comm),
debug_level=3, log_filename='log', no_splash=True,
checkpoint_every = (0 if args.restart else 5))
mesh = trimesh.creation.icosphere(subdivisions=1, radius = 0.1)
udx_mesh = mir.ParticleVectors.MembraneMesh(mesh.vertices.tolist(), mesh.faces.tolist())
pv = mir.ParticleVectors.MembraneVector("pv", mass=1.0, mesh=udx_mesh)
if args.restart:
ic = mir.InitialConditions.Restart("restart/")
else:
nobjs = 10
pos = [ np.array(domain) * t for t in np.linspace(0, 1.0, nobjs) ]
Q = [ np.array([1.0, 0., 0., 0.]) for i in range(nobjs) ]
pos_q = np.concatenate((pos, Q), axis=1)
ic = mir.InitialConditions.Membrane(pos_q.tolist())
u.registerParticleVector(pv, ic)
pv_rod = mir.ParticleVectors.RodVector('rod', mass, num_segments)
ic_rod = mir.InitialConditions.Rod(com_q_rod, center_line, torsion, a0)
# ellipsoid
axes = tuple(args.axes)
com_q_ell = [[0.5 * domain[0],
0.5 * domain[1],
0.5 * domain[2] + axes[2],
1., 0, 0, 0]]
coords = np.loadtxt(args.coords).tolist()
if args.vis:
import trimesh
ell = trimesh.creation.icosphere(subdivisions=2, radius = 1.0)
for i in range(3):
ell.vertices[:,i] *= axes[i]
mesh = mir.ParticleVectors.Mesh(ell.vertices.tolist(), ell.faces.tolist())
pv_ell = mir.ParticleVectors.RigidEllipsoidVector('ellipsoid', mass, object_size=len(coords), semi_axes=axes, mesh=mesh)
else:
pv_ell = mir.ParticleVectors.RigidEllipsoidVector('ellipsoid', mass, object_size=len(coords), semi_axes=axes)
ic_ell = mir.InitialConditions.Rigid(com_q_ell, coords)
vv_ell = mir.Integrators.RigidVelocityVerlet("vv_ell")
u.registerParticleVector(pv_ell, ic_ell)
u.registerParticleVector(pv_rod, ic_rod)
u.registerIntegrator(vv_ell)
u.setIntegrator(vv_ell, pv_ell)
])
boxv_trimesh = trimesh.creation.box(extents=0.1 * np.ones(3))
boxv_vertex_colors = np.random.uniform(size=(boxv_trimesh.vertices.shape))
boxv_trimesh.visual.vertex_colors = boxv_vertex_colors
boxv_mesh = Mesh.from_trimesh(boxv_trimesh, smooth=False)
boxf_trimesh = trimesh.creation.box(extents=0.1 * np.ones(3))
boxf_face_colors = np.random.uniform(size=boxf_trimesh.faces.shape)
boxf_trimesh.visual.face_colors = boxf_face_colors
# Instanced
poses = np.tile(np.eye(4), (2,1,1))
poses[0,:3,3] = np.array([-0.1, -0.10, 0.05])
poses[1,:3,3] = np.array([-0.15, -0.10, 0.05])
boxf_mesh = Mesh.from_trimesh(boxf_trimesh, poses=poses, smooth=False)
points = trimesh.creation.icosphere(radius=0.05).vertices
point_colors = np.random.uniform(size=points.shape)
points_mesh = Mesh.from_points(points, colors=point_colors)
direc_l = DirectionalLight(color=np.ones(3), intensity=1.0)
spot_l = SpotLight(color=np.ones(3), intensity=10.0,
innerConeAngle=np.pi / 16, outerConeAngle=np.pi / 6)
cam = PerspectiveCamera(yfov=(np.pi / 3.0))
cam_pose = np.array([
[0.0, -np.sqrt(2) / 2, np.sqrt(2) / 2, 0.5],
[1.0, 0.0, 0.0, 0.0],
[0.0, np.sqrt(2) / 2, np.sqrt(2) / 2, 0.4],
[0.0, 0.0, 0.0, 1.0]
])
scene = Scene(ambient_light=np.array([0.02, 0.02, 0.02]))
vv_sol = mir.Integrators.VelocityVerlet('vv')
u.registerParticleVector(pv_sol, ic_sol)
u.registerIntegrator(vv_sol)
u.setIntegrator(vv_sol, pv_sol)
x = 0.5 * domain[0] + args.xorigin
y = 0.5 * domain[1]
z = 0.5 * domain[2]
while x > domain[0]: x -= domain[0]
com_q = [[x, y, z, 1., 0, 0, 0]]
coords = np.loadtxt(args.coords).tolist()
if args.vis:
import trimesh
ell = trimesh.creation.icosphere(subdivisions=2, radius = 1.0)
for i in range(3):
ell.vertices[:,i] *= args.axes[i]
mesh = mir.ParticleVectors.Mesh(ell.vertices.tolist(), ell.faces.tolist())
pv_rig = mir.ParticleVectors.RigidEllipsoidVector('ellipsoid', mass=1, object_size=len(coords), semi_axes=args.axes, mesh=mesh)
else:
pv_rig = mir.ParticleVectors.RigidEllipsoidVector('ellipsoid', mass=1, object_size=len(coords), semi_axes=args.axes)
ic_rig = mir.InitialConditions.Rigid(com_q=com_q, coords=coords)
vv_rig = mir.Integrators.RigidVelocityVerlet("ellvv")
u.registerParticleVector(pv=pv_rig, ic=ic_rig)
u.registerIntegrator(vv_rig)
u.setIntegrator(vv_rig, pv_rig)
bb = mir.Bouncers.Ellipsoid("bouncer", "bounce_back")
u.registerBouncer(bb)
720)))
capsule = trimesh.creation.capsule(
radius=np.random.random() * 100,
height=np.random.random() * 1000,
count=np.clip(np.random.random(2) * 720,
20,
720).astype(int))
bodies.append(cylinder)
bodies.append(capsule)
for i in range(10):
bodies.append(trimesh.creation.random_soup(
int(np.clip(np.random.random() * 1000,
20,
1000))))
bodies.append(trimesh.creation.icosphere())
bodies.append(trimesh.creation.uv_sphere())
bodies.append(trimesh.creation.icosahedron())
return np.array(bodies)
boxv_vertex_colors = np.random.uniform(size=(boxv_trimesh.vertices.shape))
boxv_trimesh.visual.vertex_colors = boxv_vertex_colors
boxv_mesh = Mesh.from_trimesh(boxv_trimesh, smooth=False)
#------------------------------------------------------------------------------
# Creating meshes with per-face colors
#------------------------------------------------------------------------------
boxf_trimesh = trimesh.creation.box(extents=0.1*np.ones(3))
boxf_face_colors = np.random.uniform(size=boxf_trimesh.faces.shape)
boxf_trimesh.visual.face_colors = boxf_face_colors
boxf_mesh = Mesh.from_trimesh(boxf_trimesh, smooth=False)
#------------------------------------------------------------------------------
# Creating meshes from point clouds
#------------------------------------------------------------------------------
points = trimesh.creation.icosphere(radius=0.05).vertices
point_colors = np.random.uniform(size=points.shape)
points_mesh = Mesh.from_points(points, colors=point_colors)
#==============================================================================
# Light creation
#==============================================================================
direc_l = DirectionalLight(color=np.ones(3), intensity=1.0)
spot_l = SpotLight(color=np.ones(3), intensity=10.0,
innerConeAngle=np.pi/16, outerConeAngle=np.pi/6)
point_l = PointLight(color=np.ones(3), intensity=10.0)
#==============================================================================
# Camera creation
#==============================================================================
import trimesh
if __name__ == '__main__':
# print logged messages
trimesh.util.attach_to_log()
# make a sphere
mesh = trimesh.creation.icosphere()
# get a scene object containing the mesh, this is equivalent to:
# scene = trimesh.scene.Scene(mesh)
scene = mesh.scene()
# run the actual render call
png = scene.save_image(resolution=[1920, 1080], visible=True)
# the PNG is just bytes data
print('rendered bytes:', len(png))
# write the render to a volume we should have docker mounted
with open('/output/render.png', 'wb') as f:
f.write(png)
boxv_vertex_colors = np.random.uniform(size=(boxv_trimesh.vertices.shape))
boxv_trimesh.visual.vertex_colors = boxv_vertex_colors
boxv_mesh = Mesh.from_trimesh(boxv_trimesh, smooth=False)
#------------------------------------------------------------------------------
# Creating meshes with per-face colors
#------------------------------------------------------------------------------
boxf_trimesh = trimesh.creation.box(extents=0.1*np.ones(3))
boxf_face_colors = np.random.uniform(size=boxf_trimesh.faces.shape)
boxf_trimesh.visual.face_colors = boxf_face_colors
boxf_mesh = Mesh.from_trimesh(boxf_trimesh, smooth=False)
#------------------------------------------------------------------------------
# Creating meshes from point clouds
#------------------------------------------------------------------------------
points = trimesh.creation.icosphere(radius=0.05).vertices
point_colors = np.random.uniform(size=points.shape)
points_mesh = Mesh.from_points(points, colors=point_colors)
#==============================================================================
# Light creation
#==============================================================================
direc_l = DirectionalLight(color=np.ones(3), intensity=1.0)
spot_l = SpotLight(color=np.ones(3), intensity=10.0,
innerConeAngle=np.pi/16, outerConeAngle=np.pi/6)
point_l = PointLight(color=np.ones(3), intensity=10.0)
#==============================================================================
# Camera creation
#==============================================================================