Loop more fast...

Hello everyone :)

I have write a little script which allows me to detach and make an object the faces of a poly. The main part of Whole script is a string recovery from 3dsMaxScript:

obj = selection[1]
for p = polyop.getNumFaces obj to 1 by -1 do (polyop.detachFaces obj #{p} asNode:true)

Ok, the script works well, but...

If I start the script and I 500/800 faces, it is fast, but if I have more of 1000 faces, max crash or freezes... Do you know a way to make it more stable and faster the code above? I tried, but no appreciable result ...

Thank for any reply

Michele

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Michele71's picture

Thanks miauu and barigazy :)

Thanks miauu and barigazy :)

Today I'll try both codes but they are certainly better than the original! it's always nice to discover new forms of programming. A good start to continue my studying :)

Thanks again

miauu's picture

Branko provided a good

Branko provided a good example to see the differences between the FOR and the WHILE loop. :) They do the same, but with different speed.

Michele71's picture

It's true! I have always

It's true! I have always asked how to use FOR or WHILE loop :D

barigazy's picture

...

Yup. It's fester because I use predefined variables.
But it's not memory efficient solution as Kostadin method.
Do you see why? .... I tell you anyway :)
This cause memory leaking

number-=1

barigazy

miauu's picture

.

On object with 1250 polygons this:

(
	obj = selection[1]
	objFaceCnt = polyop.getNumFaces obj
	poDetachFaces = polyop.detachFaces
	for p = objFaceCnt to 1 by -1 do (poDetachFaces obj #{p} asNode:true)
)

tooks less than 3 sec.

barigazy's picture

...

I tested this on Sphere with 64 segs
#1 miauu code

(
    gc() ; t1 = timestamp() ; m1 = heapfree
    obj = selection[1]
    objFaceCnt = polyop.getNumFaces obj
    poDetachFaces = polyop.detachFaces
    for p = objFaceCnt to 1 by -1 do (poDetachFaces obj #{p} asNode:true)
    format "time:% memory:%\n" ((timestamp()- t1 as float)/1000) (m1-heapfree)
)

#2 my code

(
    gc() ; t1 = timestamp() ; m1 = heapfree
    node = selection[1]
    number = node.faces.count+1
    detachFaces = polyop.detachFaces
    while (number-=1) != 1 do (detachFaces node #{number} asNode:on)
    format "time:% memory:%\n" ((timestamp()- t1 as float)/1000) (m1-heapfree)
)

#1 -> time:5.472 memory:545648L

#2 -> time:4.752 memory:640712L

barigazy

Michele71's picture

I tried the two loops on my

I tried the two loops on my notebook (not performing) with a Sphere with 64 segs:

#1 -> time:19.456 memory:86400L
#2 -> time:16.68 memory:107384L

Original string: time:16.624 memory:109400L

Seems be fast as the example of barigazy... Is possible? You can do a test ??

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.