first i ll explain what i trying to do. so i want to process the data i getting from the arduino to control some bones ‘live’
for animation purposes. i m using pyserial. i m getting the data from the arduino thats not the problem.
the problem is that blender will only update the scene at the end of the script, so every time in the routine the serial communication is being open and closed at the end which makes the whole thing very very slow. i 've try a loop so could stay between the open and closing of the serial communication and on the console the speed at which the data come in in quite good but the object does not move at all, i’ve try it in bpy and bge. i ve try to put the serial in a library -> no use
i think if it was possible it would be great thing , having sensor to your feet and hands for controlling movements.
so if you have any idea how i could solve this , it would be great.
You need to structure your script to account for state and you need to keep you Serial object around between frames.
I recommend that you attach it to the object that the serial data will be driving. Something like this:
import bpy obj = bpy.data.objects['Armature'] if 'init' not in obj: obj['init'] = True obj['serial'] = # Allocate your serial.Serial object and store it in obj here serial = obj['serial'] # Read serial data here and update your bones
If you are doing this in the viewport directly you will be using bpy and I recommend installing this script to be called when the scene changes.
I use the ModalTimerOperator to allow some time to process the data imported with a Blender socket server named UDP_server(data) running on port 8081. There is no open or close with UDP_server() only Make Port Active. With this UDP datagrams you can receive up to 1024 bytes at a time!. Only problem is it is a one string only system. You would have to decode the string into your data upon arrival. After decoding, then you update your objects with this new data, and then return for more.