hey guys, I have a maxscript I would like translated (if possible) to python for use as an importer. The maxscript was written for me by someone on another forum but unfortunately he didn’t know anything about python and wasn’t able to write a version for blender.
hope to hear some replies and thanks ahead of time!
if (heapSize < 20000000) then
heapSize = 200000000 -- allow ~ 40 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"
fname = getOpenFileName \
caption:"Open C3 Model File" \
types:"C3 Model File(*.c3)|*.c3" \
historyCategory:"C3ObjectPresets"
f = fopen fname "rb"
fn PrintOffset Var =
(
local Var = Var
print ("This is the offset 0x" + (bit.intAsHex Var) as string)
Var
)
fn PrintCount Var =
(
local Var = Var
print ("This is the Count 0x" + (bit.intAsHex Var) as string)
Var
)
fn Readword fstream = (
return readshort fstream #unsigned
)
fn ReadFixedString bstream fixedLen =
(
local str = ""
for i = 1 to fixedLen do
(
str += bit.intAsChar (ReadByte bstream #unsigned)
)
str
)
fn convertTo32 input16 = (
inputAsInt = input16
sign = bit.get inputAsInt 16
exponent = (bit.shift (bit.and inputAsInt (bit.hexasint "7C00")) -10) as integer - 16
fraction = bit.and inputAsInt (bit.hexasint "03FF")
if sign==true then sign = 1 else sign = 0
exponentF = exponent + 127
--Ouput 32 bit integer representing a 32 bit float
outputAsFloat = bit.or (bit.or (bit.shift fraction 13) (bit.shift exponentF 23)) (bit.shift sign 31)
--Output Check
return bit.intasfloat outputasfloat
)
fn ReadHalfFloat fstream = (
return convertTo32(Readshort fstream)
)
maxlen=(getfilesize fname)
Magic1 = ReadFixedString f 0x10
Magic2 == "PHY"
do (
Magic2 = ReadFixedString f 0x3
Magic = readbyte f#unsigned
SectSize = readlong f
test = (ftell f)
nsize = readlong f
MeshName = ReadFixedString f nsize
null = readlong f
vertcount = readlong f
null = readlong f
Vert_array = #()
UV_array = #()
Face_array = #()
if magic == 0x20 Do (
for a = 1 to vertcount Do (
vx = readfloat f
vy = readfloat f
vz = readfloat f
fseek f 0x24#seek_cur
tu = (readfloat f) * 1
tv = (readfloat f) * -1
fseek f 0x14#seek_cur
append Vert_array [vx,vz,vy]
--append Normal_array [nx,ny,nz]
append UV_array [tu,tv,0]
)
)
if magic == 0x34 Do (
for a = 1 to vertcount Do (
vx = readfloat f
vy = readfloat f
vz = readfloat f
tu = (readfloat f) * 1
tv = (readfloat f) * -1
fseek f 0x14#seek_cur
append Vert_array [vx,vz,vy]
--append Normal_array [nx,ny,nz]
append UV_array [tu,tv,0]
)
)
if magic == 0x33 Do (
for a = 1 to vertcount Do (
vx = readfloat f
vy = readfloat f
vz = readfloat f
tu = (readfloat f) * 1
tv = (readfloat f) * -1
fseek f 0x20#seek_cur
append Vert_array [vx,vz,vy]
--append Normal_array [nx,ny,nz]
append UV_array [tu,tv,0]
)
)
FaceCount = readlong f
null = readlong f
for a = 1 to FaceCount Do (
f1 = (readshort f) + 1
f2 = (readshort f) + 1
f3 = (readshort f) + 1
append Face_array [f1,f2,f3] --save faces to Face_array
)
msh = mesh vertices:Vert_array faces:Face_array
msh.numTVerts = UV_array.count
buildTVFaces msh
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]
for j = 1 to Normal_array.count do setNormal msh j Normal_array[j]
printoffset (ftell f)
fseek f (test + SectSize)#seek_set
printoffset (ftell f)
Magic2 = ReadFixedString f 0x3
fseek f -3#seek_cur
) while Magic2 == "PHY"
fclose f --close file
actionMan.executeAction 0 "311" -- Tools: Zoom Extents All Selected