示例#1
0
class World:
    def __init__(self):
        self.init_bullet()
        self.init_skybox()

    def init_bullet(self):
        self.bullet_world = BulletWorld()

    def update_bullet(self, task):
        dt = ClockObject.getGlobalClock().getDt()
        self.bullet_world.doPhysics(dt)
        return task.cont

    def init_skybox(self):
        # This should probably have its own class..
        self.sky_material = Material()
        self.sky_material.clearAmbient()
        self.sky_material.clearEmission()
        self.sky_material.setAmbient(VBase4(1, 1, 1, 1))

        # This loads "basic_skybox_#" # being 0-6
        # If the skybox was made in spacescape the files must be renamed to
        # work properly, and the 2 and 3 files should be switched.
        self.skybox_texture = loader.loadCubeMap("images/skybox/red_nebula_purple_flares/Red_nebula_#.png")

        # TODO: Figure out a way (if possible) to allow 3d objects to be seen
        # through the skysphere, It already kinda does this, but its weird.

        self.skybox = NodePath(loader.loadModel("models/skybox.x"))
        self.skybox.setLightOff()
        self.skybox.setAttrib(CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))
        # self.skybox.setTwoSided(True) BETTER ^
        self.skybox.setScale(5000)
        self.skybox.clearDepthWrite
        self.skybox.setDepthWrite(False)
        self.skybox.setMaterial(self.sky_material, 1)
        self.skybox.setTexture(self.skybox_texture)
        self.skybox.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldPosition)
        # This makes it so objects behind the skybox are rendered
        self.skybox.setBin("back_to_front", 40)
        # projects the texture as it looks from render
        self.skybox.setTexProjector(TextureStage.getDefault(), render, self.skybox)
        self.skybox.setCompass()
        self.skybox.reparentTo(base.camera)