As of writing this post (3ds Max Interactive / Stingray 1.9) there isn't a way to directly use arrays in Flow, we can use them from Lua. But they would be so handy to do it all in Flow! So this is the first a series of posts on possible approaches that will let you use arrays.

The objective is to have an array with materials and assign those to a number of objects we create on the fly.

Max

Free scripts and utilities for 3ds Max from K-studio. Sweep Profile,MaxFileViewer,EffectsChannelSet,Render RenderElements,Vray-Quick Render, Multimat Name,Instance Material By Name,Get Material From Selected,Select by Material,Copy Material and Modifiers,Isolate Selection,Save Restore Selection,Set Selection Filter,Auto Save scene,Convert To. The 3ds Max Material Editor sample slots are completely black when using the Chaos Group V-Ray renderer in 3ds Max. Material slots appeared normal previously. 3ds Maxopens a modeless Material/Map Browser. Open a library group. In the list of library materials, double-click the name of the material you want. The material you chose replaces the previous material in the active sample slot.

In this post I'm going use the 'script do string' node, that way everything I do will be in the flow.

There are two parts to it:

3ds max material download

1. On level start we are going to intialise the array, in this case I wanted to make the array values easily editable so I used 'String Data' nodes that feed into the 'Script Do String' Node. One drawback is the limited number of input, but it works here as I only needed four.

In the node I use the following Lua code to build up the array:

test_array={}; test_array[0]=select(1,...); test_array[1]=select(2,...); test_array[2]=select(3,...); test_array[3]=select(4,...);

What this does:

  • first I declare that test_array is an array.
  • then a semi colon so I can add more commands in the same string
  • followed by setting the values for the four array element: in square brackets the index and the value is retrieved using the select(n,...) function with indices 0 to 3.

2. Now that the array is defined we can use it,

First we use the normal flow nodes to instance four units when you hit the 1 key on the keyboard:

  • Set the 'button name' of the 'keyboard button' node to 1
  • Hook its out to the in of the 'for loop' node
  • set the start and end values of the 'for loop' node to 0 and 3
  • the 'current value' of the 'for loop' node is hooked up to the X of te 'Vector from Component' node - that way they get created side by side
  • the actual units get created by the 'Spawn Unit on Position' node which takes the string data that contains the unit name, the position we computed in the 'Vector from Components' node. The 'loop body' of the 'For Loop' node needs to be hooked to the 'Spawn' of the 'Spawn Unit on Position' node.
  • once all that is done we get to the 'Script Do String' node which uses the 'Spawned Unit', the material slot name from the 'String Data' node and the 'Current Value' of the 'For Loop' node to run the Lua code. The 'Spawned Unit' from the 'Spawn Unit of Position' node needs to be hooked to the 'In' of the 'Script Do String' node in order for the Lua code to be triggered.
3ds max material library

The Lua code used is relative simple:

stingray.Unit.set_material(select(1,...), select(2,...), test_array[select(3,...)])

3ds Max Material Editor More Slots

What this does:

  • the stingray.Unit.set_material function needs three parameters: 1. the unit, 2. the material slot name and 3. the material name we're going to use in this slot.
  • we get the unit by calling select(1,...) - so we need to hook up the unit to the arg 1
  • we get the material slot by calling select(2,...) - so we need to feed the slot name (which you can check in the unit editor) to arg 2
  • we get the actual material name by looking up the index (which we get from select(3,...)) in the test_array array - so we need to feed the current value from the for loop to arg 3.

3ds Max More Material Slots Online

To run this in your own level you need to provide the following:

  • four materials, enter their their paths (relative to the project) in the four 'String Data' nodes of the 'initialise array' section
  • a unit, enter that path in the top 'String Data' node of the 'use array values' group and enter the material slot name (which you can find in the unit editors materials section) in the bottom 'String Data' node of that same group.
  • You may want to add a multiply or divide node before the 'X' of the 'Vector from Components' if the unit is wider than1.
Coments are closed
Scroll to top