Break Non Planar Polygons into Triangulated Polygons

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 01 January 2013   #16
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.
 
Old 01 January 2013   #17
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
 
Old 01 January 2013   #18
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
 
Old 01 January 2013   #19
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
 
Old 01 January 2013   #20
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.
 
Old 01 January 2013   #21
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
 
Old 01 January 2013   #22
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
<Mesh mesh> <edgelist> ignoreVisEdges:<boolean=false> threshhold:<float=45.>
 
Old 01 January 2013   #23
Originally Posted by denisT: here is it:
btw... i found in documentation:
meshop.getPolysUsingEdge <Mesh mesh> <edgelist> ignoreVisEdges:<boolean=false> threshhold:<float=45.>


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
 
Old 01 January 2013   #24
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.
 
Thread Closed share thread



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 vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 04:46 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.