Exemplo n.º 1
0
    def setup_scene(self):
        """Creates the scene to be rendered.
        Creates our camera, scene graph, 
        """
        # don't call 'SimpleApplication's setup_scene
        CoreApplication.setup_scene(self)

        # setup our GL state
        # enable z buffer
        glEnable(GL_DEPTH_TEST)

        # enable back face culling
        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)

        # load our texture
        # use the PIL decoder as the pyglet one is broken
        # and loads most images as greyscale
        path = os.path.join(os.path.dirname(__file__),
                            '../../data/md2/sydney.bmp')
        image = Image.open(path)
        self.texture = Texture2D(GL_TEXTURE_2D)
        self.texture.bind()
        self.texture.set_min_mag_filter(min=GL_LINEAR, mag=GL_LINEAR)
        # load the image from PIL
        # MD2 textures are inverted
        pygly.pil_texture.set_pil_image(self.texture, image, flip=False)
        self.texture.unbind()

        # create a grid of cubes
        self.grid_root = SceneNode('grid_root')
        self.scene_node.add_child(self.grid_root)

        # store a list of renderables
        path = os.path.join(os.path.dirname(__file__),
                            '../../data/md2/sydney.md2')

        self.mesh_node = RenderCallbackNode('mesh', None, self.render_node)
        # rotate the mesh to face the camera
        self.mesh_node.transform.object.rotate_y(math.pi)

        self.mesh_node.mesh = MD2_Mesh(path)
        self.mesh_node.mesh.load()

        # attach to our scene graph
        self.grid_root.add_child(self.mesh_node)

        # scale the node
        #self.mesh_node.transform.scale = 0.2

        # store current animation
        self.animation_number = 0
        self.set_animation(self.animation_number)
Exemplo n.º 2
0
    def setup_scene(self):
        """Creates the scene to be rendered.
        Creates our camera, scene graph, 
        """
        # don't call 'SimpleApplication's setup_scene
        CoreApplication.setup_scene(self)

        # setup our GL state
        # enable z buffer
        glEnable(GL_DEPTH_TEST)

        # enable back face culling
        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)

        # load our texture
        # use the PIL decoder as the pyglet one is broken
        # and loads most images as greyscale
        path = os.path.join(os.path.dirname(__file__), "../../data/md2/sydney.bmp")
        image = Image.open(path)
        self.texture = Texture2D(GL_TEXTURE_2D)
        self.texture.bind()
        self.texture.set_min_mag_filter(min=GL_LINEAR, mag=GL_LINEAR)
        # load the image from PIL
        # MD2 textures are inverted
        pygly.pil_texture.set_pil_image(self.texture, image, flip=False)
        self.texture.unbind()

        # create a grid of cubes
        self.grid_root = SceneNode("grid_root")
        self.scene_node.add_child(self.grid_root)

        # store a list of renderables
        path = os.path.join(os.path.dirname(__file__), "../../data/md2/sydney.md2")

        self.mesh_node = RenderCallbackNode("mesh", None, self.render_node)
        # rotate the mesh to face the camera
        self.mesh_node.transform.object.rotate_y(math.pi)

        self.mesh_node.mesh = MD2_Mesh(path)
        self.mesh_node.mesh.load()

        # attach to our scene graph
        self.grid_root.add_child(self.mesh_node)

        # scale the node
        # self.mesh_node.transform.scale = 0.2

        # store current animation
        self.animation_number = 0
        self.set_animation(self.animation_number)
Exemplo n.º 3
0
    def setup_scene( self ):
        """Creates the scene to be rendered.
        Creates our camera, scene graph, 
        """
        # don't call 'SimpleApplication's setup_scene
        CoreApplication.setup_scene( self )

        # setup our GL state
        # enable z buffer
        glEnable( GL_DEPTH_TEST )

        # enable back face culling
        glEnable( GL_CULL_FACE )
        glCullFace( GL_BACK )

        # create a grid of cubes
        self.grid_root = SceneNode( 'grid_root' )
        self.scene_node.add_child( self.grid_root )

        # store a list of renderables
        path = os.path.join(
            os.path.dirname( __file__ ),
            '../data/obj/capsule.obj'
            )

        self.mesh_node = RenderCallbackNode(
            'mesh',
            None,
            self.render_node
            )
        # rotate the mesh to face the camera
        self.mesh_node.transform.object.rotate_y( math.pi )

        self.mesh_node.mesh = OBJ_Mesh( path )
        self.mesh_node.mesh.load()

        # attach to our scene graph
        self.grid_root.add_child( self.mesh_node )

        # scale the node
        self.mesh_node.transform.scale = 1.0

        # create a list of groups to render
        # by default, render all groups
        # this may be in-efficient if data is contained in
        # multiple groups
        self.groups = self.mesh_node.mesh.data.meshes.keys()
Exemplo n.º 4
0
    def setup_scene(self):
        """Creates the scene to be rendered.
        Creates our camera, scene graph, 
        """
        # don't call 'SimpleApplication's setup_scene
        CoreApplication.setup_scene(self)

        # setup our GL state
        # enable z buffer
        glEnable(GL_DEPTH_TEST)

        # enable back face culling
        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)

        # create a grid of cubes
        self.grid_root = SceneNode('grid_root')
        self.scene_node.add_child(self.grid_root)

        # store a list of renderables
        path = os.path.join(os.path.dirname(__file__),
                            '../data/obj/capsule.obj')

        self.mesh_node = RenderCallbackNode('mesh', None, self.render_node)
        # rotate the mesh to face the camera
        self.mesh_node.transform.object.rotate_y(math.pi)

        self.mesh_node.mesh = OBJ_Mesh(path)
        self.mesh_node.mesh.load()

        # attach to our scene graph
        self.grid_root.add_child(self.mesh_node)

        # scale the node
        self.mesh_node.transform.scale = 1.0

        # create a list of groups to render
        # by default, render all groups
        # this may be in-efficient if data is contained in
        # multiple groups
        self.groups = self.mesh_node.mesh.data.meshes.keys()
Exemplo n.º 5
0
    def setup_scene( self ):
        """Creates the scene to be rendered.
        Creates our camera, scene graph, 
        """
        # don't call 'SimpleApplication's setup_scene
        CoreApplication.setup_scene( self )

        # setup our GL state
        # enable z buffer
        glEnable( GL_DEPTH_TEST )

        # enable back face culling
        #glEnable( GL_CULL_FACE )
        glDisable( GL_CULL_FACE )
        #glCullFace( GL_BACK )

        # create a grid of cubes
        self.grid_root = SceneNode( 'grid_root' )
        self.scene_node.add_child( self.grid_root )

        self.mesh_node = RenderCallbackNode(
            'mesh',
            None,
            self.render_node
            )
        # rotate the mesh to face the camera
        self.mesh_node.transform.object.rotate_x( -math.pi * 0.5 )

        # store a list of renderables
        mesh_path = os.path.join(
            os.path.dirname( __file__ ),
            '../data/md5/boblampclean.md5mesh'
            #'../data/md5/md5/cyberdemon/cyberdemon.md5mesh'
            )

        anim_path = os.path.join(
            os.path.dirname( __file__ ),
            '../data/md5/boblampclean.md5anim'
            #'../data/md5/md5/cyberdemon/idle.md5anim'
            )

        # load our md5 data
        self.md5mesh = MD5_Mesh()
        self.md5mesh.load( mesh_path )

        self.md5anim = MD5_Anim()
        self.md5anim.load( anim_path )

        # load the gl mesh
        self.mesh_node.mesh = Mesh( self.md5mesh )

        # load our bindpose
        self.mesh_node.baseframe = BaseFrameSkeleton( self.md5mesh )

        # load some test skeletons
        self.mesh_node.anim = Animation( self.md5anim )

        # set to base frame
        self.mesh_node.mesh.set_skeleton( self.mesh_node.baseframe )

        # load a skeleton renderer
        self.mesh_node.skeleton = SkeletonRenderer()
        #self.mesh_node.skeleton.set_skeleton( self.mesh_node.baseframe )
        self.mesh_node.skeleton.set_skeleton( self.mesh_node.anim.skeleton( 0 ) )

        # create a list of frames
        self.frames = [
            skeleton
            for skeleton in self.mesh_node.anim
            ]
        #self.frames = []
        self.frames.append( self.mesh_node.baseframe )

        self.frame = 0
        self.time_accumulator = 0.0
        self.time_per_frame = 1.0 / self.mesh_node.anim.frame_rate


        # attach to our scene graph
        self.grid_root.add_child( self.mesh_node )

        # scale the node
        self.mesh_node.transform.scale = 0.5
Exemplo n.º 6
0
    def setup_scene( self ):
        """Creates the scene to be rendered.
        Creates our camera, scene graph, 
        """
        # don't call 'SimpleApplication's setup_scene
        CoreApplication.setup_scene( self )

        # setup our GL state
        # enable z buffer
        glEnable( GL_DEPTH_TEST )

        # enable back face culling
        glEnable( GL_CULL_FACE )
        glCullFace( GL_BACK )

        # load our texture
        # use the PIL decoder as the pyglet one is broken
        # and loads most images as greyscale
        path = os.path.join(
            os.path.dirname( __file__ ),
            '../../data/md2/sydney.bmp'
            )
        image = Image.open( path )
        self.texture = Texture2D( GL_TEXTURE_2D )
        self.texture.bind()
        self.texture.set_min_mag_filter(
            min = GL_LINEAR,
            mag = GL_LINEAR
            )
        # load the image from PIL
        # MD2 textures are inverted
        pygly.pil_texture.set_pil_image( self.texture, image, flip = False )
        self.texture.unbind()

        # create a grid of cubes
        self.grid_root = SceneNode( 'grid_root' )
        self.scene_node.add_child( self.grid_root )

        # create a number of cubes
        # the grid will extend from -5 to +5
        x,z = numpy.mgrid[
            -5:5:11j,
            -5:5:11j
            ]
        x = x.flatten()
        z = z.flatten()

        positions = numpy.vstack(
            (x, numpy.zeros( x.shape ), z )
            )
        positions = positions.T

        # set the distance between the models
        positions *= 4.5

        # store a list of renderables
        self.renderables = []

        path = os.path.join(
            os.path.dirname( __file__ ),
            '../../data/md2/sydney.md2'
            )

        for position in positions:
            node = RenderCallbackNode(
                'node-%s' % position,
                None,
                self.render_node
                )
            node.mesh = MD2_Mesh( path )
            node.mesh.load()

            # attach to our scene graph
            self.grid_root.add_child( node )
            self.renderables.append( node )

            # move and scale the node
            node.transform.inertial.translation = position
            node.transform.scale = 0.2

        # create a range of animation times
        # 0.0 <= x < num_frames
        self.frames = numpy.linspace(
            0.0,
            float(self.renderables[ 0 ].mesh.num_frames),
            len(positions),
            endpoint = False
            )

        # create an array that will store our frame rates
        self.frame_rate = numpy.zeros( len(self.renderables), dtype = numpy.float )

        self.animation = ''
Exemplo n.º 7
0
    def setup_scene(self):
        """Creates the scene to be rendered.
        Creates our camera, scene graph, 
        """
        # don't call 'SimpleApplication's setup_scene
        CoreApplication.setup_scene(self)

        # setup our GL state
        # enable z buffer
        glEnable(GL_DEPTH_TEST)

        # enable back face culling
        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)

        # load our texture
        # use the PIL decoder as the pyglet one is broken
        # and loads most images as greyscale
        path = os.path.join(os.path.dirname(__file__),
                            '../../data/md2/sydney.bmp')
        image = Image.open(path)
        self.texture = Texture2D(GL_TEXTURE_2D)
        self.texture.bind()
        self.texture.set_min_mag_filter(min=GL_LINEAR, mag=GL_LINEAR)
        # load the image from PIL
        # MD2 textures are inverted
        pygly.pil_texture.set_pil_image(self.texture, image, flip=False)
        self.texture.unbind()

        # create a grid of cubes
        self.grid_root = SceneNode('grid_root')
        self.scene_node.add_child(self.grid_root)

        # create a number of cubes
        # the grid will extend from -5 to +5
        x, z = numpy.mgrid[-5:5:11j, -5:5:11j]
        x = x.flatten()
        z = z.flatten()

        positions = numpy.vstack((x, numpy.zeros(x.shape), z))
        positions = positions.T

        # set the distance between the models
        positions *= 4.5

        # store a list of renderables
        self.renderables = []

        path = os.path.join(os.path.dirname(__file__),
                            '../../data/md2/sydney.md2')

        for position in positions:
            node = RenderCallbackNode('node-%s' % position, None,
                                      self.render_node)
            node.mesh = MD2_Mesh(path)
            node.mesh.load()

            # attach to our scene graph
            self.grid_root.add_child(node)
            self.renderables.append(node)

            # move and scale the node
            node.transform.inertial.translation = position
            node.transform.scale = 0.2

        # create a range of animation times
        # 0.0 <= x < num_frames
        self.frames = numpy.linspace(0.0,
                                     float(
                                         self.renderables[0].mesh.num_frames),
                                     len(positions),
                                     endpoint=False)

        # create an array that will store our frame rates
        self.frame_rate = numpy.zeros(len(self.renderables), dtype=numpy.float)

        self.animation = ''