-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestblender.py
69 lines (55 loc) · 1.74 KB
/
testblender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sys
sys.path.append("/usr/local/Ice-3.5.0/python")
sys.path.append("/home/andreynech/projects/veter/blender")
import bpy, threading, time
import traceback, Ice
Ice.loadSlice('Hello.ice')
Ice.updateModules()
import Demo
class HelloI(Demo.Hello):
def __init__(self, obj, data, scene):
Demo.Hello.__init__(self)
self.obj = obj
self.data = data
self.scene = scene
def setLocation(self, x, y, z, current=None):
self.obj.location[0] = x
self.obj.location[1] = y
self.obj.location[2] = z
self.scene.update()
def shutdown(self, current=None):
current.adapter.getCommunicator().shutdown()
class ServerThread(threading.Thread):
def __init__(self, obj, data, scene):
threading.Thread.__init__(self)
self.obj = obj
self.data = data
self.scene = scene
def run(self):
ic = None
try:
props = Ice.createProperties()
props.load('server.config')
initdata = Ice.InitializationData()
initdata.properties = props
communicator = Ice.initialize(sys.argv, initdata)
adapter = communicator.createObjectAdapter("Hello")
object = HelloI(self.obj, self.data, self.scene)
adapter.add(object, communicator.stringToIdentity("hello"))
adapter.activate()
communicator.waitForShutdown()
except:
traceback.print_exc()
if ic:
# Clean up
try:
communicator.destroy()
except:
traceback.print_exc()
# Script execution starts here
C = bpy.context
D = bpy.data
t = ServerThread(C.object, D, C.scene)
t.start()
# Here we are leaving the main thread but ServerThread is still
# running in background