Comments (4)
Hey, I think you want to take a look at mesh.face_adjacency
:
In [1]: import trimesh
In [2]: m = trimesh.load('models/featuretype.STL')
In [3]: m
Out[3]: <trimesh.Trimesh(vertices.shape=(1722, 3), faces.shape=(3476, 3), name=`featuretype.STL`)>
In [4]: facet = m.facets[0]
In [5]: facet
Out[5]:
array([ 0, 286, ... 134, 133, 132, 130])
In [7]: import numpy as np
In [8]: facet_mask = np.zeros(len(m.faces), dtype=bool)
In [10]: facet_mask[facet] = True
# get pairs of faces where only *one* of them is included in the facet
In [11]: border = facet_mask[m.face_adjacency].sum(axis=1) == 1
In [12]: border.shape
Out[12]: (5214,)
In [14]: border
Out[14]: array([ True, False, False, ..., False, False, False])
In [15]: border.sum()
Out[15]: 374
# (m, 2) indexes of m.faces
In [16]: adjacent = m.face_adjacency[border]
In [21]: other_faces = adjacent.ravel()[~facet_mask[adjacent.ravel()]]
# make the facet blue
In [22]: m.visual.face_colors[facet] = [0,0,255,255]
# border faces red
In [23]: m.visual.face_colors[other_faces] = [255,0,0,255]
In [24]: m.show(smooth=False)
from trimesh.
Thank you for the answer. In case, my mesh has separated components (bodies), how can I only get the components attached to my facet? Sorry didn't mention it clearly in the beginning. This is why I wanted to use trimesh.graph.connected_components
.
Is the below correct?
cc_facet = trimesh.graph.connected_components(edges=m.edges[facet], min_len=4)
min_len
should be 4 or 3?
cc_mask = np.zeros(len(m.faces), dtype=np.bool)
cc_mask[np.concatenate(cc_mask)] = True
# make the facet blue
m.visual.face_colors[facet] = [0,0,255,255]
# attached facets red
m.visual.face_colors[cc_mask] = [255,0,0,255]
m.show(smooth=False)
# create a new mesh from selected cc
cc_m = m.copy()
cc_m.update_faces(cc_mask)
from trimesh.
Have you looked at mesh.split
? That might be close to what you want.
from trimesh.
Yes I tried that, but how can I extract from the split output the component of a given facet?
from trimesh.
Related Issues (20)
- Mesh Export Size Difference (Local/Remote) HOT 1
- Assigning new material to a Trimesh object does nothing HOT 1
- Efficient way to check if a list of meshes contains points closer to their surfaces HOT 2
- ray_pyembree: intersects_location and intersects_any yielding different outputs
- A few new failing tests with Pillow 10.4.0 HOT 2
- Tests for cascadio fail on s390x, wrong endianness HOT 1
- Discrepancy in Importing .obj Mesh with Vertex Texture
- Bug in trimesh.boolean check_volume variable propagation. HOT 2
- Question: Converting cadquery.occ_impl.shapes.Solid to an trimesh.Trimehs object or to trimesh.Scene HOT 2
- Proper way to update scene geometry?
- Working with multi-patch meshes
- Set material of a Scene to eliminate of effect of direction
- Volume method wrong? HOT 2
- Add ability to generate mesh of 3D text
- Bevel, Chamfer, and Filet of Edges
- failed to load texture. trimesh.util.concatenate HOT 2
- Can't install `trimesh[easy]` in docker HOT 3
- extrude_polygon not creating watertight mesh HOT 3
- Regressions in test_boolean.py with Blender 4.2.0 HOT 3
- trimesh.creation.revolve create non volume if not by 360 degree HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trimesh.