MoI discussion forum
MoI discussion forum

Full Version: Rotate Array?

Show messages: All  1-11  12-15

From: Frenchy Pilou (PILOU)
8 Mar 2020   [#12]
All that was in 2D or 3D? (you speak about "morphing between the two" )

There is also maybe the LineWeb (Michael) http://moi3d.com/forum/index.php?webtag=MOI&msg=3666.1
or CMorph (Max Smirnov) http://moi3d.com/forum/index.php?webtag=MOI&msg=6373.1
functions ... who can be help for some cases!


From: Mindset (IGNITER)
26 Feb   [#13] In reply to [#11]
Hello everyone,
I need the script to rotate, as it does, incrementally along the array to some maximum degree... but then also please, dwell (continue rotating by said maximum degree some additional elements, [perhaps by quantitative percentage] , and then decrement the rotational effect back down to none... i.e. leaving the last the element in the array result series to remain in its original orientation.
It would be nice if it could also have "Ease in/Ease out" control similar to that which is currently available under the "Limit to axis" option of the twist command.
I am most stymied, for the time being, by the dwell aspect of this perplexity; that is, how to serially rotate multiple array elements by said maximum degree.
Thanks,
MindSet
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-11  12-15