My version of Panda3D Hello, World


#1

This is my version of the Panda3D Hello, World Tutorial


from math import pi, sin, cos

from panda3d.core import Point3

from direct.showbase.ShowBase import ShowBase
from direct.interval.LerpInterval import LerpTexOffsetInterval
from direct.actor import Actor
from direct.task import Task
from direct.interval.IntervalGlobal import Sequence

from pandac.PandaModules import *
from pandac.PandaModules import Material
from pandac.PandaModules import VBase4

class MyApp(ShowBase):
 
    def __init__(self):
        ShowBase.__init__(self)
        
        # Show Frame Rate Meter
        base.setFrameRateMeter(True)

        # Setup Antialiasing
        render.setAntialias(AntialiasAttrib.MAuto)

        # Load Audio
        music = base.loader.loadSfx("audio/music.wav")
        music.play()

        wind = base.loader.loadSfx("audio/wind.wav")
        wind.setLoop(True)
        wind.play()

        # Create Water Material
        waterMaterial = Material()
        waterMaterial.setShininess(50.0)
        waterMaterial.setAmbient(VBase4(0,0,1,1))

        # Load Plane Mesh/Texture/Animate
        water = loader.loadModel('models/mesh_plane/plane.bam')
        water.setScale(500, 500, 500)
        water.setMaterial(waterMaterial)
        newTS = TextureStage('1')
        water.setTexture(newTS,loader.loadTexture('textures/water.png'))
        water.setTexScale(newTS,2)
        water.reparentTo(render)

        LerpTexOffsetInterval(water, 200, (1,0),(0,0), textureStage=newTS).loop()
        
        # Load Ship Mesh
        ship = loader.loadModel("models/mesh_ship/ship.bam")
        ship.setScale(1, 1, 1)
        ship.setPos(0, 0, 1)
        ship.setTwoSided(True)
        ship.reparentTo(render)

        # Load Pirate Mesh
        pirate = loader.loadModel("models/mesh_pirate/pirate")
        pirate.reparentTo(ship)
        pirate.setScale(0.200, 0.200, 0.200)
        pirate.setPos(0, 0, -0.970)
        pirateTex = loader.loadTexture("models/mesh_pirate/pirate.png")
        pirate.setTexture(pirateTex, 1)

        # Load Rock Mesh
        rock = loader.loadModel("models/mesh_rock/rock.bam")
        rock.setPos(30, 30, 6.600)
        rock.setScale(8, 8, 4)
        rock.reparentTo(render)

        # Load Tree Mesh/Reparent To Rock
        tree = loader.loadModel("models/mesh_palmtree/palmtree.bam")
        tree.setScale(0.200, 0.200, 0.200)
        tree.setPos(0, 0, 1.700)
        tree.setTwoSided(True)
        tree.reparentTo(rock)

        # Setup Fog
        fog = Fog("Fog")
        fog.setColor(0, 0, 0)
        fog.setExpDensity(0.01)
        fog.setLinearRange(0,400)
        fog.setLinearFallback(400, 400, 400)
        render.setFog(fog)

        # Create the four lerp intervals needed for the ship to
        # sail back and forth.
        shipPosInterval1 = ship.posInterval(30, Point3(0, -10, 1), startPos=Point3(0, 10, 1))
        shipPosInterval2 = ship.posInterval(30, Point3(0, 10, 1), startPos=Point3(0, -10, 1))
        shipHprInterval1 = ship.hprInterval(3, Point3(180, 0, 1), startHpr=Point3(0, 0, 1))
        shipHprInterval2 = ship.hprInterval(3, Point3(0, 0, 1), startHpr=Point3(180, 0, 1))
 
        # Create and play the sequence that coordinates the intervals.
        shipPace = Sequence(shipPosInterval1,
                            shipHprInterval1,
                            shipPosInterval2,
                            shipHprInterval2,
                            name="shipPace")
        shipPace.loop()

app = MyApp()
app.run()

Download


#2

no reply after more than one year. for me it look great. just like what i am looking for. not try yet actually.


#3

Oh, I can’t believe I missed this. That looks great! It could definitely use some lighting, though.


#4

Thanks for the comments, :slight_smile:. That was my first try at panda.

My work looks like this now. And will be my new Hello, World example.

Im going to make the MolesKeep larger and add in a stage for animal musicians to play this song http://zester.googlecode.com/files/01-SaReGaMa-St%20Patrick%20Day%20-%20Lord%20Mayo.mp3 in the background.