PDA

View Full Version : MXS - Script runs very slow and finally it hangs( in heavy scenes)


bkravi
04-29-2009, 10:37 AM
Hi ,

I am working on materials selection script, it works fine on small scenes but when there is huge amount of geometry, it starts smoothly in the begining but as it progress further it slows down and down until it hangs. I dont know if I need to run manual garbage collection at some point

script does following work -
- it collect all scene object and replaces them with new black mtl
- then it loops through scenematerials index and it assgins 6 predefined colors to first 6 materials then it renders the scene, after rendering it assign black color to these 6 materials which are already stored in arrray. and then it repeats this process for next 6 materials and so on...

Please help if i am doing anything wrong in script or if anything can be done more effiicient way.

as per my format command it hangs at this code ( only in very heavy scenes ):

for LAO_index = 1 to lastAccessedObjects.count do
(
assignMaterialByMat lastAccessedObjects LAO_index m_index_black 4 color_rand_value:black
)



here is my code : ( without functions)


fn selByMaterials colorMethodBase:1.0 colorMethod_flag:3 =
(
if colorMethod_flag == 3 do
(
setAllSceneMtlToBlack()
format "\n\n\n============ All Materials set to black is done! Now starting actual coloration ============\n\n\n"
)

color_index = 1

lastAccessedObjects = #() --create empty array which will later hold list of all assigned objects which we will asssign a black color to

if scenematerials.count == 0 then messagebox "Scene has no Materials applied" title:"AutoSEL"
else
(
for sceneMat_index = 1 to scenematerials.count do
(
format "\nLoop index >> %\n" sceneMat_index

cur_obj = (for o in objects where classof o != Dummy and o.isHidden == false and o.material == scenematerials[sceneMat_index] collect o)

format"\n\tMtl collected % Objects\n"cur_obj.count
if cur_obj.count == 0 do format "Material % is not used in scene so skiping loop index >> %\n" scenematerials[sceneMat_index].name sceneMat_index --notify user that this is not used in scene

if cur_obj.count == 0 do continue -----------------------------------------------------

if colorMethod_flag != 3 and classof scenematerials[sceneMat_index]== Multimaterial then assignMaterialByMat cur_obj 1 sceneMat_index 2
else
(
if colorMethod_flag != 3 then assignMaterialByMat cur_obj 1 sceneMat_index colorMethod_flag
else
(
if color_index > colorCode.count do
(
color_index = 1

print "color_index >> Calling mental ray..."

renderWithMR ("By Material_CM"+ colorMethod_flag as string) lastAccessedObjects

for LAO_index = 1 to lastAccessedObjects.count do
(
assignMaterialByMat lastAccessedObjects LAO_index m_index_black 4 color_rand_value:black
)

lastAccessedObjects = undefined --make it clean so we can add next set of objetcts to it

lastAccessedObjects = #() --define it again

print "Everything is reset"

)

if color_index <= colorCode.count do
(
format "Assigning material by color code value >>%\n"colorCode[color_index]

if classof scenematerials[sceneMat_index]== Multimaterial then assignMaterialByMat cur_obj 1 sceneMat_index colorMethod_flag

else assignMaterialByMat cur_obj 1 sceneMat_index colorMethod_flag color_rand_value:colorCode[color_index]

for j = 1 to cur_obj.count do append lastAccessedObjects cur_obj[j]

format"Last Accessed Objects count is >> %\n"lastAccessedObjects.count

format"Last Accessed Objects Name is >> %\n"cur_obj[1].name

format"Current Object count is >> %\n"cur_obj.count

)

if color_index <= colorCode.count do
(
color_index = color_index + 1

format "\t\tColor_index is Less than Color Code count so Incrementing color_index to %\n" color_index
)

)

)
minusOneValue = 1 -- this value is always going to be 1 minus than the counter arrayObj_index below

for arrayObj_index = 1 to cur_obj.count do
(

if arrayObj_index == 1 then minusOneValue = 1 else minusOneValue = arrayObj_index - 1

if arrayObj_index > 1 do
(

if cur_obj[arrayObj_index].material != cur_obj[minusOneValue].material then meditToObj cur_obj arrayObj_index

else format "Object % is instance or has Multi sub material ...Ignoring it \n" cur_obj[arrayObj_index].name
)
)
)
renderWithMR ("By Material_CM"+ colorMethod_flag as string) scenematerials
)
)

CGTalk Moderation
04-29-2009, 10:37 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.