CGTalk > Software Specific Forums > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 08-09-2010, 06:51 PM   #1
Thorn444
New Member
Peter Kerpcar
Bratislava, Slovakia
 
Join Date: May 2007
Posts: 29
is it smarter way for this ?

Hi

I have been trying again do some maxscript stuff and come to part of script where i am looking for some variable inside array which is created from point3 values and i would like to know if is any better, faster and smarter way how deal with this. My biggest issue is that i cant find any other way how search inside this values only by converting them into new integer array which i don't think is very efficient. So what do you think can you make this easier ? Thanks

my result
Code:
a = 5 -- searching for value 5 c =#() d =#() b = #([4,1,5],[3,6,5],[9,8,7]) -- array for search for j = 1 to b.count do ( c_temp = #() d_temp = #() for i = 1 to 3 do append c_temp (b[j][i] as integer) -- convert [] array into integer value append c c_temp d_temp = finditem c[j] a append d d_temp ) d
 
Old 08-09-2010, 07:04 PM   #2
Bobo
Krakatoa Guy
 
Bobo's Avatar
Borislav Petrov
Product Specialist
Thinkbox Software
Vancouver, Canada
 
Join Date: Mar 2002
Posts: 5,320
MAXScript is expression-based, so using intermediate variables to store the various stages of calculations, while allowed and possible, are not always necessary.

So you can reduce the whole searching part to a single complex expression:

Code:
a = 5 -- searching for value 5 b = #([4,1,5],[3,6,5],[9,8,7]) -- array for search result = for j in b collect (finditem (for i = 1 to 3 collect j[i]) a)


The result will be the same #(3,3,0), but with a lot less intermediate results.

On the plus side, the code will run a bit faster if you are searching through a lot of Point3 values or if you execute the same code many times because intermediate variable allocations and memory management cost time. I tested your code vs. mine with 100,000 iterations and my timing was 7.688 seconds vs. 10.109 seconds for your code.

On the negative side, the above expression might be a lot more difficult to digest if you are seeing it for the first time...
__________________
Bobo

Last edited by Bobo : 08-09-2010 at 07:07 PM.
 
Old 08-09-2010, 07:20 PM   #3
Thorn444
New Member
Peter Kerpcar
Bratislava, Slovakia
 
Join Date: May 2007
Posts: 29
hehe yes this is exactly what I was talking about. Quick and efficient how I wanted. I just didn't know the right words Thanks Bobo
 
Old 08-09-2010, 07:58 PM   #4
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,182
Send a message via ICQ to denisT
has to be a bit faster:
Code:
a = 5 b = #([4,1,5],[3,6,5],[9,8,7]) for p in b collect (finditem #(p[1],p[2],p[3]) a)


or ...

it looks ugly but it's 3.5 times faster and 15 times less of memory leaking (vs original code):
Code:
a = 5 b = #([4,1,5],[3,6,5],[9,8,7]) for p in b collect (if p[1] == a then 1 else if p[2] == a then 2 else if p[3] == a then 3 else 0)


so, the smart way is not charming sometime.

Last edited by denisT : 08-09-2010 at 09:50 PM.
 
Old 08-11-2010, 03:53 PM   #5
Thorn444
New Member
Peter Kerpcar
Bratislava, Slovakia
 
Join Date: May 2007
Posts: 29
Hi DenisT

I know i didn't mention this in my post but I was thinking about much more way which you can use generally , because i guess your both version can be use only if you know how much numbers you have in array or for small array how I used in my example array and I must maybe mention that. But anyway thanks for another option how deal with collecting stuff quicker and efficient.

Cheers
 
Old 08-11-2010, 06:56 PM   #6
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,182
Send a message via ICQ to denisT
Quote:
Originally Posted by Thorn444
Hi DenisT

I know i didn't mention this in my post but I was thinking about much more way which you can use generally , because i guess your both version can be use only if you know how much numbers you have in array or for small array ...

Cheers

I guess that Point3 value has 3 members...

Last edited by denisT : 08-11-2010 at 11:08 PM.
 
Old 08-11-2010, 06:56 PM   #7
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:39 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.