Newer
Older
#!/usr/bin/python3
# To change this template, choose Tools | Templates
# and open the template in the editor.
# ***** 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 <http://www.gnu.org/licenses/>.
# All rights reserved.
# ***** GPL LICENSE BLOCK *****
bl_info = {
"name": "Import: Sound to Animation",
"author": "Vlassius",
CoDEmanX
committed
"location": "Select a object > Object tab > Import Movement From Wav File",
"description": "Extract movement from sound file. "
"See the Object Panel at the end.",
CoDEmanX
committed
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
"Scripts/Import-Export/Import_Movement_From_Audio_File",
"tracker_url": "https://developer.blender.org/T23565",
-- Extract movement from sound file, to help in animation - import script --<br>
- NOTES:
- This script takes a wav file and get sound "movement" to help you in sync the movement to words in the wave file. <br>
- Supported Audio: .wav (wave) 8 bits and 16 bits - mono and multichanel file<br>
- At least Blender 2.64.9 is necessary to run this program.
- Curitiba - Brasil
-v 0.70Beta-
Included: SmartRender - Render just the frames that has changes
Included: Options to check SmartRender for Blender Internal Render Engine:LocRotScale, Material, Transp, Mirror
Included: User can Cancel all functions with CANCEL button- Extensive Code and flux change (bugs expected)
Included: User can Cancel all functions with ESC
Inclused: User friendly messages into UI while running (its no more necessary to look at terminal window to most users)
Cleanup: Non Stardard Chars in coments
To Do: Decrease overhead of timer loops
To Do: Try to implement Smart Render for Cycles
-v 0.60Beta-
Included: Option to use just the beat from the audio sound
Included: Option to exclude the beat from the audio sound
Included: More or less sensibility options when using the beat
Included: Audio Channel Select option
-v 0.50Beta-
Included: Auto Adjust Audio Sensity option
Cosmetic: Many changes in panel and terminal window info
Corrected: Tracker_url
Corrected: a few bytes in Memory Leaks
work around: memory leak in function: bpy.ops.transform.rotate
work around: memory leak in function: bpy.ops.anim.keyframe_insert
Camera Rotation
Empty Location-Rotation-Scale
Changed just the meta informations like version and wiki page.
Included the button "Get FPS from Scene" due to a problem to get it in the start
Return to Frame 1 after import
Filter .wav type file (by batFINGER)
If choose negative in rotation, auto check the rotation negative to Bones
change in register() unregister():
Change to bl_info.
Cosmetic Changes.
Minor change in API in how to define buttons.
change in API- Update function bpy.ops.anim.keyframe_insert_menu
-v 0.1.1 Beta
change in API- Update property of window_manager.fileselect_add
-v 0.1.0 Beta
new - improved flow to import
new - check the type of object before show options
bug - option max. and min. values
change- Updated scene properties for changes in property API.
See http://lists.blender.org/pipermail/bf-committers/2010-September/028654.html
new flow: 1) Process the sound file 2) Show Button to import key frames
- v0.0.4 ALPHA
new - Added destructive optimizer option - LostLestSignificativeDigit lost/total -> 10/255 default
new - Visual Graph to samples
new - Option to just process audio file and do not import - this is to help adjust the audio values
new - Get and show automatically the FPS (in proper field) information taking the information from scene
bug- Display sensitivity +1
bug - Corrected location of the script in description
- v0.0.3
Main change: Corrected to work INSIDE dir /install/linux2/2.53/scripts/addons
Corrected position of label "Rotation Negative"
Added correct way to deal with paths in Python os.path.join - os.path.normpath
- v0.0.2
Corrected initial error (Register() function)
Corrected some labels R. S. L.
Turned off "object field" for now
- v0.0.1
Initial version
Credit to:
Vlassius
- http://vlassius.com.br
- vlassius@vlassius.com.br
"""
import bpy
from bpy.props import *
#from io_utils import ImportHelper
import wave
def _Interna_Globals(BytesDadosTotProcess, context):
global array
array= bytearray(BytesDadosTotProcess) # cria array
arrayAutoSense= bytearray((BytesDadosTotProcess)*2) # cria array para AutoAudioSense
context.scene.imp_sound_to_anim.bArrayCriado=True
#==================================================================================================
# BLENDER UI Panel
#==================================================================================================
#
class VIEW3D_PT_CustomMenuPanel(bpy.types.Panel):
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "object"
bl_label = "Import Movement From Wav File"
def draw(self, context):
layout = self.layout
b=bpy.context.active_object.type=='EMPTY' or bpy.context.active_object.type=='ARMATURE' or \
bpy.context.active_object.type=='MESH' or \
bpy.context.active_object.type=='CAMERA' or \
bpy.context.active_object.type=='LAMP'
row.label(text="The Selected Object is: type \"" + bpy.context.active_object.type + \
"\", and it is not supported.")
row.label(text="Supported Object are Type: Armature, Mesh, Camera and Lamp")
row=layout.row()
else:
#print(context.scene.imp_sound_to_anim.bTypeImport)
if context.scene.imp_sound_to_anim.bTypeImport == 0:
#mount panel to Direct animation
row=layout.row()
layout.operator("import.sound_animation_botao_udirect")
# monta as telas quando está rodando
elif context.scene.imp_sound_to_anim.Working!="": #its running
row=layout.row()
if context.scene.imp_sound_to_anim.Working== "CheckSmartRender":
#context.scene.imp_sound_to_anim.Info_check_smartrender=
row=layout.row()
row.label(text="Checking for Smart Render...")
row=layout.row()
row.label(text=context.scene.imp_sound_to_anim.Info_check_smartrender)
row=layout.row()
elif context.scene.imp_sound_to_anim.Working== "SmartRender":
#context.scene.imp_sound_to_anim.Info_check_smartrender=
row=layout.row()
row.label(text="Processing Smart Render...")
row=layout.row()
row.label(text=context.scene.imp_sound_to_anim.Info_check_smartrender)
row=layout.row()
elif context.scene.imp_sound_to_anim.Working== "ProcessaSom":
#context.scene.imp_sound_to_anim.Info_Import=
row=layout.row()
row.label(text="Processing Sound File...")
row=layout.row()
row.label(text=context.scene.imp_sound_to_anim.Info_Import)
elif context.scene.imp_sound_to_anim.Working== "wavimport":
#context.scene.imp_sound_to_anim.Info_Import=
row=layout.row()
row.label(text="Importing Keys...")
row=layout.row()
row.label(text=context.scene.imp_sound_to_anim.Info_Import)
row=layout.row()
# botao cancel
layout.operator(OBJECT_OT_Botao_Cancel.bl_idname)
elif context.scene.imp_sound_to_anim.bTypeImport == 1:
row.label(text="2)Click Button \"Import Key Frames\",")
row=layout.row()
row.label(text="Run the animation (alt A) and Enjoy!")
row.prop(context.scene.imp_sound_to_anim,"action_auto_audio_sense")
if context.scene.imp_sound_to_anim.action_auto_audio_sense == 0: # se auto audio sense desligado
row.prop(context.scene.imp_sound_to_anim,"audio_sense")
if context.scene.imp_sound_to_anim.remove_beat == 0 :
row.prop(context.scene.imp_sound_to_anim,"use_just_beat")
if context.scene.imp_sound_to_anim.use_just_beat == 0:
row.prop(context.scene.imp_sound_to_anim,"remove_beat")
if context.scene.imp_sound_to_anim.use_just_beat or context.scene.imp_sound_to_anim.remove_beat:
if not context.scene.imp_sound_to_anim.beat_less_sensible and not context.scene.imp_sound_to_anim.beat_more_sensible:
row=layout.row()
if context.scene.imp_sound_to_anim.beat_less_sensible ==0:
row.prop(context.scene.imp_sound_to_anim,"beat_more_sensible")
if context.scene.imp_sound_to_anim.beat_more_sensible ==0:
row.prop(context.scene.imp_sound_to_anim,"beat_less_sensible")
row=layout.row()
row.prop(context.scene.imp_sound_to_anim,"action_per_second")
row=layout.row()
row.prop(context.scene.imp_sound_to_anim,"action_escale")
row.label(text="Result from 0 to " + str(round(255/context.scene.imp_sound_to_anim.action_escale,4)) + "")
row.prop(context.scene.imp_sound_to_anim,"import_type")
#coluna
row.prop(context.scene.imp_sound_to_anim,"import_where1")
row.prop(context.scene.imp_sound_to_anim,"import_where2")
row.prop(context.scene.imp_sound_to_anim,"import_where3")
row.prop(context.scene.imp_sound_to_anim,"frames_per_second")
#coluna
column= layout.column()
split=column.split(percentage=0.5)
col=split.column()
row=col.row()
row.prop(context.scene.imp_sound_to_anim,"frames_initial")
row=col.row()
row.prop(context.scene.imp_sound_to_anim,"action_min_value")
row.prop(context.scene.imp_sound_to_anim,"optimization_destructive")
row=col.row()
row.prop(context.scene.imp_sound_to_anim,"action_max_value")
row.prop(context.scene.imp_sound_to_anim,"action_offset_x")
row.prop(context.scene.imp_sound_to_anim,"action_offset_y")
row.prop(context.scene.imp_sound_to_anim,"action_offset_z")
row=layout.row()
row.prop(context.scene.imp_sound_to_anim,"audio_channel_select")
row.prop(context.scene.imp_sound_to_anim,"action_valor_igual")
#operator button
#OBJECT_OT_Botao_Go => Botao_GO
row=layout.row()
layout.operator(OBJECT_OT_Botao_Go.bl_idname)
row.label(text=context.scene.imp_sound_to_anim.Info_Import)
# preciso garantir a existencia do array porque o Blender salva no arquivo como existente sem o array existir
try:
array
except NameError:
nada=0 #dummy
else:
if context.scene.imp_sound_to_anim.bArrayCriado:
layout.operator(OBJECT_OT_Botao_Import.bl_idname)
row=layout.row()
#Layout SmartRender, somente para Blender_render
if bpy.context.scene.render.engine == "BLENDER_RENDER":
row.label(text="----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")
row=layout.row()
if context.scene.imp_sound_to_anim.Info_check_smartrender!= "":
row=layout.row()
row.label(text=context.scene.imp_sound_to_anim.Info_check_smartrender)
row=layout.row()
row.operator(OBJECT_OT_Botao_Check_SmartRender.bl_idname)
if context.scene.imp_sound_to_anim.Info_check_smartrender!= "":
row.operator(OBJECT_OT_Botao_SmartRender.bl_idname)
row=layout.row()
row.prop(context.scene.imp_sound_to_anim,"check_smartrender_loc_rot_sc")
row.prop(context.scene.imp_sound_to_anim,"check_smartrender_material_basic")
row=layout.row()
row.prop(context.scene.imp_sound_to_anim,"check_smartrender_material_transparence")
row.prop(context.scene.imp_sound_to_anim,"check_smartrender_material_mirror")
#-----------------------------
#Use Driver
#-----------------------------
if context.scene.imp_sound_to_anim.bTypeImport == 2:
row.prop(context.scene.imp_sound_to_anim,"audio_sense")
row=layout.row()
row.prop(context.scene.imp_sound_to_anim,"frames_per_second")
row.prop(context.scene.imp_sound_to_anim,"action_per_second")
row=layout.row()
layout.operator(ImportWavFile.bl_idname)
#
#==================================================================================================
# BLENDER UI PropertyGroup
#==================================================================================================
#
#Array created
bArrayCriado = IntProperty(name="",
description="Avisa que rodou process de som",
default=0)
#Script Running
Working = StringProperty(name="",
description="Script esta trabalhando",
maxlen= 1024,
default="")
description="Info about Import",
maxlen= 1024,
default= "")#this set the initial text
#Mensagem Smart Render
Info_check_smartrender = StringProperty(name="",
description="Smart Render Message",
maxlen= 1024,
default= "")#this set the initial text
#iAudioSensib=0 #sensibilidade volume do audio 0 a 5. Quanto maior, mais sensibilidade
audio_sense = IntProperty(name="Audio Sens",
description="Audio Sensibility.",
min=1,
max=6,
step=1,
default= 1)
#iFramesPorSeg=15 #Frames por segundo para key frame
#fps= (bpy.types.Scene) bpy.context.scene.render.fps
description="Frames you want per second. Better match your set up in Blender scene.",
min=1,
max=120,
step=1)
#iMovPorSeg=1 #Sensibilidade de movimento. 3= 3 movimentos por segundo
action_per_second = IntProperty(name="Act/s",
description="Actions per second. From 1 to #Frames/s",
#iDivScala=200
#scala do valor do movimento. [se =1 - 0 a 255 ] [se=255 - 0,00000 a 1,00000] [se=1000 - 0 a 0.255]
action_escale = IntProperty(name="Scale",
description="Scale the result values. See the text at right side of the field",
#iMaxValue=255
action_max_value = IntProperty(name="Clip Max",
description="Set the max value (clip higher values).",
min=1,
max=255,
#iMinValue=0
action_min_value = IntProperty(name="Clip Min",
description="Set the min value. (clip lower values)",
min=0,
max=255,
#iStartFrame=0#
frames_initial = IntProperty(name="Frame Ini",
description="Where to start to put the computed values.",
min=0,
max=999999999,
audio_channel_select = IntProperty(name="Audio Channel",
description="Choose the audio channel to use",
min=1,
max=10,
description="Offset X Values",
min=-999999,
max=999999,
description="Offset Y Values",
min=-999999,
max=999999,
description="Offset Z Values",
min=-999999,
max=999999,
default= 0)
import_type= EnumProperty(items=(('imp_t_Scale', "Scale", "Apply to Scale"),
('imp_t_Rotation', "Rotation", "Apply to Rotation"),
name="",
description= "Property to Import Values",
default='imp_t_Location')
import_where1= EnumProperty(items=(('imp_w_-z', "-z", "Apply to -z"),
('imp_w_-y', "-y", "Apply to -y"),
('imp_w_-x', "-x", "Apply to -x"),
('imp_w_z', "z", "Apply to z"),
('imp_w_y', "y", "Apply to y"),
('imp_w_x', "x", "Apply to x")
),
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
description= "Where to Import",
default='imp_w_z')
import_where2= EnumProperty(items=(('imp_w_none', "None", ""),
('imp_w_-z', "-z", "Apply to -z"),
('imp_w_-y', "-y", "Apply to -y"),
('imp_w_-x', "-x", "Apply to -x"),
('imp_w_z', "z", "Apply to z"),
('imp_w_y', "y", "Apply to y"),
('imp_w_x', "x", "Apply to x")
),
name="",
description= "Where to Import",
default='imp_w_none')
import_where3= EnumProperty(items=(('imp_w_none', "None", ""),
('imp_w_-z', "-z", "Apply to -z"),
('imp_w_-y', "-y", "Apply to -y"),
('imp_w_-x', "-x", "Apply to -x"),
('imp_w_z', "z", "Apply to z"),
('imp_w_y', "y", "Apply to y"),
('imp_w_x', "x", "Apply to x")
),
name="",
description= "Where to Import",
default='imp_w_none')
#========== Propriedades boolean =============#
# INVERTIDO!!! bNaoValorIgual=True # nao deixa repetir valores INVERTIDO!!!
action_valor_igual = BoolProperty(name="Hard Transition",
description="Use to movements like a mouth, to a arm movement, maybe you will not use this.",
default=1)
action_auto_audio_sense = BoolProperty(name="Auto Audio Sensitivity",
description="Try to discover best audio scale. ",
default=1)
use_just_beat=BoolProperty(name="Just Use The Beat",
description="Try to use just the beat to extract movement.",
remove_beat=BoolProperty(name="Remove The Beat",
description="Try to remove the beat to extract movement.",
default=0)
beat_more_sensible=BoolProperty(name="More Sensible",
description="Try To be more sensible about the beat.",
default=0)
beat_less_sensible=BoolProperty(name="Less Sensible",
description="Try to be less sensible about the beat.",
default=0)
check_smartrender_loc_rot_sc=BoolProperty(name="Loc Rot Scale",
description="Find changes in Location, Rotation and Scale Frame by Frame.",
default=1)
check_smartrender_material_basic=BoolProperty(name="Basic Material",
description="Find changes in basic material settings Frame by Frame.",
default=1)
check_smartrender_material_transparence=BoolProperty(name="Material Transparence",
description="Find changes in material transparence settings Frame by Frame.",
default=0)
check_smartrender_material_mirror=BoolProperty(name="Material Mirror",
description="Find changes in material mirror settings Frame by Frame.",
default=0)
timer_reset_func=BoolProperty(name="Reset Counters",
description="Reset Counters after stop",
default=0)
cancel_button_hit=BoolProperty(name="Cancel Hit",
description="Cancel Hit",
default=0)
optimization_destructive = IntProperty(name="Optimization",
description="Hi value = Hi optimization -> Hi loss of information.",
description="Import Direct or Driver",
default=0)
# globais do dialog open wave
filter_glob = StringProperty(default="*.wav", options={'HIDDEN'})
path = StringProperty(name="File Path", description="Filepath used for importing the WAV file", \
maxlen= 1024, default= "")
filename = StringProperty(name="File Name", description="Name of the file")
directory = StringProperty(name="Directory", description="Directory of the file")
def WavFileImport(self, context):
self.layout.operator(ImportWavFile.bl_idname, text="Import a wav file", icon='PLUGIN')
#==================================================================================================
# Use Direct
#==================================================================================================
#
class OBJECT_OT_Botao_uDirect(bpy.types.Operator):
'''Import as Direct Animation'''
bl_idname = "import.sound_animation_botao_udirect"
bl_label = "Direct to a Property"
def execute(self, context):
context.scene.imp_sound_to_anim.bTypeImport= 1
if context.scene.imp_sound_to_anim.frames_per_second == 0:
context.scene.imp_sound_to_anim.frames_per_second= bpy.context.scene.render.fps
def invoke(self, context, event):
self.execute(context)
#==================================================================================================
# Button - Import
#==================================================================================================
#
class OBJECT_OT_Botao_Import(bpy.types.Operator):
'''Import Key Frames to Blender'''
bl_idname = "import.sound_animation_botao_import"
bl_label = "Import Key Frames"
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
RunFrom=0
iSumImportFrames=0
iSumOptimizerP1=0
iSumOptimizerP2=0
iSumOptimizerP3=0
def wavimport(context, loop):
obi=OBJECT_OT_Botao_Import
# para de entrar no timer
context.scene.imp_sound_to_anim.Working=""
#reseta contadores caso seja pedido
if context.scene.imp_sound_to_anim.timer_reset_func:
obi.RunFrom=0
obi.iSumOptimizerP1=0
obi.iSumOptimizerP2=0
obi.iSumOptimizerP3=0
obi.iSumImportFrames=0
context.scene.imp_sound_to_anim.timer_reset_func=False
#limita o loop se estiver no fim
tot=len(array)-1
if obi.RunFrom+loop > tot:
loop= tot - obi.RunFrom
#scala do valor do movimento. [se =1 - 0 a 255 ] [se=255 - 0,00000 a 1,00000] [se=1000 - 0 a 0.255]
iDivScala= int(context.scene.imp_sound_to_anim.action_escale)
# nao deixa repetir valores
bNaoValorIgual=True
if context.scene.imp_sound_to_anim.action_valor_igual: bNaoValorIgual= False
# inicia no inicio pedido pelo usuario mais ponteiro RunFrom
iStartFrame= int(context.scene.imp_sound_to_anim.frames_initial) + obi.RunFrom
iMaxValue= context.scene.imp_sound_to_anim.action_max_value
iMinValue= context.scene.imp_sound_to_anim.action_min_value
bEscala=bRotacao=bEixo=False
if context.scene.imp_sound_to_anim.import_type=='imp_t_Scale':
bEscala=True;
if context.scene.imp_sound_to_anim.import_type=='imp_t_Rotation':
bRotacao=True;
if context.scene.imp_sound_to_anim.import_type=='imp_t_Location':
bEixo=True;
# atencao, nao eh boolean
iEixoXneg= iEixoYneg= iEixoZneg=1
# atencao, nao eh boolean
iRotationNeg=1
# atencao, nao eh boolean
iEscalaYneg= iEscalaZneg= iEscalaXneg=1
bEixoX=bEixoY=bEixoZ=bEscalaX=bEscalaY=bEscalaZ=bRotationX=bRotationY=bRotationZ=False
# LOCAL 1
if context.scene.imp_sound_to_anim.import_where1== 'imp_w_x':
bEixoX=True
bEscalaX=True
bRotationX=True
if context.scene.imp_sound_to_anim.import_where1== 'imp_w_y':
bEixoY=True
bEscalaY=True
bRotationY=True
if context.scene.imp_sound_to_anim.import_where1== 'imp_w_z':
bEixoZ=True
bEscalaZ=True
bRotationZ=True
if context.scene.imp_sound_to_anim.import_where1== 'imp_w_-x':
bEixoX=True
bEscalaX=True
bRotationX=True
iEixoXneg=-1
iEscalaXneg=-1
iRotationNeg=-1
if context.scene.imp_sound_to_anim.import_where1== 'imp_w_-y':
bEixoY=True
bEscalaY=True
bRotationY=True
iEixoYneg=-1
iRotationNeg=-1
iEscalaYneg=-1
if context.scene.imp_sound_to_anim.import_where1== 'imp_w_-z':
bEixoZ=True
bEscalaZ=True
bRotationZ=True
iEixoZneg=-1
iRotationNeg=-1
iEscalaZneg=-1
# LOCAL 2
if context.scene.imp_sound_to_anim.import_where2== 'imp_w_x':
bEixoX=True
bEscalaX=True
bRotationX=True
if context.scene.imp_sound_to_anim.import_where2== 'imp_w_y':
bEixoY=True
bEscalaY=True
bRotationY=True
if context.scene.imp_sound_to_anim.import_where2== 'imp_w_z':
bEixoZ=True
bEscalaZ=True
bRotationZ=True
if context.scene.imp_sound_to_anim.import_where2== 'imp_w_-x':
bEixoX=True
bEscalaX=True
bRotationX=True
iEixoXneg=-1
iEscalaXneg=-1
iRotationNeg=-1
if context.scene.imp_sound_to_anim.import_where2== 'imp_w_-y':
bEixoY=True
bEscalaY=True
bRotationY=True
iEixoYneg=-1
iRotationNeg=-1
iEscalaYneg=-1
if context.scene.imp_sound_to_anim.import_where2== 'imp_w_-z':
bEixoZ=True
bEscalaZ=True
bRotationZ=True
iEixoZneg=-1
iRotationNeg=-1
iEscalaZneg=-1
# LOCAL 3
if context.scene.imp_sound_to_anim.import_where3== 'imp_w_x':
bEixoX=True
bEscalaX=True
bRotationX=True
if context.scene.imp_sound_to_anim.import_where3== 'imp_w_y':
bEixoY=True
bEscalaY=True
bRotationY=True
if context.scene.imp_sound_to_anim.import_where3== 'imp_w_z':
bEixoZ=True
bEscalaZ=True
bRotationZ=True
if context.scene.imp_sound_to_anim.import_where3== 'imp_w_-x':
bEixoX=True
bEscalaX=True
bRotationX=True
iEixoXneg=-1
iEscalaXneg=-1
iRotationNeg=-1
if context.scene.imp_sound_to_anim.import_where3== 'imp_w_-y':
bEixoY=True
bEscalaY=True
bRotationY=True
iEixoYneg=-1
iRotationNeg=-1
iEscalaYneg=-1
if context.scene.imp_sound_to_anim.import_where3== 'imp_w_-z':
bEixoZ=True
bEscalaZ=True
bRotationZ=True
iEixoZneg=-1
iRotationNeg=-1
iEscalaZneg=-1
iMinBaseX=iMinScaleBaseX=context.scene.imp_sound_to_anim.action_offset_x
iMinBaseY=iMinScaleBaseY=context.scene.imp_sound_to_anim.action_offset_y
iMinBaseZ=iMinScaleBaseZ=context.scene.imp_sound_to_anim.action_offset_z
#escala inicia com 1 e nao com zero
iRotationAxisBaseX=context.scene.imp_sound_to_anim.action_offset_x +1
iRotationAxisBaseY=context.scene.imp_sound_to_anim.action_offset_y +1
iRotationAxisBaseZ=context.scene.imp_sound_to_anim.action_offset_z +1
#Added destructive optimizer option - LostLestSignificativeDigit lost/total
iDestructiveOptimizer=context.scene.imp_sound_to_anim.optimization_destructive
#limita ou nao o valor - velocidade
bLimitValue=False
if iMinValue<0: iMinValue=0
if iMaxValue>255: iMaxValue=255
if iMinValue>255: iMinValue=255
if iMaxValue<0: iMaxValue=0
if iMinValue!= 0: bLimitValue= True
if iMaxValue!= 255: bLimitValue= True
if obi.RunFrom==0:
print('')
print("================================================================")
from time import strftime
print(strftime("Start Import: %H:%M:%S"))
print("================================================================")
print('')
ilocationXAnt=0
ilocationYAnt=0
ilocationZAnt=0
iscaleXAnt=0
iscaleYAnt=0
iscaleZAnt=0
iRotateValAnt=0
# variavel global _Interna_Globals
if context.scene.imp_sound_to_anim.bArrayCriado:
for i in range(loop):
ival=array[i+obi.RunFrom]/iDivScala
#valor pequeno demais, vai dar zero na hora de aplicar
if ival < 0.001:
array[i+obi.RunFrom]=0
ival=0
# to increase performance and legibility
arrayI= array[i+obi.RunFrom]
arrayIP1= array[i+1+obi.RunFrom]
arrayIL1= array[i-1+obi.RunFrom]
# opcao de NAO colocar valores iguais sequenciais
if i>0 and bNaoValorIgual and arrayIL1== arrayI:
print("Importing Blender Frame: "+str(i+obi.RunFrom+1)+"\tof "+str(len(array)-1) + \
"\t(skipped by optimizer)")
obi.iSumOptimizerP3+=1
else:
# otimizacao - nao preciso mais que 2 valores iguais.
# pular key frame intermediario - Ex b, a, -, -, -, a
# tambem otimiza pelo otimizador com perda
# valor atual == anterior e posterior -> pula
if i>0 and i< len(array)-1 and abs(arrayI - arrayIL1)<=iDestructiveOptimizer and \
abs(arrayI - arrayIP1)<=iDestructiveOptimizer:
print("Importing Blender Frame: "+str(i+obi.RunFrom+1)+"\tof "+str(len(array)-1) + \
"\t(skipped by optimizer)")
if iDestructiveOptimizer>0 and arrayI != arrayIL1 or arrayI != arrayIP1:
obi.iSumOptimizerP1+=1
else: obi.iSumOptimizerP2+=1
else:
if bLimitValue:
if arrayI > iMaxValue: array[i+obi.RunFrom]=iMaxValue
if arrayI < iMinValue: array[i+obi.RunFrom]=iMinValue
ival=array[i+obi.RunFrom]/iDivScala
#passa para float com somente 3 digitos caso seja float
m_ival=ival*1000
if int(m_ival) != m_ival:
ival= int(m_ival)
ival = ival /1000
bpy.context.scene.frame_current = i+iStartFrame
#precisa fazer objeto ativo
if bpy.context.active_object.type=='MESH' or bpy.context.active_object.type=='CAMERA' or \
bpy.context.active_object.type=='EMPTY':
if bEixo:
if bEixoX: bpy.context.active_object.location.x = ival*iEixoXneg+iMinBaseX
if bEixoY: bpy.context.active_object.location.y = ival*iEixoYneg+iMinBaseY
if bEixoZ: bpy.context.active_object.location.z = ival*iEixoZneg+iMinBaseZ
if bEscala:
if bEscalaX: bpy.context.active_object.scale.x = ival*iEscalaXneg+iMinScaleBaseX
if bEscalaY: bpy.context.active_object.scale.y = ival*iEscalaYneg+iMinScaleBaseY
if bEscalaZ: bpy.context.active_object.scale.z = ival*iEscalaZneg+iMinScaleBaseZ
# 'ARMATURE' or ('MESH' and bRotacao) or ('CAMERA' and bRotacao) or 'LAMP' or 'EMPTY' and bRotacao)
if bpy.context.active_object.type=='ARMATURE' or (bpy.context.active_object.type=='MESH' and bRotacao) or \
(bpy.context.active_object.type=='CAMERA' and bRotacao) or \
bpy.context.active_object.type=='LAMP' or \
(bpy.context.active_object.type=='EMPTY' and bRotacao):
#=========== BONE ===========#
if bpy.context.active_object.type=='ARMATURE': #precisa ser objeto ativo. Nao achei como passar para editmode
if bpy.context.mode!= 'POSE': #posemode
bpy.ops.object.posemode_toggle()
#============= ALL ===========#
if bEixo:
if ilocationXAnt!=0 or ilocationYAnt!=0 or ilocationZAnt!=0:
bpy.ops.transform.translate(value=(ilocationXAnt*-1, ilocationYAnt*-1, \
ilocationZAnt*-1), constraint_axis=(bEixoX, bEixoY,bEixoZ), \
constraint_orientation='GLOBAL', mirror=False, \
proportional='DISABLED', proportional_edit_falloff='SMOOTH', \
proportional_size=1, snap=False, \
snap_target='CLOSEST', snap_point=(0, 0, 0), \
snap_align=False, snap_normal=(0, 0, 0), \
release_confirm=False)
ilocationX=ilocationY=ilocationZ=0
if bEixoX: ilocationX = ival*iEixoXneg+iMinBaseX
if bEixoY: ilocationY = ival*iEixoYneg+iMinBaseY
if bEixoZ: ilocationZ = ival*iEixoZneg+iMinBaseZ
bpy.ops.transform.translate(value=(ilocationX, ilocationY, \
ilocationZ), constraint_axis=(bEixoX, bEixoY,bEixoZ), \
constraint_orientation='GLOBAL', mirror=False, \
proportional='DISABLED', proportional_edit_falloff='SMOOTH', \
proportional_size=1, snap=False, \
snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, \
snap_normal=(0, 0, 0), release_confirm=False)
ilocationXAnt= ilocationX
ilocationYAnt= ilocationY
ilocationZAnt= ilocationZ
if bEscala:
if iscaleXAnt!=0 or iscaleYAnt!=0 or iscaleZAnt!=0:
tmpscaleXAnt=0
tmpscaleYAnt=0
tmpscaleZAnt=0
if iscaleXAnt: tmpscaleXAnt=1/iscaleXAnt
if iscaleYAnt: tmpscaleYAnt=1/iscaleYAnt
if iscaleZAnt: tmpscaleZAnt=1/iscaleZAnt
bpy.ops.transform.resize(value=(tmpscaleXAnt, tmpscaleYAnt, \
tmpscaleZAnt ), constraint_axis=(False, False, False), \
constraint_orientation='GLOBAL', mirror=False, \
proportional='DISABLED', proportional_edit_falloff='SMOOTH', \
proportional_size=1, snap=False, snap_target='CLOSEST', \
snap_point=(0, 0, 0), snap_align=False, \
snap_normal=(0, 0, 0), release_confirm=False)
iscaleX=iscaleY=iscaleZ=0
if bEscalaX: iscaleX = ival*iEscalaXneg+iMinScaleBaseX
if bEscalaY: iscaleY = ival*iEscalaYneg+iMinScaleBaseY
if bEscalaZ: iscaleZ = ival*iEscalaZneg+iMinScaleBaseZ
bpy.ops.transform.resize(value=(iscaleX, iscaleY, \
iscaleZ), constraint_axis=(False, False, False), \
constraint_orientation='GLOBAL', mirror=False, \
proportional='DISABLED', proportional_edit_falloff='SMOOTH', \
proportional_size=1, snap=False, \
snap_target='CLOSEST', snap_point=(0, 0, 0), \
snap_align=False, snap_normal=(0, 0, 0), \
release_confirm=False)
iscaleXAnt= iscaleX
iscaleYAnt= iscaleY
iscaleZAnt= iscaleZ
if bRotacao:
if iRotateValAnt!=0:
bpy.context.active_object.rotation_euler= ((iRotateValAnt*-1)+ iRotationAxisBaseX) *bRotationX , \
((iRotateValAnt*-1)+ iRotationAxisBaseY) *bRotationY , \
((iRotateValAnt*-1)+ iRotationAxisBaseZ) *bRotationZ
bpy.context.active_object.rotation_euler= ((ival*iRotationNeg)+ iRotationAxisBaseX) * bRotationX, \
((ival*iRotationNeg)+ iRotationAxisBaseY) * bRotationY, \
((ival*iRotationNeg)+ iRotationAxisBaseZ) * bRotationZ
iRotateValAnt= ival*iRotationNeg
ob = bpy.context.active_object
if bEixo:
ob.keyframe_insert(data_path="location")