diff --git a/SerializePropertyGroup.py b/SerializePropertyGroup.py new file mode 100644 index 0000000..6269412 --- /dev/null +++ b/SerializePropertyGroup.py @@ -0,0 +1,22 @@ +import sys +import os + + +thirdPartyDir = "C:\\Users\\slumber\\repos\\phd\src\\2019_rcf\\libs" + + + +if thirdPartyDir not in sys.path: + print('Adding local modules dir to the path') + sys.path.insert(0, thirdPartyDir) + + +import umsgpack +import bpy +import esper +from rna_xml import rna2xml + +try: + umsgpack.packb((getattr(bpy.data,'objects'))) +except: + pass \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..59a19d9 --- /dev/null +++ b/__init__.py @@ -0,0 +1,20 @@ +import bpy +bl_info = { + "name": "Sprite preview", + "author": "Cube Animation", + "version": (1, 0), + "blender": (2, 80, 0), + "location": "Properties > Object > Sprite Components", + "description": "Manage sprite components in blender", + "warning": "", + "wiki_url": "", + "category": "Cube Animation", +} + + +def register(): + pass + + +def unregister(): + pass diff --git a/dump_rna2xml.py b/dump_rna2xml.py new file mode 100644 index 0000000..0358dde --- /dev/null +++ b/dump_rna2xml.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +# ***** 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 2 +# 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, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Contributor(s): Campbell Barton +# +# ***** END GPL LICENSE BLOCK ***** + +# + +# This script dumps rna into xml. +# useful for finding bugs in RNA api. + +# Example usage +# blender some.blend --background -noaudio --python intern/tools/dump_rna2xml.py + +import os +import bpy +import rna_xml + + +def main(): + filename = os.path.splitext(bpy.data.filepath)[0] + ".xml" + + file = open(filename, 'w') + + if 1: + # blend file + rna_xml.rna2xml(file.write, + root_rna=bpy.data, + root_rna_skip={"window_managers"}) + else: + # theme. just another test + rna_xml.rna2xml(file.write, + root_rna=bpy.context.user_preferences.themes[0], + method='ATTR') + + file.close() + + # read back to ensure this is valid! + from xml.dom.minidom import parse + xml_nodes = parse(filename) + print("Written:", filename) + + # test reading back theme + if 1: + theme = xml_nodes.getElementsByTagName("Theme")[0] + rna_xml.xml2rna(theme, + root_rna=bpy.context.user_preferences.themes[0],) + +if __name__ == "__main__": + main() diff --git a/main.py b/main.py index 255d60a..a4a554f 100644 --- a/main.py +++ b/main.py @@ -1,62 +1,52 @@ import net_systems +import replication_system import net_components from libs.esper import esper import zmq import sys import argparse import time -from zmq.asyncio import Context, ZMQEventLoop -import asyncio - -Url = 'tcp://127.0.0.1:5555' -Ctx = Context() - - -@asyncio.coroutine -def server(): - print("Getting ready for hello world client. Ctrl-C to exit.\n") - socket = Ctx.socket(zmq.REP) - socket.bind(Url) - while True: - # Wait for next request from client - message = yield from socket.recv() - print("Received request: {}".format(message)) - # Do some "work" - yield from asyncio.sleep(1) - # Send reply back to client - message = message.decode('utf-8') - message = '{}, world'.format(message) - message = message.encode('utf-8') - print("Sending reply: {}".format(message)) - yield from socket.send(message) - # TODO: Implement a manager class for each aspect (ex: Network_Manager) # TODO: Is it right to implement server-client as ESC ?... def main(): - args = sys.argv[1:] - if len(args) != 0: - sys.exit(__doc__) + # Argument parsing + parser = argparse.ArgumentParser( + description='Launch an instance of collaboration system') + parser.add_argument('-r', choices=list(net_components.Role), + type=net_components.Role, help='role for the instance ') + + args = parser.parse_args() + + instance_role = args.r + instance_context = zmq.Context() + + print("Starting a {} instance \n".format(instance_role)) + + # Create a World instance to hold everything: + world = esper.World() + + # Instantiate a Processor (or more), and add them to the world: + world.add_processor(net_systems.SessionSystem()) + world.add_processor(replication_system.ReplicationSystem()) + + # Instanciate a session entity + session = world.create_entity() + + world.add_component( + session, net_components.NetworkInterface(context=instance_context)) + world.add_component( + session, net_components.User(role=instance_role)) + + + # A dummy main loop: try: - loop = asyncio.get_event_loop() - loop.run_until_complete(server()) + while True: + # Call world.process() to run all Processors. + world.process() + time.sleep(1) except KeyboardInterrupt: - print('\nFinished (interrupted)') - sys.exit(0) - - # Socket to talk to server - print("Connecting to hello world server...") - socket = context.socket(zmq.REQ) - socket.connect("tcp://localhost:5555") - - # Do 10 requests, waiting each time for a response - for request in range(10): - print("Sending request %s ..." % request) - socket.send(b"Hello") - - # Get the reply. - message = socket.recv() - print("Received reply %s [ %s ]" % (request, message)) + return if __name__ == '__main__': diff --git a/main_old.py b/main_old.py deleted file mode 100644 index 6566bec..0000000 --- a/main_old.py +++ /dev/null @@ -1,52 +0,0 @@ -import net_systems -import net_components -from libs.esper import esper -import zmq -import sys -import argparse -import time - -# TODO: Implement a manager class for each aspect (ex: Network_Manager) -# TODO: Is it right to implement server-client as ESC ?... -def main(): - # Argument parsing - parser = argparse.ArgumentParser( - description='Launch an instance of collaboration system') - parser.add_argument('-r', choices=list(net_components.Role), - type=net_components.Role, help='role for the instance ') - - args = parser.parse_args() - - instance_role = args.r - instance_context = zmq.Context() - - print("Starting a {} instance \n".format(instance_role)) - - # Create a World instance to hold everything: - world = esper.World() - - # Instantiate a Processor (or more), and add them to the world: - network_system = net_systems.NetworkSystem() - world.add_processor(network_system) - - # Instanciate a session entity - session = world.create_entity() - - world.add_component( - session, net_components.NetworkInterface(context=instance_context)) - world.add_component( - session, net_components.User(role=instance_role)) - - - # A dummy main loop: - try: - while True: - # Call world.process() to run all Processors. - world.process() - time.sleep(1) - except KeyboardInterrupt: - return - - -if __name__ == '__main__': - main() diff --git a/net_components.py b/net_components.py index aa15720..a9a9311 100644 --- a/net_components.py +++ b/net_components.py @@ -22,14 +22,12 @@ class User: self.role = role class NetworkInterface: - def __init__(self, host="*",context=None, socket_type=zmq.REQ,protocol='tcp',port=5555): + def __init__(self, host="*",context=None, socket_type=zmq.REP,protocol='tcp',port=5555): self.host = host self.context = context self.socket = context.socket(socket_type) - self.poller = zmq.Poller() #TODO: Is this right to it here? - self.poller.register(self.socket, zmq.POLLIN) print("{}://{}:{}".format(protocol,host,port)) self.socket.bind("tcp://*:5555") diff --git a/net_systems.py b/net_systems.py index 992c643..73793c4 100644 --- a/net_systems.py +++ b/net_systems.py @@ -1,12 +1,14 @@ import time +import asyncio import zmq +import zmq.asyncio import net_components from libs.esper import esper -class NetworkSystem(esper.Processor): +class SessionSystem(esper.Processor): """ Handle Client-Server session managment """ @@ -20,21 +22,24 @@ class NetworkSystem(esper.Processor): def process(self): # This will iterate over every Entity that has BOTH of these components: for ent, (net_interface, user) in self.world.get_components(net_components.NetworkInterface,net_components.User): - if user.role is net_components.Role.CLIENT: - net_interface.socket.send(b"Waiting server response") - if user.role is net_components.Role.SERVER: print("Server loops") try: - socks = dict(net_interface.poller.poll()) + message = net_interface.socket.recv() print("test") except KeyboardInterrupt: - break - if net_interface.socket in socks: - message = net_interface.socket.recv() + break print("test") - # process task - - \ No newline at end of file + if user.role is net_components.Role.CLIENT: + # Send reply back to client + socket.send(b"Hello") + + @asyncio.coroutine + def recv_and_process(): + sock = ctx.socket(zmq.PULL) + sock.bind(url) + msg = yield from sock.recv_multipart() # waits for msg to be ready + reply = yield from async_process(msg) + yield from sock.send_multipart(reply) diff --git a/replication_system.py b/replication_system.py new file mode 100644 index 0000000..624c994 --- /dev/null +++ b/replication_system.py @@ -0,0 +1,18 @@ +import zmq + +from libs.esper import esper + +class ReplicationSystem(esper.Processor): + """ + Handle Client-Server session managment + """ + + def __init__(self): + super().__init__() + # Initialize poll set + + + # TODO: Use zmq_poll.. + async def process(self): + # This will iterate over every Entity that has BOTH of these components: + print("test") \ No newline at end of file diff --git a/test.blend b/test.blend new file mode 100644 index 0000000..549feb8 Binary files /dev/null and b/test.blend differ diff --git a/test_net.blend b/test_net.blend new file mode 100644 index 0000000..b301dac Binary files /dev/null and b/test_net.blend differ