pode fazer algo assim para isto: bl_info = {
"name": "Drum Circles Click with Labels (8 Tambores)",
"author": "ChatGPT",
"version": (1, 3, 0),
"blender": (2, 80, 0),
"location": "3D View Sidebar > DrumVST",
"description": "Cria círculos preenchidos para tambores com nomes visíveis e toca sons ao clicar. Inclui 8 tambores.",
"category": "Sound",
}
import bpy
import os
import time
from bpy_extras import view3d_utils
addon_dir = os.path.dirname(os.path.realpath(file))
Lista atualizada com os 8 tambores
drum_names = ["kick", "snare", "hihat", "crash", "ride", "tom1", "tom2", "surdo"]
sounds = {name: os.path.join(addon_dir, "sounds", f"{name}.wav") for name in drum_names}
_last_click_time = {}
_click_count = {}
def create_text(name, location, parent_obj):
bpy.ops.object.text_add(location=location)
text_obj = bpy.context.active_object
text_obj.data.body = name.capitalize()
text_obj.name = f"Label_{name}"
text_obj.data.align_x = 'CENTER'
text_obj.data.align_y = 'CENTER'
text_obj.rotation_euler = (1.5708, 0, 0)
text_obj.scale = (0.5, 0.5, 0.5)
text_obj.parent = parent_obj
text_obj.hide_select = False
return text_obj
def create_drum_circle_and_label(name):
bpy.ops.mesh.primitive_circle_add(
vertices=32,
radius=1,
fill_type='NGON',
location=bpy.context.scene.cursor.location
)
circle_obj = bpy.context.active_object
circle_obj.name = name
mat = bpy.data.materials.new(f"Material_{name}")
hue = (0.1 + 0.1 * drum_names.index(name)) % 1.0
mat.diffuse_color = (hue, 0.4, 0.6, 1.0)
circle_obj.data.materials.append(mat)
label_location = circle_obj.location.copy()
label_location.z += 1.2
create_text(name, label_location, circle_obj)
def play_sound(filepath):
if not os.path.isfile(filepath):
print(f"[Drum Click] Som não encontrado: {filepath}")
return
snd = bpy.data.sounds.load(filepath, check_existing=True)
bpy.ops.sound.play_sound(sound=snd.name)
class DrumCreateOperator(bpy.types.Operator):
bl_idname = "view3d.create_drum_circles_with_labels"
bl_label = "Criar Círculos e Nomes dos Tambores no 3D Cursor"
def execute(self, context):
scene = context.scene
existing = set(obj.name for obj in scene.objects)
created = []
for name in drum_names:
if name not in existing:
create_drum_circle_and_label(name)
created.append(name)
self.report({'INFO'}, f"Círculos criados: {', '.join(created)}" if created else "Todos objetos já existem")
return {'FINISHED'}
class DrumClickOperator(bpy.types.Operator):
bl_idname = "view3d.drum_circles_click"
bl_label = "Ativar Clique nos Círculos de Tambores"
def modal(self, context, event):
if event.type == 'LEFTMOUSE' and event.value == 'PRESS':
region = context.region
rv3d = context.space_data.region_3d
coord = (event.mouse_region_x, event.mouse_region_y)
view_vector = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
ray_origin = view3d_utils.region_2d_to_origin_3d(region, rv3d, coord)
depsgraph = context.evaluated_depsgraph_get()
result, location, normal, index, obj, matrix = context.scene.ray_cast(
depsgraph, ray_origin, view_vector
)
if result and obj:
obj_name = obj.name.lower()
if obj_name in sounds:
now = time.time()
last = _last_click_time.get(obj_name, 0)
count = _click_count.get(obj_name, 0)
if now - last < 0.5:
count += 1
else:
count = 1
_last_click_time[obj_name] = now
_click_count[obj_name] = count
count = min(count, 5)
for _ in range(count):
play_sound(sounds[obj_name])
self.report({'INFO'}, f"Som '{obj_name}' tocado {count}x")
return {'RUNNING_MODAL'}
elif event.type in {'ESC', 'RIGHTMOUSE'}:
self.report({'INFO'}, "Drum Click desativado")
return {'CANCELLED'}
return {'PASS_THROUGH'}
def invoke(self, context, event):
context.window_manager.modal_handler_add(self)
self.report({'INFO'}, "Drum Click ativado - clique nos círculos na viewport")
return {'RUNNING_MODAL'}
class DrumClickPanel(bpy.types.Panel):
bl_label = "Drum Circles Click"
bl_idname = "VIEW3D_PT_drum_circles_click"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "DrumVST"
def draw(self, context):
layout = self.layout
layout.operator("view3d.create_drum_circles_with_labels", icon='MESH_CIRCLE')
layout.operator("view3d.drum_circles_click", icon='PLAY')
classes = (DrumCreateOperator, DrumClickOperator, DrumClickPanel)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
if name == "main":
register()