MoI discussion forum
MoI discussion forum

Full Version: Rotate Array?

Show messages: All  1-13  14-15

From: AlexPolo
26 Feb   [#14]
Hi The Scale Array script does something like this but cant seem to find it in the history of the forum.
Regards
Alex.
From: Michael Gibson
26 Feb   [#15] In reply to [#13]
Hi MindSet, you would need to modify the Update() function in the RotateArray.js script file to do that.

There is a line of code in there that calculates the parameter value from 0 to 1:

code:
var t = i / ( Factories.length - 1 );


You would need to put in some more code after that to modify the parameter with your desired behavior.

Here's an example that will step up the rotation along the first third, hold it for the middle third, and then ramp back down the last third. Put this in place of the current Update function:

code:
function Update( Factories, TotalRotationAngle )
{
	for ( var i = 0; i < Factories.length; ++i )
	{
		var t = i / ( Factories.length - 1 );

		////// Added section here
		{
			function SmoothStep( t )
			{
				// https://en.wikipedia.org/wiki/Smoothstep
				if ( t <= 0 ) return 0;
				if ( t >= 1 ) return 1;
				return t * t * (3 - 2*t);
			}

			function GetParam( t, low, high )
			{
				t = (t - low) / (high - low);
				return SmoothStep(t);
			}
		
			if ( t < 1/3 )
			{
				// Beginning third, ramp up smoothly from 0 to full rotation

				t = GetParam( t, 0, 1/3 );
			}
			else if ( t > 2/3 )
			{
				// Ending third, ramp down smoothly from full rotation to 0

				t = GetParam( t, 1, 2/3 );
			}
			else
			{
				// Middle range, hold at full rotation
				t = 1;
			}
		}
		////// End added section


		// Set the angle on the factory
		Factories[i].setInput( 2, t * TotalRotationAngle );
		
		// Update the factory to make it recalculate the rotated result.
		Factories[i].update();
	}
}

Show messages: All  1-13  14-15