I'm fairly new to maxscript, or programing in general so please forgive me if I got a thing here or there wrong.
http://www.youtube.com/watch?v=1ORnfYnlXOw
http://www.youtube.com/watch?v=dbPLKe-yMmY
http://www.youtube.com/watch?v=CEwSgXxkZMc
http://www.youtube.com/watch?v=NeQYfxi8KW4
http://www.youtube.com/watch?v=rcPfA4ix6WM
http://www.youtube.com/watch?v=LPxlqN6OoI4
http://www.youtube.com/watch?v=1dAIMdb-xYQ
the PMD samples I got from the MikUMikuDance, some PMD were packed with the program.
http://www.geocities.jp/higuchuu4/index_e.htm
and here is the sample script I did in the video
Code: Select all
f = fopen "E:\\Hacking Projects\\PMD\\MEIKO.pmd" "rb"
clearlistener()
fn ReadFixedString bstream fixedLen =
(
local str = ""
for i = 1 to fixedLen do
(
str0 = ReadByte bstream #unsigned
if str0!=0xFD AND str0!=0xFC do str+= bit.intAsChar str0
)
str
)
Face_array=#()
Vert_array=#()
UV_array=#()
fileName =ReadFixedString f 3
fileVersion=readfloat f
modelName=ReadFixedString f 20
comments=ReadFixedString f 256
count=readlong f #unsigned
for x = 1 to count do(
vx=readfloat f
vy=readfloat f
vz=readfloat f
p4=readfloat f
p5=readfloat f
p6=readfloat f
tu=readfloat f
tv=readfloat f
p9=readshort f
p10=readshort f
p11=readshort f
append Vert_array[vx,vz,vy]
append UV_array[tu,tv,0]
)
count=readlong f #unsigned
print count
for x = 1 to count/3 do(
fa=readshort f #unsigned+1
fb=readshort f #unsigned+1
fc=readshort f #unsigned+1
append Face_array[fc,fb,fa]
)
msh = mesh vertices:Vert_array faces:Face_array
msh.numTVerts = UV_array.count
buildTVFaces msh
msh.name=modelName
-- convertTo msh PolyMeshObject
for j = 1 to UV_array.count do setTVert msh j UV_array[j]
for j = 1 to Face_array.count do setTVFace msh j Face_array[j]
Print ("Last Read @ 0x"+((bit.intAsHex(ftell f))as string))
gc()
fclose f
Functions
functions are script operations that you can call at any time later in your script.
so say for example I want to spell hello world a few times, I would make a function that I could call later
example:
fn hw(
print "hello"
print "world"
)
I've now created a function, that can now be called by using the designator "hw".
so the advantage to this, is that instead of printing hellowworld over and over again when I need it. I can just type hw, and that earlier operation gets carried out
so in short a functions allow you to save space by being able to repeat an earlier defined operation.
below are some common functions I copied off of chrrox, which were handy to me. which also can be used to help you read different endians, such as reading from xbox360 game files
readBEshort, lets you read 2bytes in reversed order.. which is actually right to left.
Code: Select all
fn readBEshort fstream = (
short = readshort fstream #unsigned
short = bit.swapBytes short 1 2
return short
)
readBElong, lets you read 4bytes in big endian, aka reversed order (which is actually right to left)
Code: Select all
fn readBElong fstream = (
long = readlong fstream
long = bit.swapBytes long 1 4
long = bit.swapBytes long 2 3
return long
)
readHalfFloat, aka 16bit floats. max doesnt have a default read function on its own. this is for little endian.
if you want to reverse the byte order for bing endian (xbox360) then change the hf= line. instead of readshort, replace with. readBEshot
but make sure the readBEshort function gets paste before this. otherwise how can you call something that doesnt exist yet.
Code: Select all
fn readHalfFloat fstream = (
hf=readshort fstream #unsigned
sign = bit.get hf 16
exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
fraction = bit.and hf (bit.hexasint "03FF")
if sign==true then sign = 1 else sign = 0
exponentF = exponent + 127
outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
(bit.shift exponentF 23)) (bit.shift sign 31)
return bit.intasfloat outputasfloat*2
)
Code: Select all
fn ReadBEfloat fstream = (
fpt=readfloat fstream
itger = bit.floatAsInt fpt
hih = bit.intashex itger
while hih.count < 8 do hih = "0" + hih
shn = (substring hih 7 2) + \
(substring hih 5 2) + \
(substring hih 3 2) + \
(substring hih 1 2)
bit.intAsFloat (bit.hexasint shn)
)
Code: Select all
fn ReadFixedString bstream fixedLen = (
local str = ""
for i = 1 to fixedLen do
(
str += bit.intAsChar (ReadByte bstream #unsigned)
)
str
)