Move 'render auto tile size' addon to main repo.
[blender-addons-contrib.git] / oscurart_futurism.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 bl_info = {
20     "name": "Futurism",
21     "author": "Oscurart",
22     "version": (1, 2),
23     "blender": (2, 63, 0),
24     "location": "Object > Futurism",
25     "description": "Adds a new Mesh Object",
26     "warning": "",
27     "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
28         "Scripts/Object/Oscurart_Futurism",
29     "tracker_url": "https://developer.blender.org/T31911",
30     "category": "Add Mesh"}
31
32
33 import bpy
34
35 def object_osc_futurism (self, context,STEP, HOLD):
36     ACTOBJ=bpy.context.active_object # OBJETO ACTIVO
37     FS=bpy.context.scene.frame_start # FRAME START
38     FE=bpy.context.scene.frame_end # FRAME END
39     OBJLIST=[] # LISTA PARA OBJETOS ????
40     FC=FS # FRAME CURRENT
41     OBJNUMBER=1 # SUFIJO DE NUMERO PARA OBJETOS
42     STEPINC=0 # NUMERO PARA EVALUAR LOS PASOS
43     bpy.context.scene.frame_set(FS)  # SETEO EL FRAME CURRENT
44     OBACT = bpy.context.active_object # SETEO EL OBJETO ACTIVO
45
46     ## CREO EMPTY
47     bpy.ops.object.add()
48     bpy.context.active_object.name = "FuturismContainer"
49     EMPTY = bpy.context.active_object
50
51     # SUMO PARAMETERS AL EMPTY
52     EMPTY["FUTURISM_HOLDIN"] = 0
53     EMPTY["FUTURISM_HOLDOUT"] = 0
54
55     bpy.context.scene.objects.active = OBACT  # RECUPERO OBJETO ACTIVO
56
57     for OBJETO in range((FE+1)-FS):
58         if STEPINC == STEP:
59             # CREO UN MESH A PARTIR DE OBJETO
60             MESH=ACTOBJ.to_mesh(bpy.context.scene, True, 'PREVIEW')
61             # CREO OBJETO
62             OBJECT=bpy.data.objects.new(ACTOBJ.name[:3]+str(FC), MESH)
63             # CONECTO A LA ESCENA
64             bpy.context.scene.objects.link(OBJECT)
65             # SETEO FRAME CURRENT
66             bpy.context.scene.frame_set(FC)
67             # MARCO EXPRESIONES PARA VIEW
68             OBJECT.driver_add("hide")
69             OBJECT.animation_data.drivers[0].driver.variables.new()
70             OBJECT.animation_data.drivers[0].driver.variables.new()
71             OBJECT.animation_data.drivers[0].driver.variables.new()
72             OBJECT.animation_data.drivers[0].driver.expression= "False if frame >= %s+var_001 and frame <= %s+var_002 else True" % (str(FC),str(FC+HOLD))
73             OBJECT.animation_data.drivers[0].driver.variables[0].targets[0].id_type = 'SCENE'
74             OBJECT.animation_data.drivers[0].driver.variables[0].targets[0].id= bpy.context.scene
75             OBJECT.animation_data.drivers[0].driver.variables[0].targets[0].data_path = "current_frame"
76             OBJECT.animation_data.drivers[0].driver.variables[1].targets[0].id_type = 'OBJECT'
77             OBJECT.animation_data.drivers[0].driver.variables[1].targets[0].id= EMPTY
78             OBJECT.animation_data.drivers[0].driver.variables[1].targets[0].data_path = '["FUTURISM_HOLDIN"]'
79             OBJECT.animation_data.drivers[0].driver.variables[2].targets[0].id_type = 'OBJECT'
80             OBJECT.animation_data.drivers[0].driver.variables[2].targets[0].id= EMPTY
81             OBJECT.animation_data.drivers[0].driver.variables[2].targets[0].data_path = '["FUTURISM_HOLDOUT"]'
82
83             # MARCO EXPRESIONES PARA RENDER
84             OBJECT.driver_add("hide_render")
85             OBJECT.animation_data.drivers[1].driver.variables.new()
86             OBJECT.animation_data.drivers[1].driver.variables.new()
87             OBJECT.animation_data.drivers[1].driver.variables.new()
88             OBJECT.animation_data.drivers[1].driver.expression= "False if frame >= %s+5 and frame <= %s else True" % (str(FC),str(FC+HOLD))
89             OBJECT.animation_data.drivers[1].driver.variables[0].targets[0].id_type = 'SCENE'
90             OBJECT.animation_data.drivers[1].driver.variables[0].targets[0].id= bpy.context.scene
91             OBJECT.animation_data.drivers[1].driver.variables[0].targets[0].data_path = "current_frame"
92             OBJECT.animation_data.drivers[1].driver.variables[1].targets[0].id_type = 'OBJECT'
93             OBJECT.animation_data.drivers[1].driver.variables[1].targets[0].id= EMPTY
94             OBJECT.animation_data.drivers[1].driver.variables[1].targets[0].data_path = '["FUTURISM_HOLDIN"]'
95             OBJECT.animation_data.drivers[1].driver.variables[2].targets[0].id_type = 'OBJECT'
96             OBJECT.animation_data.drivers[1].driver.variables[2].targets[0].id= EMPTY
97             OBJECT.animation_data.drivers[1].driver.variables[2].targets[0].data_path = '["FUTURISM_HOLDOUT"]'
98             # RESETEO STEPINC
99             STEPINC=0
100             # COPIAMOS S R T
101             OBJECT.matrix_world=ACTOBJ.matrix_world
102             #EMPARENTO
103             OBJECT.parent=EMPTY
104         # AVANZO STEP Y FRAME
105         FC+=1
106         STEPINC+=1
107
108 # CLASE PARA OPERADOR
109 class Oscurart_futurism (bpy.types.Operator):
110     bl_idname = "object.duplicate_futurism"
111     bl_label = "Duplicate Futurism"
112     bl_description = "Duplicate object per frame"
113     bl_options = {'REGISTER', 'UNDO'}
114
115     scale = bpy.props.IntProperty(name='Step',default=1, min=1, max=1000)
116
117     hold = bpy.props.IntProperty(name='Hold', default=0, min=0)
118
119     @classmethod
120     def poll(cls, context):
121         return(bpy.context.active_object.type == "MESH" )
122
123     def execute(self, context):
124         object_osc_futurism(self, context, self.scale, self.hold)
125
126         return {'FINISHED'}
127
128
129 # Registration
130
131 def add_osc_futurism_button(self, context):
132     self.layout.operator(
133         Oscurart_futurism.bl_idname,
134         text="Futurism",
135         icon="PLUGIN")
136
137
138 def register():
139     bpy.utils.register_class(Oscurart_futurism)
140     bpy.types.VIEW3D_MT_object.append(add_osc_futurism_button)
141
142
143 def unregister():
144     bpy.utils.unregister_class(Oscurart_futurism)
145     bpy.types.VIEW3D_MT_object.remove(add_osc_futurism_button)
146
147
148 if __name__ == '__main__':
149     register()