def _setup_video_texture(self): """ Prepare this camera to use the VideoTexture module. Extract the references to the Blender camera and material where the images will be rendered. """ for child in self.blender_obj.children: # The camera object that will produce the image in Blender if 'CameraRobot' in child.name: camera = child # The object that contains the material where the image is rendered if 'CameraMesh' in child.name: screen = child # Considering it consists of a single mesh mesh = child.meshes[0] # Get the material name for material in mesh.materials: material_index = material.getMaterialIndex() mesh_material_name = mesh.getMaterialName(material_index) if 'MAScreenMat' in mesh_material_name: material_name = mesh_material_name try: logger.debug("\tCAMERA: %s" % camera.name) logger.debug("\tSCREEN: %s" % screen.name) logger.debug("\tMATERIAL: %s" % material_name) except UnboundLocalError as detail: logger.error(""" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ERROR: The video camera could not be properly initialized. The children object could not be found. Best solution is to re-link the camera. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! """) return (False) # Get the reference to the scene scene = GameLogic.getCurrentScene() # Link the objects using VideoTexture if not hasattr(GameLogic, 'cameras'): GameLogic.cameras = {} mat_id = VideoTexture.materialID(screen, material_name) GameLogic.cameras[self.name()] = VideoTexture.Texture(screen, mat_id) GameLogic.cameras[self.name()].source = \ VideoTexture.ImageRender(scene, camera) # Set the focal length of the camera using the Game Logic Property camera.lens = self.image_focal # Set the background to be used for the render GameLogic.cameras[self.name()].source.background = self.bg_color # Define an image size. It must be powers of two. Default 512 * 512 GameLogic.cameras[self.name()].source.capsize = \ [self.image_width, self.image_height] logger.info("Camera '{0}': Exporting an image of capsize: {1} pixels". \ format(self.name(), GameLogic.cameras[self.name()].source.capsize)) logger.info("\tFocal length of the camera is: %s" % camera.lens)
def init_video(video_obj, blank_obj): matID = VT.materialID(video_obj, 'MAvideo') G.video = VT.Texture(video_obj, matID) url = G.expandPath("//media/trailer_400p.ogg") video_source = VT.VideoFFmpeg(url) video_source.repeat = -1 video_source.scale = True video_source.flip = True G.video.source = video_source G.video_screen = video_obj G.video_blank = blank_obj G.video_screen.visible = False
def main(): cont = bge.logic.getCurrentController() obj = cont.owner novideo = cont.actuators["novideo"] try: import VideoTexture print('Playing video. Enjoy!') except: cont.activate(novideo) print('Video failed to play. :(') #if not hasattr(bge.logic, 'video'): matID = VideoTexture.materialID(obj, 'IMplaceholder.jpg') bge.logic.video = VideoTexture.Texture(obj, matID) movie = bge.logic.expandPath("//../textures/videos/team_aurora_intro.ogg") bge.logic.video.source = VideoTexture.VideoFFmpeg(movie) #bge.logic.video.source.scale = True bge.logic.video.source.play() print(movie)
def main(): cont = bge.logic.getCurrentController() obj = cont.owner novideo = cont.actuators["novideo"] try: import VideoTexture print ('Playing video. Enjoy!') except: cont.activate(novideo) print ('Video failed to play. :(') #if not hasattr(bge.logic, 'video'): matID = VideoTexture.materialID(obj, 'IMplaceholder.jpg') bge.logic.video = VideoTexture.Texture(obj, matID) movie = bge.logic.expandPath("//../textures/videos/sintel_game_intro.ogg") bge.logic.video.source = VideoTexture.VideoFFmpeg(movie) #bge.logic.video.source.scale = True bge.logic.video.source.play() print (movie)
# get video video = obj["Video"] # update the video video.refresh(True) #print scene.render.fps #print video.source.maxrate, video.source.minrate # if video hasn't been added else: # import VideoTexture module import VideoTexture # get matID for the movie screen matID = VideoTexture.materialID(obj, 'MAScreenZ') print (matID) # get the texture video = VideoTexture.Texture(obj, matID) movieName = obj['movie'] # get movie path movie = bge.logic.expandPath('//' + movieName) print(movie) # get movie video.source = VideoTexture.VideoFFmpeg(movie) # set scaling
# get the current controller controller = GameLogic.getCurrentController() # get object script is attached to obj = controller.owner # check to see video has been added if "Video" in obj: # # get video video = obj["Video"] # update the video video.refresh(True) # if video hasn't been added else: # # get matID for the movie screen matID = VideoTexture.materialID(obj, "MA" + obj['material']) # get the texture video = VideoTexture.Texture(obj, matID) movieName = obj['movie'] # get movie path movie = GameLogic.expandPath('c:/Movie/' + movieName) # get movie video.source = VideoTexture.VideoFFmpeg(movie) # set scaling video.source.scale = True
# get video video = obj["Video"] # update the video video.refresh(True) # if video hasn't been added else: # import VideoTexture module import VideoTexture # get matID for the movie screen matID = VideoTexture.materialID(obj, "MA" + obj['material']) # get the texture video = VideoTexture.Texture(obj, matID) movieName = obj['movie'] # get movie path movie = GameLogic.expandPath('//' + movieName) # get movie video.source = VideoTexture.VideoFFmpeg(movie) # set scaling video.source.scale = True
import VideoTexture import bge.logic contr = bge.logic.getCurrentController() obj = contr.owner # the creation of the texture must be done once: save the # texture object in an attribute of bge.logic module makes it persistent if not hasattr(bge.logic, 'video'): # identify a static texture by name matID = VideoTexture.materialID(obj, 'IMvideo.png') # create a dynamic texture that will replace the static texture bge.logic.video = VideoTexture.Texture(obj, matID) # define a source of image for the texture, here a movie movie = bge.logic.expandPath('//trailer_400p.ogg') bge.logic.video.source = VideoTexture.VideoFFmpeg(movie) bge.logic.video.source.scale = True # quick off the movie, but it wont play in the background bge.logic.video.source.play() # you need to call this function every frame to ensure update of the texture. bge.logic.video.refresh(True)
# Tutorial for using RenderToTexture.py can be found at www.tutorialsforblender3d.com # Released under the Creative Commons Attribution 3.0 Unported License. If you use this code, please include this information header. import GameLogic as g cont = g.getCurrentController() obj = cont.owner for scene in g.getSceneList(): if scene.name == "Main": break if "RenderToTexture" in obj: obj["RenderToTexture"].refresh(True) else: import VideoTexture cam = scene.objects[obj["camera"]] matID = VideoTexture.materialID(obj, "MA"+ obj["material"]) renderToTexture = VideoTexture.Texture(obj, matID) renderToTexture.source = VideoTexture.ImageRender(scene,cam) obj["RenderToTexture"] = renderToTexture
# Tutorial for using RenderToTexture.py can be found at www.tutorialsforblender3d.com # Released under the Creative Commons Attribution 3.0 Unported License. If you use this code, please include this information header. import GameLogic as g cont = g.getCurrentController() obj = cont.owner for scene in g.getSceneList(): if scene.name == "Main": break if "RenderToTexture" in obj: obj["RenderToTexture"].refresh(True) else: import VideoTexture cam = scene.objects[obj["camera"]] matID = VideoTexture.materialID(obj, "MA" + obj["material"]) renderToTexture = VideoTexture.Texture(obj, matID) renderToTexture.source = VideoTexture.ImageRender(scene, cam) obj["RenderToTexture"] = renderToTexture