demo_video.py :  » Game-2D-3D » Ogre3d-Python-bindings » demos » ogrevideo » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Game 2D 3D » Ogre3d Python bindings 
Ogre3d Python bindings » demos » ogrevideo » demo_video.py
# This code is in the Public Domain
# -----------------------------------------------------------------------------
# This source file is part of Python-ogre
# For the latest info, see http://python-worg/
#
# It is likely based on original code from OGRE and/or Pyogre
# For the latest info, see http://www.ogre3d.org/
#
# You may use this sample code for anything you like, it is not covered by the
# LGPL.
# -----------------------------------------------------------------------------
import sys
sys.path.insert(0,'..')
#import PythonOgreConfig
import ctypes
import os

if sys.platform == 'win32':
    newpath = os.path.abspath(os.path.join ( os.path.abspath(os.path.dirname(__file__)), '../../plugins'))
    os.environ['PATH'] =  newpath +';' + os.environ['PATH']

import ogre.renderer.OGRE as ogre
import ogre.addons.ogrevideo as theora
import SampleFramework as sf
import sys

demo = "Single" ## "Multiple" or "Cube"
# demo = "Multiple"
# demo = "Cube"
VIDEO_FILE = "konqi.ogg"

def getClip(name):
   mgr = theora.TheoraVideoManager.getSingleton()
   if mgr:
      return mgr.getVideoClipByName(name)
   else:
      raise RuntimeError, "issue"
      return None
      

class VideoApplication(sf.Application):

    def _loadResources( self ):
      if demo == "Single":  # only do audio if it's a single video stream...
           pass

      sf.Application._loadResources ( self ) #ogre.ResourceGroupManager.getSingleton().initialiseAllResourceGroups()

    def createQuad(self, name,material_name,left,top,right, bottom):
      model = self.sceneManager.createManualObject(name)
      model.begin(material_name)
      model.position(right,bottom,0)
      model.textureCoord(1,1)
      model.position(right,top   ,0)
      model.textureCoord(1,0)
      model.position(left ,top   ,0)
      model.textureCoord(0,0)
      model.position(left ,top   ,0)
      model.textureCoord(0,0)
      model.position(right,bottom,0)
      model.textureCoord(1,1)
      model.position(left, bottom,0)
      model.textureCoord(0,1)
      model.end()
      # make the model 2D
      model.setUseIdentityProjection(True)
      model.setUseIdentityView(True)
      # and atach it to the root node
      node = self.sceneManager.getRootSceneNode().createChildSceneNode()
      node.attachObject(model)

      
    def _createScene(self):
         self.Clip=None
         sceneManager = self.sceneManager
         camera = self.camera

         if 0:
            if demo == "Single":
               ## create one quad, to minimize rendering time inpact on benchmarking
               model = sceneManager.createManualObject("quad")
               model.begin("video_material")
               model.position( 1,-1,0)
               model.textureCoord(1,1)
               model.position( 1,1,0)
               model.textureCoord(1,0)
               model.position(-1,1,0)
               model.textureCoord(0,0)
               model.position(-1,1,0)
               model.textureCoord(0,0)
               model.position( 1,-1,0)
               model.textureCoord(1,1)
               model.position(-1,-1,0)
               model.textureCoord(0,1)
               model.end()
               model.setUseIdentityProjection(True)
               model.setUseIdentityView(True)
               node = sceneManager.getRootSceneNode().createChildSceneNode()
               node.attachObject(model)


            if demo == "Multiple": ## multiple videos
               ## this is for 4 concurrent videos...
               left=[ -1, 0.01,    -1,  0.01]
               top=[1,    1, -0.01, -0.01]
               right=[-0.01,    1, -0.01,     1]
               bottom=[0.01, 0.01,    -1,    -1]

               materials=["konqi","fedora01","fedora02","fedora03"]
               for i in range ( 4):
                  model = sceneManager.createManualObject("quad"+str(i))
                  model.begin(materials[i])
                  model.position( right[i],bottom[i],0)
                  model.textureCoord(1,1)
                  model.position( right[i],top[i],0)
                  model.textureCoord(1,0)
                  model.position(left[i],top[i],0)
                  model.textureCoord(0,0)
                  model.position(left[i],top[i],0)
                  model.textureCoord(0,0)
                  model.position( right[i],bottom[i],0)
                  model.textureCoord(1,1)
                  model.position(left[i],bottom[i],0)
                  model.textureCoord(0,1)
                  model.end()
                  model.setUseIdentityProjection(True)
                  model.setUseIdentityView(True)
                  node = sceneManager.getRootSceneNode().createChildSceneNode()
                  node.attachObject(model)


            ## this is video on the sides of cube
            if demo == "Cube":
               c = sceneManager.createEntity("cube", "cube.mesh")
               c.setMaterialName("video_material")

               n = sceneManager.getRootSceneNode().createChildSceneNode()
               n.attachObject(c)
               scale = 4
               n.setScale(scale, scale, scale)
               n.setPosition(ogre.Vector3(0, 0,10))
               n.yaw(ogre.Degree(30))

         self.createQuad("video_quad","video_material",-0.5,1,1,-0.94)

         self.mAudioFactory=theora.OpenAL_AudioInterfaceFactory()
         mgr=theora.OgreVideoManager.getSingleton()
         mgr.setAudioInterfaceFactory(self.mAudioFactory)
         mgr.setInputName(VIDEO_FILE)
         mgr.createDefinedTexture("video_material")
         self.clip = getClip(VIDEO_FILE)
         self.clip.setAutoRestart(1)


    def _createFrameListener(self):
        self.frameListener = VideoListener(self.renderWindow, self.camera, self.Clip)
        self.root.addFrameListener(self.frameListener)

class VideoListener(sf.FrameListener):
   def __init__(self, renderWindow, camera, video):
      self.video = video
      sf.FrameListener.__init__(self, renderWindow, camera)

   def frameStarted(self, frameEvent):
      clip =  getClip(VIDEO_FILE)
      ret = sf.FrameListener.frameStarted(self, frameEvent)
      return ret

if __name__ == '__main__':
#     try:
        application = VideoApplication()
        application.go()
#     except OgreException, e:
#         print e
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.