示例#1
0
def volumed_collision_do(model,
                         inpath,
                         outpath,
                         logpath,
                         alpha=0.05,
                         resolution=100000):
    p.vhacd(inpath, outpath, logpath, alpha=0.0005, resolution=10000)
def convert(inFile, outPath, name):
    print(inFile, outPath, name)
    meshes = trimesh.load(inFile)
    outFile = os.path.join(outPath, name) + '.obj'
    """  
    try:
        vhacd_mesh = trimesh.interfaces.vhacd.convex_decomposition(meshes,
            resolution=100000,
            pca=1, 
            #maxhulls=4, 
            #planeDownsampling=4, 
            #maxNumVerticesPerCH=32,
            #depth=8,
            #alpha=.9,
            gamma=0
            )
        scene = trimesh.scene.scene.split_scene(vhacd_mesh)
        trimesh.exchange.export.export_mesh(scene, outFile)
    except Exception as e:
        print(e)
    
    """
    print(meshes)
    trimesh.exchange.export.export_mesh(meshes, outFile)
    p.connect(p.DIRECT)
    name_log = 'vacd_log.txt'
    p.vhacd(outFile,
            outFile,
            name_log,
            pca=1,
            convexhullDownsampling=4,
            planeDownsampling=4,
            maxNumVerticesPerCH=24)
    gc.collect()
示例#3
0
    def do_vhacd(self, filename, outfile, debug=False, **kwargs):
        try:
            mesh = trimesh.load(filename)
            convex_list = trimesh.interfaces.vhacd.convex_decomposition(
                mesh, debug=debug, **kwargs)

            convex = trimesh.util.concatenate(convex_list)
            convex.export(outfile)
        except ValueError:
            print("No direct VHACD backend available, trying pybullet")
            pass

        try:
            import pybullet as p
            p.vhacd(filename, outfile, self.log_file, **kwargs)
        except ModuleNotFoundError:
            print(
                '\n' +
                "ERROR - pybullet module not found: If you want to do convex decomposisiton, make sure you install pybullet (https://pypi.org/project/pybullet) or install VHACD directly (https://github.com/mikedh/trimesh/issues/404)"
                + '\n')
            raise
        dest='fileName',
        type=str,
        required=True,
        help='File name of .obj file for which the V-HACD will be calculated.')
    argsParser.add_argument('-O',
                            '--output',
                            dest='output',
                            type=str,
                            required=True,
                            help='Desired name of V-HACD file.')
    argsParser.add_argument(
        '-r',
        '--resolution',
        dest='resolution',
        type=int,
        required=False,
        help='Maximum number of voxels generated during voxelization stage.')
    args = argsParser.parse_args()

    p.connect(p.DIRECT)
    name_in = args.fileName
    name_out = args.output
    name_log = "vhacd_log.txt"

    if (args.resolution != None):
        res = args.resolution
    else:
        res = 100_000

    p.vhacd(name_in, name_out, name_log, resolution=res)
示例#5
0
import pybullet as p
import pybullet_data as pd
import os

import glob, copy

p.connect(p.DIRECT)

obj_files = glob.glob('*.obj')

for obj_file in obj_files:
    name_out = copy.copy(obj_file)
    name_out = name_out.replace('.obj', '_vhacd.obj')
    name_log = "log.txt"
    p.vhacd(obj_file, name_out, name_log, alpha=0.04, resolution=50000)
示例#6
0
def volumed_colision(inpath, path, logpath, alpha, resolution):
	p.vhacd(inpath, path, logpath,resolution=resolution) 
示例#7
0
import pybullet as p
import pybullet_data as pd
import os
import time

p.connect(p.DIRECT)
dir = "data/"
name_in = "crane.obj"
name_out = "crane_vhacd.obj"
name_log = "log.txt"

#for more parameters, see http://pybullet.org/guide

p.vhacd(name_in, name_out, name_log, resolution=1000000, depth=20)
示例#8
0
    "--voxel_resolution",
    "-v",
    type=int,
    dest="voxel_resolution",
    default=50000,
    help=
    "The resolution at which the convex decomposition takes place; larger number usually leads to more final spheres"
)
args = parser.parse_args(sys.argv[1:])

p.connect(p.DIRECT)

############## IF OTHER CONVEX DECOMPOSITION PARAM NEEDED TO CHANGE: PLEASE DIRECTLY CHANGE THEM HERE #######################
p.vhacd(args.input_obj,
        args.convex_obj,
        args.convex_log,
        concavity=0.0025,
        alpha=0.04,
        resolution=args.voxel_resolution)
#############################################################################################################################

parts = wf.load_obj(args.convex_obj)  #, triangulate=True)

xyzr = np.zeros((len(parts), 4))
part_id = 0
for part in parts:
    bounding_box = util.bbox(part.vertices)
    big_sphere = util.box2ball(bounding_box)

    mesh_center = util.coord_avg(part.vertices)
    small_sphere = util.inscribedSphereViaPointMesh(mesh_center, part)
示例#9
0
import pybullet as p
import os

f_in = os.path.join('project', 'proj4_run', 'rsc', 'mesh', 'map.obj')
f_out = os.path.join('project', 'proj4_run', 'rsc', 'mesh', 'map_concave.obj')
log = os.path.join('project', 'proj4_run', 'rsc', 'mesh', 'log.txt')

p.vhacd(f_in, f_out, log, resolution=32000000)
示例#10
0
import pybullet as p
import pybullet_data as pd
import os

import pybullet_data

p.connect(p.DIRECT)
p.setAdditionalSearchPath(pybullet_data.getDataPath())
name_in = os.path.join(pd.getDataPath(), "duck.obj")
name_out = "duck_vhacd.obj"
name_log = "log.txt"
p.vhacd(name_in, name_out, name_log)

示例#11
0
filename, file_extension = os.path.splitext(os.path.basename(name_in))

### Create centered + scaled version
mesh = trimesh.load(name_in, skip_materials=True)
mesh.apply_translation(-mesh.centroid)
mesh.apply_scale(scale)
name_scaled = folder + "/" + filename + "-scaled" + file_extension
mesh.export(name_scaled, "obj", write_texture=False, include_texture=False)

### Decompose 

name_out = folder + "/" + filename + "-decomposed" + file_extension
name_log = "log.txt"

p.connect(p.DIRECT)
P = p.vhacd(name_scaled, name_out, name_log, alpha=0.04,resolution=50000 )

#######################################################################
# STEP2: Split using trimesh, export each convex shape to separate obj file
#######################################################################
mesh = trimesh.load(name_out)
ctr = 1
names = []

# mesh.apply_translation(-mesh.centroid)
# mesh.apply_scale(0.1)

scale = False
for m in mesh.split():
  name_m = folder + "/meshes/" + filename + "-" + str(ctr) + file_extension
示例#12
0
import pybullet as p
from pathlib import Path

p.connect(p.DIRECT)
dir = Path(__file__).parents[0]
name_in = str(dir / "peg_in_hole_board/board_hard.obj")
name_out = str(dir / "peg_in_hole_board/board_hard_vhacd.obj")
name_log = str(dir / "log.txt")
p.vhacd(name_in, name_out, name_log, alpha=0.04, resolution=64000000)