2
$\begingroup$

Trying to build a basic procedural Cube shaped rooms where

  • One collection will have many pre-made wall presets (wall with window,wall with door etc) List item
  • AN will take each wall ,make 4 copies with 90 degree offset and store them in a new collection
  • AN nodes will now pick random elements from each collection and build a room with 4 walls picked randomly

What i have accomplished:

I have a basic square wall with object origin at world center wall


Then i instance this wall 4 times with offset of 90 degrees to get 4 walls

quad instance


Now the problem starts

  • I use "Get list element" with random int input to get random walls
  • Random int seed is controlled by frames
  • when i plug this random output into another collection it appends the new wall instead of overwriting

What i want

  • As i hit play i want to see random walls flickering in and out

What i get

  • I see the collection getting filled in random order in the first 4 frames

to collection


My end goal is to export the rooms as FBX to use in other applications

$\endgroup$

1 Answer 1

1
$\begingroup$

You need to use a loop.

What you are doing is calling the same method x number of times, x being the number of frames. But in your method, although you do instantiate 4 objects you are only affecting your geometry to one of them. As far as I know the objects created in the object instancer node are put in a pool to be reused when needed, they are not destroyed and recreated every time. That would make sense in order to increase performance.

To the point.

  • Create a "Loop" with Add > Subprograms > Loop
  • Add a "Parameter" of type "Object List"
  • Create an invoke node on this loop with Add > Subprograms > "My Loop" (you can rename it)
  • Set the iterations to 4
  • Add a "Collection info" node, set it to your wall blueprints collections and plug the "objects" into your loop invoke input "Object List" input (you can rename it).
  • Use a "Get Random List Element" Node and set it to "Single", plug the frame info added to the index into the seed, that way every wall will be randomised, and every frame the setup will change. Add a big number to the frame so that the two seeds are independant.
  • Add an object instancer and set it to mesh, instances to 4.
  • Add a new parameter of type "Object List", rename it "Mesh objects". Plug the instancer into the input of the invoke node.
  • In the loop, Plug the wall blueprints into the "Get Random List Element" node.
  • Add a "Get List Element" node and plug the mesh objects into it, and the index of the loop into its index.
  • Add a "Mesh Object Output" node, plug both "Element" outputs into it (the random one into the mesh input). Ths swill automatically create a "Mesh object output" node, you can check "Use modifiers" if your walls have some. Click the button on the right of the "Mesh" line
  • Now to translate the meshes to the origin : Get the opposite of the blueprint position, and translate the mesh using a compose matrix.
  • Finally plug the index into a math node to multiply by 90, into a combine euler set to degrees and into an "Object Transforms Output" set to rotate around Z.

The final node tree:

enter image description here enter image description here

Bonus :

If you want to get ALL possible combinations. We have to use a little script and mathematics.

  • Go to the scripting workspace, add a script, name it as you wish. Write this :

    import bpy import itertools
    combinations = [range(len(blueprints.objects))]*4
    linear_combinations = [] for combination in itertools.product(*combinations): linear_combinations.extend(combination)

The result will be a very long list of integers, corresponding to each different possible combination. For 4 wall and 4 differents walls, I got 4*4*4*4*4 = 1024 different combinations. The integer being the index of the child object in the collection. for example the first few are :

enter image description here

We need to rework slightly our node tree. I won't go into detail in the loop so you can just follow the screenshot :

enter image description here

Add a "Script" node. Select your newly created script and set the input and output names exactly like in the code else it won't work. Place an invoke node to your script, and plug it like so :

enter image description here

Result :

enter image description here

Beware, it kind of crashed when I tried to add another wall blueprint element.

$\endgroup$
5
  • $\begingroup$ It is the other way around, you subtract 0,0,0 by the vector, to get the opposite. Could you share your blend file so I can take a look at it ? Maybe you plugged something in the wrong place, it is very easy to mess up when the screen becomes cluttered with nodes. You can use blend-exchange.giantcowfilms.com $\endgroup$
    – Gorgious
    Commented Feb 26, 2020 at 17:09
  • $\begingroup$ Used your setup....its working well forgot to add loop index to seed so all walls were showing up same ..now fixed... now figuring out how it works ... thank you. What purpose do the mesh transform nodes at the bottom right of node tree have ? why subtract by zero ? $\endgroup$
    – Prime007
    Commented Feb 26, 2020 at 17:10
  • $\begingroup$ blend file blend-exchange.giantcowfilms.com/b/kVQoQVxA $\endgroup$
    – Prime007
    Commented Feb 26, 2020 at 17:16
  • $\begingroup$ Usually when there is an operation in a math node, it is applied between the first and second inputs. So there we are getting the opposite of your blueprint's position in order to offset it. In your blend it doesn't serve any purpose but in your question you seemed to have modeled your blueprints some distance away from the origin. That way you can move and modify your blueprints anywhere you want $\endgroup$
    – Gorgious
    Commented Feb 26, 2020 at 17:24
  • 1
    $\begingroup$ ahh..ok ,it serves as a 'reset location' for the blueprints and i wont have to overlap them in the blueprints collection. cool $\endgroup$
    – Prime007
    Commented Feb 26, 2020 at 18:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .