...
 
Commits (3)
......@@ -68,6 +68,7 @@ else:
import bpy
from bpy import props
from bpy.types import WindowManager
import faulthandler
C = bpy.context
# =========================================
......@@ -123,7 +124,15 @@ class Chord_Properties(bpy.types.AddonPreferences):
playing = props.BoolProperty( name="Record capture", default = False )
# ----------- ADVANCED -----------
debug_osc = props.BoolProperty( name="Debug osc to console", default = False )
def on_debug_update(self, context):
if self.debug_mode:
faulthandler.enable()
print("*** Chordata Debug mode enable ***")
else:
faulthandler.disable()
print("** Chordata Debug mode disable **")
debug_mode = props.BoolProperty( name="Enable debuging for the Chordata add-on", default = False, update=on_debug_update )
notochord_parameters = props.StringProperty( default = "" )
......@@ -223,9 +232,16 @@ def register():
bpy.utils.register_module(__name__)
if bpy.context.user_preferences.addons[__package__].preferences.debug_mode:
faulthandler.enable()
print("** Chordata Debug mode enable **")
def unregister():
# bpy.utils.unregister_class(Chord_Get_Ip)
bpy.utils.unregister_module(__name__)
faulthandler.disable()
# del WindowManager.chordata
if __name__ == "__main__":
......
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"addon not found: 'cycles'\n"
]
}
],
"source": [
"import bpy\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'FINISHED'}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Enable the chordata add-on\n",
"bpy.ops.wm.addon_enable(module = \"chordata_addon\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10.42.0.230\n",
"6565\n",
"*** Chordata Debug mode enable ***\n"
]
}
],
"source": [
"#get the chordata preferences struct\n",
"chordata_prefs = bpy.context.user_preferences.addons[\"chordata_addon\"].preferences\n",
"print(chordata_prefs.ip_addr)\n",
"print(chordata_prefs.notochord_dest_port)\n",
"\n",
"chordata_prefs.debug_mode = True\n"
]
},
{
"cell_type": "raw",
"metadata": {
"scrolled": false
},
"source": [
"#Cannot run without setting an armature 'bpy.context.scene.chordata.target'\n",
"bpy.ops.chordata.receive()\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"target: None\n",
"target: <bpy_struct, Object(\"Chordata\")>\n"
]
}
],
"source": [
"print(\"target: \", bpy.context.scene.chordata.target)\n",
"\n",
"filename = \"addon_dev.blend\"\n",
"bpy.ops.wm.open_mainfile(filepath=filename)\n",
"print(\"target: \", bpy.context.scene.chordata.target)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Things changed:\n",
"- write_blender_console() shouldn't execute on headless\n",
"- `Chordata_Receive_OSC` as baseclass for Operator\n"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Check if blender is running headless\n",
"bpy.app.background\n"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Root bone: base | starting location: <Vector (-0.0000, -0.0074, -2.1916)>\n",
"Bones found in armature\n",
" [base______] Helper found\n",
" [dorsal____] Helper found\n",
" [head______] Helper found\n",
" [l-arm_____] Helper found\n",
" [l-forarm__] Helper found\n",
" [l-hand____] Helper found\n",
" [r-arm_____] Helper found\n",
" [r-forarm__] Helper found\n",
" [r-hand____] Helper found\n",
" [r-thigh___] Helper found\n",
" [r-leg_____] Helper found\n",
" [r-foot____] Helper found\n",
" [l-thigh___] Helper found\n",
" [l-leg_____] Helper found\n",
" [l-foot____] Helper found\n",
"|| No previous animation data found. ||\n",
"|| Chordata operator | Calibrating... Press ENTER to start posing ||\n",
"Receiving in 0.0.0.0:6565 (Unicast)\n",
"|| Receiving in 0.0.0.0:6565 (Unicast) ||\n",
"|| [{'INFO'}] Receiving OSC ||\n",
"Not trasmitting OSC\n",
"/Chordata/head (1.0, 0.0, 0.0, 0.0)\n",
"/Chordata/head (1.0, 0.0, 0.0, 0.0)\n",
"/Chordata/head (1.0, 0.0, 0.0, 0.0)\n",
"/Chordata/head (1.0, 0.0, 0.0, 0.0)\n",
"/Chordata/head (1.0, 0.0, 0.0, 0.0)\n",
"|| Chordata operator | Posing... Press ESC to end ||\n",
"/Chordata/head (1.0, 0.0, 0.0, 0.0)\n",
"/Chordata/head (1.0, 0.0, 0.0, 0.0)\n",
"/Chordata/head (1.0, 0.0, 0.0, 0.0)\n",
"/Chordata/head (1.0, 0.0, 0.0, 0.0)\n",
"/Chordata/head (1.0, 0.0, 0.0, 0.0)\n"
]
},
{
"data": {
"text/plain": [
"'finito'"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# In case there was another unfinished receive operator, call the cancel() fn.\n",
"from chordata_addon import receive\n",
"from time import sleep\n",
"receive_op = receive.Chordata_Receive_OSC()\n",
"\n",
"receive_op.terminate_server()\n",
"status = receive_op.initialize(bpy.context)\n",
"\n",
"if status == {'RUNNING_MODAL'}:\n",
" for i in range(10):\n",
" receive_op.process_message()\n",
" sleep(0.1)\n",
" \n",
" receive_op.end_of_calibration()\n",
" \n",
" for i in range(10):\n",
" receive_op.process_message()\n",
" sleep(0.1)\n",
" \n",
"\n",
"receive_op.cancel(bpy.context)\n",
"\"finito\"\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"\n",
"# op_state = bpy.ops.chordata.receive('EXEC_DEFAULT')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -264,7 +264,7 @@ class Chord_advanced_panel(bpy.types.Panel):
self.chord_global = context.user_preferences.addons[__package__].preferences
layout = self.layout
layout.prop(self.chord_global, "debug_osc", text="Debug OSC")
layout.prop(self.chord_global, "debug_mode", text="Debug mode", icon='LIBRARY_DATA_BROKEN')
layout.label("Control notochord")
row = layout.row(align=True)
......@@ -301,3 +301,6 @@ class Chord_advanced_panel(bpy.types.Panel):
layout.label("Sensor helpers parent")
layout.prop(context.scene.chordata, "helpers", text="", icon="OUTLINER_DATA_EMPTY")
box = layout.box()
# box.label("This button will save many Chordata setting, as well as other preferences set in the 'User preferences menu' during the current session")
box.operator("wm.save_userpref", "Save User_preferences", icon="SAVE_PREFS")
......@@ -100,6 +100,12 @@ class Chord_Clean_Anims(bpy.types.Operator):
class Receive_Base:
# ----------- UTILS -----------
def inform(self, type, message):
try:
self.report(type, message)
except AttributeError:
print("|| [{}] {} ||".format(type, message))
def prepare_armature(self):
bpy.ops.chordata.clean_anims()
self.armature.reset_pose()
......@@ -121,12 +127,12 @@ class Receive_Base:
def start_stop_animation(self):
if self.chord_global.do_set_keyframes:
self.chord_global.do_set_keyframes = False
self.report({"INFO"}, "Stop recording animation")
self.inform({"INFO"}, "Stop recording animation")
else:
bpy.ops.chordata.clean_anims()
self.chord_global.do_set_keyframes = True
self.report({"INFO"}, "Recording animation!")
self.inform({"INFO"}, "Recording animation!")
def set_keyframe(self):
......@@ -151,7 +157,7 @@ class Receive_Base:
server(addr, port, "chordata_armature_server")
except Exception as e:
u.write_blender_console(self.context, str(e))
self.report({"ERROR"}, "There was a problem creating the UDP server")
self.inform({"ERROR"}, "There was a problem creating the UDP server")
return False
msg = "Receiving in %s:%d (%s)" % \
......@@ -164,13 +170,24 @@ class Receive_Base:
#TODO: work on the OSC routing, the library is not using regex but glob??
bone_handler = self.receive_bones
if self.chord_global.debug_osc: bone_handler = self.receive_bones_verbose
if self.chord_global.debug_mode: bone_handler = self.receive_bones_verbose
osc_method("/Chordata/*", bone_handler,\
argscheme=osm.OSCARG_ADDRESS + osm.OSCARG_DATA)
self.report({"INFO"}, "Receiving OSC")
self.inform({"INFO"}, "Receiving OSC")
return True
def terminate_server(self):
server = osch.get_channel("chordata_armature_server")
if server:
server.terminate()
send.clean()
self.chord_global.receiving = False
self.chord_global.do_set_keyframes = False
osc_terminate()
def receive_bones(self, addr, values):
sensor = self.chord_regex.search(addr)
if not sensor or sensor.lastindex < 1:
......@@ -197,7 +214,7 @@ class Chordata_Receive_OSC( Receive_Base ):
self.running_headless = bpy.app.background
if not context.scene.chordata.target:
self.report({"ERROR"}, "No armature object selected")
self.inform({"ERROR"}, "No armature object selected")
return {"CANCELLED"}
chord_scene = context.scene.chordata
......@@ -235,12 +252,8 @@ class Chordata_Receive_OSC( Receive_Base ):
wm = context.window_manager
wm.event_timer_remove(self._timer)
osch.get_channel("chordata_armature_server").terminate()
send.clean()
self.chord_global.receiving = False
self.chord_global.do_set_keyframes = False
self.terminate_server()
self.text(None)
osc_terminate()
# ----------- MODAL FNs -----------
def process_message(self):
......@@ -280,7 +293,7 @@ class _OP_Chordata_Receive_OSC(bpy.types.Operator, Chordata_Receive_OSC):
elif event.type in {'RIGHTMOUSE', 'ESC'} or not self.chord_global.receiving:
if self.chord_global.manage_notochord:
bpy.ops.chordata.close_notochord("EXEC_DEFAULT")
self.report({"WARNING"}, "Connection canceled")
self.inform({"WARNING"}, "Connection canceled")
print(" <-- Connection canceled --> ")
self.cancel(context)
return {'CANCELLED'}
......