PDA

View Full Version : is there a right way to "DETRIANGULATE"!!


bmlokesh
07-17-2008, 12:27 PM
hi,

I am using max9, trying to detriangulate a polygon (editpoly) where 2 faces are present. A polygon is made up of 2 triangular faces where the giagonal edges are not welded.

I want to weld 2 edges, remove the edge and apply smoothing group for the face.

I tried to script this through max listener, could not succeed.
I tried detriangulate from script spot, no use

Can anybody guide me to do this please.



Thanks in advance

Giggsy
07-17-2008, 01:14 PM
I think I stumbled over a script like this in the maxscript help file a few days ago - maybe I can find it again ;)

MoonDoggie
07-17-2008, 02:49 PM
scriptspot has a detriangulation script, check it out!

decapitator
07-17-2008, 05:26 PM
scriptspot has a detriangulation script, check it out!If its the one I tried a while back (dont know the name anymore), its quite horrible on a bit more complex models like the car I tried it on.

j-man
07-17-2008, 05:34 PM
Hi!

well technically a polygon is a shape with at least three sides, a face! but I know what you mean. The problem is that there are loads of different rules for what makes up different types of polygons. in your case it sounds like you want to hide the hypotenuse of a bunch of faces so that they read like polygons with four edges, or two faces.

This will do that. but, it's sketchy at best!


-- www.joshuanewman.net

fn getedgelength obj edg=
(
x=(meshop.getvertsusingedge obj edg) as array
d=distance (getvert obj x[1]) (getvert obj x[2])
return d
)


for obj in selection do
(
hide=#()
fce=for f in obj.selectedfaces collect f.index
for f in fce do
(
edg=meshop.getedgesusingface obj f
hideedge=edg[1]
t=0
for i in edg do
(
l=getedgelength obj i
-- format "% % &\n" t l (l>t)
if l>t then (hideedge=i;t=l)
)
append hide hideedge
)
obj.selectededges=hide
update obj
)


Select faces in the subobject and execute.

Josh.

bmlokesh
07-18-2008, 04:12 AM
I have a car model which is done in a way where
some polygons are having 2 faces of which the edges are not welded (see attached image 01).

when I render theese faces they r coming as not smooth faces, but they standout (see attached image 03).

Even affter applying smoothing group it cannot solve this problem (see attached image 02).

I tried many scripts from script spot..........NO

I solved this face problem by welding the 2 edges and removing the edge, apply smoothing group .... I WANTED TO SCRIPT THIS BECAUSE OF 113354 FACES.

I am looking for a script which runs through the mesh to find theese kind of faces and fixes the problem.

Please guide me if their is any other way to do this

Thanks in advance

kikialex
07-18-2008, 07:29 AM
fn gaseste_daca_unghiu_dintre_tri_e_mic intrare index_1 index_2 =
(
test_1 = polyop.getFaceNormal intrare index_1
test_2 = polyop.getFaceNormal intrare index_2
rezultat = acos(dot (normalize test_1) (normalize test_2))
return rezultat
)

--gaseste_daca_unghiu_dintre_tri_e_mic selection[1] 7 2

fn bagi_un_edge_si_iti_spune_daca_e_bun obj index_e th =
(
fete =polyop.GetEdgeFaces obj index_e
if (fete.Count >= 2) and ((polyop.getFaceVerts obj fete[1]).Count != 4) and ((polyop.getFaceVerts obj fete[2]).Count != 4) do
(
iesire = gaseste_daca_unghiu_dintre_tri_e_mic obj fete[1] fete[2]
if (iesire <= th) do
(
return true
)
)
return false
)


--bagi_un_edge_si_iti_spune_daca_e_bun selection[1] 9 5

fn bagi_o_selectie_raman_edgeuri_dintr_fete_paralele obj th =
(
sel = polyop.getFaceSelection obj
sel2 = #()
for j in sel do
(
temp_sel = polyop.getFaceEdges obj j
for j in temp_sel do
(
if j != undefined do
(
append sel2 j
)
)
)
ce_iese = #()
for i in sel2 do
(
if (bagi_un_edge_si_iti_spune_daca_e_bun obj i th) do
(
if i != undefined do
(
append ce_iese i
)
)
)
return ce_iese
)

--print (bagi_o_selectie_raman_edgeuri_dintr_fete_paralele selection[1] 5)


fn bagi_edgeuri_si_vezi_daca_au_acelas_sg_la_fete obj index_e =
(
fete = polyop.GetEdgeFaces obj index_e
if (polyop.getFaceSmoothGroup obj fete[1]) == (polyop.getFaceSmoothGroup obj fete[2]) do
(
return true
)
return false
)

fn bagi_edgeuri_si_vezi_daca_au_acelas_mid_la_fete obj index_e =
(
fete = polyop.GetEdgeFaces obj index_e
if (polyop.getFaceMatID obj fete[1]) == (polyop.getFaceMatID obj fete[2]) do
(
return true
)
return false
)


fn bagi_un_array_raman_duar_cu_acelas_smooth obj array_edgeuri =
(
iesire_k = #()
for k in array_edgeuri do
(
if (bagi_edgeuri_si_vezi_daca_au_acelas_sg_la_fete obj k) do
(
append iesire_k k
)
)
return iesire_k
)

fn bagi_un_array_raman_duar_cu_acelas_mid obj array_edgeuri =
(
iesire_k = #()
for k in array_edgeuri do
(
if (bagi_edgeuri_si_vezi_daca_au_acelas_mid_la_fete obj k) do
(
append iesire_k k
)
)
return iesire_k
)



fn bagi_selectie_scoti_op obj th sm mid =
(
if (sm == true) and (mid == false) do
(
rez = (bagi_un_array_raman_duar_cu_acelas_smooth obj (bagi_o_selectie_raman_edgeuri_dintr_fete_paralele obj th))
--polyop.SetEdgeSelection obj rez
return rez
)
if (sm == true) and (mid == true) do
(
rez = (bagi_un_array_raman_duar_cu_acelas_smooth obj (bagi_o_selectie_raman_edgeuri_dintr_fete_paralele obj th))
rez2 = bagi_un_array_raman_duar_cu_acelas_mid obj rez
--polyop.SetEdgeSelection obj rez2
return rez2
)
if (sm == false) and (mid == false) do
(
rez = (bagi_o_selectie_raman_edgeuri_dintr_fete_paralele obj th)
--polyop.SetEdgeSelection obj rez
return rez
)
if (sm == false) and (mid == true) do
(
rez = (bagi_un_array_raman_duar_cu_acelas_mid obj (bagi_o_selectie_raman_edgeuri_dintr_fete_paralele obj th))
--polyop.SetEdgeSelection obj rez
return rez
)

)


fn fata_are_peste_2_pleaca_alea_scurte obj index_f array_edge scurte =
(
tdist = 0
e_ramas = undefined
edgurile_fete = (polyop.getFaceEdges obj index_f )
verifica = #()
for ef in edgurile_fete do
(
cp = (findItem array_edge ef)
if (cp != 0) do
(
append verifica ef
)
if (verifica.Count > 1) then
(
for i in verifica do
(
arr = (polyop.getEdgeVerts obj i)
dis = (distance (in coordsys world polyop.getVert obj arr[1]) (in coordsys world polyop.getVert obj arr[2]))
--print dis
--print (findItem scurte i)
if (dis > tdist ) and ((findItem scurte i) == 0) then
(
e_ramas = i
tdist = dis
)
else
(
append scurte i
)
)
)
)
return e_ramas
)


fn pastreaza_edgeuri_lungi obj th sg mID ramase=
(
scurte =#()
dupa_op = (bagi_selectie_scoti_op obj th sg mID)
fete_sel = polyop.getFaceSelection obj
for f in fete_sel do
(
de_tras = (fata_are_peste_2_pleaca_alea_scurte obj f dupa_op scurte)
if de_tras != undefined do
(
append ramase de_tras
)
)
--polyop.SetEdgeSelection obj (ramase as bitarray)
return ramase
)

fn transforma_quad obj th sg Mid =
(
undo "kiki2quad" on
(
ramase = #()
e_lungi = pastreaza_edgeuri_lungi obj.baseobject th sg mID ramase
de_sters = pastreaza_suprafata e_lungi selection[1].baseobject
polyop.SetEdgeSelection selection[1].baseobject (de_sters as bitarray)
obj.Remove selLevel:#edge
ttp = Turn_TO_poly()
ttp.keepConvex = true
ttp.limitPolySize = true
ttp.MaxPolySize = 4
addModifier obj ttp
convertTo obj (Editable_poly)
)

)




--print "XXXX"
--print (bagi_un_array_raman_duar_cu_acelas_smooth selection[1].baseobject (bagi_o_selectie_raman_edgeuri_dintr_fete_paralele selection[1].baseobject 5))

--bagi_selectie_scoti_op selection[1].baseobject 2 false !!ok

--fata_are_peste_2_pleaca_alea_scurte (selection[1].baseobject) 1356 (bagi_selectie_scoti_op selection[1].baseobject 6 true)
--fn obiect_de_curatat unghi_de_atac fii_atent_la_smooth_group fii_atent_la_material_id
--pastreaza_edgeuri_lungi selection[1].baseobject 15 false false
--transforma_quad selection[1] 15 true true
fn pastreaza_suprafata edgeuri_condamnate obj =
(
gratiate = #()
append gratiate 0
for i = 1 to (polyop.GetNumFaces obj) do
(
edgeurile_fetei = (polyop.GetFaceEdges obj i)
martor = 0
for j in edgeurile_fetei do
(
if (findItem edgeuri_condamnate j) != 0 do
(
martor += 1
)
)
if (martor > 1) do
(
append gratiate i
)
)

care_mor = #()
--print gratiate
for e = 1 to edgeuri_condamnate.Count do
(
--print (findItem gratiate edgeuri_condamnate[e])
if (findItem gratiate edgeuri_condamnate[e]) == 0 do
(
append care_mor edgeuri_condamnate[e]
)
)
return care_mor
)


rollout tri2quad "tri2quad" width:245 height:104
(
button ok_btn "select edges" pos:[7,69] width:99 height:32
spinner th_c "Search threshold" pos:[47,47] width:105 height:16 range:[0,360,24] type:#float scale:0.1
checkbox sm_grp "Look for Smoothing-Grups" pos:[7,3] width:203 height:20
checkbox mat_id "Look for Material-ID" pos:[7,24] width:203 height:20
button ok_c_ob "change object" pos:[128,69] width:99 height:32


on ok_btn pressed do
(
ramase = #()
e_lungi = pastreaza_edgeuri_lungi selection[1].baseobject th_c.Value sm_grp.State mat_id.State ramase
de_sters = pastreaza_suprafata e_lungi selection[1].baseobject
polyop.SetEdgeSelection selection[1].baseobject (de_sters as bitarray)
subObjectLevel = 2

)

on ok_c_ob pressed do
(
transforma_quad selection[1] th_c.Value sm_grp.State mat_id.State
)
)


createdialog tri2quad


This is my version of script for changing triangles to quads, the object must be editable poly and you must select the faces that you want to change.

CGTalk Moderation
07-18-2008, 07:29 AM
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.