Revision: 22427
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22427
Author:   kazanbas
Date:     2009-08-13 13:14:06 +0200 (Thu, 13 Aug 2009)

Log Message:
-----------
- 3ds importer working (without the "scale to size" option)
- changing object.matrix now updates object.loc/rot/scale
- added bpy.data.add_lamp()

Modified Paths:
--------------
    branches/soc-2009-kazanbas/release/io/import_3ds.py
    branches/soc-2009-kazanbas/release/io/import_obj.py
    branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_main_api.c
    branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_material_api.c
    branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_mesh_api.c
    branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_object.c

Modified: branches/soc-2009-kazanbas/release/io/import_3ds.py
===================================================================
--- branches/soc-2009-kazanbas/release/io/import_3ds.py 2009-08-13 09:30:36 UTC 
(rev 22426)
+++ branches/soc-2009-kazanbas/release/io/import_3ds.py 2009-08-13 11:14:06 UTC 
(rev 22427)
@@ -125,9 +125,14 @@
 
 # Importing modules
 
-from struct import calcsize, unpack
+import os
+import time
+import struct
 
+from import_obj import unpack_face_list, load_image
+
 import bpy
+import Mathutils
 
 # import Blender
 # from Blender import Mesh, Object, Material, Image, Texture, Lamp, Mathutils
@@ -149,7 +154,7 @@
 # except:
 #      from sets import Set as set
 
-BOUNDS_3DS= []
+BOUNDS_3DS = []
 
 
 #this script imports uvcoords as sticky vertex coords
@@ -157,9 +162,9 @@
 #which shold be more useful.
 
 def createBlenderTexture(material, name, image):
-       texture= bpy.data.textures.new(name)
+       texture = bpy.data.textures.new(name)
        texture.setType('Image')
-       texture.image= image
+       texture.image = image
        material.setTexture(0, texture, Texture.TexCo.UV, Texture.MapTo.COL)
 
 
@@ -170,7 +175,7 @@
 
 #Some of the chunks that we will see
 #----- Primary Chunk, at the beginning of each file
-PRIMARY= int('0x4D4D',16)
+PRIMARY = int('0x4D4D',16)
 
 #------ Main Chunks
 OBJECTINFO   =      int('0x3D3D',16);      #This gives the version of the mesh 
and is found right before the material and object information
@@ -178,8 +183,8 @@
 EDITKEYFRAME=      int('0xB000',16);      #This is the header for all of the 
key frame info
 
 #------ sub defines of OBJECTINFO
-MATERIAL=45055         #0xAFFF                         // This stored the 
texture info
-OBJECT=16384           #0x4000                         // This stores the 
faces, vertices, etc...
+MATERIAL = 45055               #0xAFFF                         // This stored 
the texture info
+OBJECT = 16384         #0x4000                         // This stores the 
faces, vertices, etc...
 
 #>------ sub defines of MATERIAL
 #------ sub defines of MATERIAL_BLOCK
@@ -213,16 +218,16 @@
 OBJECT_LAMP_LOCAL_SHADOW = int('0x4640',16);   
 OBJECT_LAMP_LOCAL_SHADOW2 = int('0x4641',16);  
 OBJECT_LAMP_SEE_CONE = int('0x4650',16);       
-OBJECT_LAMP_SPOT_RECTANGULAR= int('0x4651',16);
-OBJECT_LAMP_SPOT_OVERSHOOT= int('0x4652',16);
-OBJECT_LAMP_SPOT_PROJECTOR= int('0x4653',16);
-OBJECT_LAMP_EXCLUDE= int('0x4654',16);
-OBJECT_LAMP_RANGE= int('0x4655',16);
-OBJECT_LAMP_ROLL= int('0x4656',16);
-OBJECT_LAMP_SPOT_ASPECT= int('0x4657',16);
-OBJECT_LAMP_RAY_BIAS= int('0x4658',16);
-OBJECT_LAMP_INNER_RANGE= int('0x4659',16);
-OBJECT_LAMP_OUTER_RANGE= int('0x465A',16);
+OBJECT_LAMP_SPOT_RECTANGULAR = int('0x4651',16);
+OBJECT_LAMP_SPOT_OVERSHOOT = int('0x4652',16);
+OBJECT_LAMP_SPOT_PROJECTOR = int('0x4653',16);
+OBJECT_LAMP_EXCLUDE = int('0x4654',16);
+OBJECT_LAMP_RANGE = int('0x4655',16);
+OBJECT_LAMP_ROLL = int('0x4656',16);
+OBJECT_LAMP_SPOT_ASPECT = int('0x4657',16);
+OBJECT_LAMP_RAY_BIAS = int('0x4658',16);
+OBJECT_LAMP_INNER_RANGE = int('0x4659',16);
+OBJECT_LAMP_OUTER_RANGE = int('0x465A',16);
 OBJECT_LAMP_MULTIPLIER = int('0x465B',16);
 OBJECT_LAMP_AMBIENT_LIGHT = int('0x4680',16);
 
@@ -241,21 +246,21 @@
 OBJECT_TRANS_MATRIX  =   int('0x4160',16); # The Object Matrix
 
 global scn
-scn= None
+scn = None
 
 #the chunk class
 class chunk:
-       ID=0
-       length=0
-       bytes_read=0
+       ID = 0
+       length = 0
+       bytes_read = 0
 
        #we don't read in the bytes_read, we compute that
        binary_format='<HI'
 
        def __init__(self):
-               self.ID=0
-               self.length=0
-               self.bytes_read=0
+               self.ID = 0
+               self.length = 0
+               self.bytes_read = 0
 
        def dump(self):
                print('ID: ', self.ID)
@@ -264,95 +269,107 @@
                print('bytes_read: ', self.bytes_read)
 
 def read_chunk(file, chunk):
-       temp_data=file.read(calcsize(chunk.binary_format))
-       data=unpack(chunk.binary_format, temp_data)
-       chunk.ID=data[0]
-       chunk.length=data[1]
+       temp_data = file.read(struct.calcsize(chunk.binary_format))
+       data = struct.unpack(chunk.binary_format, temp_data)
+       chunk.ID = data[0]
+       chunk.length = data[1]
        #update the bytes read function
-       chunk.bytes_read=6
+       chunk.bytes_read = 6
 
        #if debugging
        #chunk.dump()
 
 def read_string(file):
        #read in the characters till we get a null character
-       s=''
-       while not s.endswith('\x00'):
-               s+=unpack( '<c', file.read(1) )[0]
+       s = b''
+#      s = ''
+       while not s.endswith(b'\x00'):
+#      while not s.endswith('\x00'):
+               s += struct.unpack('<c', file.read(1))[0]
+#              s += struct.unpack( '<c', file.read(1) )[0]
                #print 'string: ',s
-       
+
+       s = str(s[:-1], 'ASCII')
+#      print("read string", s)
+
        #remove the null character from the string
-       return s[:-1]
+       return s
+#      return s[:-1]
 
 ######################################################
 # IMPORT
 ######################################################
 def process_next_object_chunk(file, previous_chunk):
-       new_chunk=chunk()
-       temp_chunk=chunk()
+       new_chunk = chunk()
+       temp_chunk = chunk()
 
-       while (previous_chunk.bytes_read<previous_chunk.length):
+       while (previous_chunk.bytes_read < previous_chunk.length):
                #read the next chunk
                read_chunk(file, new_chunk)
 
 def skip_to_end(file, skip_chunk):
-       buffer_size=skip_chunk.length-skip_chunk.bytes_read
+       buffer_size = skip_chunk.length - skip_chunk.bytes_read
        binary_format='%ic' % buffer_size
-       temp_data=file.read(calcsize(binary_format))
-       skip_chunk.bytes_read+=buffer_size
+       temp_data = file.read(struct.calcsize(binary_format))
+       skip_chunk.bytes_read += buffer_size
 
 
 def add_texture_to_material(image, texture, material, mapto):
-       if mapto=='DIFFUSE':
-               map=Texture.MapTo.COL
-       elif mapto=='SPECULAR':
-               map=Texture.MapTo.SPEC
-       elif mapto=='OPACITY':
-               map=Texture.MapTo.ALPHA
-       elif mapto=='BUMP':
-               map=Texture.MapTo.NOR
-       else:
+#      if mapto=='DIFFUSE':
+#              map = Texture.MapTo.COL
+#      elif mapto=='SPECULAR':
+#              map = Texture.MapTo.SPEC
+#      elif mapto=='OPACITY':
+#              map = Texture.MapTo.ALPHA
+#      elif mapto=='BUMP':
+#              map = Texture.MapTo.NOR
+#      else:
+       if mapto not in ("COLOR", "SPECULARITY", "ALPHA", "NORMAL"):
                print('/tError:  Cannot map to "%s"\n\tassuming diffuse color. 
modify material "%s" later.' % (mapto, material.name))
-               map=Texture.MapTo.COL
+               mapto = "COLOR"
+#              map = Texture.MapTo.COL
 
-       if image: texture.setImage(image) # double check its an image.
-       free_tex_slots= [i for i, tex in enumerate( material.getTextures() ) if 
tex==None]
-       if not free_tex_slots:
-               print('/tError: Cannot add "%s" map. 10 Texture slots alredy 
used.' % mapto)
-       else:
-               
material.setTexture(free_tex_slots[0],texture,Texture.TexCo.UV,map)
+       if image: texture.image = image
+#      if image: texture.setImage(image) # double check its an image.
 
+       material.add_texture(texture, "UV", mapto)
+#      free_tex_slots = [i for i, tex in enumerate( material.getTextures() ) 
if tex == None]
+#      if not free_tex_slots:
+#              print('/tError: Cannot add "%s" map. 10 Texture slots alredy 
used.' % mapto)
+#      else:
+#              
material.setTexture(free_tex_slots[0],texture,Texture.TexCo.UV,map)
 
+
 def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
        #print previous_chunk.bytes_read, 'BYTES READ'
-       contextObName= None
-       contextLamp= [None, None] # object, Data
-       contextMaterial= None
-       contextMatrix_rot= None # Blender.Mathutils.Matrix(); 
contextMatrix.identity()
-       #contextMatrix_tx= None # Blender.Mathutils.Matrix(); 
contextMatrix.identity()
-       contextMesh_vertls= None
-       contextMesh_facels= None
-       contextMeshMaterials= {} # matname:[face_idxs]
-       contextMeshUV= None
+       contextObName = None
+       contextLamp = [None, None] # object, Data
+       contextMaterial = None
+       contextMatrix_rot = None # Blender.Mathutils.Matrix(); 
contextMatrix.identity()
+       #contextMatrix_tx = None # Blender.Mathutils.Matrix(); 
contextMatrix.identity()
+       contextMesh_vertls = None
+       contextMesh_facels = None
+       contextMeshMaterials = {} # matname:[face_idxs]
+       contextMeshUV = None
        
-       TEXTURE_DICT={}
-       MATDICT={}
-       TEXMODE= Mesh.FaceModes['TEX']
+       TEXTURE_DICT = {}
+       MATDICT = {}
+#      TEXMODE = Mesh.FaceModes['TEX']
        
        # Localspace variable names, faster.
-       STRUCT_SIZE_1CHAR= calcsize('c')
-       STRUCT_SIZE_2FLOAT= calcsize('2f')
-       STRUCT_SIZE_3FLOAT= calcsize('3f')
-       STRUCT_SIZE_UNSIGNED_SHORT= calcsize('H')
-       STRUCT_SIZE_4UNSIGNED_SHORT= calcsize('4H')
-       STRUCT_SIZE_4x3MAT= calcsize('ffffffffffff')
-       _STRUCT_SIZE_4x3MAT= calcsize('fffffffffffff')
-       # STRUCT_SIZE_4x3MAT= calcsize('ffffffffffff')
+       STRUCT_SIZE_1CHAR = struct.calcsize('c')
+       STRUCT_SIZE_2FLOAT = struct.calcsize('2f')
+       STRUCT_SIZE_3FLOAT = struct.calcsize('3f')
+       STRUCT_SIZE_UNSIGNED_SHORT = struct.calcsize('H')
+       STRUCT_SIZE_4UNSIGNED_SHORT = struct.calcsize('4H')
+       STRUCT_SIZE_4x3MAT = struct.calcsize('ffffffffffff')
+       _STRUCT_SIZE_4x3MAT = struct.calcsize('fffffffffffff')
+       # STRUCT_SIZE_4x3MAT = calcsize('ffffffffffff')
        # print STRUCT_SIZE_4x3MAT, ' STRUCT_SIZE_4x3MAT'
        
        def putContextMesh(myContextMesh_vertls, myContextMesh_facels, 
myContextMeshMaterials):
                
-               materialFaces= set() # faces that have a material. Can optimize?
+               materialFaces = set() # faces that have a material. Can 
optimize?
                
                # Now make copies with assigned materils.
                
@@ -363,13 +380,13 @@
                        '''
                        
                        faceVertUsers = [False] * len(myContextMesh_vertls)
-                       ok=0
+                       ok = 0
                        for fIdx in faces:
                                for vindex in myContextMesh_facels[fIdx]:
                                        faceVertUsers[vindex] = True
                                        if matName != None: # if matName is 
none then this is a set(), meaning we are using the untextured faces and do not 
need to store textured faces.
                                                materialFaces.add(fIdx)
-                                       ok=1
+                                       ok = 1
                        
                        if not ok:
                                return
@@ -381,370 +398,460 @@
                        myVertMapping = dict( [ (ii, i) for i, ii in 
enumerate(vertsToUse) ] )
                        
                        tempName= '%s_%s' % (contextObName, matName) # matName 
may be None.
-                       bmesh = bpy.data.meshes.new(tempName)
+                       bmesh = bpy.data.add_mesh(tempName)
+#                      bmesh = bpy.data.meshes.new(tempName)
                        
                        if matName == None:
-                               img= None
+                               img = None
                        else:
                                bmat = MATDICT[matName][1]
-                               bmesh.materials= [bmat]
-                               try:    img= TEXTURE_DICT[bmat.name]
-                               except: img= None
+                               bmesh.add_material(bmat)
+#                              bmesh.materials = [bmat]
+                               try:    img = TEXTURE_DICT[bmat.name]
+                               except: img = None
                                
-                       bmesh_verts = bmesh.verts
-                       bmesh_verts.extend( [Vector()] )
-                       bmesh_verts.extend( [myContextMesh_vertls[i] for i in 
vertsToUse] )
-                       # +1 because of DUMMYVERT
-                       face_mapping= bmesh.faces.extend( [ [ bmesh_verts[ 
myVertMapping[vindex]+1] for vindex in myContextMesh_facels[fIdx]] for fIdx in 
faces ], indexList=True )
+#                      bmesh_verts = bmesh.verts
+                       if len(vertsToUse):

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to