def update_mesh(self, ob): data = ob.data # operators seems much slower, we add a classmedthod to call the code directly from handlers (see handler.py) bm = bmesh.from_edit_mesh(data) uv_lay = bm.loops.layers.uv.active mesh_index = 0 # we only support one bm per object bundle = Bundle() if uv_lay: for face in bm.faces: for vindex, vertex in enumerate(face.verts): bundle.add( Message("/bge/scene/objects/meshes/update_face_co", ob.name, mesh_index, face.index, vindex, vertex.co[0], vertex.co[1], vertex.co[2])) for vindex, loop in enumerate(face.loops): uv = loop[uv_lay].uv bundle.add( Message("/bge/scene/objects/meshes/update_face_uv", ob.name, mesh_index, face.index, vindex, uv[0], uv[1])) else: for face in bm.faces: for vindex, vertex in enumerate(face.verts): bundle.add( Message("/bge/scene/objects/meshes/update_face_co", ob.name, mesh_index, face.index, vindex, vertex.co[0], vertex.co[1], vertex.co[2])) Client().send(bundle)
def _send_output(self, output, timestamp, name): """Send pipeline outputs through the LSL or OSC stream. NOT PER CHANNEL Args: output (scalar): output of the pipeline timestamp (float): timestamp """ for out in self._output_threads: if isinstance(out, str): # LSL outlet raise NotImplementedError # self._outlet.push_sample([output], timestamp=timestamp) else: # OSC output stream if USE_LIBLO: if (np.array(output).size == 1): new_output = [('f', np.asscalar(output))] message = Message('/{}'.format(name), *new_output) else: new_output = [('f', x) for x in output[:]] message = Message('/{}'.format(name), *new_output) # send(out, Bundle(timestamp, message)) send(out, message) else: raise NotImplementedError # self._client.send_message(}{}'.format(name),output[:]) if self.verbose: print('Output: {}'.format(output))
def execute(self, context): settings = context.window_manager.blive_settings active_camera = context.scene.camera # count Viewports n = len([ i for i in context.scene.objects if i.type == 'CAMERA' and i.data.viewport.active ]) if n == 0: active_camera.data.viewport.active = True # set one basic viewport based on window size active_camera.data.viewport.left = 0 active_camera.data.viewport.right = settings.bge_window_width active_camera.data.viewport.top = 0 active_camera.data.viewport.bottom = settings.bge_window_height settings.numviewports = 1 else: settings.numviewports = n vpcam = [i for i in context.scene.objects if i.type == 'CAMERA'] bundle = Bundle() for cam in vpcam: vp = cam.data.viewport bundle.add( Message("/bge/scene/cameras/setViewport", cam.name, vp.left, vp.bottom, vp.right, vp.top)) bundle.add( Message("/bge/scene/cameras/useViewport", cam.name, int(vp.active))) Client().send(bundle) return {'FINISHED'}
def update_lamp(self, lamp): data = lamp.data bundle = Bundle() bundle.add(Message("/bge/scene/lights/energy", lamp.name, data.energy)) bundle.add( Message("/bge/scene/lights/color", lamp.name, data.color[0], data.color[1], data.color[2])) if data.type == 'POINT': bundle.add( Message("/bge/scene/lights/distance", lamp.name, data.distance)) bundle.add( Message("/bge/scene/lights/lin_attenuation", lamp.name, data.linear_attenuation)) bundle.add( Message("/bge/scene/lights/quad_attenuation", lamp.name, data.quadratic_attenuation)) elif data.type == 'SPOT': bundle.add( Message("/bge/scene/lights/distance", lamp.name, data.distance)) bundle.add( Message("/bge/scene/lights/lin_attenuation", lamp.name, data.linear_attenuation)) bundle.add( Message("/bge/scene/lights/quad_attenuation", lamp.name, data.quadratic_attenuation)) bundle.add( Message("/bge/scene/lights/spotsize", lamp.name, math.degrees(data.spot_size))) bundle.add( Message("/bge/scene/lights/spotblend", lamp.name, data.spot_blend)) Client().send(bundle)
def execute(self): if self.state == "PLAY": Client().send(Message("/bge/logic/media/play", self.image)) elif self.state == "PAUSE": Client().send(Message("/bge/logic/media/pause", self.image)) elif self.state == "STOP": Client().send(Message("/bge/logic/media/stop", self.image)) elif self.state == "CLOSE": Client().send(Message("/bge/logic/media/close", self.image)) pass
def _reply(cls, typehandler, path, args, types, source, user_data): obj, attr = cls._get_instance(path, args) data = typehandler.get(obj, attr) target = cls._parse_instance(args) msg = Message(path) if target: msg.add(*target) if data: msg.add(*data) bge.logic.server.send(source.url, msg)
def update_projectionmatrix(self, camera): data = camera.data # operators seems much slower, we add a classmedthod to call the code directly for internal use (see handler.py) bundle = Bundle() e = 1.0 / math.tan(data.angle / 2.0) a = bpy.context.scene.game_settings.resolution_y / bpy.context.scene.game_settings.resolution_x n = data.clip_start f = data.clip_end msg_matrix = Message('/bge/scene/cameras/projection_matrix') msg_matrix.add(camera.name, e, 0.0, 2.0 * data.shift_x, 0.0, 0.0, e / a, 2.0 * data.shift_y / a, 0.0, 0.0, 0.0, (f + n) / (n - f), (2 * f * n) / (n - f), 0.0, 0.0, -1.0, 0.0) perspective = 1 if data.type == 'ORTHO': perspective = 0 msg_persp = Message('/bge/scene/cameras/perspective') msg_persp.add(camera.name, perspective) bundle.add(msg_persp) bundle.add(msg_matrix) Client().send(bundle)
def _send_outputs(self, output, timestamp, name): """Send pipeline outputs through the LSL or OSC stream. Args: output (scalar): output of the pipeline timestamp (float): timestamp """ for out in self._output_threads: if isinstance(out, str): # LSL outlet self._outlet.push_sample([output], timestamp=timestamp) else: # OSC output stream if USE_LIBLO: for c in range(self.n_channels): new_output = [('f', x) for x in output[:, c]] message = Message('/{}{}'.format(name, c), *new_output) #send(out, Bundle(timestamp, message)) send(out, message) else: for c in range(self.n_channels): self._client.send_message('/{}{}'.format(name, c), output[:, c]) if self.verbose: print('Output: {}'.format(output))
def execute(self, context): Client().send( Message("/bge/logic/media/openMovie", self.obname, self.imgname, self.filepath, int(self.audio), self.inpoint, self.outpoint, int(self.loop), self.preseek, int(self.deinterlace))) return {'FINISHED'}
def _send_sparseOutput(self, output, timestamp, name): for out in self._sparseOutput_threads: if isinstance(out, str): # LSL outlet raise NotImplementedError else: # OSC output stream if USE_LIBLO: if (np.array(output).size == 1): new_output = [('f', np.asscalar(output))] message = Message('/{}'.format(name), *new_output) else: new_output = [('f', x) for x in output[:]] message = Message('/{}'.format(name), *new_output) #send(out, Bundle(timestamp, message)) send(out, message) else: raise NotImplementedError if self.verbose: print('spareOutput: {}'.format(output))
def execute(self): # test if first arg contains '/' (path) if self.msg.split(' ')[0].count('/'): msg = Message(self.msg.split(' ')[0]) for i in self.msg.split(' ')[1:]: # digits are ints if i.isdigit(): msg.add(int(i)) # try convert args with '.' to float otherwise stays string elif i.count('.') == 1: try: msg.add(float(i)) except ValueError: msg.add(i) # all other args parsed as strings else: msg.add(i) Client().send(msg)
def execute(self, context): # open new blendfinle in blender and the the gameengine bpy.ops.wm.open_mainfile(filepath=self.filepath) Client().send(Message("/bge/logic/startGame", self.filepath)) # reconnect server = context.window_manager.blive_settings.server port = context.window_manager.blive_settings.port Client().connect(server, port) return {'FINISHED'}
def update_projectionmatrix(self, camera): data = camera.data # operators seems much slower, we add a classmedthod to call the code directly for internal use (see handler.py) bundle = Bundle() e = 1.0/math.tan(data.angle/2.0) a = bpy.context.scene.game_settings.resolution_y/bpy.context.scene.game_settings.resolution_x n = data.clip_start f = data.clip_end msg_matrix = Message('/bge/scene/cameras/projection_matrix') msg_matrix.add(camera.name, e, 0.0, 2.0*data.shift_x, 0.0, 0.0, e/a, 2.0*data.shift_y/a, 0.0, 0.0, 0.0, (f+n)/(n-f), (2*f*n)/(n-f), 0.0, 0.0, -1.0, 0.0 ) perspective = 1 if data.type == 'ORTHO': perspective = 0 msg_persp = Message('/bge/scene/cameras/perspective') msg_persp.add(camera.name, perspective) bundle.add(msg_persp) bundle.add(msg_matrix) Client().send(bundle)
def _method_reply(cls, path, source, target, data): msg = Message(path) if target: msg.add(*target) if data: msg.add(*data) bge.logic.server.send(source.url, msg)
def object_update_handler(scene): # check objects updates for ob in scene.objects: if ob.is_updated: bundle = Bundle() bundle.add( Message("/bge/scene/objects/position", ob.name, ob.location[0], ob.location[1], ob.location[2])) bundle.add( Message("/bge/scene/objects/orientation", ob.name, ob.rotation_euler[0], ob.rotation_euler[1], ob.rotation_euler[2])) if ob.type in {'MESH', 'FONT'}: bundle.add( Message("/bge/scene/objects/scaling", ob.name, ob.scale[0], ob.scale[1], ob.scale[2])) Client().send(bundle) if ob.is_updated_data: if ob.type == 'CAMERA': ops.BLive_OT_osc_camera_projectionmatrix.update_projectionmatrix( ob) elif ob.type == 'LAMP': ops.BLive_OT_osc_object_lamp.update_lamp(ob) elif ob.type == 'MESH' and ob.mode == 'EDIT': ops.BLive_OT_osc_object_meshdata.update_mesh(ob) # workaround for object color for i in ob.material_slots: if ob.type in {'MESH', 'FONT'} and len( bpy.data.materials) and bpy.data.materials[ i.name].use_object_color: Client().send( Message("/bge/scene/objects/color", ob.name, ob.color[0], ob.color[1], ob.color[2], ob.color[3]))
def execute(self, context): debug = context.window_manager.blive_debug # test if first arg contains '/' (path) if debug.message.split(' ')[0].count('/'): msg = Message(debug.message.split(' ')[0]) for i in debug.message.split(' ')[1:]: # digits are ints if i.isdigit(): msg.add(int(i)) # try convert args with '.' to float otherwise stays string elif i.count('.') == 1: try: msg.add(float(i)) except ValueError: msg.add(i) # all other args parsed as strings else: msg.add(i) Client().send(msg) return {'FINISHED'} else: return {'CANCELLED'}
def execute(self, context): debug = context.window_manager.blive_debug # test if first arg contains '/' (path) if debug.message.split(' ')[0].count('/'): msg = Message(debug.message.split(' ')[0]) for i in debug.message.split(' ')[1:]: # digits are ints if i.isdigit(): msg.add(int(i)) # try convert args with '.' to float otherwise stays string elif i.count('.') == 1: try: msg.add(float(i)) except ValueError: msg.add(i) # all other args parsed as strings else: msg.add(i) Client().send(msg) return{'FINISHED'} else: return{'CANCELLED'}
def _send_sparseOutput_vec(self, output, timestamp, name): """Send pipeline outputs through the LSL or OSC stream. Args: output (scalar): output of the pipeline timestamp (float): timestamp """ for out in self._sparseOutput_threads: if isinstance(out, str): # LSL outlet self._outlet.push_sample([output], timestamp=timestamp) else: # OSC output stream if USE_LIBLO: new_output = [('f', x) for x in output[0, :]] message = Message('/{}'.format(name), *new_output) #send(out, Bundle(timestamp, message)) send(out, message) if self.verbose: print('sparseOutput: {}'.format(output))
def _reply(cls, typehandler, path, args, types, source, user_data): try: obj, attr = cls._get_instance(path, args) data = typehandler.get(obj, attr) target = cls._parse_instance(args) msg = Message(path) if target: msg.add(*target) if data: msg.add(*data) bge.logic.server.send(source.url, msg) except BLiveError as err: bge.logic.server.send(source.url, "/bge/error", err.reason, source.url)
def execute(self, context): Client().send( Message("/bge/logic/media/enableLoop", self.imgname, int(self.loop))) return {'FINISHED'}
def execute(self): m = Message("/bge/logic/media/openCamera", self.object, self.image, self.filepath, self.width, self.height, self.deinterlace, self.rate) Client().send(m)
def _send_bands(self, output, timestamp, names): for out in self._output_threads: for i in range(5): new_output = [('f', output[i])] message = Message('/{}'.format(names[i]), *new_output) send(out, message)
def execute(self): if self.object in bpy.context.scene.objects: bpy.context.scene.objects[self.object].hide = not self.visible Client().send( Message("/bge/scene/objects/visible", self.object, int(self.visible)))
def execute(self): m = Message("/bge/logic/media/openMovie", self.object, self.image, self.filepath, int(self.audio), self.inp, self.outp, int(self.loop), self.preseek, int(self.deinterlace)) Client().send(m)
def _send_float(self, output, timestamp, name): for out in self._output_threads: new_output = [('f', output)] message = Message('/{}'.format(name), *new_output) send(out, message)
def execute(self): Client().send( Message("/bge/scene/objects/playAction", self.object, self.action, self.start, self.end, self.layer))
def execute(self, context): Client().send( Message("/bge/logic/media/deinterlace", self.imgname, int(self.deinterlace))) return {'FINISHED'}
def execute(self): # change scene in blender too if self.scene in bpy.data.scenes: bpy.context.screen.scene = bpy.data.scenes[self.scene] Client().send(Message("/bge/scene/replace", self.scene))
def execute(self, context): Client().send(Message("/bge/logic/media/stop", self.imgname)) return {'FINISHED'}
def _send_output(self, output, timestamp, name): for out in self._output_threads: if (np.array(output).size == 1): new_output = [('f', np.asscalar(output))] message = Message('/{}'.format(name), *new_output) send(out, message)
def execute(self, context): Client().send( Message("/bge/logic/media/audioVolume", self.imgname, self.volume)) return {'FINISHED'}
def execute(self, context): Client().send( Message("/bge/logic/media/setRange", self.imgname, self.inp, self.outp)) return {'FINISHED'}
def _send_output_vec(self, output, timestamp, name): for out in self._output_threads: new_output = [('f', x) for x in output[0, :]] message = Message('/{}'.format(name), *new_output) send(out, message)