# Break Non Planar Polygons into Triangulated Polygons

 01 January 2013 #16 denisT MAX Doctor   portfolio Denis Trofimov CA, USA   Join Date: Jul 2009 Posts: 9,949 Originally Posted by wallworm: Denis... you are verifiably... A GOD. You have all answers. honestly before i found the simple solution i wrote 5 different functions with various luck... here is the best one: `````` fn planarTriangulate node = ( mesh = converttomesh node theHold.Begin() for f in mesh.faces as bitarray do ( for k=1 to 3 do setEdgeVis mesh f k on ) converttopoly node ee = for e in node.edges as bitarray collect ( ff = polyop.getedgefaces node e if ff.count >= 2 and (polyop.getfacenormal node ff[1] != polyop.getfacenormal node ff[2]) then (polyop.getEdgeVerts node e) else dontcollect ) -- node.selectededges = ee as bitarray if theHold.Holding() do theHold.Cancel() for v in ee do polyop.createedge node v[1] v[2] update p )`````` works pretty fast. share quote
 01 January 2013 #17 wallworm Shawn Olson   portfolio Shawn Olson Wall Worm Columbus, USA   Join Date: Jul 2011 Posts: 222 Denis, the function listed above has errors... perhaps you pasted a different version from your final? Anyway, since the above turn_to_poly modifier fixed the problem, now I'm trying to adapt your function to simply return true or false if a node has non-planar polygons. But I seem to be failing. For the moment in this function, I want to detect any object so convert only to mesh as a copy. But the results are inconsistent. This is how I adapted it. It seems to be correct a lot... but some objects it fails on. `````` fn hasNonPlanarPolygon node = ( local hasNonPlanarPolygon = false if superClassOf node == GeometryClass then ( local mesh = copy node converttomesh mesh for e in mesh.faces as bitarray while hasNonPlanarPolygon == false do ( ff = (meshop.getPolysUsingFace mesh e ignoreVisEdges:true) as array if ff.count >= 2 and (getfacenormal mesh ff[1] != getfacenormal mesh ff[2]) then ( hasNonPlanarPolygon = true ) ) delete mesh ) return hasNonPlanarPolygon ) `````` __________________ Shawn Olson Autodesk Expert Elite 3ds Max Charter Member Developer of: Wall Worm Tools for the Source Game Engine CorVex Level Design Plugin share quote
 01 January 2013 #18 denisT MAX Doctor   portfolio Denis Trofimov CA, USA   Join Date: Jul 2009 Posts: 9,949 Originally Posted by wallworm: Denis, the function listed above has errors... perhaps you pasted a different version from your final? c'mon! errors! there is only one small bug (like this ¤). to fix it just change p at the end of function to node share quote
 01 January 2013 #19 wallworm Shawn Olson   portfolio Shawn Olson Wall Worm Columbus, USA   Join Date: Jul 2011 Posts: 222 Originally Posted by denisT: c'mon! errors! there is only one small bug (like this ¤). to fix it just change p at the end of function to node Yeah I know I only mentioned so you could edit post if you felt like it __________________ Shawn Olson Autodesk Expert Elite 3ds Max Charter Member Developer of: Wall Worm Tools for the Source Game Engine CorVex Level Design Plugin share quote
 01 January 2013 #20 denisT MAX Doctor   portfolio Denis Trofimov CA, USA   Join Date: Jul 2009 Posts: 9,949 Originally Posted by wallworm: Yeah I know I only mentioned so you could edit post if you felt like it unfixed author's bugs sometimes help others to understand how the code works that's the main difference between bugs and errors. share quote
 01 January 2013 #21 wallworm Shawn Olson   portfolio Shawn Olson Wall Worm Columbus, USA   Join Date: Jul 2011 Posts: 222 Originally Posted by denisT: unfixed author's bugs sometimes help others to understand how the code works that's the main difference between bugs and errors. Well many of us are gracious. Extremely. __________________ Shawn Olson Autodesk Expert Elite 3ds Max Charter Member Developer of: Wall Worm Tools for the Source Game Engine CorVex Level Design Plugin share quote
 01 January 2013 #22 denisT MAX Doctor   portfolio Denis Trofimov CA, USA   Join Date: Jul 2009 Posts: 9,949 Originally Posted by wallworm: I'm trying to adapt your function to simply return true or false if a node has non-planar polygons. But I seem to be failing. here is it: `````` fn hasNonPlanarFaces node threshold:0.0001 = if iskindof node GeometryClass do ( mesh = snapshotasmesh node done = #{} has = off for f=1 to mesh.numfaces while not has where not done[f] do ( ff = meshop.getPolysUsingFace mesh f join done ff if ff.numberset > 1 do ( ff = ff as array n = getfacenormal mesh ff[1] for k=2 to ff.count while not has do ( has = (abs (1.0 - (dot n (getfacenormal mesh ff[k]))) > threshold) -- if has do format "%: % != %\n" ff n (getfacenormal mesh ff[k]) ) ) ) free mesh has )`````` btw... i found in documentation: meshop.getPolysUsingEdge ignoreVisEdges: threshhold: share quote
 01 January 2013 #23 wallworm Shawn Olson   portfolio Shawn Olson Wall Worm Columbus, USA   Join Date: Jul 2011 Posts: 222 Originally Posted by denisT: here is it: btw... i found in documentation: meshop.getPolysUsingEdge ignoreVisEdges: threshhold: Thanks for the function... I'll test it later today. I did test with with meshop.getPolysUsingEdge but was failing... will look at it again. __________________ Shawn Olson Autodesk Expert Elite 3ds Max Charter Member Developer of: Wall Worm Tools for the Source Game Engine CorVex Level Design Plugin share quote
 01 January 2013 #24 CGTalk Moderation Expert   Join Date: Sep 2003 Posts: 1,066,473 Thread automatically closed This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum. __________________ CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.