PyOgre Tutorial3

CellShading Demo con PyOgre (l'esempio si trova nella cartella example di pyogre)

http://www.ogre3d.org/wiki/index.php/Image:Pyogre3.JPG

   1 # This code is in the Public Domain
   2 import pyogre.ogre as ogre
   3 import SampleFramework as sf
   4 # Custom parameter bindings
   5 CUSTOM_SHININESS = 1
   6 CUSTOM_DIFFUSE = 2
   7 CUSTOM_SPECULAR = 3
   8 
   9 class CelShadingApplication(sf.Application):
  10    def _createScene(self):
  11        sceneManager = self.sceneManager
  12        capabilities = ogre.Root.getSingleton().renderSystem.capabilities
  13        if not capabilities.hasCapability(ogre.RSC_VERTEX_PROGRAM) or not capabilities.hasCapability(ogre.RSC_FRAGMENT_PROGRAM):
  14            raise ogre.Exception(111, 'Your card does not support vertex and fragment programs, so cannot run this demo. Sorry!', 'celshadingdemo.py')
  15        # Accept default settings: point light, white diffuse, just set position
  16        light = sceneManager.createLight('MainLight')
  17        self.rotationNode = sceneManager.rootSceneNode.createChildSceneNode()
  18        self.rotationNode.createChildSceneNode((20,40,50)).attachObject(light)
  19        # create head entity
  20        entity = sceneManager.createEntity('head', 'ogrehead.mesh')
  21        self.camera.position = (20, 0, 100)
  22        self.camera.lookAt(0, 0, 0)
  23        # eyes
  24        sub = entity.getSubEntity(0)
  25        sub.materialName = 'Examples/CelShading'
  26        sub.setCustomParameter(CUSTOM_SHININESS, (35.0, 0.0, 0.0, 0.0))
  27        sub.setCustomParameter(CUSTOM_DIFFUSE, (1.0, 0.3, 0.3, 1.0))
  28        sub.setCustomParameter(CUSTOM_SPECULAR, (1.0, 0.6, 0.6, 1.0))
  29        # skin
  30        sub = entity.getSubEntity(1)
  31        sub.materialName = 'Examples/CelShading'
  32        sub.setCustomParameter(CUSTOM_SHININESS, (10.0, 0.0, 0.0, 0.0))
  33        sub.setCustomParameter(CUSTOM_DIFFUSE, (0.0, 0.5, 0.0, 1.0))
  34        sub.setCustomParameter(CUSTOM_SPECULAR, (0.3, 0.5, 0.3, 1.0))
  35        # earring
  36        sub = entity.getSubEntity(2)
  37        sub.materialName = 'Examples/CelShading'
  38        sub.setCustomParameter(CUSTOM_SHININESS, (25.0, 0.0, 0.0, 0.0))
  39        sub.setCustomParameter(CUSTOM_DIFFUSE, (1.0, 1.0, 0.0, 1.0))
  40        sub.setCustomParameter(CUSTOM_SPECULAR, (1.0, 1.0, 0.7, 1.0))
  41        # teeth
  42        sub = entity.getSubEntity(3)
  43        sub.materialName = 'Examples/CelShading'
  44        sub.setCustomParameter(CUSTOM_SHININESS, (20.0, 0.0, 0.0, 0.0))
  45        sub.setCustomParameter(CUSTOM_DIFFUSE, (1.0, 1.0, 0.7, 1.0))
  46        sub.setCustomParameter(CUSTOM_SPECULAR, (1.0, 1.0, 1.0, 1.0))
  47        sceneManager.rootSceneNode.createChildSceneNode().attachObject(entity)
  48        self.renderWindow.getViewport(0).backgroundColour = (1, 1, 1)
  49    def _createFrameListener(self):
  50        self.frameListener = CelShadingListener(self.renderWindow, self.camera, self.rotationNode)
  51        self.root.addFrameListener(self.frameListener)
  52 class CelShadingListener(sf.FrameListener):
  53    def __init__(self, renderWindow, camera, rotationNode):
  54        sf.FrameListener.__init__(self, renderWindow, camera)
  55        self.rotationNode = rotationNode
  56    def frameStarted(self, frameEvent):
  57        self.rotationNode.yaw(ogre.Radian(ogre.Degree(frameEvent.timeSinceLastFrame * 30)))
  58        return sf.FrameListener.frameStarted(self, frameEvent)
  59 
  60 if __name__ == '__main__':
  61    application = CelShadingApplication()
  62    application.go()


Torna alla pagina precedente (Pagina2), Vai alla pagina successiva (Pagina4)

PyOgreTutorial


PyOgreTutorial/TutorialPag3 (last edited 2008-01-03 13:52:09 by IacoPy)