Example #1
0
    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)
Example #2
0
    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'}
Example #3
0
    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)
Example #4
0
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]))
Example #5
0
def object_update_handler(scene):
	if scene.is_updated:
		print("Scene updated")

	# --- check objects updates
	for ob in scene.objects:
		if ob.is_updated:
			bundle = Bundle()
			bundle.add(Message("/scene/objects/position", ob.name, ob.location[0], ob.location[1], ob.location[2]))
			bundle.add(Message("/scene/objects/orientation", ob.name, ob.rotation_euler[0], ob.rotation_euler[1], ob.rotation_euler[2]))

			if ob.type == 'MESH':
				bundle.add(Message("/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':
				camera = ob.data
				#ops.osc_object_camera(camera)
			elif ob.type == 'LAMP':
				lamp = ob.data
				#ops.osc_object_lamp(lamp)
			elif ob.type == 'MESH' and ob.mode == 'EDIT':
				#ops.osc_object_meshdata(ob)
				pass
Example #6
0
    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'}
Example #7
0
    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)
Example #8
0
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]))
Example #9
0
    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)
Example #10
0
 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)
Example #11
0
 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)