Post by DarkPikachu on Jul 19, 2014 12:03:02 GMT -5
this script handles the Wavefront .obj or binary .mod model file format.
this format does not support bones, but is a very simple format to test with.
I'm currently porting the script from v3.0a to the v3.0a update.
(this means you won't have to port your scripts to the v3.0 release) ;)
I'm working from the end to the beginning, since v3.0a already has a mildly decent import interface...
so more will come in time. ;)
Export:
this format does not support bones, but is a very simple format to test with.
I'm currently porting the script from v3.0a to the v3.0a update.
(this means you won't have to port your scripts to the v3.0 release) ;)
I'm working from the end to the beginning, since v3.0a already has a mildly decent import interface...
so more will come in time. ;)
Export:
def ExportModel(FType,Cmd):
#global vcnt,ncnt,ucnt
vcnt,ncnt,ucnt=1,1,1 #index starts at 1
String('# OBJ created with UMC3.0a\n')
def OBJ_Facepoint(FPID):
global vcnt,ncnt,ucnt; v,vt,vn = ugeGetVert(FPID),None,ugeGetUV(FPID)
return str(v+vcnt)+('/'+str(vt+ucnt)+('/'+str(vn+ncnt) if vn!=None else '') if vt!=None else ('//'+str(vn+ncnt) if vn!=None else ''))
while ugeScenesExist():
while ugeObjectsExist():
string('o '+ugeGetObjectName()+'\n')
if ugeMeshObject():
for Vert in ugeGetVertArr(): string('v '+str(Vert[0])+' '+str(Vert[1])+(' '+str(Vert[2]) if len(Vert)==3 else ' 0.0')+'\n')
string('\n')
#for Normal in ugeGetNormalArr(): string('vn '+str(Normal[0])+' '+str(Normal[1])+(' '+str(Normal[2]) if len(Normal)==3 else ' 0.0')+'\n')
string('\n')
for UV in ugeGetUVArr(): string('vt '+str(UV[0])+' '+(str(UV[1]) if len(UV)==2 else ' 0.0')+'\n')
string('\n')
while ugePrimitivesExist():
switch( ugeGetPrimType() )
FacePoints = ugeGetFacePoints()
FPLen = len(FacePoints)
i=0
if Case(UMC_POINTS):
while i<FPLen:
FP0=OBJ_Facepoint(Facepoints[i])
String('f '+FP0+'\n'); i+=1
if Case(UMC_LINES):
while i<FPLen-1:
FP0,FP1=OBJ_Facepoint(Facepoints[i]),OBJ_Facepoint(Facepoints[i+1])
String('f '+FP0+' '+FP1+'\n'); i+=2
if Case(UMC_LINESTRIP):
while i<FPLen-1:
FP0,FP1=OBJ_Facepoint(Facepoints[i]),OBJ_Facepoint(Facepoints[i+1])
String('f '+FP0+' '+FP1+'\n' if FP0!=FP1 else ''); i+=1
if Case(UMC_LINELOOP):
while i<FPLen-1:
FP0,FP1=OBJ_Facepoint(Facepoints[i]),OBJ_Facepoint(Facepoints[i+1])
String('f '+FP0+' '+FP1+'\n' if FP0!=FP1 else ''); i+=1
if Case(UMC_TRIANGLES):
while i<FPLen-2:
FP0,FP1,FP2=OBJ_Facepoint(Facepoints[i]),OBJ_Facepoint(Facepoints[i+1]),OBJ_Facepoint(Facepoints[i+2])
String('f '+FP2+' '+FP1+' '+FP0+'\n'); i+=3
if Case(UMC_TRIANGLESTRIP):
while i<FPLen-2:
FP0,FP1,FP2=OBJ_Facepoint(Facepoints[i]),OBJ_Facepoint(Facepoints[i+1]),OBJ_Facepoint(Facepoints[i+2])
String('f '+(FP0 if(i%2)else FP2)+' '+FP1+' '+(FP2 if(i%2)else FP0)+'\n' if (FP0!=FP1!=FP2!=FP0) else ''); i+=1
if Case(UMC_TRIANGLEFAN):
while i<FPLen-2:
FP0,FP1,FP2=OBJ_Facepoint(Facepoints[0]),OBJ_Facepoint(Facepoints[i+1]),OBJ_Facepoint(Facepoints[i+2])
String('f '+(FP0 if(i%2)else FP2)+' '+FP1+' '+(FP2 if(i%2)else FP0)+'\n' if (FP0!=FP1!=FP2!=FP0) else ''); i+=1
if Case(UMC_QUADS):
while i<FPLen-3:
FP0,FP1,FP2,FP3=OBJ_Facepoint(Facepoints[i]),OBJ_Facepoint(Facepoints[i+1]),OBJ_Facepoint(Facepoints[i+2]),OBJ_Facepoint(Facepoints[i+3])
String('f '+FP0+' '+FP1+' '+FP2+' '+FP3+'\n'); i+=4
if Case(UMC_QUADSTRIP):
while i<FPLen-3:
FP0,FP1,FP2,FP3=OBJ_Facepoint(Facepoints[i]),OBJ_Facepoint(Facepoints[i+1]),OBJ_Facepoint(Facepoints[i+2]),OBJ_Facepoint(Facepoints[i+3])
String('f '+FP0+' '+FP1+' '+FP2+' '+FP3+'\n' if (FP0!=FP1!=FP2!=FP3!=FP0!=FP2!=FP1!=FP3) else ''); i+=2
if Case(UMC_POLYGON):
pass #TODO... (not widely used)
String('\n')
vcnt+=len(Verts)
ncnt+=len(Normals)
ucnt+=len(UVs)