Esempio n. 1
0
    def startEffects(self):
        if not self.fireflies:
            self.fireflies = Fireflies()
        if self.fireflies:
            if hasattr(base, 'cr'):
                self.fireflies.reparentTo(base.localAvatar)
                self.fireflies.startLoop()
            base.ambientMgr.requestFadeIn(SoundGlobals.AMBIENT_JUNGLE, duration=10, finalVolume=PiratesGlobals.DEFAULT_AMBIENT_VOLUME, priority=1)
            self.swamp_water = None
            reflection = Reflection.getGlobalReflection()
            if 'jungle_a' in self.modelPrefix:
                water_color = base.config.GetBool('want-shaders', 1) and base.win and base.win.getGsg() and base.win.getGsg().getShaderModel() >= GraphicsStateGuardian.SM20 and Vec4(13, 15, 21, 255.0)
                self.water = Swamp(self.modelPrefix + 'water', self.parent, reflection, None, None, water_color)
                self.water.reflection_factor = 0.3
                self.water.set_reflection_parameters_np()
            else:
                water = loader.loadModel(self.modelPrefix + 'water')
                water.reparentTo(self.parent)
                color = Vec4(0)
                water.setColorScale(color)
                mask = 4294967295L
                stencil = StencilAttrib.make(1, StencilAttrib.SCFAlways, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOReplace, 1, mask, mask)
                water.setAttrib(stencil)
                water.setBin('water', 0)
                self.reflection = reflection
                taskMgr.add(self.camTask, 'jungleEffectsCamTask-' + str(id(self)), priority=49)
                water.setFogOff()
        for file in self.randomAnimalSoundFiles:
            sfx = loadSfx(file)
            self.randomSfx.append(sfx)

        taskMgr.doMethodLater(self.RANDOM_SOUND_PERIOD, self.checkForRandomSound, name='checkForRandomSound-' + str(id(self)))
        return
 def startEffects(self):
     reflection = Reflection.getGlobalReflection()
     non_shader_water_color = Vec4(0.0, 1.0 / 255.0, 4.0 / 255.0, 1.0)
     shader_water_color = Vec4(0.0, 1.0, 4.0, 255.0)
     if self.parent.uniqueId in self.WaterCaves:
         if base.config.GetBool('want-shaders', 1) and base.win and base.win.getGsg() and base.win.getGsg().getShaderModel() >= GraphicsStateGuardian.SM20:
             self.water = Swamp('models/caves/cave_a_water', self.parent, reflection, None, None, shader_water_color)
             self.water.reflection_factor = 0.3
             self.water.set_reflection_parameters_np()
         else:
             water = loader.loadModel('models/caves/cave_a_water')
             water.reparentTo(self.parent)
             color = non_shader_water_color
             water.setColorScale(color)
             water.setTextureOff(1)
             mask = 4294967295L
             stencil = StencilAttrib.make(1, StencilAttrib.SCFAlways, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOReplace, 1, mask, mask)
             water.setAttrib(stencil)
             water.setBin('water', 0)
             self.reflection = reflection
             taskMgr.add(self.camTask, 'caveEffectsCamTask-' + str(id(self)), priority=49)
             water.setFogOff()
     elif self.parent.uniqueId in self.LavaCaves:
         if base.config.GetBool('want-shaders', 1) and base.win and base.win.getGsg() and base.win.getGsg().getShaderModel() >= GraphicsStateGuardian.SM20:
             self.water = Swamp(self.modelPrefix + 'lava', self.parent, reflection, None, None, shader_water_color)
             l1 = LerpScaleInterval(self.water.seamodel, 2, Vec3(1.006, 1.006, 1.0), Vec3(1.0, 1.0, 1.0), blendType='easeInOut')
             l2 = LerpScaleInterval(self.water.seamodel, 2, Vec3(1.0, 1.0, 1.0), Vec3(1.006, 1.006, 1.0), blendType='easeInOut')
             seq = Sequence(l1, l2)
             seq.loop()
             self.water.reflection_factor = 0.3
             self.water.set_reflection_parameters_np()
         else:
             water = loader.loadModel(self.modelPrefix + 'lava')
             water.reparentTo(self.parent)
             water.setFogOff()
     base.ambientMgr.requestFadeIn(SoundGlobals.AMBIENT_CAVE, duration=10, finalVolume=PiratesGlobals.DEFAULT_AMBIENT_VOLUME, priority=1)
     if self.water:
         self.water.supports_sky_only = self.supports_sky_only
     if reflection:
         if base.options.reflection >= 1:
             reflection.reflectShowThroughOnly(False)
             reflection.enable(True)
     return
    def startEffects(self):
        self.swamp_water = None
        if base.config.GetBool(
                'want-shaders',
                1) and base.win and base.win.getGsg() and base.win.getGsg(
                ).getShaderModel() >= GraphicsStateGuardian.SM20:
            reflection = Reflection.getGlobalReflection()
            self.swamp_water = Swamp(self.modelPath + '_water', self.parent,
                                     reflection)
        else:
            self.water = loader.loadModel(self.modelPath + '_water')
            self.water.reparentTo(self.parent)
            self.water.setTransparency(TransparencyAttrib.MNone, 100)
            alpha_test_attrib = AlphaTestAttrib.make(RenderAttrib.MAlways, 0)
            self.water.setAttrib(alpha_test_attrib, 100)
        if not self.fireflies:
            self.fireflies = Fireflies()

        if self.fireflies and hasattr(base, 'cr'):
            self.fireflies.reparentTo(base.localAvatar)
            self.fireflies.startLoop()

        if not self.groundFog:
            self.groundFog = GroundFog()

        if self.groundFog and hasattr(base, 'options'):
            if base.options.getSpecialEffectsSetting(
            ) >= base.options.SpecialEffectsMedium:
                self.groundFog.reparentTo(base.localAvatar)
                self.groundFog.startLoop(
                    base.options.getSpecialEffectsSetting())

        if hasattr(base, 'cr') and not hasattr(base.cr, 'isFake'):
            taskMgr.add(self.adjustGroundFogZ,
                        self.parent.uniqueName('groundFogZTask'))

        base.ambientMgr.requestFadeIn(
            SoundGlobals.AMBIENT_SWAMP,
            duration=10,
            finalVolume=PiratesGlobals.DEFAULT_AMBIENT_VOLUME,
            priority=1)
        for file in self.randomAnimalSoundFiles:
            sfx = loadSfx(file)
            self.randomSfx.append(sfx)

        taskMgr.doMethodLater(self.RANDOM_SOUND_PERIOD,
                              self.checkForRandomSound,
                              name='checkForRandomSound-' + str(id(self)))
 def initializeIslandWaterParameters(self, reference):
     debug = False
     island_water_parameters = IslandWaterParameters()
     world_position = self.getPos(render)
     world_x_offset = world_position[0]
     world_y_offset = world_position[1]
     world_z_offset = world_position[2]
     if debug:
         print self, '=', self.getName()
         print 'GAME AREA X OFF, Y OFF, Z OFF = ', world_x_offset, world_y_offset, world_z_offset
     self.swampAreaNode = reference.find('**/ocean')
     model = reference.find('**/water_color')
     if model:
         if debug:
             print 'WATER COLOR X OFF, Y OFF, Z OFF = ', world_x_offset, world_y_offset, world_z_offset
         model.hide()
         min_point = Point3(0)
         max_point = Point3(0)
         model.calcTightBounds(min_point, max_point)
         size = max_point - min_point
         if self.getH() == 180 or self.getH() == -180:
             x = -min_point[0] + world_x_offset
             y = -min_point[1] + world_y_offset
             x_size = -size[0]
             y_size = -size[1]
         else:
             x = min_point[0] + world_x_offset
             y = min_point[1] + world_y_offset
             x_size = size[0]
             y_size = size[1]
         island_water_parameters.map_x_origin = x
         island_water_parameters.map_y_origin = y
         island_water_parameters.map_x_scale = x_size
         island_water_parameters.map_y_scale = y_size
         if debug:
             print 'X, Y, X SIZE, Y SIZE = ', min_point[0], min_point[
                 1], x_size, y_size
         texture = model.findTexture('*')
         if texture:
             island_water_parameters.water_color_texture = texture
             if debug:
                 print 'WATER COLOR TEXTURE', texture
     elif debug:
         print '*** water_color NODE NOT FOUND'
     model = reference.find('**/water_alpha')
     if model:
         if debug:
             print 'WATER ALPHA X OFF, Y OFF, Z OFF = ', world_x_offset, world_y_offset, world_z_offset
         model.hide()
         min_point = Point3(0)
         max_point = Point3(0)
         model.calcTightBounds(min_point, max_point)
         size = max_point - min_point
         if self.getH() == 180 or self.getH() == -180:
             x = -min_point[0] + world_x_offset
             y = -min_point[1] + world_y_offset
             x_size = -size[0]
             y_size = -size[1]
         else:
             x = min_point[0] + world_x_offset
             y = min_point[1] + world_y_offset
             x_size = size[0]
             y_size = size[1]
         island_water_parameters.alpha_map_x_origin = x
         island_water_parameters.alpha_map_y_origin = y
         island_water_parameters.alpha_map_x_scale = x_size
         island_water_parameters.alpha_map_y_scale = y_size
         if debug:
             print 'ALPHA X, Y, X SIZE, Y SIZE = ', min_point[0], min_point[
                 1], x_size, y_size
         texture = model.findTexture('*')
         if texture:
             island_water_parameters.water_alpha_texture = texture
             if debug:
                 print 'WATER ALPHA TEXTURE', texture
     elif debug:
         print '*** water_alpha NODE NOT FOUND'
     use_shader = False
     if base.config.GetBool(
             'want-shaders',
             1) and base.win and base.win.getGsg() and base.win.getGsg(
             ).getShaderModel() >= GraphicsStateGuardian.SM20:
         use_shader = True
     model_ns = reference.find('**/water_swamp_ns')
     if model_ns:
         if use_shader:
             model_ns.hide()
         else:
             model_ns.show()
             model = model_ns
             model.setBin('water', 1)
             parent = model.getParent()
             model.detachNode()
             stencil_one_node_path = NodePath('stencil_one')
             stencil_one_node_path.reparentTo(parent)
             model.instanceTo(stencil_one_node_path)
             mask = 4294967295L
             stencil_one = StencilAttrib.make(1, StencilAttrib.SCFEqual,
                                              StencilAttrib.SOKeep,
                                              StencilAttrib.SOKeep,
                                              StencilAttrib.SOKeep, 1, mask,
                                              mask)
             stencil_one_node_path.setAttrib(stencil_one, 100)
             stencil_one_node_path.setDepthTest(0)
             if not base.useStencils:
                 stencil_one_node_path.hide()
     model_alpha_texture = None
     model_alpha = reference.find('**/water_alpha_swamp')
     if model_alpha:
         model_alpha_texture = model_alpha.findTexture('*')
         model_alpha.hide()
         if debug:
             print 'model_alpha_texture', model_alpha_texture
         if False:
             texture = model_alpha_texture
             card_x_size = 0.5
             card_y_size = 0.5
             card = CardMaker('test_texture_card')
             card.setFrame(-card_x_size, card_x_size, -card_y_size,
                           card_y_size)
             card_node_path = NodePath(card.generate())
             card_node_path.setTexture(texture, 1)
             card_node_path.node().setBounds(OmniBoundingVolume())
             card_node_path.node().setFinal(1)
             card_node_path.reparentTo(render2d)
     else:
         model_alpha = None
     model = reference.find('**/water_color_swamp')
     if model:
         if use_shader:
             model.show()
             model_texture = model.findTexture('*')
             if debug:
                 print 'WATER COLOR SWAMP X OFF, Y OFF, Z OFF = ', world_x_offset, world_y_offset, world_z_offset
             parent = model.getParent()
             model.detachNode()
             stencil_one_node_path = NodePath('stencil_one')
             stencil_one_node_path.reparentTo(parent)
             model.instanceTo(stencil_one_node_path)
             mask = 4294967295L
             stencil_one = StencilAttrib.make(1, StencilAttrib.SCFEqual,
                                              StencilAttrib.SOKeep,
                                              StencilAttrib.SOKeep,
                                              StencilAttrib.SOKeep, 1, mask,
                                              mask)
             stencil_one_node_path.setAttrib(stencil_one, 100)
             stencil_one_node_path.setDepthTest(0)
             if not base.useStencils:
                 stencil_one_node_path.hide()
             min_point = Point3(0)
             max_point = Point3(0)
             model.calcTightBounds(min_point, max_point)
             size = max_point - min_point
             if self.getH() == 180 or self.getH() == -180:
                 x = -min_point[0] + world_x_offset
                 y = -min_point[1] + world_y_offset
                 x_size = -size[0]
                 y_size = -size[1]
             else:
                 x = min_point[0] + world_x_offset
                 y = min_point[1] + world_y_offset
                 x_size = size[0]
                 y_size = size[1]
             if debug:
                 print 'min_point', min_point
                 print 'max_point', max_point
                 print 'size', size
                 print 'x y', x, y
             island_water_parameters.swamp_map_x_origin = x
             island_water_parameters.swamp_map_y_origin = y
             island_water_parameters.swamp_map_x_scale = x_size
             island_water_parameters.swamp_map_y_scale = y_size
             if debug:
                 print 'X, Y, X SIZE, Y SIZE = ', min_point[0], min_point[
                     1], x_size, y_size
             texture = model.findTexture('*')
             if texture:
                 island_water_parameters.swamp_water_color_texture = texture
                 if debug:
                     print 'SWAMP WATER COLOR TEXTURE', texture
             water_color_file_path = island_water_parameters.default_water_color_file_path
             alpha_texture_file_path = island_water_parameters.default_water_alpha_file_path
             opacity_texture_file_path = None
             shader_file_path = 'models/swamps/cuba_swamp001_2X.cg'
             reflection = Reflection.getGlobalReflection()
             self.swamp_water = Swamp(None, None, reflection, model,
                                      shader_file_path)
             island_water_parameters.swamp_water = self.swamp_water
             unload_previous_texture = True
             self.swamp_water.set_water_color_texture(
                 water_color_file_path, unload_previous_texture,
                 model_texture)
             self.swamp_water.set_water_alpha_texture(
                 alpha_texture_file_path, unload_previous_texture,
                 model_alpha_texture)
             self.swamp_water.set_wrap_or_clamp(True)
             r = 37.0
             g = 62.0
             b = 40.0
             self.swamp_water.water_r = r
             self.swamp_water.water_g = g
             self.swamp_water.water_b = b
             island_water_parameters.swamp_color_r = r
             island_water_parameters.swamp_color_g = g
             island_water_parameters.swamp_color_b = b
             x = 0.0
             y = 1.0
             speed = 3.2
             island_water_parameters.swamp_direction_x = x
             island_water_parameters.swamp_direction_y = y
             island_water_parameters.swamp_speed = speed
             self.swamp_water.update_water_direction_and_speed(x, y, speed)
         else:
             model.hide()
     elif debug:
         print '*** water_color_swamp NODE NOT FOUND'
     self.islandWaterParameters = island_water_parameters
     return