# Trimesh mesh color

By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I want to plot a triangular mesh, and color each edge with a different color. The matlab documentation for trimesh states there's a color argument, but it doesn't state what its structure should be - as the triangles share edges, how do I know where to position which color inside the vector C?

I was struggling with this problem yesterday, and I think I have the solution. It turns out that in general if you want to be very detailed with which edge is which color, you have to be very sneaky. So you understand what the problem is, I'll first review how the command trimesh Tri,X,Y,Z,C assigns colors in the first place.

The argument C has be a vector of numbers with length equaling the number of vertices not edges. The way it colors edges is as follows. If we have 4 vertices and we assign. The next edge found is 2 to 3, which is colored using the color of point 2, which is The next edge is 3 to 1, which has color The next edge is 3 to 2 with color 30; notice this edge has already been colored 20 but this new color overwrites the old color. And then edge 2 to 4 is colored 20 and edge 4 to 3 is colored The problem is that without using a special trick, this coloring scheme can make it literally impossible to color the edges exactly as you want.

Your case in point: if you have more edges than vertices as in my example and you want each edge to be colored differently, you are out of luck because the edges are colored according to the colors assigned to the vertices. But if we make multiple copies of each vertex and, consequently, multiple copies of each edgethen we are back in business.

Also, our lives are made easier by the fact that Tri accepts not just faces but also individual edges as well. As an example of what I mean, suppose you wanted edge 2 to 3 to have the color 50 in the example above. To do this, make a new point, point 5, which is the same as point 2 i. Redefine Tri and C as follows:.

Notice that the last three numbers in Tri do not define a face but rather an edge the edge 3 to 5, which is the same as 2 to 3.

This edge will be colored by whatever color point 5 is assigned. In this manner, you can overwrite the colors of every edge individually. Just be sure to put these edges at the end of the Tri matrix so that their colorings overwrite any previous undesired colorings. If you don't care about having faces filled in, you can even have a Tri matrix with nothing but edges.Trimesh is a pure Python 2. The goal of the library is to provide a fully featured Trimesh object which allows for easy manipulation and analysis, in the style of the Polygon object in the Shapely library.

Bases: trimesh. Invert the mesh in-place by reversing the winding of every face and negating normals without dumping the cache. If a mesh has vertices that are closer than trimesh.

Align a mesh with another mesh or a PointCloud using the principal axes of inertia as a starting point which is refined by iterative closest point. Removes all face references so that every face contains three unique vertex indices and no faces are adjacent. The point in space which is the average of the triangle centroids weighted by the area of each triangle.

The approximate perpendicular projection of the non-shared vertices in a pair of adjacent faces onto the shared edge of the two faces. Check if a mesh has all the properties required to represent a valid volume, rather than just a surface. A transform which moves the current mesh so the principal inertia vectors are on the X,Y, and Z axis, and the centroid is at the origin. A metric for the overall scale of the mesh, the length of the diagonal of the axis aligned bounding box of the mesh.

If a mesh has rotational symmetry return the two vectors which make up a section coordinate frame. Does the bookkeeping to avoid recomputing things so this function should be used rather than directly modifying self.

How many connected groups of vertices exist in this mesh. Note that this number may differ from result in mesh. For each sample, it computes the stable resting poses of the mesh on a a planar workspace and evaluates the probabilities of landing in each pose if the object is dropped onto the table randomly. This method returns the 4x4 homogeneous transform matrices that place the shape against the planar surface with the z-axis pointing upwards and a list of the probabilities for each pose.

The transforms and probabilties that are returned are sorted, with the most probable pose first.

Given an array of points determine whether or not they are inside the mesh. This raises an error if called on a non-watertight mesh. By default, copied meshes will have emptied cache to avoid memory issues and so may be slow on initial operations until caches are regenerated.Sign in to comment.

Sign in to answer this question. Unable to complete the action because of changes made to the page. Reload the page to see its updated state. Choose a web site to get translated content where available and see local events and offers.

Based on your location, we recommend that you select:. Select the China site in Chinese or English for best site performance. Other MathWorks country sites are not optimized for visits from your location. Toggle Main Navigation. Search Answers Clear Filters. Answers Support MathWorks. Search Support Clear Filters. Support Answers MathWorks. Search MathWorks. MathWorks Answers Support. Open Mobile Search. Trial software. You are now following this question You will see updates in your activity feed.

You may receive emails, depending on your notification preferences. Coloring of specific elements using trimesh. David on 23 Jun Vote 0. Commented: David on 24 Jun Accepted Answer: Kelly Kearney.

**Blender Quick Tip: quick color fill and masking**

I'm using trimesh to plot a triangular mesh having all nodal positions stored in x,y,z and a corresponding nodal connection vector in Tri, generating a mesh following the trimesh-command as:. I understand how to use the handle m to change e. However, now I would like to color specific elements differently from the whole mesh.

I have a list of all nodal points 'belonging' to a specific color and would like to somehow fix that using the trimesh-handle.

### Select a Web Site

Anyone have an idea on how to achieve that? Accepted Answer. Kelly Kearney on 23 Jun Vote 1. Cancel Copy to Clipboard. I think the easiest way to do this would be to simply create two separate meshes, one that includes all points and one that only includes the ones you want to treat specially.

David on 24 Jun Thanks Kelly!

That was exactly was I was looking for! More Answers 0. See Also.Documentation Help Center. T is usually the output of a Delaunay triangulation of a 3-D set of points. A row of T contains indices into X of the vertices of a tetrahedron.

X is an n -by-3 matrix, representing n points in 3 dimension. The tetrahedron colors are defined by the vector Cwhich is used as indices into the current colormap. Each tetrahedron has a different color modulo the number of colors available in the current colormap. Each element of h is a handle to the set of patches forming one tetrahedron. You can use these handles to view a particular tetrahedron by turning the patch 'Visible' property 'on' or 'off'.

For example, the default transparency parameter is set to 0. See Patch Properties for information about the available properties. Generate a 3-D Delaunay triangulation, then use tetramesh to visualize the tetrahedrons.

A modified version of this example exists on your system. Do you want to open this version instead? Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.

Select the China site in Chinese or English for best site performance. Other MathWorks country sites are not optimized for visits from your location. Toggle Main Navigation. Search Support Support MathWorks.

### The TriMesh class

Off-Canvas Navigation Menu Toggle. Description tetramesh T,X,c displays the tetrahedrons defined in the m -by-4 matrix T as mesh. Open Live Script. See Also delaunayTriangulation delaunayn freeBoundary triangulation patch triangulation trimesh trisurf.

No, overwrite the modified version Yes. Select a Web Site Choose a web site to get translated content where available and see local events and offers. Select web site.Editable Mesh - Quick Navigation. Meshes hold the actual vertex and face arrays, and so on, in a triangular mesh.

The prime purpose of the TriMesh class is to allow scripted primitive object plug-ins to access and build the Mesh object inside geometry objects. This class has a large range of mesh manipulation and construction functions, corresponding to the low-level mesh operations on Editable Mesh scene nodes. Only the update function updates the mesh's internal caches and images in 3ds Max viewports.

This is because updates can be computationally expensive and you don't want them performed on every function call. However, you must make sure you do call the update function after a series of changes and before the mesh is to be worked on in 3ds Max or by other functions in MAXScript. Coordinates are given in the MAXScript working coordinate system. If the update function is called on an object that is selected and currently open in the Modify panel, it will drop the current selection in order to avoid a potential crash in 3ds Maxwhich at the moment, does not support scripted changes to an object open in the Modify panel.

If you are creating or modifying a mesh, and have not yet run update on the mesh, 3ds Max will crash if you minimize and then maximize the 3ds Max window. This is because an only partially created mesh is created, and the internal 3ds Max mesh structure is left in an unstable state.

Creates an empty mesh. Creates a flat rectangular mesh with the given size and number of segments. The default length and width are 50, the default number of segments is 5. Creates a mesh of the given geometry but with no topology i. You have to individually place the vertices and create the faces from the vertices. The default number of vertices and faces are 36 and 50, respectively. Creates a mesh using the specified TriMesh value as the mesh source.

Creates a mesh from an array of vertices and faces. Each Point3 value in the vertices array specifies the position of the vertex in the current coordinate system. Each Point3 value in the faces array specifies the 3 vertex indices that form the face.

## Subscribe to RSS

The materialIDs array specifies the material ID to be assigned to each face. Each Point3 value in the tverts array specifies the UVW coordinates of the texture vertices.

See Texture Mapping in the methods section for more information on texture vertices. An example of construction a mesh using this form of the constructor is:.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Have a question about this project?

Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub? Sign in to your account. Hi mikedh. May I ask how could I fix a non-watertight model to watertight after getting the broken faces trimesh. Thanks for your help dbukenberger. Hey, yeah mesh. More degenerate cases like a vertex in the middle of an unsplit edge, larger holes, planar holes, etc aren't handled and probably require manual repair in meshlab or blender.

You can visualize broken faces like:. Which shows toggle wireframe with w and culling with c :. I'm getting this. Hey clbarnes yeah that should really not raise. The function returns mesh. Could you send me a mesh that fails that check to take a look at? The following simple example passes for me:. I looked through the code and found the issue in my case at least.

Inspecting my meshes, several of them have multiple "disjointed meshes" inside which happen to share some edges without having duplicate faces. In that case some edges are present 4 times which produce the strange result where the mesh is actually composed of several submeshes which are all watertight but the resulting global mesh is not watertight because some edges are used 4 times instead of 2! Yeah it would be awesome if you could put together toy examples for any cases you can think of that demonstrate this!

It makes it a lot easier to test a fix, and would be great to have in CI as well. For some reason I can't get an example to reproduce this, but looking at the logic flow it seems like this should really be:. Skip to content. Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up. New issue. Jump to bottom. How to fix non-watertight model? Copy link Quote reply.HoloViews is designed to make working with data easier, including support for large or small trimeshes.

With HoloViews, you first declare a hv. Trimesh object, then you apply the datashade or just aggregate operation if the data is large enough to require datashader. Notice that HoloViews expects the triangles and vertices in the opposite order as datashader's cvs.

Here you can zoom in on either of these plots, but they will only update if you have a live Python server not a static web page. The Wireframe plot will initially look like a collection of dots as the triangles are all tinybut zooming in will reveal the shape if you are just looking at the static web page, eventually you will see individual pixels in the original datashaded rasterized plot, not the full trimesh available.

Notice how a few of the "wires" cross the center, because Delaunay triangulation has filled in the central region; other techniques as mentioned previously would be needed to avoid those. For examples of Datashader's trimesh in use, see the Chesapeake and Delaware Bays notebook:. Right click to download this notebook from GitHub.

TriMesh trishv.