์๋ฌด๋ฆฌ ์ข์ ์ถฉ๊ณ ๋ผ ํด๋, ๋น์ ์ด ํ์ํ ๊ฒ์ด๋ผ๋ ํ์ ์ด ์๊ธฐ๊ธฐ ์ ๊น์ง๋ ์ด๋ ํ ์ถฉ๊ณ ๋ ๋ฐ๋ฅด์ง ๋ง๋ผ. -๋ฐ์ด๋น๋ ์๋ฒ ๋ฆฌ
๏ปฟ * ์๋ฌธ๋งํฌ :
http://www.scriptspot.com/bobo/mxs2/mxs_tut/lesson01.html
http://www.scriptspot.com/bobo/mxs2/mxs_tut/lesson01.html
- ์ธ์ ๋์ฒ๋ผ ๋ด๋ง๋๋ก ๋ฒ์ญ์ ๋๋ค.
๊ฐ์ #
์ด ๊ธ์ ์ ๋ฌธ๊ฐ๋ค์๊ฒ ๋งฅ์ค์คํฌ๋ฆฝํธ๋ฅผ ์๋ ค์ฃผ๊ณ ์ํ๋ ๊ฒ์ด ์๋๋ค. ๊ธฐ๋ณธ์ ์ธ ๊ฒ๋ง์ ์ค๋ช
ํ ๊ฒ์ด๋ฉฐ ๋๋ ค์ํ ํ์๋ ์๋ค - ๋งฅ์ค์คํฌ๋ฆฝํธ๋ ์ฝ๊ณ , ์ตํต์ฑ์์ผ๋ฉฐ ์ฌ๋ฏธ์๋ค. ์ฐ๋ฆฌ๋ ๋นํธ๋งต์ผ๋ก ๋ถํฐ ํฝ์
์ ๋ณด๋ฅผ ์ฝ์ด๋ค์ด๋ ์งง์ ์ฝ๋๋ฅผ ์์ฑํ๊ณ ํฝ์
๋ฐ์ดํ์ ๊ธฐ์ดํ ์
์ฒด๋ฅผ ์์ฑํ ๊ฒ์ด๋ค. ๊ทธ๋ฆฌ๊ณ ๋ํ ํ ์ค๋ง ๋ฐ๊พธ๋ ๊ฒ๋ง์ผ๋ก ์๋ง์ ํจ๊ณผ๋ค์ ์์ฑํ๋๋ฐ ์ฌ์ฉ๋ ์ ์๋ ์ฝ๋๋ฅผ ๋ณด๊ฒ ๋ ๊ฒ์ด๋ค. ์ฒซ๋จ๊ณ๋ก ๊ธฐ๋ณธ ํจ์ ์ฝ๋๋ฅผ ์์ฑํด๋ณด๋๋ก ํ์. (์ธํฐํ์ด์ค๊ฐ ์๋๋ค. ์ด๊ฒ์ 2์ฅ์์ ๋ค๋ฃฌ๋ค.) ์ด ์ฒซ๋ฒ์งธ ๋ฒ์ ผ์์๋ ๋ช๋ช ๊ฐ๋ค์ "ํ๋์ฝ๋ฉ"๋์ด์๋ค. (์ด๊ฒ์ ๋์ค์๋ ์ฌ์ฉ์ ์ ์ํ์์ผ๋ก ๋ฐ๋์ด์ง ๊ฒ์ด๋ค)
์์ ํ ์คํฌ๋ฆฝํธ ์์ค์ฝ๋์ ์คํํ๋๋ฐ ํ์ํ ๊ฒ์ ์ ๋ฐํ์ 'M' ๊ธ์ ํ๋๋ฅผ ๋ณด์ฌ์ฃผ๋ ๋นํธ๋งต ์ด๋ฏธ์ง(40x40x32bit)๋
http://www.scriptspot.com/bobo/mxs2/mxs_tut/lesson01.zip์์ ๋ค์ด๋ก๋ ๋ฐ์ ์ ์๋ค.
http://www.scriptspot.com/bobo/mxs2/mxs_tut/lesson01.zip์์ ๋ค์ด๋ก๋ ๋ฐ์ ์ ์๋ค.
MAXScript(MXS) ์ฌ์ฉ์ ์ํ ๋ช๊ฐ์ง ์ฉ์ด๋ค #
- ์ปค๋งจ๋๋ผ์ธ ํ๋กฌํํธ์์์ MXS๋ฅผ ์ฌ์ฉํ ์ ์๋ค. ๋ค์๊ณผ ๊ฐ์ด ์ฝ๋๋ฅผ ์ ๊ณ Enterํค๋ฅผ ๋๋ฌ ์คํํด๋ณธ๋ค.
box ()
๊ธฐ๋ณธ์ค์ ์ ๊ฐ์ง ์ ์ก๋ฉด์ฒด๊ฐ 0,0,0 ์ขํ์ ๋ํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
- ์คํฌ๋ฆฝํธํ์ผ์์์ ๋ช ๋ น๋ค์ ์์ฑํ ์ ์์ผ๋ฉฐ ์ฐจํ ์ฌ์ฉ์ ์ํด ๊ทธ๊ฒ๋ค์ ์ ์ฅํ ์ ์๋ค. ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๊ธฐ์ํด์๋ Utility->MAXScript->Open Script๋ฉ๋ด๋ฅผ ์ ํํ ํ, Ctrl+E๋ฅผ ๋๋ฆ์ผ๋ก์จ ๊ทธ๊ฒ์ ์คํ์ํจ๋ค.
- ๋งฅ์ค ํ๋ฌ๊ทธ์ธ๊ณผ ๋น์ทํ ํํ์ ์ฌ์ฉ์ ์ธํฐํ์ด์ค๋ฅผ ์ ๊ณตํ๋ Scripted Utility๋ฅผ ์์ฑํ ์ ์๋ค. (2๋ฒ์งธ ํํ ๋ฆฌ์ผ ์ฐธ์กฐ)
- MAXScript Controller๋ ์ ๋๋ฉ์ด์
์ฝํธ๋กค๋ก์จ ์คํฌ๋ฆฝํธ๋ฅผ ๋ฐ์๋ค์ธ๋ค.
์, ์ด์ ์ฝ๋๋ฅผ ์ ์ด๋ณด์! #
--MAXScript Tutorials --LESSON 01 --by Borislav Petrov [FA] --bobo@email.archlab.tuwien.ac.at ----------------------------------------------- --Visit --http://support.ktx.com/~10 --for more MAXScript information and resources. --Visit the Diner --http://support.ktx.com/~8 --for a public discussion on these Tutorials. ----------------------------------------------- --Open a New Max scene --Load the script --PRESS Ctrl+E to Evaluate work_bmp = openbitmap "c:\\mxstut\\m.tga" --open an existing TGA bitmap from the tutorials directory. --make sure to change the path if your path is different. bmp_w = work_bmp.width --read the width of the bitmap into a variable bmp_h = work_bmp.height --read the height of the bitmap into a variable progressstart "Generating Objects..." --display progress indicator for h = 1 to bmp_h do --loop through all rows in the image ( pixel_line = getpixels work_bmp [0,(h-1)] bmp_w --store a single row #h into an array progressupdate (h as float /bmp_h *100) --update the progress indicator for w = 1 to bmp_w do --loop through all pixels in the current row ( size_value = 100 + (pixel_line[w].r+pixel_line[w].g+pixel_line[w].b)/3 --calculate a value based on the luminosity (R+G+B)/3 of the pixel. new_object = box length:100 width:100 height:size_value --create a new box with height based on the pixel value above new_object.pos = [w*100, (-h*100), 0] --put the new object on a new position based on the pixel's coords. --NOTE that in MAX, 0,0 is lower left corner, in images the UPPER left --this explains the - sign in (-h*100) --100 is the distance between objects. new_material = standardmaterial diffuse:pixel_line[w] --create a new standard material with diffuse color taken from the pixel's color new_object.material = new_material --assign the new material to the new object )--end w loop )--end h loop progressend () --end of the progress display close work_bmp --close the bitmap
work_bmp = openbitmap "c:\\mxstut\\m.tga"
A Bitmap is a MAX object and as every MAX object used in MAXScript it is stored in a variable. The openbitmap command opens an existing image. The file type can be any type supported by MAX, including animations (multi-frame bitmaps) like AVI, MOV and IFL. NOTE that you have to use \\ instead of \ when specifying paths in MAXScript!
์ด๋ฏธ์ง๋ ๋ค์๊ณผ ๊ฐ๋ค. (์ฌ๊ธฐ์๋ 3๋ฐฐ๋ก ํ๋ํ๋ค):
bmp_w = work_bmp.width bmp_h = work_bmp.height
We create two new variables to hold the current size of the loaded image. If you change the path to load a different image, the script will still work correctly. The user variable work_bmp represents the bitmap object.
Every object in MAX has its own properties. Properties are accessed by typing the object followed by a dot "." and the property name. To check what properties are available for a certain object, you can either look in the Online Help or type showproperties object
For example:
my_box = box () [์ํฐ๋ฅผ ๋๋ฅธ๋ค] showproperties my_box [์ํฐ๋ฅผ ๋๋ฅธ๋ค] .height : float .length : float .lengthsegs : integer .width : float .widthsegs : integer .mapCoords : boolean .heightsegs : integer
progressstart "Generating Objects..."
MAXScript provides some commands to display and control a progress indicator.
We just started a new one.
It displays the prompt text and still does not update.
for h = 1 to bmp_h do
(
This is a LOOP which consists of a variable, a start and end value.
The variable changes the value starting with the start value and stops growing when the end value is reached.
Our variable h starts with 1 and ends with the last line in the bitmap, bmp_h
All statements following the DO statement and between the brackets ( ) are repeated until the end value is reached.
It is a good idea to use a REMARK like "--end x loop" to denote the closing bracket so you can easily identify closing brackets.
Also, you can indent the whole loop for visual clearness.
You can also click near a bracket and press the Ctrl+B keys to invoke the "Bracket Balancer".
It shows the bracket pairs in the script by selecting them and any code inbetween.
NOTE that loops in MXS can be used in many different ways - to collect scene objects etc.
pixel_line = getpixels work_bmp 0,(h-1) bmp_w
We start reading the Bitmap now.
"pixel_line" is the user name of an ARRAY that will hold a whole row of pixels.
An array is a one-dimensional list of values which can be accessed using an index value.
All arrays in MAXScript are 1-based, this means that the first element has index 1.
For example, the first pixel in our case wouldl be accessed through pixel_line[1]
MAXScript uses dynamic arrays that change their size and have automatic memory management as you add values to the list.
If you want to initialize an empty array, you have to write my_array = #().
Since a MAXScript variable can be a scene object, text string or number, you can for example build lists of scene objects, or their names, or any of their numeric properies...
The getpixels command operates on the bitmap object.
It expects two values for the X and Y coordinates of the first pixel X,Y and a number of pixels to read (in our case the width of the image)
This function is relatively slow, it is a good idea to read as many pixels as possible into an array, and access the array elements instead of
getting single pixels.
NOTE that other than arrays, a Bitmap is a 2-dimensional 0-based list, where the first pixel in the upper left corner has coords 0,0 and NOT 1,1.
You must keep this in mind when looping through the image.
This is why we have the 0,h-1 instead of 1,h.
progressupdate (h as float /bmp_h *100)
We have already started a new progress indicator.
Now we will update it.
It accepts values between 0 and 100.(%).
By dividing the current loop value taken as a floating point number through the end value, we get values between 0.0 and 1.0.
Multiplied with 100 it returns what we need - percentage between 0 and 100.
The progress indicator can be also used to test the Esc/Cancel user input, but we will skip this today.
for w = 1 to bmp_w do
(
Now we start a second loop inside of the first one that counts from 1 to the last pixel in the row.
size_value = 100 + (pixel_line[w].r+pixel_line[w].g+pixel_line[w].b)/3
This line is the actual formula used to get a relation between the pixels and the geometry we will create.
In the future, we will play with different formulas to get lots of functions in the same script.
In this case, we take the Red, Green and Blue values from the single pixel variable's color saved in the array.
We add them together and divide by 3.
Then we add 100 to have at least 100 units for our geometry when the pixel is Black 0,0,0.
The value is thus based on the pixel's LUMINOSITY. (Greyscale Intensity).
You could easily change the formula to something like
size_value = 100 + (pixel_line[w].r)
In this case, only the red value will be used.
Pure red, violet and yellow colors will result in a value of 355 (100+255).
Any other colors with less Red components will be lower, down to 100. (100+0)
new_object = box length:100 width:100 height:size_value
Now we create a new BOX primitive with length and width = 100, and the already calculated value as height.
The new object is put into a new variable (as every MAX object).
We can now access the object's properties through variable name, dot, property name:
new_object.pos = w*100, (-h*100), 0
The .POS (or .POSITION) property defines the position in 3D space of any geometry object.
We use a Point3 value in the form X,Y,Z to specify 3D coordinates.
NOTE that in MAX, 0,0,0 is lower left corner when seen from the Top Viewport
In images, the UPPER left corner is 0,0 - this explains the sign in (-h*100)
100 is the distance between objects.
new_material = standardmaterial diffuse:pixel_line[w]
We create a new standard material with diffuse color taken from the pixel's color.
The material is also a MAX object saved in a variable and has its properties.
new_object.material = new_material
We change the .MATERIAL property of the new object - we assign the new material variable to it.
)--end w loop
Before the w loop has finished, the script WILL NOT go any farther...
)--end h loop
Everytime the w loop finishes, the h loop increases by 1. After it has finished, the script goes on...
progressend ()
We hide the progress display now.
close work_bmp
We also close the bitmap.
HEY, WE ARE READY!
This is what you should get after executing the script (Ctrl+E):
In the next LESSON 02, we will create a User Interface to the utility, and define some variables to achieve different effects.
Have fun!
Borislav Petrov FA








