Notifications
Clear all

[Closed] How to place objects randomly along a spline?

Hi everyone,

I need to make a script (because I didn’t find this function I need included into MAX) which places 5 objects in a random order along a spline. The idea behind this is that I got 5 differnet “domino-stones” with which I want to build I domino game. The problem with the allign tool is that there is no random function and I want that the dominos are placed in a random order.
Have you any idea about this sctipt or another method?

Thanks in advance.
VooDooMatrix

9 Replies

My idea:
You try change randomly objects pivot and use the spacing tool.

I believe scatter will work, no? If not then maybe a particle system such as parray or pflow?

Hi,

thank you for your answers. Unfortunatly I am not that familiar with 3DSMax. Could you please explain it a bit more detailed?

Thank you in advance.

Oops… maybe that wont help.

function placeObjsOnSpline inputSpline inputObjs =
   (
   	local objsToPlace = #{1..inputObjs.count} as array;
   	for i = 1 to inputObjs.count do
   	(		
   		placeObjIndex = (random 1 objsToPlace.count);
 	 inputObjs[objsToPlace[placeObjIndex]].position = (pathInterp inputSpline (i / inputObjs.count as float)); 
   		
   		objsToPlace = (deleteItem objsToPlace placeObjIndex);
   	);
   );

Usage:
placeObjsOnSpline
i.e.

placeObjsOnSpline $'Line01' #($'Point01',$'Point02',$'Point03',$'Point04',$'Point05')

However this doesn’t do orientation, I might get a chance to update it.

THANK YOU
woohoo

This is nearly what I ment – I will experiment a bit with the script. I am on my way in learnin this stuff.

Now the objects are placed in a random distance to the next. Like it is in domino the objects are placed in nearly the same distance from each other, but the order of the objects is randonmly. The random-order thing works perfectly and maybe you got another Idea for that “same distance” – thing – but I will also try a bit around

Thanks again.

c ya
VooDoo

Hi,

I experimented a bit around and come up to the following untill now:


-- Aufruf: placeObjsOnSpline $'Line01' #($'Box01',$'Box02',$'Box03',$'Sphere01',$'Sphere02') 25 10
function placeObjsOnSpline inputSpline inputObjs inputDistance inputCount =
   (
   local objsToPlace = #{1..inputCount} as array;
   x = curveLength inputSpline as float;
   x = (inputDistance * 100) / (x * 100) as float;
   y = 0;
   i = 1;
   
  for i = 1 to inputCount do -- Loop for creating an array with instances
	   (
	   placeObjIndex = (random 1 inputObjs.count);
	   objsToPlace[i] = instance inputObjs[placeObjIndex];
   );


   for i = 1 to inputCount do -- Place objects in array on spline
	   (
	    y = ((i-1) * x);
		print y;
		if y<=1 then objsToPlace[i].position = (pathInterp inputSpline (y));
   );
   );

As you see this is based on the script posted above.
But I got some problems with it:

  1. I want to place the randomly chosen objects in the same distance to each other on this spline starting with the beginning of the spline (therefore the (i-1)). I thought this would work, but MAX doesn’t place them in the same distance to each other.
    Have you any idea how to realize this?

  2. Another thing is that I want to place more then the given objects on the spline. This means I want to make instances of the objects I gave to the function and place them on the spline. Therefore is the “inputCount” argument which should specify how many instances should be made in general. So if inputCount is 10 and you give 3 Objects to the function there should be 10 randomly chosen (from the 3 given objects) objects on the spline :).
    Now instances would make it possible that I only need to edit the source-object to change all of them ^^ – would make it way easier – but if I use “instance” as above it doesn’t work that way

  3. How can I make the direction of the new objects follow the tangents of the spline?

It would be gread if you could waste one ore two thoughts on my problem.

Thanks in advance.
Tom

  1. Your problem with the distances isn’t that it’s placing it randomly on the spline, it’s actually placing them the same distance apart, however if your spline ‘curves’ extremly then you will get spacing ‘streatched’ around that curve. Try creating a line (just two points) and running the original script on that. You should find that they are placed exactly the same distance apart.

  2. Aren’t you just better off creating the instances before you run the script? so the exectution would be

placeObjsOnSpline $'Line03' #($'Point01',$'Point02',$'Point03',$'Point04',$'Point05',$'Point06',$'Point07',$'Point08',$'Point09',$'Point10',)

Where point06 to point10 are instances.

  1. Try the following:
function placeObjsOnSpline inputSpline inputObjs =
    (
 	   local objsToPlace = #{1..inputObjs.count} as array;
 	   for i = 1 to inputObjs.count do
 	   (		
 		placeObjIndex = (random 1 objsToPlace.count);
 		inputObjs[objsToPlace[placeObjIndex]].pos.controller = path follow:true;
 		PosCont = inputObjs[objsToPlace[placeObjIndex]].pos.controller;
 		PosCont.path = inputSpline;
 		PosCont.axis = 2;
 		PosCont.percent = ((i / inputObjs.count as float) * 100);
 		objsToPlace = (deleteItem objsToPlace placeObjIndex);
 		
 	   );
    );
    
 placeObjsOnSpline $'Line01' #($'Point01',$'Point02',$'Point03',$'Point04',$'Point05');

Hi,

thank you so much for your thoughts and script.

To 1.: It seems as I can’t change this – but good to know. Thanks

To 2.: I tryed both methods (in script and before) – The Problem if I do this before the script is that I got rather large numbers of objects that I want to create (aprox. 120) – and if I do create them before I run the script I have to build a rather long command-line for the script (with all the 120 objects) – for this I think it’s better to create the objects directly in the script.

To 3.: Woohoo – This does what I wanted – the directions are now very good and I will modify it just with my dinstance-Argument and maybe with the instance-stuff.

I thank you very very much

c ya
Tom