Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Using a predefined Array vs Objects on the fly

Using a predefined Array vs Objects on the fly

Anonymous
Not applicable
281 Views
1 Reply
Message 1 of 2

Using a predefined Array vs Objects on the fly

Anonymous
Not applicable
How in the world working on a pre-defined array is 100 times slower than collecting it on the fly?

The following script will create a biped and re-apply on each bone its position transform from frame 1 to 100. On the first try I used a pre-defined array and on the second i am collecting on the fly.

The result:

Pre-Defined array took: 1520 miliseconds
Collecting on the fly: 3 miliseconds



here is the code:

(
local newBip = biped.createnew 100 0
local boneList = for i in objects where (classof i) == biped_object collect i
local timeStart = undefined

timeStart = timestamp()
for i = 1 to 100 do
(
for b in bonelist do at time i biped.settransform b #pos (biped.gettransform b #pos) true
)
format "Operation took: % miliseconds \n" ((timestamp()) - timeStart)


timeStart = timestamp()
for i = 1 to 100 do
(
for b in objects where (classof i) == biped_object do at time i biped.settransform b #pos (biped.gettransform b #pos) true
)
format "Operation took: % miliseconds \n" ((timestamp()) - timeStart)

)
0 Likes
282 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
for b in objects where (classof i) == biped_object


You have a small mistake there (checking the class of i instead of b, always false). Second version isn't collecting anything.
Once this is fixed, this can not be faster than first version.
0 Likes