⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testogre.py

📁 使用stl技术,(还没看,是听说的)
💻 PY
字号:
import localogre as ogre
import sys

root = ogre.Root()

# setup resources
config = ogre.ConfigFile()
config.load( 'resources.cfg'  )
for key, path in config.getSettingsIterator():
    ogre.ResourceManager.addCommonArchiveEx( path, key )

#configure
carryOn = root.showConfigDialog()
if not carryOn:
    sys.exit('Quit from Config Dialog') 

renderWindow = root.initialise( True )

# chooseSceneManager
sceneManager = root.getSceneManager( ogre.SceneType.ST_GENERIC )

# createCamera
camera = sceneManager.createCamera( 'PlayerCam' )
camera.setPosition( ogre.Vector3( 0, 0, 500 ) )
camera.lookAt( ogre.Vector3( 0, 0, -300 ) )
camera.setNearClipDistance( 5 )

# createViewports
viewport = renderWindow.addViewport( camera, 0, 0.0, 0.0, 1.0, 1.0 )
#viewport = renderWindow.addViewport( camera )
viewport.setBackgroundColour( ogre.ColourValue(0,0,0) )

# set mipmaps ignored...

# create scene
sceneManager.setAmbientLight( ogre.ColourValue(0.2,0.2,0.2) )
sceneManager.setSkyDome( True, 'Examples/CloudySky', 4.0, 8.0 )

light = sceneManager.createLight( 'MainLight' )
light.setPosition( 20, 80, 50 )

plane = ogre.Plane()
plane.normal = ogre.Vector3.UNIT_Y
plane.d = 200
planeSpecification = ogre.PlaneSpecification( plane, 200000.0, 200000.0 )
planeSpecification.setTesselation( 20, 20 )
planeSpecification.setTiling( 50.0, 50.0 )
planeSpecification.upVector = ogre.Vector3.UNIT_Z
ogre.MeshManager.getSingleton().createPlane( 'FloorPlane',
                                             planeSpecification )


##ogre.MeshManager.getSingleton().createPlane( 'FloorPlane',plane,
##                                                         200000.0,200000.0,
##                                                         20, 20,
##                                                         True,1,
##                                                         50.0,50.0,
##                                                         ogre.Vector3.UNIT_Z )  # hardware stuff parameters...
# create floor entity
entity = sceneManager.createEntity( 'floor', 'FloorPlane' )
entity.setMaterialName( 'Examples/RustySteel' )
sceneManager.getRootSceneNode().createChildSceneNode( ogre.Vector3.ZERO, ogre.Quaternion.IDENTITY ).attachObject( entity )

# create head entity
headNode = sceneManager.getRootSceneNode().createChildSceneNode( ogre.Vector3.ZERO, ogre.Quaternion.IDENTITY )
entity = sceneManager.createEntity( 'head', 'ogrehead.mesh' )
headNode.attachObject( entity )

# make sure the camera track this node
camera.setAutoTracking( True, headNode )

# create the camera node & attach camera
cameraNode = sceneManager.getRootSceneNode().createChildSceneNode( ogre.Vector3.ZERO, ogre.Quaternion.IDENTITY )
cameraNode.attachObject( camera )

# set up spline animation of node
animation = sceneManager.createAnimation( 'CameraTrack', 10 )
animation.setInterpolationMode( ogre.Animation.InterpolationMode.IM_SPLINE )
animationTrack = animation.createTrack( 0, cameraNode )
key = animationTrack.createKeyFrame( 0 )
key = animationTrack.createKeyFrame( 2.5 )
key.setTranslate( ogre.Vector3( 500.0, 500.0, -1000.0 ) )
key = animationTrack.createKeyFrame( 5 )
key.setTranslate( ogre.Vector3( -1500.0, -1500.0, -600.0 ) )
key = animationTrack.createKeyFrame( 7.5 )
key.setTranslate( ogre.Vector3( 0.0, -100.0, 0.0 ) )
key = animationTrack.createKeyFrame( 10.0 )
key.setTranslate( ogre.Vector3( 0.0, 0.0, 0.0 ) )
animationState = sceneManager.createAnimationState( 'CameraTrack' )
animationState.setEnabled( True )

# add some fog
sceneManager.setFog( ogre.FogMode.FOG_EXP, ogre.ColourValue.White, 0.0002 )


# main loop
class EscapeListener(ogre.FrameListener):
    def __init__( self, renderWindow, cameraAnimationState ):
        ogre.FrameListener.__init__( self ) # no default constructor...
        self.cameraAnimationState = cameraAnimationState
        self.inputDevice = ogre.PlatformManager.getSingleton().createInputReader()
        self.inputDevice.initialise( renderWindow, True, True, False ) #yuk

    def __del__(self): 
        ogre.PlatformManager.getSingleton().destroyInputReader( self.inputDevice ) 

    def frameStarted( self, frameEvent ):
        self.cameraAnimationState.addTime( frameEvent.timeSinceLastFrame )
        return ogre.FrameListener.frameStarted( self, frameEvent )

    def frameEnded(self, frameEvent): 
        self.inputDevice.capture()

        stopMainLoop = self.inputDevice.isKeyDown(ogre.KeyCode.KC_ESCAPE)
        if stopMainLoop:
            print 'Quitting, escape pressed...'
        return not stopMainLoop

listener = EscapeListener( renderWindow, animationState )
root.addFrameListener( listener )

root.startRendering()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -