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.

how to keep a running total in MCG without static varibles ?

how to keep a running total in MCG without static varibles ?

kenzor
Enthusiast Enthusiast
1,263 Views
7 Replies
Message 1 of 8

how to keep a running total in MCG without static varibles ?

kenzor
Enthusiast
Enthusiast

I know maxscript exceptionally well but I'm a new to MCG.

I looking to create some parameteric towers but i seem to be failing at the first hurdle. 

Basically i'd like to make tower of random objects as a geometry plugin in MCG were the user supplies a list of object an a integer number, and a random seed.. 

But without a varible to keep a running total of the height I'm getting a bit lost. I realise that we are meant to follow a functional programing model in MCG but it just feels unreasonably convoluted

 

If this was maxscript i'd do something like:-

 

- set height to zero

- initialise empty array of meshes

- for i = 1 to n (   

-     pick object from list 

-     move the object up by the current value of height

-     height = height + object.BBox.z

-     append object to array

-     )

- output mesh array as geometry 

 

In the image below i've managed to make a simple array of clones, but this only works because i can simply multiple the index by a set value.

How do I keep a running total of the current height without some sort of global varible to keep a running total as i do in my maxscript example? Should I use the cache node ? Is this overkill ?

 

Programming without variables is kinda melting my brain I've used a bunch of other visual programing languages in which this would be really easy.

 

What's a good approach to make a tower of randomly sized objects ?  How do i keep a running total of the height to offset the next object in the tower ?

 

Thanks in advance for any help 

-ken

 

mcg towermcg tower

0 Likes
1,264 Views
7 Replies
Replies (7)
Message 2 of 8

Swordslayer
Advisor
Advisor
0 Likes
Message 3 of 8

kenzor
Enthusiast
Enthusiast

thanks for the reply Swordslayer. 

I see. So this means in MCG I need an array where in maxscript a simple float would do.

( just so were clear I need to match the height offset to the bounding box of the mesh in the previous floor in the building )

Do I need to do everything with arrays? This would make the pseudo code MCG for my building generator something like:-

- user inputs the number of floors

- Make an array of random numbers based on the number of floors

- Take my random number array and make an array of meshes

- Take my mesh array and make and array of Bounding box heights.

- Take the bounding box height array and sum them to make an array of offset heights

- Apply the offset height array to my mesh array

- Merge the mesh array to output my final Geometry.

 

I realise I need to learn to think 'functional' rather than 'procedural' but this seems crazy is there a better way ?

0 Likes
Message 4 of 8

Swordslayer
Advisor
Advisor

While I agree that for some things, the mcg approach is pretty convoluted (I wouldn't use mcg in production), what you described here is far from crazy (unless you're into microoptimizations but then the only good option in max is C++). It might make sense to use mesh-height pairs instead of separating meshes and bbox heights but other than that you got it right.

0 Likes
Message 5 of 8

kenzor
Enthusiast
Enthusiast

Actually I think there is a better way.

There's a great blog post here https://area.autodesk.com/blogs/the-3ds-max-blog/the-array-looping-cook-book/

There's a few ways of aggregating arrays that look way more efficient.  

0 Likes
Message 6 of 8

Swordslayer
Advisor
Advisor

Depends on the use case, you want one attach call at the end for efficency and for that you need an array of meshes and offsets - you won't get that with Aggregate.

0 Likes
Message 7 of 8

kenzor
Enthusiast
Enthusiast

arg you're probably right. I'm such a NOOB at this I think I'll need to work through all the different methods just a as learning exercise. 

 

Vojtěch I like your http://creativescratchpad.blogspot.co.uk/2011/06/maxscript-one-liners-for-artists.html  I was thinking of doing some thing similar as a weekly tweet https://twitter.com/designimageinfo/status/987757084224745472

 

0 Likes
Message 8 of 8

kenzor
Enthusiast
Enthusiast

So heres my first version with lots of arrays. 

 

First Tower.jpg

 

I feel that i should be able to make an array of random meshes directly without having to make an array of random numbers first but i can't get it to work

0 Likes