Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Michael Dawson-Haggerty
    @mikedh
    hey, not at the moment. If you converted them to a trimesh.path.Path3D and then passed colors to trimesh.rendering.path_to_vertexlist you could probably visualize it that way
    WangJian
    @StefanWangsjtu
    This message was deleted
    Hi there, I got a problem when I try to create a Trimesh object by
    'tri_mesh = trimesh.Trimesh(vertices=self.vertices, faces=self.vertices, face_normals=self.normals) ',
    'self.vertices.shape, self.faces.shape, self.normals.shape = (92846, 3) , (185743, 3), (185743, 3)'
    But
    'tri_mesh.vertices.shape, tri_mesh.faces.shape, tri_mesh.face_normals.shape = (92846, 3) (92846, 3) (92846, 3) '。
    I couldn't understand what happend.
    Michael Dawson-Haggerty
    @mikedh
    hey, I think the issue is you're setting faces=self.vertices rather than faces=self.faces
    WangJian
    @StefanWangsjtu
    Oh.....my fault. Thank you so much for your reply,sir.
    tjiagoM
    @tjiagoM
    Hello all, I'm loading several meshes to the same scene and wanted to change the color of some. Is there any way to change the default color when or after calling load_mesh()? Using mesh.visual.face_colors doesn't seem to produce a clear effect, because I kinda see some color being changed, but it's not all of the mesh...
    hoosha
    @hoosha
    You need to apply it to all the faces. like this:
    mesh2 = trimesh.load_mesh('mesh/example005.stl') mesh2.visual.face_colors=trimesh.visual.random_color()
    or
    mesh.visual.face_colors = trimesh.visual.interpolate(facecolor,color_map='jet')
    facecolor is a vector of the same length as mesh.faces
    tjiagoM
    @tjiagoM
    thanks, the first option works!
    hoosha
    @hoosha
    @mikedh Hi Michael how can I quickly get a list of three neighboring faces of any given face?
    Michael Dawson-Haggerty
    @mikedh
    Hmm, maybe something with a sparse matrix?
    Not fully developed thought, but you could get a COO matrix:
    In [1]: import trimesh
    
    In [2]: m = trimesh.creation.icosphere()
    
    In [3]: m.face_adjacency
    Out[3]: 
    array([[ 394,  992],
           [ 538, 1189],
           [ 416,  970],
           ...,
           [  86,  340],
           [ 340,  348],
           [ 337,  348]])
    
    In [4]: g = trimesh.graph.edges_to_coo(m.face_adjacency, count=len(m.face
       ...: s))
    
    In [5]: g
    Out[5]: 
    <1280x1280 sparse matrix of type '<class 'numpy.bool_'>'
        with 1920 stored elements in COOrdinate format>
    
    In [6]: import numpy as np
    
    In [7]: np.sum(g, axis=0)
    Out[7]: matrix([[0, 0, 0, ..., 2, 2, 3]], dtype=int64)
    
    In [8]: np.sum(g, axis=1)
    Out[8]: 
    matrix([[3],
            [3],
            [3],
            ...,
            [1],
            [1],
            [0]], dtype=int64)
    Tobias Dünser
    @prog-r-amer
    @mikedh hi, is there an order to the face indices?
    Michael Dawson-Haggerty
    @mikedh
    hey, they should be loaded in the same order as the source file
    generally the winding preference is counterclockwise
    Tobias Dünser
    @prog-r-amer
    ok, cause I am using a box primitive right now
    and wanted to know which one is upper left and lower right
    Michael Dawson-Haggerty
    @mikedh
    which face?
    Tobias Dünser
    @prog-r-amer
    the upper one
    Michael Dawson-Haggerty
    @mikedh
    you could do something like
    In [1]: import trimesh
    
    In [2]: m = trimesh.creation.box()
    
    In [3]: m
    Out[3]: <trimesh.base.Trimesh at 0x7effccdba710>
    
    In [4]: m.vertices
    Out[4]: 
    TrackedArray([[-0.5, -0.5, -0.5],
                  [-0.5, -0.5,  0.5],
                  [-0.5,  0.5, -0.5],
                  [-0.5,  0.5,  0.5],
                  [ 0.5, -0.5, -0.5],
                  [ 0.5, -0.5,  0.5],
                  [ 0.5,  0.5, -0.5],
                  [ 0.5,  0.5,  0.5]])
    
    In [6]: import numpy as np
    
    In [7]: at_extrema = np.isclose(m.vertices[:,2], m.vertices[:,2].max())
    
    In [8]: at_extrema
    Out[8]: TrackedArray([False,  True, False,  True, False,  True, False,  True])
    
    
    In [10]: at_extrema[m.faces]
    Out[10]: 
    TrackedArray([[ True,  True, False],
                  [False,  True, False],
                  [False,  True, False],
                  [False, False, False],
                  [ True,  True,  True],
                  [ True,  True, False],
                  [ True,  True,  True],
                  [ True,  True, False],
                  [False, False, False],
                  [False,  True, False],
                  [False,  True, False],
                  [ True,  True, False]])
    
    In [11]: at_extrema[m.faces].all(axis=1)
    Out[11]: 
    TrackedArray([False, False, False, False,  True, False,  True, False,
                  False, False, False, False])
    
    In [12]: top = at_extrema[m.faces].all(axis=1)
    
    In [13]: m.visual.face_colors[top] = [255,0,0,255]
    
    In [14]: m.show()
    or you could check the face normals of the mesh
    but relying on order is probably kind of flaky
    Tobias Dünser
    @prog-r-amer
    thanks
    Michael Dawson-Haggerty
    @mikedh
    np
    Xiuming Zhang
    @xiumingzhang
    @mikedh hey Mike! Great work. I have a question that I feel better suited here rather than as a github issue: I wonder how obj.ray.intersects_location (the pyembree one) works under the hood; does it cache the tree in obj, or does it recompute the tree every time obj.ray.intersects_location gets called?
    I guess should be the former, but just want to double check. In my case, I call obj.ray.intersects_location() multiple times on the same object obj. Do I need to worry about the recomputation of the tree, or is it take care of under the hood?
    hoosha
    @hoosha
    Hi, is there a way to merge all the meshes in a Trimesh object (that is a list of meshes) into a single mesh object? something like reverse of split?
    hoosha
    @hoosha
    I see that obj files with multiple part sometimes load as a list of mesh objects but in case of some files as a single mesh object!
    Dvir Ginzburg
    @dvirginz
    Am I missing the documentation?
    Tried to find it under docs / examples but some of the links are broken.
    Michael Dawson-Haggerty
    @mikedh
    hey, it's built into: https://trimsh.org/
    Dvir Ginzburg
    @dvirginz
    I don't want to open github issues just because
    Michael Dawson-Haggerty
    @mikedh
    @hoosha you can try trimesh.util.concatentate:
    In [1]: import trimesh
    
    In [2]: m = [trimesh.primitives.Sphere() for i in range(10)]
    
    In [3]: m
    Out[3]: 
    [<trimesh.primitives.Sphere at 0x7fe317ff0ef0>,
     <trimesh.primitives.Sphere at 0x7fe317782080>,
     <trimesh.primitives.Sphere at 0x7fe3177822e8>,
     <trimesh.primitives.Sphere at 0x7fe317782550>,
     <trimesh.primitives.Sphere at 0x7fe3177827b8>,
     <trimesh.primitives.Sphere at 0x7fe317782a20>,
     <trimesh.primitives.Sphere at 0x7fe317782c88>,
     <trimesh.primitives.Sphere at 0x7fe317782ef0>,
     <trimesh.primitives.Sphere at 0x7fe317787198>,
     <trimesh.primitives.Sphere at 0x7fe317787400>]
    
    In [4]: trimesh.util.concatenate(m)
    Out[4]: <trimesh.base.Trimesh at 0x7fe317742f28>
    Dvir Ginzburg
    @dvirginz
    @mikedh thanks a lot, trimesh is absolutely amazing.
    I'm trying to implement the LBO operator on python,
    Michael Dawson-Haggerty
    @mikedh
    no worries, and thanks!
    Dvir Ginzburg
    @dvirginz
    I'm trying to implement the LBO operator on python, https://en.m.wikipedia.org/wiki/Laplace%E2%80%93Beltrami_operator,
    And I need to compute the laplacian of the mesh (mass and stiffness matrices),
    I see that you use the laplacian as part of some of the modules.
    Is there a way to explicitly extract those in trimesh?
    Michael Dawson-Haggerty
    @mikedh
    well, there's mesh.moment_inertia
    Mihai ANDRIES
    @science-code
    image.png
    Hello! I hope you are doing well. I cannot import Trimesh in python 2.7.12 on Ubuntu 16.04. Can anyone help me with this issue? Thanks!
    Mihai ANDRIES
    @science-code
    @mikedh Thanks for solving the issue! It works now!
    Douglas Lemos
    @dougwdl_twitter
    hi
    i have error
    File "/usr/local/lib/python3.6/site-packages/trimesh/path/path.py", line 1311, in simplify_spline
    smooth=smooth)
    TypeError: simplify_spline() got an unexpected keyword argument 'path_indexes'
    a = trimesh.load_path(cycloidal_profile(count_pin=count_pin,
    count_cam=count_pin - 1,
    eccentricity=eccentricity,
    radius_pin=radius_pin,
    radius_pattern=radius_pattern,
    resolution=32))
    print(a)
    # replace the polyline entity with a bajillion points with a
    # tightly fit B-Spline
    a = a.simplify_spline(smooth=1e-6)
    Michael Dawson-Haggerty
    @mikedh
    ah @dougwdl_twitter that's a bug, fixed in mikedh/trimesh@0cf1b22