📄 skeletonanimationdemo.py
字号:
import localogre as ogre
import sampleframework
NUM_ROBOTS = 10
class SkeletalApplication(sampleframework.Application):
def _createScene( self ):
sceneManager = self.sceneManager
camera = self.camera
ogre.Animation.setDefaultInterpolationMode( ogre.Animation.InterpolationMode.IM_SPLINE )
sceneManager.setAmbientLight( ogre.ColourValue( 0.5, 0.5, 0.5 ) )
global NUM_ROBOTS
self.animationStates = []
self.animationSpeeds = []
for index in xrange(0, NUM_ROBOTS):
entity = sceneManager.createEntity( 'robot%d' % index, 'robot.mesh' )
sceneManager.getRootSceneNode().createChildSceneNode(
ogre.Vector3(0, 0, index * 50 - NUM_ROBOTS * 50 / 2.0), ogre.Quaternion.IDENTITY ).attachObject( entity )
self.animationStates.append( entity.getAnimationState( 'Walk' ) )
self.animationStates[-1].setEnabled( True )
self.animationSpeeds.append( ogre.Math.RangeRandom( 0.5, 1.5 ) )
light = sceneManager.createLight( 'BlueLight' )
light.setPosition( -200, -80, -100 )
light.setDiffuseColour( 0.5, 0.5, 1.0 )
light = sceneManager.createLight( 'GreenLight' )
light.setPosition( 0, 0, -100 )
light.setDiffuseColour( 0.5, 1.0, 0.5 )
camera.setPosition( 100, 50, 100 )
camera.lookAt( -50, 50, 0 )
# Report whether hardware skinning is enabled or not
technique = entity.getSubEntity(0).getMaterial().getBestTechnique(0)
techniquePass = technique.getPass(0)
if techniquePass.hasVertexProgram() and techniquePass.getVertexProgram().isSkeletalAnimationIncluded():
self.renderWindow.setDebugText( 'Hardware skinning is enabled' )
else:
self.renderWindow.setDebugText( 'Software skinning is enabled' )
def _createFrameListener( self ):
self.frameListener = SkeletalAnimationFrameListener( self.renderWindow, self.camera,
self.animationStates, self.animationSpeeds )
self.root.addFrameListener( self.frameListener )
class SkeletalAnimationFrameListener(sampleframework.FrameListener):
def __init__( self, renderWindow, camera, animationStates, animationSpeeds ):
sampleframework.FrameListener.__init__( self, renderWindow, camera )
self.animationStates = animationStates
self.animationSpeeds = animationSpeeds
def frameStarted( self, frameEvent ):
for index in xrange(0,len(self.animationStates)):
self.animationStates[index].addTime( frameEvent.timeSinceLastFrame * self.animationSpeeds[index] )
return sampleframework.FrameListener.frameStarted( self, frameEvent )
if __name__ == '__main__':
application = SkeletalApplication()
application.go()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -