Fix T52833: OBJ triangulate doesn't match viewport
[blender-addons.git] / add_advanced_objects_menu / __init__.py
blob46a3dffc7e5ef3a48449c2d243c48d6ded0bf654
1 # ##### BEGIN GPL LICENSE BLOCK #####
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.
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.
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.
17 # ##### END GPL LICENSE BLOCK #####
19 # Contributed to by:
20 # meta-androcto, Bill Currie, Jorge Hernandez - Melenedez Jacob Morris, Oscurart #
21 # Rebellion, Antonis Karvelas, Eleanor Howick, lijenstina, Daniel Schalla, Domlysz #
22 # Unnikrishnan(kodemax), Florian Meyer, Omar ahmed, Brian Hinton (Nichod), liero #
23 # Atom, Dannyboy, Mano-Wii, Kursad Karatas, teldredge, Phil Cote #
25 bl_info = {
26 "name": "Add Advanced Objects",
27 "author": "Meta Androcto",
28 "version": (0, 1, 5),
29 "blender": (2, 78, 0),
30 "location": "View3D > Add ",
31 "description": "Add Object & Camera extras",
32 "warning": "",
33 "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6"
34 "/Py/Scripts/Object/Add_Advanced",
35 "category": "Object"}
37 if "bpy" in locals():
38 import importlib
40 importlib.reload(add_light_template)
41 importlib.reload(scene_objects_bi)
42 importlib.reload(scene_objects_cycles)
43 importlib.reload(scene_texture_render)
44 importlib.reload(trilighting)
45 importlib.reload(pixelate_3d)
46 importlib.reload(object_add_chain)
47 importlib.reload(oscurart_chain_maker)
48 importlib.reload(circle_array)
49 importlib.reload(copy2)
50 importlib.reload(make_struts)
51 importlib.reload(random_box_structure)
52 importlib.reload(cubester)
53 importlib.reload(rope_alpha)
54 importlib.reload(add_mesh_aggregate)
55 importlib.reload(arrange_on_curve)
56 importlib.reload(mesh_easylattice)
59 else:
60 from . import add_light_template
61 from . import scene_objects_bi
62 from . import scene_objects_cycles
63 from . import scene_texture_render
64 from . import trilighting
65 from . import pixelate_3d
66 from . import object_add_chain
67 from . import oscurart_chain_maker
68 from . import circle_array
69 from . import copy2
70 from . import make_struts
71 from . import random_box_structure
72 from . import cubester
73 from . import rope_alpha
74 from . import add_mesh_aggregate
75 from . import arrange_on_curve
76 from . import mesh_easylattice
79 import bpy
80 from bpy.types import (
81 Menu,
82 AddonPreferences,
83 PropertyGroup,
85 from bpy.props import (
86 BoolProperty,
87 EnumProperty,
88 FloatProperty,
89 IntProperty,
90 StringProperty,
91 PointerProperty,
95 # Define the "Scenes" menu
96 class INFO_MT_scene_elements_add(Menu):
97 bl_idname = "INFO_MT_scene_elements"
98 bl_label = "Test Scenes"
100 def draw(self, context):
101 layout = self.layout
102 layout.operator_context = 'INVOKE_REGION_WIN'
103 layout.operator("bi.add_scene",
104 text="Scene_Objects_BI")
105 layout.operator("objects_cycles.add_scene",
106 text="Scene_Objects_Cycles")
107 layout.operator("objects_texture.add_scene",
108 text="Scene_Textures_Cycles")
111 # Define the "Lights" menu
112 class INFO_MT_mesh_lamps_add(Menu):
113 bl_idname = "INFO_MT_scene_lamps"
114 bl_label = "Lighting Sets"
116 def draw(self, context):
117 layout = self.layout
118 layout.operator_context = 'INVOKE_REGION_WIN'
119 layout.operator("object.add_light_template",
120 text="Add Light Template")
121 layout.operator("object.trilighting",
122 text="Add Tri Lighting")
125 # Define the "Chains" menu
126 class INFO_MT_mesh_chain_add(Menu):
127 bl_idname = "INFO_MT_mesh_chain"
128 bl_label = "Chains"
130 def draw(self, context):
131 layout = self.layout
132 layout.operator_context = 'INVOKE_REGION_WIN'
133 layout.operator("mesh.primitive_chain_add", icon="LINKED")
134 layout.operator("mesh.primitive_oscurart_chain_add", icon="LINKED")
137 # Define the "Array" Menu
138 class INFO_MT_array_mods_add(Menu):
139 bl_idname = "INFO_MT_array_mods"
140 bl_label = "Array Mods"
142 def draw(self, context):
143 layout = self.layout
144 layout.operator_context = 'INVOKE_REGION_WIN'
146 layout.menu("INFO_MT_mesh_chain", icon="LINKED")
148 layout.operator("objects.circle_array_operator",
149 text="Circle Array", icon="MOD_ARRAY")
150 layout.operator("object.agregate_mesh",
151 text="Aggregate Mesh", icon="MOD_ARRAY")
152 layout.operator("mesh.copy2",
153 text="Copy To Vert/Edge", icon="MOD_ARRAY")
156 # Define the "Blocks" Menu
157 class INFO_MT_quick_blocks_add(Menu):
158 bl_idname = "INFO_MT_quick_tools"
159 bl_label = "Block Tools"
161 def draw(self, context):
162 layout = self.layout
163 layout.operator_context = 'INVOKE_REGION_WIN'
165 layout.operator("object.pixelate", icon="MESH_GRID")
166 layout.operator("mesh.generate_struts",
167 text="Struts", icon="GRID")
168 layout.operator("object.make_structure",
169 text="Random Boxes", icon="SEQ_SEQUENCER")
170 layout.operator("object.easy_lattice",
171 text="Easy Lattice", icon="MOD_LATTICE")
174 # Define the "Phsysics Tools" Menu
175 class INFO_MT_Physics_tools_add(Menu):
176 bl_idname = "INFO_MT_physics_tools"
177 bl_label = "Physics Tools"
179 def draw(self, context):
180 layout = self.layout
181 layout.operator_context = 'INVOKE_REGION_WIN'
183 layout.operator("ball.rope",
184 text="Wrecking Ball", icon='PHYSICS')
185 layout.operator("clot.rope",
186 text="Cloth Rope", icon='PHYSICS')
189 # Define "Extras" menu
190 def menu(self, context):
191 layout = self.layout
192 layout.operator_context = 'INVOKE_REGION_WIN'
193 self.layout.separator()
194 self.layout.menu("INFO_MT_scene_elements", icon="SCENE_DATA")
195 self.layout.menu("INFO_MT_scene_lamps", icon="LAMP_SPOT")
196 self.layout.separator()
197 self.layout.menu("INFO_MT_array_mods", icon="MOD_ARRAY")
198 self.layout.menu("INFO_MT_quick_tools", icon="MOD_BUILD")
199 self.layout.menu("INFO_MT_physics_tools", icon="PHYSICS")
202 # Addons Preferences
203 class AdvancedObjPreferences(AddonPreferences):
204 bl_idname = __name__
206 show_menu_list = BoolProperty(
207 name="Menu List",
208 description="Show/Hide the Add Menu items",
209 default=False
211 show_panel_list = BoolProperty(
212 name="Panels List",
213 description="Show/Hide the Panel items",
214 default=False
217 def draw(self, context):
218 layout = self.layout
220 icon_1 = "TRIA_RIGHT" if not self.show_menu_list else "TRIA_DOWN"
221 box = layout.box()
222 box.prop(self, "show_menu_list", emboss=False, icon=icon_1)
224 if self.show_menu_list:
225 box.label(text="Items located in the Add Menu (default shortcut Ctrl + A):",
226 icon="LAYER_USED")
227 box.label(text="Test Scenes:", icon="LAYER_ACTIVE")
228 box.label(text="Scene Objects BI, Scene Objects Cycles, Scene Textures Cycles",
229 icon="LAYER_USED")
230 box.label(text="Lighting Sets:", icon="LAYER_ACTIVE")
231 box.label(text="Add Light Template, Add Tri Lighting", icon="LAYER_USED")
232 box.label(text="Array Mods:", icon="LAYER_ACTIVE")
233 box.label(text="Circle Array, Chains submenu, Copy Vert/Edge and Aggregate Mesh",
234 icon="LAYER_ACTIVE")
235 box.label(text="Chains Submenu - Add Chain, Chain to Bones",
236 icon="LAYER_ACTIVE")
237 box.label(text="Block Tools:", icon="LAYER_ACTIVE")
238 box.label(text="Pixelate Object, Struts, Random Boxes, Easy Lattice",
239 icon="LAYER_USED")
240 box.label(text="Physics Tools:", icon="LAYER_ACTIVE")
241 box.label(text="Wrecking Ball and Cloth Rope", icon="LAYER_USED")
243 icon_2 = "TRIA_RIGHT" if not self.show_panel_list else "TRIA_DOWN"
244 box = layout.box()
245 box.prop(self, "show_panel_list", emboss=False, icon=icon_2)
247 if self.show_panel_list:
248 box.label(text="Panels located in 3D View Tools Region > Create",
249 icon="LAYER_ACTIVE")
250 box.label(text="CubeSter", icon="LAYER_USED")
251 box.label(text="Arrange on Curve (Shown if an Active Curve Object is it the 3D View)",
252 icon="LAYER_USED")
255 # Cubester update functions
256 def find_audio_length(self, context):
257 adv_obj = context.scene.advanced_objects
258 audio_file = adv_obj.cubester_audio_path
259 length = 0
261 if audio_file != "":
262 # confirm that strip hasn't been loaded yet
263 get_sequence = getattr(context.scene.sequence_editor, "sequences_all", [])
264 for strip in get_sequence:
265 if type(strip) == bpy.types.SoundSequence and strip.sound.filepath == audio_file:
266 length = strip.frame_final_duration
268 if length == 0:
269 area = context.area
270 old_type = area.type
271 area.type = "SEQUENCE_EDITOR"
272 try:
273 bpy.ops.sequencer.sound_strip_add(filepath=audio_file)
274 adv_obj.cubester_check_audio = True
275 except Exception as e:
276 print("\n[Add Advanced Objects]\n Function: "
277 "find_audio_length\n {}\n".format(e))
278 adv_obj.cubester_check_audio = False
279 pass
281 area.type = old_type
283 # find audio file
284 for strip in context.scene.sequence_editor.sequences_all:
285 if type(strip) == bpy.types.SoundSequence and strip.sound.filepath == audio_file:
286 adv_obj.cubester_check_audio = True
287 length = strip.frame_final_duration
289 adv_obj.cubester_audio_file_length = length
292 # load image if possible
293 def adjust_selected_image(self, context):
294 scene = context.scene.advanced_objects
295 try:
296 image = bpy.data.images.load(scene.cubester_load_image)
297 scene.cubester_image = image.name
298 except Exception as e:
299 print("\n[Add Advanced Objects]\n Function: "
300 "adjust_selected_image\n {}\n".format(e))
303 # load color image if possible
304 def adjust_selected_color_image(self, context):
305 scene = context.scene.advanced_objects
306 try:
307 image = bpy.data.images.load(scene.cubester_load_color_image)
308 scene.cubester_color_image = image.name
309 except Exception as e:
310 print("\nAdd Advanced Objects]\n Function: "
311 "adjust_selected_color_image\n {}\n".format(e))
314 class AdvancedObjProperties(PropertyGroup):
315 # cubester
316 # main properties
317 cubester_check_audio = BoolProperty(
318 name="",
319 default=False
321 cubester_audio_image = EnumProperty(
322 name="Input Type",
323 items=(("image", "Image",
324 "Use an Image as input for generating Geometry", "IMAGE_COL", 0),
325 ("audio", "Audio",
326 "Use a Sound Strip as input for generating Geometry", "FILE_SOUND", 1))
328 cubester_audio_file_length = IntProperty(
329 default=0
331 # audio
332 cubester_audio_path = StringProperty(
333 default="",
334 name="Audio File",
335 subtype="FILE_PATH",
336 update=find_audio_length
338 cubester_audio_min_freq = IntProperty(
339 name="Minimum Frequency",
340 min=20, max=100000,
341 default=20
343 cubester_audio_max_freq = IntProperty(
344 name="Maximum Frequency",
345 min=21, max=999999,
346 default=5000
348 cubester_audio_offset_type = EnumProperty(
349 name="Offset Type",
350 items=(("freq", "Frequency Offset", ""),
351 ("frame", "Frame Offset", "")),
352 description="Type of offset per row of mesh"
354 cubester_audio_frame_offset = IntProperty(
355 name="Frame Offset",
356 min=0, max=10,
357 default=2
359 cubester_audio_block_layout = EnumProperty(
360 name="Block Layout",
361 items=(("rectangle", "Rectangular", ""),
362 ("radial", "Radial", ""))
364 cubester_audio_width_blocks = IntProperty(
365 name="Width Block Count",
366 min=1, max=10000,
367 default=5
369 cubester_audio_length_blocks = IntProperty(
370 name="Length Block Count",
371 min=1, max=10000,
372 default=50
374 # image
375 cubester_load_type = EnumProperty(
376 name="Image Input Type",
377 items=(("single", "Single Image", ""),
378 ("multiple", "Image Sequence", ""))
380 cubester_image = StringProperty(
381 default="",
382 name=""
384 cubester_load_image = StringProperty(
385 default="",
386 name="Load Image",
387 subtype="FILE_PATH",
388 update=adjust_selected_image
390 cubester_skip_images = IntProperty(
391 name="Image Step",
392 min=1, max=30,
393 default=1,
394 description="Step from image to image by this number"
396 cubester_max_images = IntProperty(
397 name="Max Number Of Images",
398 min=2, max=1000,
399 default=10,
400 description="Maximum number of images to be used"
402 cubester_frame_step = IntProperty(
403 name="Frame Step Size",
404 min=1, max=10,
405 default=4,
406 description="The number of frames each picture is used"
408 cubester_skip_pixels = IntProperty(
409 name="Skip # Pixels",
410 min=0, max=256,
411 default=64,
412 description="Skip this number of pixels before placing the next"
414 cubester_mesh_style = EnumProperty(
415 name="Mesh Type",
416 items=(("blocks", "Blocks", ""),
417 ("plane", "Plane", "")),
418 description="Compose mesh of multiple blocks or of a single plane"
420 cubester_block_style = EnumProperty(
421 name="Block Style",
422 items=(("size", "Vary Size", ""),
423 ("position", "Vary Position", "")),
424 description="Vary Z-size of block, or vary Z-position"
426 cubester_height_scale = FloatProperty(
427 name="Height Scale",
428 subtype="DISTANCE",
429 min=0.1, max=2,
430 default=0.2
432 cubester_invert = BoolProperty(
433 name="Invert Height",
434 default=False
436 # general adjustments
437 cubester_size_per_hundred_pixels = FloatProperty(
438 name="Size Per 100 Blocks/Points",
439 subtype="DISTANCE",
440 min=0.001, max=5,
441 default=1
443 # material based stuff
444 cubester_materials = EnumProperty(
445 name="Material",
446 items=(("vertex", "Vertex Colors", ""),
447 ("image", "Image", "")),
448 description="Color with vertex colors, or uv unwrap and use an image"
450 cubester_use_image_color = BoolProperty(
451 name="Use Original Image Colors'?",
452 default=True,
453 description="Use original image colors, or replace with an another one"
455 cubester_color_image = StringProperty(
456 default="",
457 name=""
459 cubester_load_color_image = StringProperty(
460 default="",
461 name="Load Color Image",
462 subtype="FILE_PATH",
463 update=adjust_selected_color_image
465 cubester_vertex_colors = {}
466 # advanced
467 cubester_advanced = BoolProperty(
468 name="Advanced Options",
469 default=False
471 cubester_random_weights = BoolProperty(
472 name="Random Weights",
473 default=False
475 cubester_weight_r = FloatProperty(
476 name="Red",
477 subtype="FACTOR",
478 min=0.01, max=1.0,
479 default=0.25
481 cubester_weight_g = FloatProperty(
482 name="Green",
483 subtype="FACTOR",
484 min=0.01, max=1.0,
485 default=0.25
487 cubester_weight_b = FloatProperty(
488 name="Blue",
489 subtype="FACTOR",
490 min=0.01, max=1.0,
491 default=0.25
493 cubester_weight_a = FloatProperty(
494 name="Alpha",
495 subtype="FACTOR",
496 min=0.01, max=1.0,
497 default=0.25
500 # arrange_on_curve
501 arrange_c_use_selected = BoolProperty(
502 name="Use Selected",
503 description="Use the selected objects to duplicate",
504 default=True,
506 arrange_c_obj_arranjar = StringProperty(
507 name=""
509 arrange_c_select_type = EnumProperty(
510 name="Type",
511 description="Select object or group",
512 items=[
513 ('O', "Object", "Make duplicates of a specific object"),
514 ('G', "Group", "Make duplicates of the objects in a group"),
516 default='O',
520 def register():
521 bpy.utils.register_module(__name__)
523 bpy.types.Scene.advanced_objects = PointerProperty(
524 type=AdvancedObjProperties
527 # Add "Extras" menu to the "Add" menu
528 bpy.types.INFO_MT_add.append(menu)
529 try:
530 bpy.types.VIEW3D_MT_AddMenu.append(menu)
531 except:
532 pass
535 def unregister():
536 # Remove "Extras" menu from the "Add" menu.
537 bpy.types.INFO_MT_add.remove(menu)
538 try:
539 bpy.types.VIEW3D_MT_AddMenu.remove(menu)
540 except:
541 pass
543 bpy.utils.unregister_module(__name__)
544 del bpy.types.Scene.advanced_objects
546 # cleanup Easy Lattice Scene Property if it was created
547 if hasattr(bpy.types.Scene, "activelatticeobject"):
548 del bpy.types.Scene.activelatticeobject
551 if __name__ == "__main__":
552 register()