Triangulate triangles ?
-
I will do that!
-
Beat me to it
You might want to change the
faces = ents.grep(Sketchup::Face)
to
faces = **sel**.grep(Sketchup::Face)
So then the user changes only selected faces ?
OR perhaps
faces = sel.grep(Sketchup::Face) faces = ents.grep(Sketchup::Face) **unless faces[0]**
so it works on a selection OR everything if there is no selection...Also you want to make it undoable, so add
**model.start_operation('subtri')** faces.each... ...end **model.commit_operation**
-
Hahaha!
TIG I would be very happy if you modify your existing plugin to add Pilou is feature request.
I am interested in making this for learning and I have some additional ideas I want to explore. I consider you my mentor TIG and there will never be competition between you and me I promise!
By the way thanks for the suggestion!
Here is updated code...
model = Sketchup.active_model ents = model.active_entities sel = model.selection faces = sel.grep(Sketchup;;Face) model.start_operation('csplit') faces.each do |face| vertices = face.vertices bbox = face.bounds cpoint = bbox.center vertices.each do |vertex| p1 = cpoint p2 = vertex line = ents.add_line p1,p2 end end sel.clear model.commit_operation
-
OK
I'll make a simple script and publish it shortly... -
Thank you TIG!
-
Thanks Pilou !
You convinced TIG...
And Thanks TIG, I think it's a must have ! -
Try this http://sketchucation.com/forums/viewtopic.php?p=495430#p495430
TriangulateAllFaces
... -
I think the triangulation is not the same...
-
Both of these are very useful so maybe add an option to choose between the two.
-
To do the former you need to first triangulate all faces, then find each triangle's center using the angles' bisectors' intersections...
-
Not as easy as using the center of face.bounds.center is it.
If I find the best way to do it with code I'll let you know...Best of luck!
-
I sure don't call the code below a success but its definitely interesting...
model = Sketchup.active_model ents = model.active_entities sel = model.selection faces = sel.grep(Sketchup;;Face) model.start_operation('csplit') faces.each do |face| vertices = face.vertices edges = face.edges bbox = face.bounds cpoint = bbox.center edges.each do |e| e1 = e.start.position e2 = e.end.position x = (e2.x + e1.x) / 2 y = (e2.y + e1.y) / 2 z = (e2.z + e1.z) / 2 vertices.each do |vertex| p1 = [x, y, z] p2 = vertex line = ents.add_line p1,p2 end end end sel.clear model.commit_operation
Note: I also find strange that new edges don't intersect with each othere making a new vertex...why is this?
-
If the second time you apply script you do each face individually inside a group, then you get very pretty geometry.
-
Renderiza,
That's not success, that's brilliance!
I'll start designing tiles right away...
Thanks!
JQL
-
Wish you success or better yet brilliance in your designs!
-
you make big progress and be near the success!
@unknownuser said:
Not as easy as using the center of face.bounds.center is it.
If I find the best way to do it with code I'll let you know.
Why not take the image of the first post as "pseudo code" ?
- Calculate the point x,y,z crossing of 2 lines from 2 vertices to their middle opposite edge
(point can be also the calculate center of gravity of 3 points! - draw 3 lines from this point to the 3 vertices
Tig has finalized his "triangulate" method!
Medians stay in race!Triangulate all faces by Tig (function was repeated for a sort of fractal system - only 3 triangles at start)
- Calculate the point x,y,z crossing of 2 lines from 2 vertices to their middle opposite edge
-
Thanks guys! Will definitely study your suggestions.
-
I Think you could use the circumcentre as well, for skewed triangles.. Maybe that's what Pilou is trying to Point out.
Here's some code I'm using for that. You might have to rewrite it to fit your needs..
I just ripped it out from a plugin I'm working on..# Arguments need 3 point3D objects from triangle. def points3_circumC(p1,p2,p3) #(Only 2 lines is actually needed for calculation) #Init Vectors for calculation. vec1 = p1.vector_to(p2) vec2 = p1.vector_to(p3) fakeZ = vec1.cross(vec2) #cross Plane... #midpoints mp1 = p1.offset(vec1, vec1.length/2) mp2 = p1.offset(vec2, vec2.length/2) #cross vectors.. vec1 = vec1.cross(fakeZ) vec2 = vec2.cross(fakeZ) #lines line1 = [mp1, vec1] line2 = [mp2, vec2] return c = Geom.intersect_line_line(line1, line2) #point3D end
edit: Ehh.. looks like TIG already bashed out a working plugin for this.
-
It works!
Here is the code...
model = Sketchup.active_model ents = model.active_entities sel = model.selection faces = sel.grep(Sketchup;;Face) model.start_operation('csplit') faces.each do |face| v = face.vertices cx = v[0].position.x + v[1].position.x + v[2].position.x cy = v[0].position.y + v[1].position.y + v[2].position.y cz = v[0].position.z + v[1].position.z + v[2].position.z px = cx / 3 py = cy / 3 pz = cz / 3 v.each do |vertex| p1 = [px, py, pz] p2 = vertex line = ents.add_line p1,p2 end end sel.clear model.commit_operation
Note: At the moment the above code works with triangles only.
For squares we can use the code bellow...
model = Sketchup.active_model ents = model.active_entities sel = model.selection faces = sel.grep(Sketchup;;Face) model.start_operation('csplit') faces.each do |face| v = face.vertices cx = v[0].position.x + v[1].position.x + v[2].position.x + v[3].position.x cy = v[0].position.y + v[1].position.y + v[2].position.y + v[3].position.y cz = v[0].position.z + v[1].position.z + v[2].position.z + v[3].position.z px = cx / 4 py = cy / 4 pz = cz / 4 v.each do |vertex| p1 = [px, py, pz] p2 = vertex line = ents.add_line p1,p2 end end sel.clear model.commit_operation
-
The following code will work on all geometry types like triangle, square, ect...
model = Sketchup.active_model ents = model.active_entities sel = model.selection faces = sel.grep(Sketchup;;Face) @addx = [] @addy = [] @addz = [] model.start_operation('csplit') faces.each do |face| @addx.clear @addy.clear @addz.clear v = face.vertices num = v.length v.each_with_index {|vert,i| @addx << " + v[#{i}].position.x" @addy << " + v[#{i}].position.y" @addz << " + v[#{i}].position.z" } ax = @addx * "," sumx = ax.delete "," ay = @addy * "," sumy = ay.delete "," az = @addz * "," sumz = az.delete "," cx = eval("#{sumx}") cy = eval("#{sumy}") cz = eval("#{sumz}") px = cx / num py = cy / num pz = cz / num v.each do |vertex| p1 = [px, py, pz] p2 = vertex line = ents.add_line p1,p2 end end sel.clear model.commit_operation
Note: To test code above you can copy & paste it to one of this ruby consoles...
http://renderizastudio.blogspot.com/2013/06/top-ruby-consoles-for-sketchup.html
Advertisement