[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2306] trunk/py/scripts/addons/ io_coat3D: Cleaning the code.

Kalle-Samuli Riihikoski haikalle at gmail.com
Mon Sep 5 16:08:01 CEST 2011


Revision: 2306
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2306
Author:   haikalle
Date:     2011-09-05 14:08:00 +0000 (Mon, 05 Sep 2011)
Log Message:
-----------
Cleaning the code. Also added support for multres objects. 

Modified Paths:
--------------
    trunk/py/scripts/addons/io_coat3D/__init__.py
    trunk/py/scripts/addons/io_coat3D/coat.py
    trunk/py/scripts/addons/io_coat3D/tex.py

Modified: trunk/py/scripts/addons/io_coat3D/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_coat3D/__init__.py	2011-09-05 11:41:40 UTC (rev 2305)
+++ trunk/py/scripts/addons/io_coat3D/__init__.py	2011-09-05 14:08:00 UTC (rev 2306)
@@ -121,12 +121,6 @@
             description="Export Coarse.",
             default= True
         )
-   
-        smooth_on = BoolProperty(
-            name="Auto Smooth",
-            description="Add Modifiers and export.",
-            default= True
-        )
         exportfile = BoolProperty(
             name="No Import File",
             description="Add Modifiers and export.",
@@ -147,6 +141,11 @@
             description="Remember position.",
             default= True
         )
+        multires = BoolProperty(
+            name="Multires. Levels",
+            description="Saves Multiresolution data.",
+            default= True
+        )
         importtextures = BoolProperty(
             name="Bring Textures",
             description="Import Textures.",

Modified: trunk/py/scripts/addons/io_coat3D/coat.py
===================================================================
--- trunk/py/scripts/addons/io_coat3D/coat.py	2011-09-05 11:41:40 UTC (rev 2305)
+++ trunk/py/scripts/addons/io_coat3D/coat.py	2011-09-05 14:08:00 UTC (rev 2306)
@@ -27,7 +27,6 @@
 bpy.coat3D['active_coat'] = ''
 bpy.coat3D['status'] = 0
 
-
 class ObjectButtonsPanel():
     bl_space_type = 'PROPERTIES'
     bl_region_type = 'WINDOW'
@@ -106,8 +105,8 @@
             colR.label(text="Import Settings:")
             colR.prop(coat3D,"importmesh")
             colR.prop(coat3D,"importmod")
-            colR.prop(coat3D,"smooth_on")
             colR.prop(coat3D,"importtextures")
+            colR.prop(coat3D,"multires")
             row = layout.row()
         
         if(bpy.context.selected_objects):
@@ -199,7 +198,6 @@
     bl_description = "Export your custom property"
     bl_options = {'UNDO'}
 
-    
     def invoke(self, context, event):
         checkname = ''
         coat3D = bpy.context.scene.coat3D
@@ -266,7 +264,6 @@
 
         return {'FINISHED'}
 
-
 class SCENE_OT_import(bpy.types.Operator):
     bl_idname = "import_applink.pilgway_3d_coat"
     bl_label = "import your custom property"
@@ -281,6 +278,7 @@
         act_first = bpy.context.scene.objects.active
         for act_name in test:
             if act_name.type == 'MESH' and os.path.isfile(act_name.coat3D.objectdir):
+                multires_on = False
                 activeobj = act_name.name
                 mat_list = []
                 scene.objects[activeobj].select = True
@@ -289,6 +287,18 @@
                 coat3D.rota = objekti.rotation_euler
                 coa = act_name.coat3D
 
+                if(coat3D.multires):
+                    for modifiers in objekti.modifiers:
+                        if modifiers.type == 'MULTIRES' and (modifiers.total_levels > 0):
+                            bpy.ops.object.multires_external_pack()
+                            multires = coat3D.exchangedir
+                            multires += ('%stemp.btx'%(os.sep))
+                            bpy.ops.object.multires_external_save(filepath=multires)
+                            #bpy.ops.object.multires_external_pack()
+                            multires_on = True
+                            multires_name = modifiers.name
+                            break
+                        
                 exportfile = coat3D.exchangedir
                 path3b_n = coat3D.exchangedir
                 path3b_n += ('last_saved_3b_file.txt')
@@ -303,11 +313,19 @@
                     os.remove(exportfile)
                     
                 if(objekti.material_slots):
+                    act_mat_index = objekti.active_material_index
+                    if(not(hasattr(objekti.active_material,'texture_slots'))):
+                        materials_old = bpy.data.materials.keys()
+                        bpy.ops.material.new()
+                        materials_new = bpy.data.materials.keys()
+                        new_ma = list(set(materials_new).difference(set(materials_old)))
+                        new_mat = new_ma[0]
+                        ki = bpy.data.materials[new_mat]
+                        objekti.material_slots[act_mat_index].material = ki
                     for obj_mat in objekti.material_slots:
                         mat_list.append(obj_mat.material)
-                    act_mat_index = objekti.active_material_index
 
-
+                 
                 if(coat3D.importmesh and os.path.isfile(coa.objectdir)):
                     mtl = coa.objectdir
                     mtl = mtl.replace('.obj','.mtl')
@@ -342,11 +360,6 @@
                     objekti.select = True
                     bpy.context.scene.objects.active = objekti
 
-                    if(coat3D.smooth_on):
-                        bpy.ops.object.shade_smooth()
-                    else:
-                        bpy.ops.object.shade_flat()
-
                 if(os.path.isfile(path3b_n)):
                     path3b_fil = open(path3b_n)
                     for lin in path3b_fil:
@@ -364,23 +377,36 @@
                     
                 if(mat_list):
                     for obj_mate in objekti.material_slots:
-                        for tex_slot in obj_mate.material.texture_slots:
-                            if(hasattr(tex_slot,'texture')):
-                                if(tex_slot.texture.type == 'IMAGE'):
-                                    if tex_slot.texture.image is not None:
-                                        tex_slot.texture.image.reload()
+                        if(hasattr(obj_mate.material,'texture_slots')):
+                            for tex_slot in obj_mate.material.texture_slots:
+                                if(hasattr(tex_slot,'texture')):
+                                    if(tex_slot.texture.type == 'IMAGE'):
+                                        if tex_slot.texture.image is not None:
+                                            tex_slot.texture.image.reload()
                                                                 
-
                 if(coat3D.importmod):
                     for mod_index in objekti.modifiers[:]:
                         objekti.modifiers.remove(mod_index)
                         
-                
-                        
                 if(coat3D.importtextures):
                                 export = ''
                                 tex.gettex(mat_list,objekti,scene,export)
-        
+
+                if(multires_on):
+                    temp_file = coat3D.exchangedir
+                    temp_file += ('%stemp2.btx'%(os.sep))
+                    if(objekti.modifiers[multires_name].levels == 0):
+                        objekti.modifiers[multires_name].levels = 1
+                        bpy.ops.object.multires_external_save(filepath=temp_file)
+                        objekti.modifiers[multires_name].filepath = multires
+                        objekti.modifiers[multires_name].levels = 0
+
+                    else:
+                        bpy.ops.object.multires_external_save(filepath=temp_file)
+                        objekti.modifiers[multires_name].filepath = multires
+                    #bpy.ops.object.multires_external_pack()
+                bpy.ops.object.shade_smooth()
+                
         for act_name in test:
             act_name.select = True
         bpy.context.scene.objects.active = act_first
@@ -393,7 +419,6 @@
     bl_description = "Bring 3D-Coat Mesh"
     bl_options = {'UNDO'}
 
-    
     def invoke(self, context, event):
 
         coat3D = bpy.context.scene.coat3D
@@ -452,16 +477,12 @@
         
         bpy.context.scene.objects.active = new_obj
 
-        if(coat3D.smooth_on):
-            bpy.ops.object.shade_smooth()
-        else:
-            bpy.ops.object.shade_flat()
-
+        bpy.ops.object.shade_smooth()
+       
         Blender_tex = ("%s%stextures.txt"%(coat3D.exchangedir,os.sep))
         mat_list.append(new_obj.material_slots[0].material)
         tex.gettex(mat_list, new_obj, scene,export)
 
-
         return {'FINISHED'}
 
 class SCENE_OT_load3b(bpy.types.Operator):
@@ -487,7 +508,6 @@
             file.write("\n[3B]")
             file.close()
 
-
         return {'FINISHED'}
 
 class SCENE_OT_deltex(bpy.types.Operator):
@@ -495,7 +515,6 @@
     bl_label = "Picks Object's name into path"
     bl_description = "Loads 3b linked into object"
 
-    
     def invoke(self, context, event):
         if(bpy.context.selected_objects):
             if(context.selected_objects[0].type == 'MESH'):
@@ -518,11 +537,9 @@
     
         return {'FINISHED'}
 
-
 from bpy import *
 from mathutils import Vector, Matrix
 
-
 # 3D-Coat Dynamic Menu
 class VIEW3D_MT_Coat_Dynamic_Menu(bpy.types.Menu):
     bl_label = "3D-Coat Applink Menu"
@@ -584,9 +601,6 @@
                     layout.operator("import3b_applink.pilgway_3d_coat", text="Bring from 3D-Coat")
                     layout.separator()
                 
-          
-            
-        
 class VIEW3D_MT_ImportMenu(bpy.types.Menu):
     bl_label = "Import Settings"
 
@@ -634,7 +648,6 @@
     kmi = km.keymap_items.new('wm.call_menu2', 'Q', 'PRESS')
     kmi.properties.name = "VIEW3D_MT_Coat_Dynamic_Menu"
 
-
 def unregister():
     bpy.utils.unregister_module(__name__)
 

Modified: trunk/py/scripts/addons/io_coat3D/tex.py
===================================================================
--- trunk/py/scripts/addons/io_coat3D/tex.py	2011-09-05 11:41:40 UTC (rev 2305)
+++ trunk/py/scripts/addons/io_coat3D/tex.py	2011-09-05 14:08:00 UTC (rev 2306)
@@ -20,26 +20,6 @@
 import bpy
 import os
 
-def objname(path):
-
-    path2 = os.path.dirname(path) + os.sep
-    pituus = len(path2)
-    nimi = path[pituus:]
-    return nimi
-
-def justname(name):
-    monesko = name.rfind('.')
-    justname = name[:monesko]
-    return justname
-
-def setgallery():
-    newname =''
-    tex_name =[]
-    index_tex = 0
-    for tt in bpy.data.textures:
-        tex_name.append(tt.name)
-    return tex_name
-
 def find_index(objekti):
         luku = 0
         for tex in objekti.active_material.texture_slots:
@@ -52,7 +32,6 @@
 
     coat3D = bpy.context.scene.coat3D
     
-    
     if(bpy.context.scene.render.engine == 'VRAY_RENDER' or bpy.context.scene.render.engine == 'VRAY_RENDER_PREVIEW'):
         vray = True
     else:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list