本文整理汇总了Python中trimesh.load方法的典型用法代码示例。如果您正苦于以下问题:Python trimesh.load方法的具体用法?Python trimesh.load怎么用?Python trimesh.load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trimesh
的用法示例。
在下文中一共展示了trimesh.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def load(self, model_path, idx):
file_path = os.path.join(model_path, self.file_name)
pointcloud_dict = np.load(file_path)
points = pointcloud_dict['points'].astype(np.float32)
normals = pointcloud_dict['normals'].astype(np.float32)
data = {
None: points.T,
'normals': normals.T,
}
if self.with_transforms:
data['loc'] = pointcloud_dict['loc'].astype(np.float32)
data['scale'] = pointcloud_dict['scale'].astype(np.float32)
if self.transform is not None:
data = self.transform(data)
return data
示例2: load
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def load(self, model_path, idx, c_idx=None, start_idx=0, **kwargs):
''' Loads the points subsequence field.
Args:
model_path (str): path to model
idx (int): ID of data point
category (int): index of category
start_idx (int): id of sequence start
'''
files = self.load_files(model_path, start_idx)
# Load loc and scale from t_0
points_dict = np.load(files[0])
loc0 = points_dict['loc'].astype(np.float32)
scale0 = points_dict['scale'].astype(np.float32)
if self.all_steps:
data = self.load_all_steps(files, points_dict, loc0, scale0)
else:
data = self.load_single_step(files, points_dict, loc0, scale0)
if self.transform is not None:
data = self.transform(data)
return data
示例3: load_and_scale_mesh
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def load_and_scale_mesh(mesh_path, loc=None, scale=None):
''' Loads and scales a mesh.
Args:
mesh_path (str): mesh path
loc (tuple): location
scale (float): scaling factor
'''
mesh = trimesh.load(mesh_path, process=False)
# Compute location and scale
if loc is None or scale is None:
bbox = mesh.bounding_box.bounds
loc = (bbox[0] + bbox[1]) / 2
scale = (bbox[1] - bbox[0]).max()
mesh.apply_translation(-loc)
mesh.apply_scale(1/scale)
return loc, scale, mesh
示例4: default_scene
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def default_scene(obj_file, width=640, height=480, use_distortion=True):
mesh_trimesh = trimesh.load(obj_file)
mesh = ColoredTriMesh.from_trimesh(mesh_trimesh)
# rot = Rotation.from_euler("xyz", [180, 0, 0], degrees=True).as_matrix()
rot = Rotation.from_euler("xyz", [180, 0, 0], degrees=True).as_matrix()
camera = differentiable_renderer.default_camera(
width, height, 80, mesh.vertices, rot
)
if use_distortion:
camera.distortion = np.array([-0.5, 0.5, 0, 0, 0])
bg_color = np.array((0.8, 0.8, 0.8))
scene = differentiable_renderer.Scene3D()
light_ambient = 0
light_directional = 0.3 * np.array([1, -1, 0])
scene.set_light(light_directional=light_directional, light_ambient=light_ambient)
scene.set_mesh(mesh)
background_image = np.ones((height, width, 3)) * bg_color
scene.set_background(background_image)
return scene, camera
示例5: visual_mesh
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def visual_mesh(self, mesh):
"""Setter of visual mesh
Parameters
----------
mesh : None, trimesh.Trimesh, sequence of trimesh.Trimesh, or str
A set of visual meshes for the link in the link frame.
"""
if not (mesh is None
or isinstance(mesh, trimesh.Trimesh)
or (isinstance(mesh, collections.Sequence)
and all(isinstance(m, trimesh.Trimesh) for m in mesh))
or isinstance(mesh, str)):
raise TypeError(
'mesh must be None, trimesh.Trimesh, sequence of '
'trimesh.Trimesh, or path of mesh file, but got: {}'.format(
type(mesh)))
if isinstance(mesh, str):
mesh = trimesh.load(mesh)
self._visual_mesh = mesh
示例6: load
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def load(self, model_path, idx, category):
''' Loads the data point.
Args:
model_path (str): path to model
idx (int): ID of data point
category (int): index of category
'''
file_path = os.path.join(model_path, self.file_name)
with open(file_path, 'rb') as f:
voxels = binvox_rw.read_as_3d_array(f)
voxels = voxels.data.astype(np.float32)
if self.transform is not None:
voxels = self.transform(voxels)
return voxels
示例7: main
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def main(argv):
if len(argv) > 1:
raise app.UsageError('Too many command-line arguments.')
if not FLAGS.input_mesh:
raise IOError('--input_mesh must be specified.')
if not FLAGS.output_ply:
raise IOError('--output_ply must be specified.')
mesh = trimesh.load(FLAGS.input_mesh)
mesh = normalize_mesh(mesh)
sample_pts, sample_normals = sample_mesh(mesh)
print('Computed {} samples from mesh.'.format(sample_pts.shape[0]))
print('Writing sampled points to {}'.format(FLAGS.output_ply))
pu.write_point_ply(FLAGS.output_ply, sample_pts, sample_normals)
示例8: load
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def load(file_obj, file_type=None, **kwargs):
"""Loads a triangle mesh from the given GFile/file path.
Args:
file_obj: A tf.io.gfile.GFile object or a string specifying the mesh file
path.
file_type: A string specifying the type of the file (e.g. 'obj', 'stl'). If
not specified the file_type will be inferred from the file name.
**kwargs: Additional arguments that should be passed to trimesh.load().
Returns:
A trimesh.Trimesh or trimesh.Scene.
"""
if isinstance(file_obj, str):
with tf.io.gfile.GFile(file_obj, 'r') as f:
if file_type is None:
file_type = trimesh.util.split_extension(file_obj)
return trimesh.load(
file_obj=f,
file_type=file_type,
resolver=GFileResolver(file_obj),
**kwargs)
if trimesh.util.is_file(file_obj):
if not hasattr(file_obj, 'name') or not file_obj.name:
raise ValueError(
'file_obj must have attribute "name". Try passing the file name instead.'
)
if file_type is None:
file_type = trimesh.util.split_extension(file_obj.name)
return trimesh.load(
file_obj=file_obj,
file_type=file_type,
resolver=GFileResolver(file_obj.name),
**kwargs)
raise ValueError('file_obj should be either a file object or a string')
示例9: get_contact_info
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def get_contact_info(
hand_vert,
hand_faces,
obj_vert,
obj_faces,
result_close=None,
result_distance=None,
contact_thresh=25,
):
obj_mesh_dict = {"vertices": obj_vert, "faces": obj_faces}
obj_mesh = trimesh.load(obj_mesh_dict)
trimesh.repair.fix_normals(obj_mesh)
# hand_mesh_dict = {'vertices': hand_vert, 'faces': hand_faces}
# hand_mesh = trimesh.load(hand_mesh_dict)
# trimesh.repair.fix_normals(hand_mesh)
if result_close is None or result_distance is None:
result_close, result_distance, _ = trimesh.proximity.closest_point(
obj_mesh, hand_vert
)
penetrating, exterior = mesh_vert_int_exts(
obj_mesh, hand_vert, result_distance
)
below_dist = result_distance < contact_thresh
missed_mask = below_dist & exterior
return result_close, missed_mask, penetrating
示例10: load_objects
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def load_objects(
obj_root='/sequoia/data2/dataset/handatasets/fhb/Object_models',
object_names=['juice']):
all_models = OrderedDict()
for obj_name in object_names:
import trimesh
obj_path = os.path.join(obj_root, '{}_model'.format(obj_name),
'{}_model.ply'.format(obj_name))
mesh = trimesh.load(obj_path)
all_models[obj_name] = {
'verts': np.array(mesh.vertices),
'faces': np.array(mesh.faces)
}
return all_models
示例11: load_single_step
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def load_single_step(self, files, points_dict, loc0, scale0):
''' Loads data for a single step.
Args:
files (list): list of files
points_dict (dict): points dictionary for first step of sequence
loc0 (tuple): location of first time step mesh
scale0 (float): scale of first time step mesh
'''
if self.fixed_time_step is None:
# Random time step
time_step = np.random.choice(self.seq_len)
else:
time_step = int(self.fixed_time_step)
if time_step != 0:
points_dict = np.load(files[time_step])
# Load points
points = points_dict['points'].astype(np.float32)
occupancies = points_dict['occupancies']
if self.unpackbits:
occupancies = np.unpackbits(occupancies)[:points.shape[0]]
occupancies = occupancies.astype(np.float32)
loc = points_dict['loc'].astype(np.float32)
scale = points_dict['scale'].astype(np.float32)
# Transform to loc0, scale0
points = (loc + scale * points - loc0) / scale0
if self.seq_len > 1:
time = np.array(
time_step / (self.seq_len - 1), dtype=np.float32)
else:
time = np.array([1], dtype=np.float32)
data = {
None: points,
'occ': occupancies,
'time': time,
}
return data
示例12: load_single_file
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def load_single_file(self, file_path):
''' Loads a single file.
Args:
file_path (str): file path
'''
pointcloud_dict = np.load(file_path)
points = pointcloud_dict['points'].astype(np.float32)
loc = pointcloud_dict['loc'].astype(np.float32)
scale = pointcloud_dict['scale'].astype(np.float32)
return points, loc, scale
示例13: meshlab_poisson
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def meshlab_poisson(pointcloud):
r''' Runs the meshlab ball pivoting algorithm.
Args:
pointcloud (numpy tensor): input point cloud
'''
with tempfile.TemporaryDirectory() as tmpdir:
script_path = os.path.join(tmpdir, 'script.mlx')
input_path = os.path.join(tmpdir, 'input.ply')
output_path = os.path.join(tmpdir, 'out.off')
# Write script
with open(script_path, 'w') as f:
f.write(FILTER_SCRIPT_RECONSTRUCTION)
# Write pointcloud
export_pointcloud(pointcloud, input_path, as_text=False)
# Export
env = os.environ
subprocess.Popen('meshlabserver -i ' + input_path + ' -o '
+ output_path + ' -s ' + script_path,
env=env, cwd=os.getcwd(), shell=True,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
).wait()
mesh = trimesh.load(output_path, process=False)
return mesh
示例14: getVolumeFromOFF
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def getVolumeFromOFF(path, sideLen=32):
mesh = trimesh.load(path)
volume = trimesh.voxel.Voxel(mesh, 0.5).raw
(x, y, z) = map(float, volume.shape)
volume = nd.zoom(volume.astype(float),
(sideLen/x, sideLen/y, sideLen/z),
order=1,
mode='nearest')
volume[np.nonzero(volume)] = 1.0
return volume.astype(np.bool)
示例15: load
# 需要导入模块: import trimesh [as 别名]
# 或者: from trimesh import load [as 别名]
def load(self):
path = self.find_scene(self.meta.path)
if not path:
raise ValueError("Scene '{}' not found".format(self.meta.path))
file_obj = str(path)
if file_obj.endswith('.gz'):
file_obj = gzip.GzipFile(file_obj)
stl_mesh = trimesh.load(file_obj, file_type='stl')
scene = Scene(self.meta.resolved_path)
scene_mesh = Mesh("mesh")
scene_mesh.material = Material("default")
vao = VAO("mesh", mode=moderngl.TRIANGLES)
vao.buffer(numpy.array(stl_mesh.vertices, dtype='f4'), '3f', ['in_position'])
vao.buffer(numpy.array(stl_mesh.vertex_normals, dtype='f4'), '3f', ['in_normal'])
vao.index_buffer(numpy.array(stl_mesh.faces, dtype='u4'))
scene_mesh.vao = vao
scene_mesh.add_attribute('POSITION', 'in_position', 3)
scene_mesh.add_attribute('NORMAL', 'in_normal', 3)
scene.meshes.append(scene_mesh)
scene.root_nodes.append(Node(mesh=scene_mesh))
scene.prepare()
return scene