Ejemplo n.º 1
0
class ToontownFogManager:
    def __init__(self):
        self.fog = None
        self.fogMode = None
        print("Initialized Fog Manager")

        self.fog = Fog("ActiveFog")
        self.fog.setColor(1, 1, 1)

        self.fogTypes = {
            0: Fog.MExponential,
            1: Fog.MExponentialSquared,
            2: Fog.MLinear
        }

    def setFog(self, np):
        np.setFog(self.fog)

    def setColor(self, r, g, b):
        self.fog.setColor(r, g, b)

    def clearFog(self):
        return render.clearFog()

    def getFogMode(self):
        self.fogMode = self.fog.getMode()

    def setFogMode(self, id):
        mode = self.fog.setMode(self.fogTypes[id])
        self.fogMode = mode

    ## For Exponential Fog

    def setDensity(self, density):
        """
        Determines the density value used for exponential fog calculations.

        :param float density: A value between [0, 1]
        """
        self.fog.setExpDensity(density)

    ## For Linear Fog

    def setLinearRange(self, range, opacity):
        """
        Specifies the effects of the fog in linear distance units. This is only used if the mode is M_linear.

        This specifies a fog that begins at distance onset units from the origin, and becomes totally opaque at distance
        <opaque units> from the origin, along the forward axis (usually Y).

        This function also implicitly sets the mode the M_linear, if it is not already set.

        :param float opacity: [0, 1]
        """
        self.fog.setLinearRange(range, opacity)

    def setLinearFallback(self, angle, onset, opaque):
        """
        :param float angle: the minimum viewing angle (angle between the camera direction and fog direction) at which
         the fallback effect will be employed.
        :type onset: float
        :param float opaque: [0, 1]

        Defines how the fog should be rendered when the fog effect is diminished in this way.

        Onset and opaque specify camera-relative onset and opaque distances that will be fallen back on, overriding the
        Fog node's own onset and opaque distances.

        The linear fallback workaround will only look good in certain situations, for example when the fog is deep inside a dark cave.

        So in general, exponential mode fog is more useful than the default linear mode fog.
        """
        self.fog.setLinearFallback(angle, onset, opaque)