Ejemplo n.º 1
0
"""
Find the closest point
on the mesh to each random point
"""
import trimesh
import numpy as np
from vtkplotter import Text, show

mesh = trimesh.load_remote(
    'https://github.com/mikedh/trimesh/raw/master/models/cycloidal.ply')
points = mesh.bounding_box_oriented.sample_volume(count=30)

# find the closest point on the mesh to each random point
closest_points, distances, triangle_id = mesh.nearest.on_surface(points)
#print('Distance from point to surface of mesh:\n{}'.format(distances))

# create a PointCloud object out of each (n,3) list of points
cloud_original = trimesh.points.PointCloud(points)
cloud_close = trimesh.points.PointCloud(closest_points)

# create a unique color for each point
cloud_colors = np.array([trimesh.visual.random_color() for i in points])

# set the colors on the random point and its nearest point to be the same
cloud_original.vertices_color = cloud_colors
cloud_close.vertices_color = cloud_colors

## create a scene containing the mesh and two sets of points
show(mesh, cloud_original, cloud_close, Text(__doc__), bg='w')
Ejemplo n.º 2
0
scene.add(dir_light)

# --- instantiate object
geometry = THREE.BoxGeometry()
material = THREE.MeshFlatMaterial()
cube = THREE.Mesh(geometry, material)
cube.scale = (.1, .1, .1)
cube.position = (0, .2, .05)
cube.keyframe_insert("position", 0)
cube.position = (0, .5, .25)
cube.keyframe_insert("position", 10)
scene.add(cube)

# --- raw mesh object
url = "https://storage.googleapis.com/tensorflow-graphics/public/spot.ply"
mesh = trimesh.load_remote(url)
faces = np.array(mesh.faces)
vertices = np.array(mesh.vertices)
# --- mesh from vertices/faces
geometry = THREE.BufferGeometry()
geometry.set_index(faces)
geometry.set_attribute("position", THREE.Float32BufferAttribute(vertices, 3))
material = THREE.MeshPhongMaterial()
spot = THREE.Mesh(geometry, material)
spot.position = (-0.14, 0.22, 0)
spot.scale = (.5, .5, .5)
spot.quaternion = mathutils.Quaternion((1, 0, 0), np.pi / 2)
scene.add(spot)

# --- Invisible ground
geometry = THREE.PlaneGeometry()