View Full Version : How can i make this faster? python script
01-17-2012, 10:23 PM
It basicly takes whatever is selected, and duplicates itself at each of its faces. I have it commented out at the end, but it can do the same opporation for the duplicated surfaces aswell. Needless to say this can get out of hand quick and takes forever if its anything more than a cube?
Is there any part that i could make it faster?
I was using instancing instead of duplicating and that took on average of 2* as long?
i did a couple test but couldn get it working, but is there a way to do this with particles? recource?
Thanks in advance for any advice!
OR can i do multithreading with this? Use 100% of proccesors. right now its only using 13% of my cpu
01-18-2012, 10:33 AM
I'm not really familiar with coding using pymel unfortunately so I can't help with anything specific, however, from what I've seen, read and heard I believe that pyMel is great for quickly writing code, but can perform a lot slower, especially when creating nodes (which is what you're doing right?)
I'm guessing that writing this completely in MEL or basic python may exhibit some speed increase... whether enough I have no idea.
Additionally, getting the face position by selecting it and querying the manip position, while a clever trick, may not be that smart in terms of performance speed with a lot of faces to iterate. This is something you'd have to test though to be sure.
Getting the face positions and normals via the API (or via a pyMel hook to the API?) may be quicker than your current methods.
01-18-2012, 11:46 AM
here is moded version of the script:
I changed the face-center function to one, using API call from python as Nathan suggested. Tested it on a 2500 polys sphere - the old one took ~ 2.5 sec to calculate, the API one took about 0.03 sec.
There is new variable called method - change it to compare both functions.
Also refreshing after each call is probably the next slowest thing, so I disabled it. Other changes I've made are commented.
Another thing, which I don't have the time to implement now is using the MItMeshPolygon to get the face normal, and store it with the position, so you wont need the normal constraint, which will speed up the process also.
Hope that helps.
01-18-2012, 10:59 PM
very cool thanks! looks like i need to learn the api side of things... One thing i will have to say is that the main speed concern of mine is happening in the 'duplicate' section.
originally i was inctancing... but this was waaaayy slower and even with cubes i was seeing slowdowns
it seems to be slowing down exponentially the more it runs. so a low polly (90 somethign faces) object duplicates 90 times and then 90 times for each... totalling around 8100 objs in the end. i left my home computer try a 96 face sphere and it made it the 79th in 8 hours. the first few it does really pretty quick... seconds, but as it goes on it just dies...
i feel like they should all take the same time, or slow down a little as more pollys are in the scene, but this is just terrible..
oh and it does a 24 sided sphere in 17 seconds.
01-18-2012, 10:59 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.