feat: ground work for sound sync

This commit is contained in:
Swann
2020-09-19 00:47:46 +02:00
parent 6385830f53
commit 6f73b7fc29
5 changed files with 88 additions and 8 deletions

View File

@ -35,7 +35,8 @@ __all__ = [
'bl_lattice', 'bl_lattice',
'bl_lightprobe', 'bl_lightprobe',
'bl_speaker', 'bl_speaker',
'bl_font' 'bl_font',
'bl_sound'
] # Order here defines execution order ] # Order here defines execution order
from . import * from . import *

View File

@ -51,12 +51,6 @@ class BlFont(BlDatablock):
logging.info(f'loading {font_path}') logging.info(f'loading {font_path}')
return bpy.data.fonts.load(font_path) return bpy.data.fonts.load(font_path)
return bpy.data.images.new(
name=data['name'],
width=data['size'][0],
height=data['size'][1]
)
def _load(self, data, target): def _load(self, data, target):
pass pass

View File

@ -0,0 +1,73 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
import mathutils
import os
import logging
import pathlib
from .. import utils
from .dump_anything import Loader, Dumper
from .bl_datablock import BlDatablock
class BlSound(BlDatablock):
bl_id = "sounds"
bl_class = bpy.types.Sound
bl_delay_refresh = 1
bl_delay_apply = 1
bl_automatic_push = True
bl_check_common = False
bl_icon = 'SOUND'
def _construct(self, data):
if 'file' in data.keys():
prefs = utils.get_preferences()
ext = data['filepath'].split(".")[-1]
sound_name = f"{self.uuid}.{ext}"
sound_path = os.path.join(prefs.cache_directory, sound_name)
os.makedirs(prefs.cache_directory, exist_ok=True)
file = open(sound_path, 'wb')
file.write(data["file"])
file.close()
logging.info(f'loading {sound_path}')
return bpy.data.sounds.load(sound_path)
def _load(self, data, target):
loader = Loader()
loader.load(target, data)
def _dump(self, instance=None):
if not instance.packed_file:
# prefs = utils.get_preferences()
# ext = pathlib.Path(instance.filepath).suffix
# sound_name = f"{self.uuid}{ext}"
# sound_path = os.path.join(prefs.cache_directory, sound_name)
# instance.filepath = sound_path
instance.pack()
return {
'filepath':instance.filepath,
'name':instance.name,
'file': instance.packed_file.data
}
def diff(self):
return False

View File

@ -49,6 +49,7 @@ class BlSpeaker(BlDatablock):
'volume', 'volume',
'name', 'name',
'pitch', 'pitch',
'sound',
'volume_min', 'volume_min',
'volume_max', 'volume_max',
'attenuation', 'attenuation',
@ -61,6 +62,15 @@ class BlSpeaker(BlDatablock):
return dumper.dump(instance) return dumper.dump(instance)
def _resolve_deps_implementation(self):
# TODO: resolve material
deps = []
sound = self.instance.sound
if sound:
deps.append(sound)
return deps

View File

@ -595,6 +595,8 @@ class Loader:
instance.write(bpy.data.collections.get(dump)) instance.write(bpy.data.collections.get(dump))
elif isinstance(rna_property_type, T.VectorFont): elif isinstance(rna_property_type, T.VectorFont):
instance.write(bpy.data.fonts.get(dump)) instance.write(bpy.data.fonts.get(dump))
elif isinstance(rna_property_type, T.Sound):
instance.write(bpy.data.sounds.get(dump))
def _load_matrix(self, matrix, dump): def _load_matrix(self, matrix, dump):
matrix.write(mathutils.Matrix(dump)) matrix.write(mathutils.Matrix(dump))