Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Antoine Beyeler
    @abey79
    Hello, I have a project where I need to compute line segment vs. mesh intersection, accounting for visibility. Each line segment should be transformed in 0, 1 or more segments where, assuming a projection direction (eg. z axis), including the part of the segment that is in front of the mesh and the parts that are not overlapping with the mesh, excluding both the part that is inside the mesh (assuming its watertight) and the part that is "behind" the mesh (along projection axis). Basically, I'm trying to "render" line segments into vector data (not raster), accounting for opaque meshes in the scene. I'm very new to Trimesh, is there an easy way to achieve this?
    I assume ray-mesh intersection is where to start, but I would then have to somehow subtract the silhouette of the mesh from the segment part that is behind.
    Jesse Vander Does
    @FreakTheMighty
    Does anyone know whether the collision manager considers an object fully contained by another a hit?
    Jesse Vander Does
    @FreakTheMighty
    To be more specific, I'm trying to slide a box collider over a scene and find which meshes or are within it. Here is my sample code
    import numpy as np
    import trimesh
    
    debug_material = trimesh.visual.material.PBRMaterial(baseColorFactor=np.array((255,0,0,80), dtype=np.uint), alphaMode='BLEND')
    
    scene = trimesh.load_mesh('./data/simple.glb')
    scene_bounds = scene.bounding_box
    
    
    max_bounds = scene_bounds.extents.min()
    box_count = 2
    grid_width = int(max_bounds/box_count)
    
    grid = scene_bounds.sample_grid(step=grid_width)
    
    cm, _ = trimesh.collision.scene_to_collision(scene)
    
    # Sliding box collider
    box = trimesh.primitives.Box()
    box.apply_scale(grid_width)
    cm.add_object('selection', box)
    
    
    # List of unique objects that were hit
    was_hit = set([])
    
    for g in grid:
        print('####')
        print(g)
        matrix = np.eye(4)
        matrix[:3, 3] = np.array(g)
    
        debug_box = box.copy()
        debug_box.apply_transform(matrix)
    
        debug_box.visual.material = debug_material
        hit, hit_list, l = cm.in_collision_single(box, transform=matrix, return_names=True, return_data=True)
        if hit:
            for item in hit_list:
                if item is not 'selection':
                    mesh_name = scene.graph.get(item)[1]
                    if item not in was_hit:
                        was_hit.add(mesh_name)
        scene.add_geometry(debug_box)
    
    scene.export(file_obj=open('/tmp/debug.glb', 'wb'), file_type='glb')
    print('Total hit %s' % len(was_hit))
    print('Total geo %s' % len(scene.geometry))
    And here is the sample GLB I'm using
    Only 10 mesh are hit, but there are 16 in the scene. Initially, I thought it was missing objects that were fully enclosed by the box collider, but, but I'm finding to two large objects that should intersect multiple times also do not register.
    My gut tells me that my "debug" object is not accurately representing the CollissionManager transform, but I can't figure out what I'm doing wrong.
    sariug
    @sariug
    hello
    how can we add a mesh to another mesh ?
    hoosha
    @hoosha
    Use + to add two meshes!
    mesh1 = mesh1 + mesh2
    sariug
    @sariug
    hello, I was checkin the example of gauss curvature
    gauss = np.array([discrete_gaussian_curvature_measure(mesh, mesh.vertices, r)/sphere_ball_intersection(1, r) for r in radii])
    why is the division of sphere_ball_intersection ?
    Tobias Vitt
    @tobiasvitt
    Hey, Is there a way to colorise a VoxelGrid? After applying voxelize(d) the colors of the mesh are gone.
    Andrew Annex
    @AndrewAnnex
    hey all, I am running into an issue with ray.intersects_location returning much larger distances than expected between two meshes. I first use closest_point to find points on the lower surface of interest and the indexes for the normals. then use ray.intersects_location with those lower surface points using the closes face normals to those points from the index returned by closest_point. I can tell something is off because if I explicitly set the normals to be [0,0,1], ray.intersects_location return points with different x and y coordinates then the ray origins (the rays should be orthogonal to the xy axis plane). am I missing something?
    sariug
    @sariug
    uh was gonan ask something but lets wait until the questions above are answered :)
    ChrisGithubWork
    @ChrisGithubWork
    Hey at all,
    i do have a question but i don't know if this is the right place.
    I tried the voxel package and voxeled a lot of stuff. But now i wan't to digg deeper but i'm stuck now.
    I want to extract the vertex information of every voxel, bacause i need them to manipulate the geometry. So i'm looking for something like: for voxel in allvoxels: give me voxel with his eight vertices. Is this possible?
    ChrisCarragher
    @ChrisCarragher
    Hi, so I am just getting started with trimesh, is there some documentation I am missing or is it a matter of going through the code?
    I am trying the basic example but with a 3mf file and I get "'Scene' object has no attribute 'is_watertight'", how do I import a 3mf as a mesh or how do I split/convert a Scene to a mesh? Thanks
    Mihai ANDRIES
    @science-code
    Hello! After an update in scikit-image, pillow, I cannot generate mesh images anymore with Trimesh. Have you encountered this problem already?
    Instead of a mesh image, it generates a print-screen.
    @ChrisCarragher If your question is still open, I would export an mesh in STL format from your 3mf file, and then load this STL with Trimesh.
    Michael Dawson-Haggerty
    @mikedh
    hey @ChrisCarragher a 3MF can contain multiple meshes, you can access them through scene.geometry or dump them all into a single mesh with scene.dump(concatenate=True)
    @science-code were you using scene.save_image?
    Mihai ANDRIES
    @science-code
    @mikedh I use this:
    # Example: https://github.com/mikedh/trimesh/issues/115#issuecomment-351866100
    data = mesh.scene().save_image(resolution=[1480,1480], visible=False)
    rendered = Image.open(trimesh.util.wrap_as_stream(data))
    rendered.show()
    $ pip show pillow
    Version: 7.0.0
    Required-by: scikit-image, imageio
    Name: scikit-image
    Version: 0.15.0
    Name: imageio
    Version: 2.8.0
    Michael Dawson-Haggerty
    @mikedh
    hmm if anything I would suspect a recent pyglet upgrade for this
    they released recently
    Mihai ANDRIES
    @science-code
    @mikedh it seems that the error comes from this part:
    data = scene.save_image(resolution=[480,480], visible=True) #False)
    It works with "visible=True", but does not work with "visible=False".
    Moreover, even with "visible=True", the first mesh image is completely black.
    Mihai ANDRIES
    @science-code
    @mikedh Any ideas from where this might come?
    Mihai ANDRIES
    @science-code
    Currently using this alternative, which has the same fault (every once in a while, a mesh image is just black):

    Alternative code for generating a mesh-image

    from trimesh import viewer as trimesh_viewer

    ...

    data = trimesh_viewer.render_scene(mesh.scene(), resolution=[480,480], visible=True)

    I suppose it also slows down image generation, due to "visible=True".
    ChrisCarragher
    @ChrisCarragher
    @mikedh Thank you!
    Mihai ANDRIES
    @science-code
    @mikedh I would be grateful for any suggestion you may have :-)
    Michael Dawson-Haggerty
    @mikedh
    Hey, whether visible=False works depends a lot on your platform: mikedh/trimesh#125
    Jason McInerney
    @wwwslinger
    Hi. I can't find this anywhere, but my goal is to take an STL of a non-uniformly curved surface and determine how to cut a flat sheet to cover it with as few segments as possible. Any thoughts on how to approach it using trimesh?
    Mihai ANDRIES
    @science-code
    @wwwslinger if your object is convex, you could use a convex envelope.
    @wwwslinger another alternative would be to simplify the mesh while enforcing constraints on its surface. You can use the "Decimate" function of MeshLabServer for this.
    @mikedh It used to work with visible=False, but stopped since I installed some python packages. The platform is the same as before, so this isn't the issue. I've tried to identify which python package broke the mesh-image generation, but in vain.
    Jason McInerney
    @wwwslinger
    It is convex @science-code , thanks. Simplifying would be cool, too, since it does has some structure past the surface edges that I need to somehow cut off
    @science-code I can seem to find Decimate in there, just ParaDecimate -- is that the same? Do you have link to an example perhaps?
    Mihai ANDRIES
    @science-code
    @wwwslinger here's a python code that does the simplification down to 2000 triangles in the final mesh:

    You need to install meshlab for that work.
    To change the number of triangles in the final mesh, edit the value on line 21:

    <Param type="RichInt" value="2000" name="TargetFaceNum"/>

    Jason McInerney
    @wwwslinger
    @science-code thanks for the script. I tested it out, but am getting a not found for the Remove Unreferenced Vertex Filter. Is there a default somewhere that I can plug in?