(no commit message)
authorOscurart Eugenio Pignataro <info@oscurart.com.ar>
Thu, 2 Aug 2012 17:15:12 +0000 (17:15 +0000)
committerOscurart Eugenio Pignataro <info@oscurart.com.ar>
Thu, 2 Aug 2012 17:15:12 +0000 (17:15 +0000)
add_mesh_chain_rope/oscurart_chain_maker.py

index 893a5658fd47fd6a3355c1a96b02a753678caf2b..47089b886e1888633119ec825c64c25d11912139 100644 (file)
@@ -38,62 +38,61 @@ import bpy
 
 def makeChain (context, mult, curverig): 
     
-        # SI EL CONTEXTO ES OBJECT CORRE LA FUNCION
-        if bpy.context.mode == 'OBJECT':        
-            VAR_SWITCH=abs(1)
-            ARMATURE=bpy.context.active_object
-            
-            def creahuesocero(hueso):
-                ## CREO DATA PARA ESLABON
-                mesh=bpy.data.meshes.new("objectData"+str(hueso.name))
-                object=bpy.data.objects.new("EslabonCero"+str(hueso.name),mesh)
-                mesh.from_pydata(
-                [(-0.04986128956079483,-0.6918092370033264,-0.17846597731113434),(-0.04986128956079483,-0.6918091773986816,0.17846640944480896),(-0.049861326813697815,-0.154555082321167,0.17846627533435822),(-0.049861326813697815,-0.15455523133277893,-0.17846614122390747),(-0.04986133798956871,-0.03475356101989746,0.25805795192718506),(-0.04986133798956871,-0.03475397825241089,-0.25805795192718506),(-0.049861278384923935,-0.8116106986999512,-0.2580576539039612),(-0.049861278384923935,-0.8116104602813721,0.25805822014808655),(-0.04986128211021423,-0.7692053318023682,2.6668965347198537e-07),(-0.04986127093434334,-0.923523485660553,2.7834033744511544e-07),(-0.04986133426427841,-0.0771591067314148,3.5627678585115063e-08),(-0.04986134544014931,0.0771591067314148,-3.5627678585115063e-08),(0.04986133798956871,-0.03475397825241089,-0.25805795192718506),(0.04986133053898811,0.0771591067314148,-3.5627678585115063e-08),(0.04986133798956871,-0.03475356101989746,0.25805795192718506),(0.04986134544014931,-0.15455523133277893,-0.17846614122390747),(0.04986134544014931,-0.0771591067314148,3.5627678585115063e-08),(0.04986134544014931,-0.154555082321167,0.17846627533435822),(0.049861397594213486,-0.8116106986999512,-0.2580576539039612),(0.04986140504479408,-0.923523485660553,2.7834033744511544e-07),(0.049861397594213486,-0.8116104602813721,0.25805822014808655),(0.04986139014363289,-0.6918091773986816,0.17846640944480896),(0.04986139014363289,-0.7692053318023682,2.6668965347198537e-07),(0.04986139014363289,-0.6918092370033264,-0.17846597731113434)],
+        bpy.ops.object.mode_set(mode='OBJECT')      
+        VAR_SWITCH=abs(1)
+        ARMATURE=bpy.context.active_object
+        
+        def creahuesocero(hueso):
+            ## CREO DATA PARA ESLABON
+            mesh=bpy.data.meshes.new("objectData"+str(hueso.name))
+            object=bpy.data.objects.new("EslabonCero"+str(hueso.name),mesh)
+            mesh.from_pydata(
+            [(-0.04986128956079483,-0.6918092370033264,-0.17846597731113434),(-0.04986128956079483,-0.6918091773986816,0.17846640944480896),(-0.049861326813697815,-0.154555082321167,0.17846627533435822),(-0.049861326813697815,-0.15455523133277893,-0.17846614122390747),(-0.04986133798956871,-0.03475356101989746,0.25805795192718506),(-0.04986133798956871,-0.03475397825241089,-0.25805795192718506),(-0.049861278384923935,-0.8116106986999512,-0.2580576539039612),(-0.049861278384923935,-0.8116104602813721,0.25805822014808655),(-0.04986128211021423,-0.7692053318023682,2.6668965347198537e-07),(-0.04986127093434334,-0.923523485660553,2.7834033744511544e-07),(-0.04986133426427841,-0.0771591067314148,3.5627678585115063e-08),(-0.04986134544014931,0.0771591067314148,-3.5627678585115063e-08),(0.04986133798956871,-0.03475397825241089,-0.25805795192718506),(0.04986133053898811,0.0771591067314148,-3.5627678585115063e-08),(0.04986133798956871,-0.03475356101989746,0.25805795192718506),(0.04986134544014931,-0.15455523133277893,-0.17846614122390747),(0.04986134544014931,-0.0771591067314148,3.5627678585115063e-08),(0.04986134544014931,-0.154555082321167,0.17846627533435822),(0.049861397594213486,-0.8116106986999512,-0.2580576539039612),(0.04986140504479408,-0.923523485660553,2.7834033744511544e-07),(0.049861397594213486,-0.8116104602813721,0.25805822014808655),(0.04986139014363289,-0.6918091773986816,0.17846640944480896),(0.04986139014363289,-0.7692053318023682,2.6668965347198537e-07),(0.04986139014363289,-0.6918092370033264,-0.17846597731113434)],
+        [(1,2),(0,3),(3,5),(2,4),(0,6),(5,6),(1,7),(4,7),(0,8),(1,8),(7,9),(6,9),(8,9),(2,10),(3,10),(4,11),(5,11),(10,11),(5,12),(12,13),(11,13),(13,14),(4,14),(10,16),(15,16),(3,15),(2,17),(16,17),(9,19),(18,19),(6,18),(7,20),(19,20),(8,22),(21,22),(1,21),(0,23),(22,23),(14,20),(12,18),(15,23),(17,21),(12,15),(13,16),(14,17),(20,21),(19,22),(18,23)],
+        [(6,0,3,5),(1,7,4,2),(0,6,9,8),(8,9,7,1),(2,4,11,10),(10,11,5,3),(11,13,12,5),(4,14,13,11),(3,15,16,10),(10,16,17,2),(6,18,19,9),(9,19,20,7),(1,21,22,8),(23,0,8,22),(7,20,14,4),(5,12,18,6),(0,23,15,3),(2,17,21,1),(16,15,12,13),(17,16,13,14),(22,21,20,19),(23,22,19,18),(21,17,14,20),(15,23,18,12)]
+            )
+            bpy.context.scene.objects.link(object)
+            ## ESCALO EL HUESO
+            bpy.data.objects['EslabonCero'+str(hueso.name)].scale= (hueso.length*mult,hueso.length*mult,hueso.length*mult)
+            
+            ## EMPARENTO
+            bpy.data.objects['EslabonCero'+str(hueso.name)].parent=ARMATURE
+            bpy.data.objects['EslabonCero'+str(hueso.name)].parent_type = 'BONE'
+            bpy.data.objects['EslabonCero'+str(hueso.name)].parent_bone=hueso.name   
+        
+        
+        def creahuesonoventa(hueso):
+            ## CREO DATA PARA ESLABON
+            mesh=bpy.data.meshes.new("objectData"+str(hueso.name))
+            object=bpy.data.objects.new("EslabonNov"+str(hueso.name),mesh)
+            mesh.from_pydata(
+            [(0.1784660965204239,-0.6918091773986816,-0.049861203879117966),(-0.1784662902355194,-0.6918091773986816,-0.04986126348376274),(-0.17846627533435822,-0.1545550525188446,-0.04986134544014931),(0.17846617102622986,-0.15455520153045654,-0.04986128583550453),(-0.25805795192718506,-0.03475359082221985,-0.049861375242471695),(0.25805795192718506,-0.034753888845443726,-0.04986129328608513),(0.2580578327178955,-0.8116105794906616,-0.04986117407679558),(-0.2580580413341522,-0.8116105198860168,-0.049861256033182144),(-9.672299938756623e-08,-0.7692052721977234,-0.04986122250556946),(-8.99775329799013e-08,-0.923523485660553,-0.04986120015382767),(-7.764004550381287e-09,-0.07715904712677002,-0.049861326813697815),(4.509517737005808e-08,0.0771591067314148,-0.049861349165439606),(0.25805795192718506,-0.034753888845443726,0.049861375242471695),(-2.2038317837314025e-08,0.0771591067314148,0.049861326813697815),(-0.25805795192718506,-0.03475359082221985,0.04986129328608513),(0.17846617102622986,-0.15455520153045654,0.04986138269305229),(-1.529285498236277e-08,-0.07715907692909241,0.049861352890729904),(-0.17846627533435822,-0.1545550525188446,0.049861323088407516),(0.2580578029155731,-0.8116105794906616,0.049861494451761246),(-1.5711103173998708e-07,-0.923523485660553,0.04986147582530975),(-0.2580580711364746,-0.8116105198860168,0.04986141249537468),(-0.1784663051366806,-0.6918091773986816,0.049861419945955276),(-1.340541757599567e-07,-0.7692052721977234,0.049861449748277664),(0.1784660816192627,-0.6918091773986816,0.04986146464943886)],
             [(1,2),(0,3),(3,5),(2,4),(0,6),(5,6),(1,7),(4,7),(0,8),(1,8),(7,9),(6,9),(8,9),(2,10),(3,10),(4,11),(5,11),(10,11),(5,12),(12,13),(11,13),(13,14),(4,14),(10,16),(15,16),(3,15),(2,17),(16,17),(9,19),(18,19),(6,18),(7,20),(19,20),(8,22),(21,22),(1,21),(0,23),(22,23),(14,20),(12,18),(15,23),(17,21),(12,15),(13,16),(14,17),(20,21),(19,22),(18,23)],
             [(6,0,3,5),(1,7,4,2),(0,6,9,8),(8,9,7,1),(2,4,11,10),(10,11,5,3),(11,13,12,5),(4,14,13,11),(3,15,16,10),(10,16,17,2),(6,18,19,9),(9,19,20,7),(1,21,22,8),(23,0,8,22),(7,20,14,4),(5,12,18,6),(0,23,15,3),(2,17,21,1),(16,15,12,13),(17,16,13,14),(22,21,20,19),(23,22,19,18),(21,17,14,20),(15,23,18,12)]
-                )
-                bpy.context.scene.objects.link(object)
-                ## ESCALO EL HUESO
-                bpy.data.objects['EslabonCero'+str(hueso.name)].scale= (hueso.length*mult,hueso.length*mult,hueso.length*mult)
-                
-                ## EMPARENTO
-                bpy.data.objects['EslabonCero'+str(hueso.name)].parent=ARMATURE
-                bpy.data.objects['EslabonCero'+str(hueso.name)].parent_type = 'BONE'
-                bpy.data.objects['EslabonCero'+str(hueso.name)].parent_bone=hueso.name   
-            
-            
-            def creahuesonoventa(hueso):
-                ## CREO DATA PARA ESLABON
-                mesh=bpy.data.meshes.new("objectData"+str(hueso.name))
-                object=bpy.data.objects.new("EslabonNov"+str(hueso.name),mesh)
-                mesh.from_pydata(
-                [(0.1784660965204239,-0.6918091773986816,-0.049861203879117966),(-0.1784662902355194,-0.6918091773986816,-0.04986126348376274),(-0.17846627533435822,-0.1545550525188446,-0.04986134544014931),(0.17846617102622986,-0.15455520153045654,-0.04986128583550453),(-0.25805795192718506,-0.03475359082221985,-0.049861375242471695),(0.25805795192718506,-0.034753888845443726,-0.04986129328608513),(0.2580578327178955,-0.8116105794906616,-0.04986117407679558),(-0.2580580413341522,-0.8116105198860168,-0.049861256033182144),(-9.672299938756623e-08,-0.7692052721977234,-0.04986122250556946),(-8.99775329799013e-08,-0.923523485660553,-0.04986120015382767),(-7.764004550381287e-09,-0.07715904712677002,-0.049861326813697815),(4.509517737005808e-08,0.0771591067314148,-0.049861349165439606),(0.25805795192718506,-0.034753888845443726,0.049861375242471695),(-2.2038317837314025e-08,0.0771591067314148,0.049861326813697815),(-0.25805795192718506,-0.03475359082221985,0.04986129328608513),(0.17846617102622986,-0.15455520153045654,0.04986138269305229),(-1.529285498236277e-08,-0.07715907692909241,0.049861352890729904),(-0.17846627533435822,-0.1545550525188446,0.049861323088407516),(0.2580578029155731,-0.8116105794906616,0.049861494451761246),(-1.5711103173998708e-07,-0.923523485660553,0.04986147582530975),(-0.2580580711364746,-0.8116105198860168,0.04986141249537468),(-0.1784663051366806,-0.6918091773986816,0.049861419945955276),(-1.340541757599567e-07,-0.7692052721977234,0.049861449748277664),(0.1784660816192627,-0.6918091773986816,0.04986146464943886)],
-                [(1,2),(0,3),(3,5),(2,4),(0,6),(5,6),(1,7),(4,7),(0,8),(1,8),(7,9),(6,9),(8,9),(2,10),(3,10),(4,11),(5,11),(10,11),(5,12),(12,13),(11,13),(13,14),(4,14),(10,16),(15,16),(3,15),(2,17),(16,17),(9,19),(18,19),(6,18),(7,20),(19,20),(8,22),(21,22),(1,21),(0,23),(22,23),(14,20),(12,18),(15,23),(17,21),(12,15),(13,16),(14,17),(20,21),(19,22),(18,23)],
-                [(6,0,3,5),(1,7,4,2),(0,6,9,8),(8,9,7,1),(2,4,11,10),(10,11,5,3),(11,13,12,5),(4,14,13,11),(3,15,16,10),(10,16,17,2),(6,18,19,9),(9,19,20,7),(1,21,22,8),(23,0,8,22),(7,20,14,4),(5,12,18,6),(0,23,15,3),(2,17,21,1),(16,15,12,13),(17,16,13,14),(22,21,20,19),(23,22,19,18),(21,17,14,20),(15,23,18,12)]
-                )
-                bpy.context.scene.objects.link(object)
-                
-                ## ESCALO EL HUESO
-                bpy.data.objects['EslabonNov'+str(hueso.name)].scale= (hueso.length*mult,hueso.length*mult,hueso.length*mult)
-            
-                ## EMPARENTO
-                bpy.data.objects['EslabonNov'+str(hueso.name)].parent=ARMATURE
-                bpy.data.objects['EslabonNov'+str(hueso.name)].parent_type = 'BONE'
-                bpy.data.objects['EslabonNov'+str(hueso.name)].parent_bone=hueso.name   
-            
-            
-            
-            for hueso in bpy.context.active_object.pose.bones:
-                if VAR_SWITCH == 1:
-                    creahuesocero(hueso)
-                else:
-                    creahuesonoventa(hueso)    
-                if VAR_SWITCH == 1:
-                    VAR_SWITCH = 0
-                    print(VAR_SWITCH)
-                else :
-                    VAR_SWITCH = 1
-                    print(VAR_SWITCH)
+            )
+            bpy.context.scene.objects.link(object)
+            
+            ## ESCALO EL HUESO
+            bpy.data.objects['EslabonNov'+str(hueso.name)].scale= (hueso.length*mult,hueso.length*mult,hueso.length*mult)
+        
+            ## EMPARENTO
+            bpy.data.objects['EslabonNov'+str(hueso.name)].parent=ARMATURE
+            bpy.data.objects['EslabonNov'+str(hueso.name)].parent_type = 'BONE'
+            bpy.data.objects['EslabonNov'+str(hueso.name)].parent_bone=hueso.name   
+        
+        
+        
+        for hueso in bpy.context.active_object.pose.bones:
+            if VAR_SWITCH == 1:
+                creahuesocero(hueso)
+            else:
+                creahuesonoventa(hueso)    
+            if VAR_SWITCH == 1:
+                VAR_SWITCH = 0
+                print(VAR_SWITCH)
+            else :
+                VAR_SWITCH = 1
+                print(VAR_SWITCH)
                     
                     
         # SI NO TILDAMOS CURVERIG
@@ -196,7 +195,7 @@ class MESH_OT_chain_maker(bpy.types.Operator):
 
     @classmethod
     def poll(cls, context):
-        return(bpy.context.active_object.type == "ARMATURE" and bpy.context.active_object.mode == "OBJECT"
+        return(bpy.context.active_object.type == "ARMATURE" ) 
     
     def execute(self, context):
         makeChain(context, 
@@ -218,4 +217,4 @@ def unregister():
     
  
 if __name__ == "__main__":
-    register()    
+    register()    
\ No newline at end of file