Board index FlightGear Development

Blender 2.6 AC3D Importer & Exporter

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Re: Blender 2.6 AC3D Importer & Exporter

Postby helijah » Fri May 04, 2012 7:24 pm

mr_no wrote in Fri May 04, 2012 5:27 pm:I've managed to import and export ngons as well as normal edges and everything else.
If you want to check it out you can get it here:
mr_no_blender263_AC3D_04052012.zip
That's what I use for my work.


OK thanks mr_no ! Your import don't work here, but your export work fine !

Finally : TheTom import script
: mr_no expot script

Now I can continue to model :)

You know what ? ...... I m happy :)

Regards Emmanuel
Some planes (and other) for FlightGear
http://helijah.free.fr
and
http://embaranger.free.fr
User avatar
helijah
 
Posts: 1097
Joined: Wed Dec 27, 2006 12:35 pm
Location: Chartres (France)
Callsign: helijah
IRC name: helijah
Version: GIT
OS: GNU/Linux

Re: Blender 2.6 AC3D Importer & Exporter

Postby mr_no » Fri May 04, 2012 8:56 pm

Hey helijah, please take a screenshots of error you get with my import script. Is it the texture path?
I tested a lot of models and all work, even yours.
Image
Mosquito-XE JT-5B-autogyro Extra-300s STOL-Ch701
User avatar
mr_no
 
Posts: 362
Joined: Thu Jan 19, 2012 2:20 pm

Re: Blender 2.6 AC3D Importer & Exporter

Postby mr_no » Fri May 04, 2012 9:20 pm

Well... There's one issue with "texrep ". I just found and fixed it when importing b105. If you ever use texrep the above exporter with not write decimal point values. No one actually uses texrep that's why I didn't notice that. :P
Mosquito-XE JT-5B-autogyro Extra-300s STOL-Ch701
User avatar
mr_no
 
Posts: 362
Joined: Thu Jan 19, 2012 2:20 pm

Re: Blender 2.6 AC3D Importer & Exporter

Postby helijah » Fri May 04, 2012 9:34 pm

OK :)

Image

Regards Emmanuel
Some planes (and other) for FlightGear
http://helijah.free.fr
and
http://embaranger.free.fr
User avatar
helijah
 
Posts: 1097
Joined: Wed Dec 27, 2006 12:35 pm
Location: Chartres (France)
Callsign: helijah
IRC name: helijah
Version: GIT
OS: GNU/Linux

Re: Blender 2.6 AC3D Importer & Exporter

Postby mr_no » Fri May 04, 2012 10:52 pm

The only thing I can think of is that you didn't install it right. Try a fresh installation of the script. :shock:
Mosquito-XE JT-5B-autogyro Extra-300s STOL-Ch701
User avatar
mr_no
 
Posts: 362
Joined: Thu Jan 19, 2012 2:20 pm

Re: Blender 2.6 AC3D Importer & Exporter

Postby helijah » Sat May 05, 2012 12:30 am

AAARRGGH oops sorry. I'm going too fast. Effectively to avoid interference between your import and import TheTom, I erase your import (keeping only export). Sorry: (

So, I erased everything and put everything back properly. And actually your import / export work fine, both.

Again sorry for this frightens. Shame on me !

Fantastic I can continue my Tu 134 :)

Regards Emmanuel
Some planes (and other) for FlightGear
http://helijah.free.fr
and
http://embaranger.free.fr
User avatar
helijah
 
Posts: 1097
Joined: Wed Dec 27, 2006 12:35 pm
Location: Chartres (France)
Callsign: helijah
IRC name: helijah
Version: GIT
OS: GNU/Linux

Re: Blender 2.6 AC3D Importer & Exporter

Postby Tigran » Tue Jun 12, 2012 3:19 pm

just a small fix for export part.. Materials were not well exported (each face in a mesh could have its own material)

sorry, but i did not polish the script (can remove a lot of stuff)

Code: Select all
'''
====================================================================================================================



            EXPORT


====================================================================================================================
'''
import os
import bpy
import mathutils

from math import radians
from math import degrees




TEX_PATH      = False
APPLY_MODIFIERS = True
SELECT_ONLY      = True

list_material = []


parent = mathutils.Vector()


path_name = ""
def extract_path(name_path):
   global path_name
   """
   name = ""
   rep = name_path.split('/')
   
   for i in range(len(rep)-1):
      name += rep[i] + '/'

   path_name = name
   """
   path_name = os.path.dirname(os.path.normpath(name_path))
   #print( "extract_path() : %s " % path_name )






def without_path(name_path):
   name = ""
   for c in reversed(name_path):
      if c != '/':
         name = c + name
      else:
         break
   return name







def write_file(fi, s):
   fi.write("%s" % s)

def writeln_file(fi, s):
   fi.write("%s\n" % s)


def significatif( st ):
   new_str = ""
   if st.find('.') == -1:
      return st
      
   decimal = st.find('.')
   entier = st[:decimal]
   mantisse = st[decimal:]
      
   sup = False
   
   for c in reversed(mantisse):
      if c != '0' and c!='.':
         new_str = c + new_str
         sup = True
      else:
         if sup:
            new_str = c + new_str

   if new_str !="":
      new_str = entier + new_str
   else:
      new_str = entier

   if new_str == '-':
      new_str = '0'
      
   #print( "nombre %s %s   resultat %s" % (entier,mantisse,new_str) )
   return new_str
      
      

def write_edges( f, mesh ):
   nbEdges = len(mesh.edges)
   writeln_file( f, "numsurf " + str(nbEdges) )

   no = 1
   try:
      material = mesh.materials[0]
   except:
      no = 0

   if no ==1:
      matName = material.name
      try:
         no = list_material.index(matName)
      except:
         no = 0

   for i in range(nbEdges):
      edge = mesh.edges[i]
      
      nbVertices = len(edge.vertices)

      writeln_file( f, "SURF 0x02" )
      writeln_file( f, "mat %d" % no )
      writeln_file( f, "refs "+str(nbVertices) )
      
      for ed in edge.vertices:
         writeln_file( f, "%d 0 0" % ed )
      #writeln_file( f, "%d 0 0" % (edge.vertices[0]) )
      #writeln_file( f, "%d 0 0" % (edge.vertices[1]) )
      
   #writeln_file( f, "kids 0" )



def write_faces( f, mesh ):
   
   #nbFaces = len(mesh.faces)
   nbFaces = len(mesh.polygons)
   
   
   # if O face    mesh = edge
   if nbFaces == 0 :
      write_edges( f, mesh )
      return
      
   #  count face of mesh
   writeln_file( f, "numsurf " + str(nbFaces) )
   
   
#   process_materials = 0
   mesh_materials = mesh.materials
#for material in mesh_materials:
#      if material !=None :
#         process_materials = 1
#         break
#   mesh_materials = [x for x in mesh_materials if x is not None]
   
   totUvNr=0   
   uvnr=0
   # for each face
   for i in range(nbFaces):
      face = mesh.polygons[i]
      nbVertices = len(face.vertices)
      uvnr=nbVertices*2
      
      try :
         uv_tex = mesh.uv_layers.active.data[:]
         uv = []
         for j in range(nbVertices):
            uv.append(uv_tex[totUvNr+j].uv[0])
            uv.append(uv_tex[totUvNr+j].uv[1])
      
      except:
         uv =[]
         for j in range(uvnr):
            uv += [0.0]

      totUvNr = totUvNr+ nbVertices   
      #if len(mesh.materials) != 0:
      #   no = mesh.faces[i].material_index
      #   matName = mesh.materials[no].name
      #   no = list_material.index(matName)
         #print( "Face no %d material %s no %d" % (i,matName,no) )
      '''
      Surf section   SURF %d

      The start of a surface. The parameter specifies the surface type and flags. T
      he first 4 bits (flags & 0xF) is the type (0 = polygon, 1 = closedline, 2 = line).
      The next four bits (flags >> 4) specify the shading and backface.
      bit1 = shaded surface bit2 = twosided.
      '''
      flaglow  = 0 # polygon
      flaghigh = 0
      
      if face.use_smooth:
         flaghigh = flaghigh+ 1
         
      if mesh.show_double_sided:
         flaghigh = flaghigh+ 2
         
      surfstr = "SURF 0x%d%d" % (flaghigh, flaglow)
      
      # face header
      #writeln_file( f, "SURF 0x10" ) old and not good
      writeln_file( f, surfstr)
      
# calculating material number:
      matno = 0 # by default, put 'default white'
                matno = 0 # by default, put 'default white'                                                                                                                                                                         
                if len(mesh_materials) > 0:                                                                                                                                                                                         
                        if mesh_materials[face.material_index] is not None:                                                                                                                                                         
                                matno = list_material.index(mesh_materials[face.material_index].name)+1 #+1 because we have 'default white'   
      # found material used by face
         
      writeln_file( f, "mat %d" % matno)
      writeln_file( f, "refs "+str(nbVertices) )
      # write two first vertex
      #writeln_file( f, "%d %s %s" % ( face.vertices[0], significatif("%0.12f"%uv[0]), significatif("%0.12f"%uv[1]) ) )
      #writeln_file( f, "%d %s %s" % ( face.vertices[1], significatif("%0.12f"%uv[2]), significatif("%0.12f"%uv[3]) ) )
      # if triangle
      
      #if nbVertices >= 3:
      #   writeln_file( f, "%d %s %s" % ( face.vertices[2], significatif("%0.12f"%uv[4]), significatif("%0.12f"%uv[5]) ) )
      # if quad
      #if nbVertices == 4:
      #   writeln_file( f, "%d %s %s" % ( face.vertices[3], significatif("%0.12f"%uv[6]), significatif("%0.12f"%uv[7]) ) )
   
      iVxy = 0
      for iVert in range(nbVertices):
         writeln_file( f, "%d %s %s" % ( face.vertices[iVert], significatif("%0.12f"%uv[iVxy]), significatif("%0.12f"%uv[iVxy+1]) ) )
         iVxy=iVxy+2
         
   #writeln_file( f, "kids 0" )




def print_matrix( matrix ):
   l = matrix[3]
   #for l in matrix:
   print( "matrix %f %f %f %f" % (l[0],l[1],l[2],l[3]) )



def extrait_translation_matrix( matrix ):
   t = matrix[3]
   ret = mathutils.Vector( (t[0],t[1],t[2]) )
   return ret

def write_vertice( f, obj, mesh ):

   scale = obj.scale
   location = obj.location
   euler = obj.rotation_euler

   delta_scale = obj.delta_scale
   delta_location = obj.delta_location
   delta_euler = obj.delta_rotation_euler

   euler_string = "x=%0.6f y=%0.6f z=%0.6f" % (euler[0],euler[1],euler[2])
   scale_string = "x=%0.6f y=%0.6f z=%0.6f" % (scale[0],scale[1],scale[2])
   location_string = "x=%0.6f y=%0.6f z=%0.6f" % (location[0],location[1],location[2])

   delta_location_string = "x=%0.6f y=%0.6f z=%0.6f" % (delta_location[0],delta_location[1],delta_location[2])
   delta_scale_string = "x=%0.6f y=%0.6f z=%0.6f" % (delta_scale[0],delta_scale[1],delta_scale[2])
   delta_euler_string = "x=%0.6f y=%0.6f z=%0.6f" % (delta_euler[0],delta_euler[1],delta_euler[2])

   nbVertices = len(mesh.vertices)
   
   l = obj.matrix_basis[0]

# commented out next 5 lines of code
# print( "*** Objet %s" % obj.name )
# print( "Contraints %d" % len(obj.constraints) )

# print_matrix( obj.matrix_basis )
# print_matrix( obj.matrix_local )
# print_matrix( obj.matrix_world )


   '''
   b = True
   delta = mathutils.Vector( (0.0,0.0,0.0) )
   Obj = obj
   while(b):
      if Obj.parent != None:
         Obj = Obj.parent
         delta -=  mathutils.Vector( Obj.location )
      else:
         b = False
   '''
   delta =  extrait_translation_matrix(obj.matrix_world) - extrait_translation_matrix(obj.matrix_basis)
   delta =  extrait_translation_matrix(obj.matrix_world) - extrait_translation_matrix(obj.matrix_basis)
   parent = extrait_translation_matrix(obj.matrix_local) - extrait_translation_matrix(obj.matrix_basis)

   '''
   print( "matrix %f %f %f %f" % ( obj.matrix_basis[0], obj.matrix_basis[1], obj.matrix_basis[2], obj.matrix_basis[3] )  )
   print( "matrix %f %f %f %f" % ( matrix_basis[4], matrix_basis[5], matrix_basis[6], matrix_basis[7] )  )
   print( "matrix %f %f %f %f" % ( matrix_basis[8], matrix_basis[9], matrix_basis[10], matrix_basis[11] )  )
   print( "matrix %f %f %f %f" % ( matrix_basis[12], matrix_basis[13], matrix_basis[14], matrix_basis[15] )  )
   print( "Delta location %s" % delta_location_string )
   print( "Delta scale %s" % delta_scale_string )
   print( "Delta euler %s" % delta_euler_string )
   '''
# print( "Location %s" % location_string )
   '''
   print( "Scale %s" % scale_string )
   print( "Euler %s" % euler_string )
   '''
   
   writeln_file( f, "numvert " + str(nbVertices) )
   
   vec3_locat   = mathutils.Vector(location)
   vec3_scale   = mathutils.Vector(scale)
   euler_euler   = mathutils.Euler(euler)
   mat_euler   = euler_euler.to_matrix()
   # for each vertex
   for v in mesh.vertices:
      vec3_vert = mathutils.Vector(v.co)
      vec3_resu = mathutils.Vector()

      vec3_vert.x *= vec3_scale.x
      vec3_vert.y *= vec3_scale.y
      vec3_vert.z *= vec3_scale.z

      v   = mathutils.Vector(vec3_vert)
      vec3_vert = mat_euler * v
      '''
      vec3_vert *= vec3_scale
      don't work
      
      '''
      #vec3_resu = vec3_vert
      #vec3_resu = vec3_vert + delta + extrait_translation_matrix(obj.matrix_local)
      #vec3_resu = vec3_vert + delta
      vec3_resu = vec3_vert + extrait_translation_matrix(obj.matrix_local) - extrait_translation_matrix(obj.matrix_basis)

      str_x = significatif("%0.6f" % vec3_resu.x)
      str_y = significatif("%0.6f" % vec3_resu.z)
      str_z = significatif("%0.6f" % -vec3_resu.y)
      # write vertex into ac file
      writeln_file( f, str_x +' '+ str_y +' '+ str_z )      
      





def extrait_crease( obj, mesh ):
   pi = 3.141592653589793238462643383279502884197
   if len(obj.modifiers)!=0:
      for mod in obj.modifiers:
         if ((mod.type=='EDGE_SPLIT') and (mod.use_edge_angle==True) ):
            return (mod.split_angle/pi)*180.0
   if mesh.use_auto_smooth:   
      if mesh.auto_smooth_angle!=0.0:
         return (mesh.auto_smooth_angle/pi)*180.0
   else:
      #return -1.0
      return 179.0
   
   return 30.0
      
   

def write_header_mesh( f, obj, mesh ):

   tex_name = ""
   texrepx = 1
   texrepy = 1
   
   #if ( (len(mesh.material_slots)>0)
   #   and ( len(mesh.materials[0].texture_slots)>0)
   #   and (mesh.materials[0].texture_slots[0].texture.type =='IMAGE')):
   
   try:
      #material = mesh.materials[0]
      if mesh.materials[0].texture_slots[0].texture.type =='IMAGE':
         tex_name = mesh.materials[0].texture_slots[0].texture.image.filepath
         #tex_name = mesh.uv_textures[0].data[0].image.name
         #print(mesh.uv_textures[0].data[0].image.filepath)
         #print(mesh.uv_textures[0].data[0].image.name)
         #writeln_file( f, "Texture name : %s" % tex_name )
         texrepx = mesh.materials[0].texture_slots[0].texture.repeat_x
         texrepy = mesh.materials[0].texture_slots[0].texture.repeat_y
   except:
      tex_name = ""
      #print( "Impossible read image name nb mesh.materials = %d  nb uv_texture[0].data  = %d" % (len(mesh.materials),len(mesh.uv_textures[0].data)) )
      #pass
      
   #if tex_name == "":
      
   #if ( (tex_name == "")
   #   and (len(mesh.uv_textures[0].data)>0)
   #   and (mesh.uv_textures[0].data[0].image!=None) ):

   try:
      #material = mesh.materials[0]
      tex_name = mesh.tessface_uv_textures[0].data[0].image.filepath
      #tex_name = mesh.uv_textures[0].data[0].image.name
      #print(mesh.uv_textures[0].data[0].image.filepath)
      #print(mesh.uv_textures[0].data[0].image.name)
      #writeln_file( f, "Texture name : %s" % tex_name )
   except:
      tex_name = ""
      #print( "Impossible read image name nb mesh.materials = %d  nb uv_texture[0].data  = %d" % (len(mesh.materials),len(mesh.uv_textures[0].data)) )
      #pass
         
   if TEX_PATH==False:
      tex_name = without_path(tex_name)
   else:
      tex_name = tex_name[2:]
      print(tex_name)
   
   #mesh location
   vec3_locat   = mathutils.Vector(obj.location) + parent
      
   writeln_file( f, "OBJECT poly" )
   writeln_file( f, 'name "' + obj.name + '"' )
   str_x = significatif("%0.6f" % vec3_locat.x)
   str_y = significatif("%0.6f" % vec3_locat.z)
   str_z = significatif("%0.6f" % -vec3_locat.y)
   writeln_file( f, "loc %s %s %s" % (str_x, str_y, str_z) )
   writeln_file( f, 'data %d'%len(obj.name) )
   writeln_file( f, obj.name )
   if tex_name != "":
      relative_name_tex = tex_name
      #print( relative_name_tex )
      #writeln_file( f, 'texture "%s"' % relative_name_tex )
      writeln_file( f, 'texture "%s"' % relative_name_tex )
      
      #ImageTexture.repeat_x   ImageTexture.repeat_y
      #writeln_file( f, 'texrep 1 1' )
      writeln_file( f, 'texrep %d %d' % (texrepx,  texrepy) )
      
   cr = extrait_crease(obj,mesh)
   if cr != -1.0:
      writeln_file( f, 'crease %0.6f' % extrait_crease(obj,mesh) )
      
      

'''
def texture(self, faces):
      tex = ""
      for f in faces:
         if f.image:
            tex = f.image.name
            break
      if tex:
         image = Image.Get(tex)
         texfname = image.filename
         if SET_TEX_DIR:
            texfname = bsys.basename(texfname)
            if TEX_DIR:
               texfname = bsys.join(TEX_DIR, texfname)
         buf = 'texture "%s"\n' % texfname
         xrep = image.xrep
         yrep = image.yrep
         buf += 'texrep %s %s\n' % (xrep, yrep)
         self.file.write(buf)
'''


def write_material( f, sel_obj ):
   global list_material

   list_material = []
   
   
   writeln_file( f, 'MATERIAL "DefaultWhite" rgb 1 1 1  amb 1 1 1  emis 0 0 0  spec 0.5 0.5 0.5  shi 64  trans 0' )
   
   for obj in sel_obj:
      if obj.type != 'MESH':
         continue
      '''
      if len(obj.material_slots)==0:
         continue
         
      material = obj.active_material
      name = material.name

      try:
         no = list_material.index(name)
      except:
         # first use material -> write into ac file
         list_material += [name]

         write_file( f, 'MATERIAL "%s"' % str(name) )
         # color
         color = material.diffuse_color
         str_color = significatif("%0.6f"%color[0]) +' '+ significatif("%0.6f"%color[1]) +' '+ significatif("%0.6f"%color[2])
         write_file( f, " rgb %s" % str_color )
         # amb
         amb = significatif( "%0.6f"% material.ambient )
         #print( str(name) + " Ambient = " + amb)
         write_file( f, " amb %s %s %s"%(amb,amb,amb) )
         # emit
         emit = significatif( "%0.6f"%material.emit)
         write_file( f, " emis %s %s %s"%(emit,emit,emit) )
         # specular
         spec = material.specular_color
         str_spec = significatif( "%0.6f"%spec[0]) +' '+ significatif( "%0.6f"%spec[1]) +' '+ significatif( "%0.6f"%spec[2])
         write_file( f, " spec %s" % str_spec )
         # shininess
         write_file( f, " shi %d" % material.specular_hardness )
         # transparent
         write_file( f, " trans %s" % significatif("%0.6f" % (1.0-material.alpha)) )
   
         writeln_file( f, "" )
       '''
      
      
      if len(obj.data.materials)==0:
         continue
         
      for material in obj.data.materials:
         
         if (( material !=None)  and  (material.name !='DefaultWhite') ):
            name = material.name

            try:
               no = list_material.index(name)
            except:
               # first use material -> write into ac file
               list_material += [name]

               write_file( f, 'MATERIAL "%s"' % str(name) )
               # color
               color = material.diffuse_color
               str_color = significatif("%0.6f"%color[0]) +' '+ significatif("%0.6f"%color[1]) +' '+ significatif("%0.6f"%color[2])
               write_file( f, " rgb %s" % str_color )
               # amb
               amb = significatif( "%0.6f"% material.ambient )
               #print( str(name) + " Ambient = " + amb)
               write_file( f, " amb %s %s %s"%(amb,amb,amb) )
               # emit
               emit = significatif( "%0.6f"%material.emit)
               write_file( f, " emis %s %s %s"%(emit,emit,emit) )
               # specular
               spec = material.specular_color
               str_spec = significatif( "%0.6f"%spec[0]) +' '+ significatif( "%0.6f"%spec[1]) +' '+ significatif( "%0.6f"%spec[2])
               write_file( f, " spec %s" % str_spec )
               # shininess
               #write_file( f, " shi %d" % material.specular_hardness )
            
               # shininess
               #write_file( f, " shi %d" % material.specular_hardness )
               write_file( f, " shi %d" % int( material.specular_intensity * 128 ) )
               #shininess of materials is taken from the shader specularity value in Blender,
               #old mapped from [0.0, 2.0] to [0, 128]
               #noting above 1.0 so mapped from [0.0, 1.0] to [0, 128]
               
               # transparent
               write_file( f, " trans %s" % significatif("%0.6f" % (1.0-material.alpha)) )
      
               writeln_file( f, "" )




def test_son( list_objects, obj,name_parent ):
   if obj.parent!=None:
      if obj.parent.name == name_parent:
         return True
   elif name_parent == 'world':
      return True

   return False


def count_son( list_objects, name_parent ):
   nb = 0
   for obj in list_objects:
         if obj.parent!=None:
            if obj.parent.name == name_parent:
               nb += 1
         elif name_parent == 'world':
            nb += 1
   return nb


def recurs_son( f, context, list_objects, obj ):
   print( "Ecriture de %s" % obj.name )


   if obj.type == 'MESH':
      mesh = obj.to_mesh( context.scene, APPLY_MODIFIERS, 'PREVIEW' )
      write_header_mesh( f, obj, mesh )
      write_vertice( f, obj, mesh )
      write_faces( f, mesh )
   elif obj.type == 'EMPTY':
      f.write("OBJECT group\n" )
      f.write('name "' + obj.name + '"\n' )
      vec3_locat   = mathutils.Vector(obj.location)
      str_x = significatif("%0.6f" % vec3_locat.x)
      str_y = significatif("%0.6f" % vec3_locat.z)
      str_z = significatif("%0.6f" % -vec3_locat.y)
      f.write("loc %s %s %s\n" % (str_x, str_y, str_z) )
      
      


   nb = count_son(list_objects, obj.name)
   f.write("kids %d\n" % nb )
   #print( "%d enfants" % nb )
   
   if nb != 0:
      for obj_ in list_objects:
         if test_son( list_objects, obj_, obj.name ):
            recurs_son( f, context, list_objects, obj_ )
   #print ( " fin enfant de %s" % obj.name )
   

      
#def write_ac_file( context, filename, select_only, tex_path, apply_modifiers ):
def write_ac_file( context, filename, select_only, apply_modifiers ):
   global   SELECT_ONLY, TEX_PATH, APPLY_MODIFIERS
   
   SELECT_ONLY      = select_only
   TEX_PATH         = False
   APPLY_MODIFIERS    = apply_modifiers

   '''
   for wm in bpy.data.window_managers:
      for win in wm.windows:
         print( win.screen.name )
   '''
   #return
   #bpy.ops.wm.mouse_position()
   extract_path( filename )
   
   f = open(filename, 'w')

   f.write("%s\n" %  "AC3Db" )
   
   if SELECT_ONLY:
      list_objects = context.selected_objects
   else:
      list_objects = context.scene.objects
   
   # create dictionnary for mesh order
   dic_obj_meshs = {}
   for obj in list_objects:
      if obj.type == 'MESH' or obj.type == 'EMPTY':
         dic_obj_meshs[obj.name] = obj
         
   list_objects_sort = []
   for name in sorted(dic_obj_meshs.keys()):
      list_objects_sort.append( dic_obj_meshs[name] )
   
   
   # write materials   
   write_material( f, list_objects )
   # Header
   # object world
   f.write("%s\n" % "OBJECT world" )
   string_to_write = "kids %d" % count_son(list_objects, 'world' )
   f.write("%s\n" % string_to_write )
   
   for obj in list_objects_sort:
      if test_son(list_objects, obj, 'world' ):
         recurs_son( f, context, list_objects, obj )
   
   f.close()
   return

Last edited by Tigran on Tue Jun 19, 2012 2:58 pm, edited 1 time in total.
Tigran
 
Posts: 2
Joined: Tue Jun 12, 2012 3:15 pm

Re: Blender 2.6 AC3D Importer & Exporter

Postby TheTom » Tue Jun 12, 2012 5:12 pm

I just did a quick check and I think the other plugin (https://github.com/majic79/Blender-AC3D.git) shouldn't suffer from this problem.

Maybe we should start comparing the features and bugs of both versions and also try to merge them. I don't like the current state of having two plugins supposed to do actually the same thing...
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 10:20 am

Re: Blender 2.6 AC3D Importer & Exporter

Postby mr_no » Tue Jun 12, 2012 10:08 pm

Tigran wrote in Tue Jun 12, 2012 3:19 pm:just a small fix for export part.. Materials were not well exported (each face in a mesh could have its own material)

I intentionally left this out because I always use one material per object. In FG It's very rare that someone uses more than one. In FG most airplane models have only a few materials. Also the importing is easier.

The most important: You can only have one texture per object in AC3D format even if you used many materials!!!
So why have many materials when you used the same texture? This will complicate things for you.
Also I recommend" one object -one material" to make UV mapping easier.

But in the end you do as you like.

The importer will have to be adjusted too, because it assumes "one object-one material".
I'll do this later.

TheTom wrote in Tue Jun 12, 2012 5:12 pm:Maybe we should start comparing the features and bugs of both versions and also try to merge them. I don't like the current state of having two plugins supposed to do actually the same thing...

When Blender 2.63 came out we were waiting for you to update your script but you were nowhere to be found. I had to jump in. Also you script constantly suffered with problems like material duplicates and smoothing errors that I didn't like.

My script is posted only in this thread so you can see how some problems are solved and so modeller don't stop their work. You should look at this script and fix the issues your script has, including compatibility with Blender 2.63.
Last edited by mr_no on Tue Jun 12, 2012 10:26 pm, edited 1 time in total.
Mosquito-XE JT-5B-autogyro Extra-300s STOL-Ch701
User avatar
mr_no
 
Posts: 362
Joined: Thu Jan 19, 2012 2:20 pm

Re: Blender 2.6 AC3D Importer & Exporter

Postby TheTom » Tue Jun 12, 2012 10:23 pm

mr_no wrote in Tue Jun 12, 2012 10:08 pm:My script is posted only in this thread so you can see how some problems are solved and so modeller don't stop their work. You should look at this script and fix the issues your script has, including compatibility with Blender 2.63.

Are there any open problems with 2.63 exporting? I'm using it without any problems with a quite complex objects using uv mapped textures and ngons.
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 10:20 am

Re: Blender 2.6 AC3D Importer & Exporter

Postby mr_no » Tue Jun 12, 2012 10:37 pm

The last time I used your script the importer didn't work. I don't know how it is today. The exporter may work now, but the script isn't complete if the importer doesn't work.
Mosquito-XE JT-5B-autogyro Extra-300s STOL-Ch701
User avatar
mr_no
 
Posts: 362
Joined: Thu Jan 19, 2012 2:20 pm

Re: Blender 2.6 AC3D Importer & Exporter

Postby TheTom » Tue Jun 12, 2012 10:58 pm

Then please try it again. I normally don't use it myself, but I just did a quick import which didn't show any obvious problems...
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 10:20 am

Re: Blender 2.6 AC3D Importer & Exporter

Postby Tigran » Wed Jun 13, 2012 8:56 am

So why have many materials when you used the same texture? This will complicate things for you.


Hi, I was using this script for other purposes (to export a 3d scene for speed dreams racing simulator)
Initially I had a scene with some trees with no texture and using two materials (one of green color another of brown)
So I've just modified the scripts for my needs and put it back here if someone else need it one day...

Regards,
Tigran
Tigran
 
Posts: 2
Joined: Tue Jun 12, 2012 3:15 pm

Re: Blender 2.6 AC3D Importer & Exporter

Postby mr_no » Wed Jun 13, 2012 2:21 pm

Tigran, that is something completely different. Thank you for pointing out the bug.
Mosquito-XE JT-5B-autogyro Extra-300s STOL-Ch701
User avatar
mr_no
 
Posts: 362
Joined: Thu Jan 19, 2012 2:20 pm

Re: Blender 2.6 AC3D Importer & Exporter

Postby mr_no » Wed Jun 13, 2012 2:50 pm

TheTom, try importing cessna c172p. You'll see broken surface left on the panel. Also from the original 39 materials in the .ac file the imported model has over 50 materials.
Also your exporter exports ngons as triangles not as original ngons. The conversion ngons to triangles isn't longer needed since Blender 2.63 supports ngons. You can also import and export original ngons in my script.
Mosquito-XE JT-5B-autogyro Extra-300s STOL-Ch701
User avatar
mr_no
 
Posts: 362
Joined: Thu Jan 19, 2012 2:20 pm

PreviousNext

Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest