Using Polygon Mesh
-
If you just wish to color your model, you can just apply a new material to the Faces.
-
@adamb said:
If you just wish to color your model, you can just apply a new material to the Faces.
Yes, but if for example i had a landscape with changing lighting conditions and wanted to break up a selected face within the model into an arbitrary number (perhaps user defined) of polygons that I then could store in an array...how could I do this?
-
The polymesh way only triangulates the face - so a rectangle is simply split into two triangles - no more.
If you want to divide a face into smaller faces there are already several examples - Thomthom has EdgeTools and there's my Quadrilateralizer - for two different approaches...
To split a face you'll need to draw [looped] edges over it and use entities.intersect_with() - how you decide to divide up the face's edges etc is up to you... -
@arjunameridian said:
I'm writing ruby code where I would like to convert a selected face into a subset of either 1) points or 2) polygons and store them in an array. Then, I would like to iterate through the array and potentially color-code the points or polygons based on some arbitrary criteria.
PolygonMesh
will help you to triangulate any face, including with holes. This is only useful for painting, in particular when the face has concave sides or holes, but not for creating a geometrical mesh, because the triangulation is not well balanced.You can take inspiration of the following code. <triangles> will contain the triangles of the face.
def triangles_of_faces(face) mesh = face.mesh pts = mesh.points triangles = [] mesh.polygons.each do |p| triangles.push p.collect { |i| pts[i.abs-1] } end triangles end
Fredo
-
@unknownuser said:
but not for creating a geometrical mesh, because the triangulation is not well balanced.
I've noticed that SketchUp often create less than ideal triangulation. You got an alternative triangulation method?
-
@thomthom said:
Re: Using Polygon Mesh
@thomthom said:
@unknownuser said:
but not for creating a geometrical mesh, because the triangulation is not well balanced.
I've noticed that SketchUp often create less than ideal triangulation. You got an alternative triangulation method?
It may not be perfect, but if you've ever written a general purpose, multi-boundary (with holes), arbitrary polygon triangulation function, you might want to walk (run?) away. There are so many nasty little corner cases that the fact that it largely works - with outline fonts too which generate seriously complex paths, is impressive.
Conditioning the aspect ratio of generated triangles so as to avoid "shards" with tiny interior angles and therefore very touchy vertex normals is absolutely a good thing. Just a lot of work to do.
But if you like, I've got code that handles quads
Adam
-
-
-
-
Advertisement