-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoperator_add_speakers_to_objects.py
72 lines (59 loc) · 2.41 KB
/
operator_add_speakers_to_objects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import bpy
from bpy.types import Operator
from bpy.props import BoolProperty, StringProperty, EnumProperty, FloatProperty
from .intern.add_sound_to_meshes import add_speakers_to_meshes, TriggerMode
class AddSoundToMeshOperator(Operator):
"""Add a speaker to each selected object"""
bl_idname = "object.add_speakers_to_obj"
bl_label = "Add Sounds to Meshes"
TRIGGER_OPTIONS = (
(TriggerMode.START_FRAME,
"Start Frame",
"Sound will play on the first frame of the animation"),
(TriggerMode.MIN_DISTANCE,
"Minimum Distance",
"Sound will play when the object is closest to the camera"),
(TriggerMode.RANDOM,
"Random",
"Sound will play exactly once, at a random time"),
(TriggerMode.RANDOM_GAUSSIAN,
"Random (Gaussian)",
"Sound will play exactly once, at a guassian random time with " +
"stdev of 1 and mean in the middle of the animation")
)
@classmethod
def poll(cls, context):
sounds_avail = bpy.data.sounds
return len(context.selected_objects) > 0 and len(sounds_avail) > 0
use_sounds: StringProperty(
name="Sound Prefix",
description="Sounds having names starting with thie field will be assigned randomly to each speaker"
)
sync_audio_peak: BoolProperty(
name="Sync Audio Peak",
default=True,
description="Synchronize speaker audio to loudest peak instead of beginning of file"
)
trigger_mode: EnumProperty(
items=TRIGGER_OPTIONS,
name="Trigger",
description="Select when each sound will play",
default=TriggerMode.MIN_DISTANCE,
)
gaussian_stddev: FloatProperty(
name="Gaussian StDev",
description="Standard Deviation of Gaussian random time",
default=1.,
min=0.001,
max=6.,
)
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
add_speakers_to_meshes(bpy.context.selected_objects, bpy.context,
sound=None,
sound_name_prefix=self.use_sounds,
trigger_mode=self.trigger_mode,
sync_peak=self.sync_audio_peak,
gaussian_stddev=self.gaussian_stddev)
return {'FINISHED'}