[Plugin] triangulateFaces.rb v1.2 20101120

[Plugin] triangulateFaces.rb v1.2 20101120

Postby TIG » Fri Jul 03, 2009 5:47 pm

Now new improved 'triangulate' - It now 'triangulates' [almost] everything...

Script: triangulate.rb
Code Usage: triangulate(array_of_faces)
Result: it triangulates faces in array...
Plugin Usage:
Result: it triangulates faces in selection...
Known Issues:
Even complex single looped faces should work OK.
Simple faces with one or two holes are also usually OK.
Very large numbers of faces might cause a 'white-out',
processing is continuing, please be patient...
Complex faces with complex multiple holes in them might 'splat' !
Add some extra dividing lines and retry...
Very small faces might not work properly and 'splat' ! Scale them...
Failed triangulations are warned and can be undone...
Save your work before using this tool...
v1.0 First issue. 20090703
v1.1 4 sided faces with 3 in line vertices trapped.
undo operation added. 20090703 pm
v1.2 L-shaped AND 4-sided faces trapped. 20090703 pm+
v1.3 Menu added, warns if no suitable selection. 20090703 pm++
v2.0 Now triangulates all >= 4-sided faces and traps awkward L/U/holed
shapes etc. 20090707
v2.1 Renamed 'triangulatefaces' to avoid clashes with delauney/cloud etc.
20090708

Now Obsolete - see triangulateFaces.rb later in thread... HERE http://forums.sketchucation.com/viewtop ... 13#p175613
1
Last edited by TIG on Thu Dec 03, 2009 11:29 pm, edited 10 times in total.
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulate.rb v1.1

Postby TIG » Fri Jul 03, 2009 6:14 pm

Updated
v1.1 4-sided faces with 3 in line vertices trapped,undo operation added 20090703pm
viewtopic.php?p=169956#p169956
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulate.rb v1.1

Postby Chris Fullmer » Fri Jul 03, 2009 6:31 pm

Are you going to put into the menu system? Or just run it in the webconsole? or...?
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Plugin] triangulate.rb v1.1

Postby sepo » Fri Jul 03, 2009 6:35 pm

Well it does not appear in plugins menu nor in context menu.
1

sepo 
 

Re: [Plugin] triangulate.rb v1.1

Postby Burkhard » Fri Jul 03, 2009 6:47 pm

What's the difference to this plugin?
Author unknown!
0
User avatar
Burkhard 
Premium Member
Premium Member
 

Re: [Plugin] triangulate.rb v1.1

Postby Burkhard » Fri Jul 03, 2009 9:59 pm

It is possible to add a seperate " add detail" tool for further triangulations?
It could be usefull for detail modeling.

1- Triangulate face and open:
2- Input Box with values like: 10x and available smoothcheckbox
3- Set complete triangulation in one step

You can seperate the Sandbox " add detail" from the original script. But then the new script should be coded ( with strings) in the same way to add it in one toolbar.

usefull?
0
User avatar
Burkhard 
Premium Member
Premium Member
 

Re: [Plugin] triangulate.rb v1.2

Postby TIG » Fri Jul 03, 2009 10:51 pm

Here's v1.2 viewtopic.php?p=169956#p169956

Burkhard: To add extra detail sub-division to faces use my Advertex+.rb tools - using the appropriate modifier key you can add a vertex onto a face and new edges will then be added up to it from every face-vertex...
It's a little different from the other script (which I don't recall seeing before) - mine only sub-divides quads - as Chris's request and it also traps for any possible new 'dividing' edges not falling on the face - e.g. with L-shaped or 3nr co-linear-vertex faces...

B/Chris: It runs by selecting some faces and then typing triangulate in the Ruby-console... To add a menu item you can simply add these lines onto the end of the script using a plain-text editor...
Code: Select all
### Menu ###
UI.menu("Plugins").add_item("Triangulate 4-edged Face in Selection"){triangulate}if not file_loaded?(File.basename(__FILE__))
file_loaded(File.basename(__FILE__))
0
Last edited by TIG on Fri Jul 03, 2009 11:07 pm, edited 1 time in total.
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulate.rb v1.2

Postby TIG » Fri Jul 03, 2009 11:03 pm

OK, OK... 8-) Here's v1.3 viewtopic.php?p=169956#p169956
It now has a menu and traps for unsuitable selections...

I only made it as a quick hack because Chris asked how to triangulate the quad faces of a sphere........................
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulate.rb v2.0

Postby TIG » Tue Jul 07, 2009 8:44 pm

Here's v2.0, now new improved - 'triangulates' [almost] everything...
viewtopic.php?p=169956#p169956
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulate.rb v2.0

Postby Chris Fullmer » Tue Jul 07, 2009 9:36 pm

Thanks TIG, this is great!!!
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Plugin] triangulate.rb v2.1

Postby TIG » Wed Jul 08, 2009 9:51 am

Here's v2.1, I've renamed the command triangulatefaces(array_of_faces) as 'triangulate' was already a defined command inside delauney/cloud scripts etc, used to triangulate points...
viewtopic.php?p=169956#p169956
Please replace earlier versions with this new file to avoid clashes...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulate.rb v2.1

Postby sepo » Wed Jul 08, 2009 12:01 pm

Cheers Tig...nice one.
0

sepo 
 

Re: [Plugin] triangulate.rb v2.1

Postby CPhillips » Fri Jul 24, 2009 2:29 am

Here is the method I use:

Code: Select all
def triangulateFace(face)
    ents=Sketchup.active_model.active_entities
    faces=face.mesh.polygons
    verts=face.mesh.points
    faces.each{|f|
        ents.add_line(verts[f[0].abs-1],verts[f[1].abs-1])
        ents.add_line(verts[f[1].abs-1],verts[f[2].abs-1])
        ents.add_line(verts[f[2].abs-1],verts[f[0].abs-1])
    }       
end


The nice thing is it cant fail to triangulate regardless of the shape or number of holes. But it unfortunately adds faces to the "holes". Or rather Sketchup does. Does anyone a way to add an edge without Sketchup attempting the "heal" the face?
0

CPhillips 
PluginStore Author
PluginStore Author
 

Re: [Plugin] triangulate.rb v2.1

Postby TIG » Fri Jul 24, 2009 9:57 am

I thought of that approach but abandoned it because of that facing hole problem...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulate.rb v2.1

Postby kwistenbiebel » Fri Jul 24, 2009 12:46 pm

Thank you TIG for this plugin. :thumb:

Do we still need to add those extra lines in the ruby console to get the plugin in a menu?
I couldn't find it in the Plugins/Tools menu, thus my question...
0

kwistenbiebel 
 

Re: [Plugin] triangulate.rb v2.1

Postby TIG » Fri Jul 24, 2009 1:11 pm

kwistenbiebel wrote:Thank you TIG for this plugin. :thumb:

Do we still need to add those extra lines in the ruby console to get a menu?
I couldn't find it in the Plugins/Tools menu, thus my question...

'Triangulate Faces in Selection' should be in the Plugins menu...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulate.rb v2.1

Postby kwistenbiebel » Fri Jul 24, 2009 1:25 pm

Strange, I can't find it anywhere in my long long plugin list :oops: .
Maybe it clashes with some other plugin? (I do have WxSU installed which caused me trouble with other plugins in the past).
By the way, I am on SU6 Pro.
0

kwistenbiebel 
 

Re: [Plugin] triangulate.rb v2.1

Postby TIG » Fri Jul 24, 2009 4:12 pm

kwistenbiebel wrote:Strange, I can't find it anywhere in my long long plugin list :oops: .
Maybe it clashes with some other plugin? (I do have WxSU installed which caused me trouble with other plugins in the past).
By the way, I am on SU6 Pro.

If you have 2.1 open it in a text editor and read the last bit it should define the menu...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulate.rb v2.1

Postby CPhillips » Wed Jul 29, 2009 8:07 pm

I finally figured out how to triangulate any face without the side effect of filling holes.

Code: Select all
def triangulateFace(face)
    mesh=face.mesh(1)
    faces=mesh.polygons
    verts=mesh.points
    uvs=mesh.uvs(true)
    outmesh = Geom::PolygonMesh.new
    faces.each{|f|
        outmesh.add_polygon(verts[f[0].abs-1],verts[f[1].abs-1],verts[f[2].abs-1])
    }
    ents=Sketchup.active_model.active_entities
    mat=face.material
    face.erase!
    grp = ents.add_group
    grp.entities.add_faces_from_mesh(outmesh)
    grp.entities.each{|e|
        if(e.class==Sketchup::Edge)
            e.smooth=false
            e.soft=false           
        elsif(e.class==Sketchup::Face && mat!=nil)
               #handle materials and uvs.
            uva=verts.index(e.vertices[0].position)
            uvb=verts.index(e.vertices[1].position)
            uvc=verts.index(e.vertices[2].position)
            e.material=mat
            e.position_material(mat,[verts[uva],uvs[uva],verts[uvb],uvs[uvb],verts[uvc],uvs[uvc]],true)
        end
    }
    grp.explode
end
0

CPhillips 
PluginStore Author
PluginStore Author
 

Re: [Plugin] triangulateFaces.rb v1.2 20101120

Postby TIG » Thu Jul 30, 2009 9:59 am

Thanks to CPhillips's inciteful ideas I have now made a 'joint' script called 'triangulateFaces.rb' which is attached. It uses CPhillips's triangulateFace(face) code [with a slight TIG addition for back_materials] and the TIG Plugin triangulateFaces(face_array)...
Originally 2009 (c) CPhillips* then (c) TIG** THEN (c) ThomThom ***
Script: triangulateFaces.rb
Code Usage: triangulateFace(face)*
Result: it triangulates a face... all Texture UVs are kept.
Plugin Usage: triangulateFaces(faces_array)**
Result: it triangulates faces in a selection...
v1.0
First Release: Def Code 'mesh' idea by CPhillips*,
retained back_materials added by TIG [failed] ###,
Plugin parts by TIG**. 20090729
v1.1
Rewritten entirely by TIG... THEN completely corrected by Thomthom (TT)!***
It now retains all Texture mapping successfully. 20091203
v1.2
Triangulated faces with 4 sides glitch fixed using intersection.

Get the latest version from here

Download

1
Last edited by TIG on Thu Dec 03, 2009 11:28 pm, edited 2 times in total.
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulateFaces.rb v2.1

Postby Coronel » Thu Jul 30, 2009 12:40 pm

Could you please clarify for a 3D newie the purpose of triangulation in this case?
Does it means the model will be correct or will work better or is merely a way of get more detail?
0

Coronel 
 

Re: [Plugin] triangulateFaces.rb v2.1

Postby TIG » Thu Jul 30, 2009 8:39 pm

Coronel wrote:Could you please clarify for a 3D newie the purpose of triangulation in this case?
Does it means the model will be correct or will work better or is merely a way of get more detail?

If you have a mesh that's rectangular it won't deform consistently. If you triangulate the faces they will... etc.
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulateFaces.rb v1.0

Postby CPhillips » Thu Jul 30, 2009 10:34 pm

I needed the triangulation to prepare a model for export.

Thanks for incorporating it into your script TIG! Why is it that back facing UV's didn't work?
0

CPhillips 
PluginStore Author
PluginStore Author
 

Re: [Plugin] triangulateFaces.rb v1.0

Postby TIG » Thu Jul 30, 2009 10:53 pm

CPhillips wrote:I needed the triangulation to prepare a model for export.

Thanks for incorporating it into your script TIG! Why is it that back facing UV's didn't work?

There is only a method to 'position material textures on a face' - and that assumes a 'front_face' - there's no 'back_face' method ? ...
0
Last edited by TIG on Fri Jul 31, 2009 6:44 pm, edited 1 time in total.
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulateFaces.rb v1.0

Postby CPhillips » Fri Jul 31, 2009 12:41 am

TIG wrote:
CPhillips wrote:I needed the triangulation to prepare a model for export.

Thanks for incorporating it into your script TIG! Why is it that back facing UV's didn't work?

There is only a method to 'place material textures on a face' - and that assumes a 'front_face' - there's no 'back_face' method...


Do you mean position_material? It takes a bool for front or back material

http://code.google.com/apis/sketchup/do ... n_material
0

CPhillips 
PluginStore Author
PluginStore Author
 

Re: [Plugin] triangulateFaces.rb v1.0

Postby ideas_arte » Fri Jul 31, 2009 5:36 pm

Thanx really useful!


where download? :oops:
0

ideas_arte 
 

Re: [Plugin] triangulateFaces.rb v1.0

Postby Jim » Fri Jul 31, 2009 5:49 pm

ideas_arte wrote:where download?


That's a valid question; it is not clear which version is the latest, and it is harder than necessary to locate the download.

The download is about 5 posts before this one.
0
Hi

Jim 
Global Moderator
 

Re: [Plugin] triangulateFaces.rb v1.0

Postby TIG » Fri Jul 31, 2009 6:45 pm

CPhillips wrote:
TIG wrote:
CPhillips wrote:I needed the triangulation to prepare a model for export.

Thanks for incorporating it into your script TIG! Why is it that back facing UV's didn't work?

There is only a method to 'place material textures on a face' - and that assumes a 'front_face' - there's no 'back_face' method...


Do you mean position_material? It takes a bool for front or back material

http://code.google.com/apis/sketchup/do ... n_material

Duh! :oops: I'll adjust the code and re-post...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulateFaces.rb v1.0

Postby TIG » Fri Jul 31, 2009 10:02 pm

There's something afoot... What I posted before worked - on keeping the front face texture mapping but not on the back_face... Now when I try it it fails to map both faces ? Any ideas - CPhillips's idea worked fine in tests but now seems to fail...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] triangulateFaces.rb v1.0

Postby CPhillips » Sat Aug 01, 2009 2:38 am

Post the code and I'll have a look. It might be the face.mesh(1). I think you need to use a different number when you want back uv's as well.
0

CPhillips 
PluginStore Author
PluginStore Author
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 

Next


 

Return to Plugins

Who is online

Users browsing this forum: No registered users and 11 guests

Visit our sponsors: