How to create an animated equalizer in 3dMax using Maxscript?

This tutorial will explain how to use MaxScript to create an animated bar equalizer effect in 3dmax, and provide code description and implementation.

Similar to creating animated bar equalizer effects, it is difficult to achieve manually because they need to be adjusted at each frame. Therefore, in this tutorial, we will use the MaxScript function of 3dmax to write a simple and short script (with instructions) to achieve this effect. Let’s get started.

1. Let's first create a chamfer box and clone it a few times by holding down the shift key and dragging it. I already have 10 chamfer boxes in the scene.

              

2. Now, go to "Script->New Script" to launch the Maxscript editor. Let's write some code.

 
 
a= $ChamferBox* as array
with animate on 
for i=0 to 100 by 2 do
at time i
(		
	a.height = random 1 60
)

    Run the script:    

a= $ChamferBox* as array

This line will add all chamfer boxes to an array. Because arrays allow us to modify multiple objects at once, we can now modify all chamfer boxes at the same time.

for i=0 to 100 by 2 do

We use a For loop to repeat the random command multiple times. I want my script to create a keyframe after every two frames during script execution, so instead of I=0 to 100 do I use by 2 in the For loop.

 

at time i
(
a.height = random 1 60
)

This code randomizes the height of all our array elements every frame (range: from 1 to 60).

As we can see, all elements of the array have random heights every frame, but note that each box has the same height value every frame.

          

3. Let's modify the code to make it better and more interesting. Here is a modified version of the script:

 
 
a= $ChamferBox* as array
with animate on 
for i=0 to 100 by 2 do
at time i
(		
   a[1].height = random 1 60
   a[2].height = random 1 60
   a[3].height = random 1 60
   a[4].height = random 1 60	
   a[5].height = random 1 60
   a[6].height = random 1 60
   a[7].height = random 1 60
   a[8].height = random 1 60
   a[9].height = random 1 60
   a[10].height = random 1 60
)

      Run the script:

          

illustrate:

As you can see, I just write each element of the array separately.

a[1].height = random 1 60

The numbers between the square brackets represent the array elements, so every time we execute the script it will randomize each array element one by one and each box will get a different height value every frame. I have 10 boxes in the array, so I wrote 10 lines of code, one line for each box.

Hope you like this tutorial!

Guess you like

Origin blog.csdn.net/mufenglaoshi/article/details/134973182