PDA

View Full Version : delete random polygon


womanonfire
09-15-2003, 11:31 PM
is there a script out there that will help me delete random polygons from my model? maybe to say what percentage i would like to see dissapppear.... leave holes in the model, most modellers nightmare, in my case, a dream.

wrend
09-16-2003, 03:37 AM
use Selection Constraints to get a selectn, then rub 'em.

zachgrachan
09-16-2003, 06:19 AM
So far this is what I got, about 1 hour into it:


int $i = 0;
int $randomNum = 0;

int $removeFaces = 25; //insert desired number of removed polys
int $totalFaces = 400 ; //insert poly count of selected faces here

doMenuComponentSelection("pSphere1", "facet"); //insert name of object here


for($i;$i<=$removeFaces;$i++)
{
$randomNum = rand(0, $totalFaces);
select -r pSphere1.f[$randomNum];
delete;
}





right now you have to edit the code each use, but I'll work on a GUI.

GrafOrlok
09-16-2003, 08:16 AM
hm... sounds like just selecting random faces manually and deleting them would be faster then...
:p

womanonfire
09-16-2003, 08:30 AM
@wrend: yes this does what i need it to do, thank you.

@zachgrachan: could be an interesting script once it has a gui. but for my immediate needs the Polygon Selection Constraints are doing the trick.

@graf: i think zachgrachan saw this as a mel coding excercise and it was nice of him to try to write a script. i didn't want to select and delete by hand because that just wasn't 'random' enough.

zachgrachan
09-16-2003, 01:00 PM
I'm always looking for scripts to write, hopefully someday soon somebody'll pay me to do it, heehee.

Are y'all saying that changing the couple of numbers/names is too slow, or that the selection constraints are way easy? 'Cause paint selecting doesn't seem like it'll be very random.

womanonfire
09-16-2003, 02:54 PM
the Select Constraints thing is way easy. but it is a very generalized tool that seems to change the global behavior of any selection you make. once you set the tool to select random edegs/vert/faces that is all you can do until you turn it off. a bit overkill when i just wanted to do it this once... but it works easily and well.

Typeing things into a script to do the same thing seems like uneccessary steps. but if your script had a gui and maybe the options were simplified from the vast array offered by Select Constraints it would be a good thing.

zachgrachan
09-16-2003, 03:06 PM
what is select constraints? I was thinking you were talking about painting a selection of faces. How exactly do you set it to select random faces? New tricks are always helpful.

womanonfire
09-16-2003, 05:10 PM
menu
Edit Polygons/Selection/Selection Constraints...
(i didn't know about it til wrend up there told me either ;) )

mhovland
09-16-2003, 06:43 PM
Here is an edited version with an interface.

Any problems, let me know.

zachgrachan
09-16-2003, 09:54 PM
Awesome!

I was just sitting down to do that, been in class all day. Thanks! Though I still may do it just for the practice...

Looking through it, I see formLayout. I've never really been able to get it to work. Can you tell me something the docs don't? Is there a trick or something?

mhovland
09-17-2003, 07:58 PM
There really isn't any trick to using formLayout. I was leary of using it at first also, but once I figured it out, it is really all I use. I prefer it because of the absolute control I get.

If you want to practice using it, here is what I would recommend.

Create a window, and give it a form layout. Then create a few buttons, and practice attaching them in different ways.

The most basic attachment is -attachForm. This attaches the control to the form, with an offset in pixels.

so using the following code:

///////
window -t "test Window" -h 200 -w 200 -s 0 myWin;
formLayout myWinForm;
button -l "button one" butOne ;

formLayout -edit
-attachForm butOne "left" 2
-attachForm butOne "top" 2
-attachForm butOne "right" 2
-attachForm butOne "bottom" 2

myWinForm;

showWindow myWin;
/////

we are attaching all four edges of the button to the edges of the form with a 2 pixel offset.

The next attachment is the -attachControl. This does the same thing as attach form, except you are attaching one edge of a control, to another edge of a control with an offset in pixels.

Lets revist the code above, and attach a second button

////////
window -t "test Window" -h 200 -w 200 -s 0 myWin;
formLayout myWinForm;
button -l "button one" -h 25 -w 100 butOne ;
button -l "button two" -h 25 -w 100 butTwo;

formLayout -edit
-attachForm butOne "left" 2
-attachForm butOne "top" 2

-attachControl butTwo "top" 2 butOne
-attachForm butTwo "left" 2

myWinForm;

showWindow myWin;
///////

or we can attach the controls side by side like this

///////
window -t "test Window" -h 200 -w 200 -s 0 myWin;
formLayout myWinForm;
button -l "button one" -h 25 -w 100 butOne ;
button -l "button two" -h 25 -w 100 butTwo;

formLayout -edit
-attachForm butOne "left" 2
-attachForm butOne "top" 2

-attachControl butTwo "left" 2 butOne
-attachForm butTwo "top" 2

myWinForm;

showWindow myWin;
//////////

The big gotchas are the way you define the attachments seems a little counter intuitive, but it gets easier the more you do it.

The other attachment method to play with is the -attachOppositeControl. This one was the hardest for me to figure out, but is really quite useful. It will take another post to explain it, so if you need help, let me know.


Now here is a little personal preference, that I had to figure out the hard way, in terms of interface layout.

You will notice in the script I posted earlier, that I create variables to hold all the interface items (i.e. string $newWindow = `window myNewWin`; ) but I also include a Maya internal name for the items (the last part of the window command, "myNewWin").

I used to never assign a Maya internal name, and if I needed to access the information from an interface item in another procedure, I would make the variable holding the item a global variable. This works, but you run the risk of stepping on your global variables. If you have a global variable in more than one script named the same thing, which is real easy to do if you don't use descriptive names, you can have unexpected results. If you include a Maya internal name, and access the information using it, you don't have to declare global variables, which is always prefered. :buttrock: :thumbsup:

That was long winded, wasn't it? Hope it helped. If you have any more questions let me know. I can always be reached at

mhovland@midwaygames.com

zachgrachan
09-18-2003, 02:48 AM
you know, I really love this forum... you ask a question, and people take time and put forth effort to answer.... thanks for all the help, I'll check that out after I turn in my current project/fiasco tomorrow.

Thanks again!

CGTalk Moderation
01-16-2006, 03:00 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.