Esempio n. 1
0
    def __init__(self):
        ShowBase.__init__(self)
        self.loader.destroy()
        self.loader = CogInvasionLoader(self)
        builtins.loader = self.loader
        self.graphicsEngine.setDefaultLoader(self.loader.loader)

        self.makeAllPipes()

        from panda3d.core import RenderAttribRegistry
        from panda3d.core import ShaderAttrib, TransparencyAttrib
        from panda3d.bsp import BSPMaterialAttrib
        attribRegistry = RenderAttribRegistry.getGlobalPtr()
        attribRegistry.setSlotSort(BSPMaterialAttrib.getClassSlot(), 0)
        attribRegistry.setSlotSort(ShaderAttrib.getClassSlot(), 1)
        attribRegistry.setSlotSort(TransparencyAttrib.getClassSlot(), 2)

        self.bloomToggle = False
        self.hdrToggle = False
        self.fxaaToggle = CIGlobals.getSettingsMgr().getSetting("aa").getValue() == "FXAA"
        self.aoToggle = False

        # Initialized in initStuff()
        self.shaderGenerator = None

        self.initialize()
def setBSPMaterial(self, mat, override=0):
    try:
        from panda3d.bsp import BSPMaterialAttrib, BSPMaterial
    except:
        raise ImportError("BSP library needed for setBSPMaterial()")
    if isinstance(mat, str):
        mat = BSPMaterial.getFromFile(mat)
    self.setAttrib(BSPMaterialAttrib.make(mat), override)
Esempio n. 3
0
 def setMaterial(self, mat):
     self.material.material = mat
     if mat:
         self.state3D = self.state3D.setAttrib(BSPMaterialAttrib.make(mat.material))
         if mat.material.hasKeyvalue("$translucent") and bool(int(mat.material.getKeyvalue("$translucent"))):
             self.state3D = self.state3D.setAttrib(TransparencyAttrib.make(TransparencyAttrib.MDual))
         if self.geom3D:
             self.solid.setFaceGeomState(self.geom3D, self.state3D)
Esempio n. 4
0
def makeOverrideShader(nodepath, overrideShader):
    """ Tries to apply an override shader to the specified nodepath/geometry. """

    try:
        nodepath.setAttrib(
            BSPMaterialAttrib.makeOverrideShader(overrideShader))
    except:
        nodeName = "N/A"
        matName = "N/A"

        try:
            nodeName = nodepath.getName()
        except:
            pass

        try:
            matName = str(overrideShader)
        except:
            pass

        notify.warning(
            'Failed to apply shader to {0} with Material file called: {1}'.
            format(nodeName, matName))
Esempio n. 5
0
def makeBulletCollFromGeoms(rootNode,
                            exclusions=[],
                            enableNow=True,
                            world=None):
    """
    Creates and attaches bullet triangle mesh nodes underneath each GeomNode
    of `rootNode`, which contains the same mesh as the Geoms.
    This can be expensive if the geometry contains lots of triangles or GeomNodes.
    """

    if not world:
        world = base.physicsWorld

    # BulletRigidBodyNode -> triangle index -> surfaceprop
    # (it's so we know which surface we are walking on)
    result = {}

    for faceNp in rootNode.findAllMatches("**"):
        if faceNp.getName() in exclusions:
            continue
        if faceNp.node().getType() != GeomNode.getClassType():
            continue

        # Create a separate list of geoms for each possible face type
        # ( a wall or floor )
        type2geoms = {}
        for i in xrange(faceNp.node().getNumGeoms()):
            geom = faceNp.node().getGeom(i)
            state = faceNp.node().getGeomState(i)
            if not geom.getPrimitive(0).isIndexed():
                continue
            if state.hasAttrib(BSPFaceAttrib.getClassSlot()):
                bca = state.getAttrib(BSPFaceAttrib.getClassSlot())
                facetype = bca.getFaceType()
            else:
                facetype = BSPFaceAttrib.FACETYPE_WALL

            if not type2geoms.has_key(facetype):
                type2geoms[facetype] = [(geom, state)]
            else:
                type2geoms[facetype].append((geom, state))

        # Now create a separate body node to group each face type,
        # and assign the correct bit
        for facetype, geoms in type2geoms.items():
            data = {}
            numGeoms = 0
            mesh = BulletTriangleMesh()
            for i in xrange(len(geoms)):
                geom, state = geoms[i]
                mesh.addGeom(geom, True)
                surfaceprop = "default"
                if state.hasAttrib(BSPMaterialAttrib.getClassSlot()):
                    mat = state.getAttrib(
                        BSPMaterialAttrib.getClassSlot()).getMaterial()
                    if mat:
                        surfaceprop = mat.getSurfaceProp()
                for j in xrange(geom.getNumPrimitives()):
                    prim = geom.getPrimitive(j)
                    prim = prim.decompose()
                    tris = prim.getNumVertices() / 3
                    for tidx in xrange(tris):
                        data[numGeoms] = surfaceprop
                        numGeoms += 1
            shape = BulletTriangleMeshShape(mesh, False)
            rbnode = BulletRigidBodyNode(faceNp.getName() + "_bullet_type" +
                                         str(facetype))
            rbnode.setKinematic(True)
            rbnode.addShape(shape)
            rbnodeNp = NodePath(rbnode)
            rbnodeNp.reparentTo(faceNp)
            if facetype == BSPFaceAttrib.FACETYPE_WALL:
                rbnodeNp.setCollideMask(CIGlobals.WallGroup)
            elif facetype == BSPFaceAttrib.FACETYPE_FLOOR:
                rbnodeNp.setCollideMask(CIGlobals.FloorGroup)
            if enableNow:
                world.attachRigidBody(rbnode)
            result[rbnode] = data

    return result
Esempio n. 6
0
    def __init__(self, *args, **kwargs):
        ShowBase.__init__(self, *args, **kwargs)

        from panda3d.core import RenderAttribRegistry
        from panda3d.core import ShaderAttrib, TransparencyAttrib
        from panda3d.bsp import BSPMaterialAttrib
        attribRegistry = RenderAttribRegistry.getGlobalPtr()
        attribRegistry.setSlotSort(BSPMaterialAttrib.getClassSlot(), 0)
        attribRegistry.setSlotSort(ShaderAttrib.getClassSlot(), 1)
        attribRegistry.setSlotSort(TransparencyAttrib.getClassSlot(), 2)

        gsg = self.win.getGsg()

        # Let's print out the Graphics information.
        self.notify.info(
            'Graphics Information:\n\tVendor: {0}\n\tRenderer: {1}\n'
            '\tVersion: {2}\n\tSupports Cube Maps: {3}\n'
            '\tSupports 3D Textures: {4}\n\tSupports Compute Shaders: {5}'.
            format(gsg.getDriverVendor(), gsg.getDriverRenderer(),
                   gsg.getDriverVersion(), str(gsg.getSupportsCubeMap()),
                   str(gsg.getSupports3dTexture()),
                   str(gsg.getSupportsComputeShaders())))

        # Enable shader generation on all of the main scenes
        if gsg.getSupportsBasicShaders() and gsg.getSupportsGlsl():
            self.render.setShaderAuto()
            self.render2d.setShaderAuto()
            self.render2dp.setShaderAuto()
            self.aspect2d.setShaderAuto()
            self.pixel2d.setShaderAuto()
        else:
            # I don't know how this could be possible
            self.notify.error("GLSL shaders unsupported by graphics driver.")
            return

        self.camNode.setCameraMask(CAMERA_MAIN)

        # Any ComputeNodes should be parented to this node, not render.
        # We isolate ComputeNodes to avoid traversing the same ComputeNodes
        # when doing multi-pass rendering.
        self.computeRoot = NodePath('computeRoot')
        self.computeCam = self.makeCamera(self.win)
        self.computeCam.node().setCameraMask(CAMERA_COMPUTE)
        self.computeCam.node().setCullBounds(OmniBoundingVolume())
        self.computeCam.node().setFinal(True)
        self.computeCam.reparentTo(self.computeRoot)

        self.bspLoader = None
        self.bspLevel = None
        self.brushCollisionMaterialData = {}
        self.createBSPLoader()

        self.audio3d = None
        self.create3DAudio()

        # Initialized in createShaderGenerator()
        self.shaderGenerator = None

        # Initialized in createPostProcess()
        self.filters = None

        self.render.show(CAMERA_SHADOW)
        self.render.setAttrib(LightRampAttrib.makeIdentity())