PDA

View Full Version : A helpful tool for selecting / matID / uv


stuh505
01-23-2005, 08:59 PM
This tool is designed to make the process of dividing a model into different material ID sections much easier. I made this for myself because I was finding it literally impossible to select the proper areas due to the number of inside faces of my model.

It works on editable meshes or editable polys.

In short, what you can do is select edges to form a closed Gaussian loop and then select a face inside this encirclement and have it select all the faces that are enclosed. ITs not very picky and doesnt matter if you have lots of extra edges defined inside or outside the loop. It can also use the transition to other matIDs as bounding edges thus making dividing a model into sections really quick. And ive put in tools at the bottom to make it so you can assign the matIDs really quickly, things like Flash etc are really helpful for checking matID locations without losing selection set.

its also recommended for best use that you assign a multi subo object material with different colors for each matID onto the object so you can see the matID sections as you work

http://img168.exs.cx/img168/9850/guiview8pq.jpg

Define Edges Group

EdgeMode - Puts the currently selected editable mesh or editable poly into edge sub-object mode
Define - Defines the currently selected edges as bounding edges

Fill Faces Group

FaceMode - Puts the currently selected editable mesh into face sub-object mode, or the currently selected editable poly into polygon sub-object mode
FillRegion - Expands the currently selected face(s) to fill the region bounded by the defined edges
Max Iterations - Use this spinner to control the number of iterations that fillRegion will run each click. Use a high value to fill the entire region in 1 click (this may take a second). Use lower values to fill the selection size slowly out from the originally selected face(s), allowing you to visualize any leaks in the bounding edges.
Bound by MatID - Check this button to consider the edges between faces of other matID's to be bounding edges for the fill operation.

Set Material ID Group

Flash - Use this button to toggle the highlighting of the material ID in the associated spinner. Use this when you want to visualize faces of a matID without losing the current selection.
Select - Use this button to select the matID in the associated spinner.
Set - Use this button to set the currently selected faces to the matID of the associated spinner.


popup button:
macroscript MatIDFill category:"Heinrich"
tooltip:"MatID Fill"
(
createDialog heinrichMatFiller
)

actual code:
rollout heinrichMatFiller "MatID Fill" width:160 height:376
(
checkButton edgeMode "EdgeMode" pos:[16,112] width:60 height:20
checkButton faceMode "FaceMode" pos:[16,176] width:60 height:20
button defineEdges "Define" pos:[80,112] width:60 height:20
button fillRegion "Fill Region" pos:[80,176] width:60 height:20
checkbox boundByMatID "Bound by MatID" pos:[16,232] width:128 height:16 checked:true
button setID "Set" pos:[24,336] width:60 height:20
checkButton flashID "Flash" pos:[24,288] width:60 height:20
groupBox grp4 "Set Material ID" pos:[8,264] width:144 height:104
bitmap bmp1 "Bitmap" pos:[8,8] width:140 height:74 enabled:true fileName:"C:\Documents and Settings\Stuart Heinrich\Desktop\HeinrichLoop\heinrichfill.jpg"
button selectID "Select" pos:[24,312] width:60 height:20
spinner spn_maxIter "" pos:[88,208] width:44 height:16 enabled:true range:[1,200,10] type:#integer
label lbl5 "Max Iterations:" pos:[16,208] width:72 height:19
groupBox grp18 "Define Edges" pos:[8,88] width:144 height:56
groupBox grp19 "Fill Faces" pos:[8,152] width:144 height:104
spinner spn_Flash "" pos:[88,288] width:48 height:16 range:[1,100,1] type:#integer
spinner spn_Select "" pos:[88,312] width:48 height:16 range:[1,100,1] type:#integer
spinner spn_Set "" pos:[88,336] width:48 height:16 range:[1,100,1] type:#integer
global storeFaceSel=#()
on edgeMode changed state do
(
if state==on and selection.count==1 then
(
subObjectLevel = 2
max modify mode
faceMode.state = false --pop button up
)
)

on faceMode changed state do
(
if state==on then
(
if classOf(selection[1]) as string=="Editable_mesh" then
(
subObjectLevel = 3;
max modify mode
edgeMode.state = false --pop button up
) else if classOf(selection[1]) as string=="Editable_Poly" then
(
subObjectLevel = 4;
max modify mode
edgeMode.state = false --pop button up
)
)
)

on defineEdges pressed do
(
obj = selection[1]
global wallEdges = getEdgeSelection obj

messageBox ((wallEdges as array).count as string + " border edges defined.") title:"MatID Fill"
)

on fillRegion pressed do
(
finished=false;
i=0;

while finished==false and i<spn_maxIter.value do
(
obj = selection[1] --get selected object

faceSel = getFaceSelection obj --get selected faces


if classOf(obj) as string=="Editable_mesh" then
(
originalMatID = getFaceMatID obj (faceSel as array)[1] --store original matID of first face selected
edgeSel = meshop.getEdgesUsingFace obj faceSel -- get edges using face
edgeSel = meshop.getEdgesReverseEdge obj edgeSel + edgeSel -- addend reverse edges
wallEdges = wallEdges + meshop.getEdgesReverseEdge obj wallEdges
edgeSel = edgeSel - wallEdges --stop growing selection at wall
newFaceSel = meshop.getFacesUsingEdge obj edgeSel -- get all new faces

if boundByMatID.state==true do --ignore unoriginal matID's
(
for f = 1 to obj.numfaces do
(
if getFaceMatID obj f!=originalMatID do
(
deleteItem newFaceSel f --dont add faces of new matID to selection
)
)
)--end if bound by mat id

) else if classOf(obj) as string=="Editable_Poly" then
(
originalMatID = polyop.getFaceMatID obj (faceSel as array)[1] --store original matID of first face selected
edgeSel = polyop.getEdgesUsingFace obj faceSel -- get edges using face
edgeSel = edgeSel - wallEdges --stop growing selection at wall
newFaceSel = polyop.getFacesUsingEdge obj edgeSel -- get all new faces
if boundByMatID.state==true do --ignore unoriginal matID's
(
for f = 1 to obj.numfaces do
(
if polyop.getFaceMatID obj f!=originalMatID do
(
deleteItem newFaceSel f --dont add faces of new matID to selection
)
)
)--end if bound by mat id
)--end editable poly conditional


if oldFaceSel==newFaceSel do
finished=true;
i = i+1;

setFaceSelection obj newFaceSel -- select polys

update obj

max modify mode

subObjectLevel = 4
)
) -- end fillRegion pressed
on flashID changed state do
(
obj = selection[1]

if state==on do
(
if classOf(obj) as string=="Editable_mesh" then
(
obj = selection[1] --get selected object
storeFaceSel = getFaceSelection obj --store selected faces
flashFaceSel = #() --empty bitarray

for f = 1 to obj.numfaces do
(
if getFaceMatID obj f==spn_Flash.value do
(
append flashFaceSel f
)
)--end for loop
setFaceSelection obj flashFaceSel
)--end editable mesh conditional
else if classOf(obj) as string=="Editable_Poly" then
(
obj = selection[1] --get selected object
storeFaceSel = getFaceSelection obj --store selected faces
flashFaceSel = #() --empty bitarray

for f = 1 to obj.numfaces do
(
if polyop.getFaceMatID obj f==spn_Flash.value do
(
append flashFaceSel f
)
)
setFaceSelection obj flashFaceSel
)--end editable poly conditional

)--end state on conditional

if state==off do
(
setFaceSelection obj storeFaceSel
)
)-- end flashID changed state
on setID pressed do
(
obj = selection[1]

if classOf(obj) as string=="Editable_mesh" then
(
obj = selection[1]
faceSel = getFaceSelection obj
selList = faceSel as array -- store bitarray as array
for count = 1 to selList.count do
(
setFaceMatID obj selList[count] spn_Set.value
)
)--end editable mesh section
else if classOf(obj) as string=="Editable_Poly" then
(
obj = selection[1]
faceSel = getFaceSelection obj
selList = faceSel as array -- store bitarray as array
for count = 1 to selList.count do
(
polyop.setFaceMatID obj selList[count] spn_Set.value
)
)--end editable poly section
)--end setID pressed
on selectID pressed do
(
obj = selection[1]

if classOf(obj) as string=="Editable_mesh" then
(
obj = selection[1] --get selected object
newFaceSel = #() --empty bitarray

for f = 1 to obj.numfaces do
(
if getFaceMatID obj f==spn_Select.value do
(
append newFaceSel f
)

)
setFaceSelection obj newFaceSel
)--end mesh section
else if classOf(obj) as string=="Editable_Poly" then
(
obj = selection[1] --get selected object
newFaceSel = #() --empty bitarray

for f = 1 to obj.numfaces do
(
if polyop.getFaceMatID obj f==spn_Select.value do
(
append newFaceSel f
)

)
setFaceSelection obj newFaceSel
)--end poly section
)--end selectID pressed
)--end rollout

moomin109
01-26-2005, 07:10 PM
This looks like it could be very handy (at least I think so).

Any chance of creating an easy to install plugin for us less-confident Max users? (unless I'm missing something?)

stuh505
01-26-2005, 08:10 PM
I've unwrapped about 20 complex objects with it so far for my project and I've found it to be an invaluable little tool...so hopefully others will too.

I haven't used maxscript much myself...this is basically the first thing I've made with it, so I don't know about an easy to install version...I'll look into it when I have time.

To get it working in max now, you can just go to create new Maxscript...paste the code in (both of them), then Evaluate them both from that window (file option). After you have evaluated them you can go to customize user interface and under the new category Heinrich select MatIDFill and drag it onto a toolbar or new floating toolbar...this will create a button which you can press to run the app. Hope that helps

moomin109
01-26-2005, 08:47 PM
It helps alot thanks, I'll give this thing a go and get back to you :thumbsup:

ulukai33
01-26-2005, 09:55 PM
Would you mind if some one more experienced would make the installator for you? (not me :) )

stuh505
01-31-2005, 10:53 PM
sure, it'd be great if someone else wanted to make the installer...i would then provide the bmp for the image(or they could get it by taking a screenshot because that is life size) and it would be very nice...if someone were to do that, it would be nice if they told me how they did it, though. by the way there is a small bug in the above code, one of the lines is inside of the loop slowing things down which i have just fixed in an edit.

CGTalk Moderation
01-31-2006, 11:00 PM
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.