def convert_to_stl(obj, savename, scale_ratio=1, pos=np.zeros(3), rotmat=np.eye(3)): """ :param obj: trimesh or file path :param savename: :return: author: weiwei date: 20201207 """ trimesh = trm.load(obj) tmptrimesh = scale(trimesh, scale_ratio) homomat = rm.homomat_from_posrot(pos, rotmat) tmptrimesh.apply_transform(homomat) tmptrimesh.export(savename)
def scale(obj, scale_ratio): """ :param obj: trimesh or file path :param scale_ratio: float, scale all axis equally :return: author: weiwei date: 20201116 """ if isinstance(obj, trm.Trimesh): tmpmesh = obj.copy() tmpmesh.apply_scale(scale_ratio) return tmpmesh elif isinstance(obj, str): originalmesh = trm.load(obj) tmpmesh = originalmesh.copy() tmpmesh.apply_scale(scale_ratio) return tmpmesh
author: weiwei date: 20170221 """ objtrm = trm.load_mesh(objpath) pdnp = nodepath_from_vvnf(objtrm.vertices, objtrm.vertex_normals, objtrm.faces) return pdnp if __name__ == '__main__': import os, math, basis import basis.trimesh as trimesh import visualization.panda.world as wd from panda3d.core import TransparencyAttrib wd.World(cam_pos=[1.0, 1, .0, 1.0], lookat_pos=[0, 0, 0]) objpath = os.path.join(basis.__path__[0], 'objects', 'bunnysim.stl') bt = trimesh.load(objpath) btch = bt.convex_hull pdnp = nodepath_from_vfnf(bt.vertices, bt.face_normals, bt.faces) pdnp.reparentTo(base.render) pdnp_cvxh = nodepath_from_vfnf(btch.vertices, btch.face_normals, btch.faces) pdnp_cvxh.setTransparency(TransparencyAttrib.MDual) pdnp_cvxh.setColor(0, 1, 0, .3) pdnp_cvxh.reparentTo(base.render) pdnp2 = nodepath_from_vvnf(bt.vertices, bt.vertex_normals, bt.faces) pdnp2.setPos(0, 0, .1) pdnp2.reparentTo(base.render) base.run()