Exemplo n.º 1
0
    def __init__(self, parentNP=render, reflection=None, todMgr=None):
        Water.__init__(self, 'Sea')
        if base.win.getFbProperties().getStencilBits() == 0:
            self.use_water_bin = False
        self.p3 = Point3()
        self.parentNP = parentNP
        self.followWater = base.config.GetBool('ships-follow-water', 1)
        self.damper = 0.2 * 180.0 / math.pi
        self.floats = {}
        self.floatmasses = {}
        self.patch = SeaPatchRoot()
        self.patch.setSeaLevel(0)
        self.hidden = False
        self.usingFlatWater = False
        if base.camera:
            self.setCenter(base.camera)
            self.setAnchor(render)
        patchNode = SeaPatchNode('seapatch', self.patch)
        patchNode.setWantReflect(0)
        self.patchNP = NodePath(patchNode)
        self.patchNP.setColorScale(0.15, 0.4, 0.5, 1.0)
        self.patchNP.setTwoSided(True)
        self.patchNP.hide()
        shader_file_path = None
        if base.config.GetBool('want-shaders', 1):
            if base.win:
                if base.win.getGsg():
                    if base.win.getGsg().getShaderModel() >= GraphicsStateGuardian.SM20:
                        patchNode.setWantColor(0)
                        shader_directory = 'models/sea/'
                        shader_file_name_array = [
                         '', 'water008_11.cg', 'water008_20.cg', 'water008_2X.cg']
                        shader_model = base.win.getGsg().getShaderModel()
                        maximum_shader_model = len(shader_file_name_array) - 1
                        if shader_model > maximum_shader_model:
                            shader_model = maximum_shader_model
                        file_name = shader_file_name_array[shader_model]
                        shader_file_path = shader_directory + file_name
                        self.shader = loader.loadShader(shader_file_path)
                        if self.shader:
                            pass
                    if self.shader:
                        if base.win.getGsg().getShaderModel() == GraphicsStateGuardian.SM20:
                            self.seamodel = loader.loadModel('models/sea/SeaPatch34')
                        else:
                            self.seamodel = loader.loadModel('models/sea/SeaPatch31')
                    else:
                        if base.options.getTerrainDetailSetting() == 0:
                            self.seamodel = loader.loadModel('models/sea/pir_m_are_wld_seaPatch_low')
                        else:
                            self.seamodel = loader.loadModel('models/sea/SeaPatch31')
                    self.seamodel.setScale(2, 1, 1)
                    self.seamodel.flattenMedium()
                    mask = 4294967295L
                    if self.use_water_bin:
                        self.seamodel.setBin('water', 0)
                        stencil = StencilAttrib.makeWithClear(1, StencilAttrib.SCFAlways, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOReplace, 1, mask, mask, 1, 0)
                        self.seamodel.setAttrib(stencil)
                    else:
                        self.seamodel.setBin('background', 200)
                    self.seamodel.hide(OTPRender.MainCameraBitmask)
                    self.seamodel.showThrough(OTPRender.EnviroCameraBitmask)
                    self.reflectStage = None
                    if False:
                        self.model = loader.loadModel('models/misc/smiley')
                        self.model.reparentTo(render)
                        self.model.setPos(0.0, 50.0, 10.0)
                        self.model.setHpr(0.0, 180.0, 0.0)
                        self.model.setBin('water', 100)
                        self.model2 = loader.loadModel('models/misc/smiley')
                        self.model2.reparentTo(render)
                        self.model2.setPos(10.0, 50.0, 15.0)
                        self.model2.setHpr(180.0, 0.0, 0.0)
                        self.model2.setBin('water', 50)
                        self.model3 = loader.loadModel('models/misc/smiley')
                        self.model3.reparentTo(render)
                        self.model3.setPos(-10.0, 50.0, 15.0)
                        self.model3.setHpr(0.0, 0.0, 0.0)
                        self.model3.setBin('water', 50)
                        stencil = StencilAttrib.make(1, StencilAttrib.SCFEqual, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOKeep, 1, mask, mask)
                        self.model.setAttrib(stencil)
                        stencil = StencilAttrib.make(1, StencilAttrib.SCFEqual, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOKeep, 0, mask, mask)
                        self.model3.setAttrib(stencil)
                    self.flatSea = self.seamodel.find('**/flatsea')
                    flat2 = self.flatSea.copyTo(self.flatSea)
                    flat2.setScale(2, 2, 1)
                    flat2.setZ(-4)
                    flat4 = self.flatSea.copyTo(self.flatSea)
                    flat4.setScale(4, 4, 1)
                    flat4.setZ(-8)
                    if not self.flatSea.isEmpty():
                        self.flatSea.setTag('flat_sea', 'true')
                        self.flatSea.setPos(0, 0, -1)
                        if False:
                            self.flatSea.setScale(1.3)
                        if self.use_water_bin:
                            self.flatSea.setDepthWrite(0)
                    self.flatSea.flattenStrong()
                    if self.use_water_bin:
                        self.patchNP.setBin('water', 10)
                    else:
                        self.patchNP.setBin('ground', -10)
                    self.todMgr = todMgr
                    if self.getTodMgr():
                        self.patchNP.setLightOff()
                        self.patchNP.setLight(self.getTodMgr().alight)
                    seaMin, seaMax = self.seamodel.getTightBounds()
                    seaDelta = seaMax - seaMin
                    cp = CollisionPolygon(Point3(-1.0, -1.0, 0), Point3(1.0, -1.0, 0), Point3(1.0, 1.0, 0), Point3(-1.0, 1.0, 0))
                    cNode = CollisionNode('seaCollision')
                    cNode.setCollideMask(PiratesGlobals.TargetBitmask)
                    cNode.addSolid(cp)
                    cNodePath = NodePath(cNode)
                    cNodePath.reparentTo(self.seamodel)
                    cNodePath.setScale(Vec3(seaDelta).length())
                    cNodePath.setZ(-3)
                    cNodePath.setTag('objType', str(PiratesGlobals.COLL_SEA))
                    cNodePath.reparentTo(self.parentNP)
                    self.cNodePath = cNodePath
                    ccPlane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
                    ccNode = CollisionNode('seaCamCollision')
                    ccNode.setCollideMask(PiratesGlobals.CameraBitmask)
                    ccNode.addSolid(ccPlane)
                    ccNodePath = NodePath(ccNode)
                    ccNodePath.reparentTo(self.seamodel)
                    self.ccNodePath = ccNodePath
                    self.seamodel.reparentTo(self.patchNP)
                    self.patchNP.flattenLight()
                    patchNode.collectGeometry()
                    self.enabled = False
                    self.enable()
                    if self.use_alpha_map:
                        if self.enable_alpha_map:
                            self.patchNP.setTransparency(1)
                            alpha_test_attrib = AlphaTestAttrib.make(RenderAttrib.MAlways, 0)
                            self.patchNP.setAttrib(alpha_test_attrib, 100)
                    if self.water_panel != None:
                        self.water_panel.setSeaPatch(self)
                    if self.enable_parameter_keys:

                        def showSeaPatchPanel():
                            from pirates.seapatch import SeaPatchPanel
                            self.spp = SeaPatchPanel.SeaPatchPanel()
                            self.spp.setPatch(self)

                        self.accept('shift-5', showSeaPatchPanel)
                    self.setting_0()
                    self.patchNP.setTransparency(0)
                    buffer_width = 512
                    buffer_height = 512
                    self.texture_extension = '.jpg'
                    if self.shader:
                        self.seamodel.setShader(self.shader)
                        self.seamodel.setFogOff()
                        if self.use_alpha_map:
                            self.patchNP.setTransparency(1)
                        self.base_texture = loader.loadTexture('maps/oceanWater2' + self.texture_extension)
                        self.texture_d = self.base_texture.loadRelated(InternalName.make('-d'))
                        self.texture_n = self.base_texture.loadRelated(InternalName.make('-n'))
                        self.texture_bb = self.base_texture.loadRelated(InternalName.make('-bb'))
                        self.setting_0()
                        self.water_r = 77
                        self.water_g = 128
                        self.water_b = 179
                        self.water_a = 255
                        self.set_water_color()
                        default_water_color_texture_filename = 'maps/ocean_color_1' + self.texture_extension
                        default_water_alpha_texture_filename = 'maps/default_inv_alpha' + self.texture_extension
                        self.set_water_color_texture(default_water_color_texture_filename)
                        self.set_water_alpha_texture(default_water_alpha_texture_filename)
                        if self.enable_water_panel:
                            self.water_panel.set_texture(default_water_color_texture_filename)
                            self.water_panel.set_shader(shader_file_path)
                    self.reflection = True and reflection and reflection
                else:
                    self.reflection = Reflection('seapatch', buffer_width, buffer_height, render, Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
                self.reflection_enabled() and self.reflection_on()
            else:
                self.reflection_off()
            self.reflection.reflectShowThroughOnly(self.reflect_show_through_only)
            self.seamodel.setShaderInput(self.reflectiontexture_name, self.reflection.reflection_texture)
            OTPRender.renderReflection(False, self.patchNP, 'p_ocean_water', None)
        else:
            self.reflection_factor = 0.0
            self.set_reflection_parameters_np()
        if not self.shader:
            self.accept('timeOfDayChange', self._timeChange)
            if self.reflection:
                self.reflection.createCard('water', 6)
            self.setting_0()
            self.reflection_factor = 0.2
            self.set_reflection_parameters_np()
            if False:
                default_water_color_texture_filename = 'maps/ocean_color_1' + self.texture_extension
                self.set_water_color_texture(default_water_color_texture_filename)
                self.setup_color_map()
        self.create_interface()
        self.patchNP.reparentTo(self.parentNP)
        self.accept('grid-detail-changed', self.updateWater)
        return
Exemplo n.º 2
0
    def __init__(self, parentNP = render, reflection = None, todMgr = None):
        Water.__init__(self, 'Sea')
        if base.win.getFbProperties().getStencilBits() == 0:
            self.use_water_bin = False
        
        self.p3 = Point3()
        self.parentNP = parentNP
        self.followWater = base.config.GetBool('ships-follow-water', 1)
        self.damper = 0.20000000000000001 * 180.0 / math.pi
        self.floats = { }
        self.floatmasses = { }
        self.patch = SeaPatchRoot()
        self.patch.setSeaLevel(0)
        self.hidden = False
        self.usingFlatWater = False
        if base.camera:
            self.setCenter(base.camera)
            self.setAnchor(render)
        
        patchNode = SeaPatchNode('seapatch', self.patch)
        patchNode.setWantReflect(0)
        self.patchNP = NodePath(patchNode)
        self.patchNP.setColorScale(0.14999999999999999, 0.40000000000000002, 0.5, 1.0)
        self.patchNP.setTwoSided(True)
        self.patchNP.hide()
        shader_file_path = None
        if base.config.GetBool('want-shaders', 1) and base.win and base.win.getGsg() and base.win.getGsg().getShaderModel() >= GraphicsStateGuardian.SM20:
            patchNode.setWantColor(0)
            shader_directory = 'models/sea/'
            shader_file_name_array = [
                '',
                'water008_11.cg',
                'water008_20.cg',
                'water008_2X.cg']
            shader_model = base.win.getGsg().getShaderModel()
            maximum_shader_model = len(shader_file_name_array) - 1
            if shader_model > maximum_shader_model:
                shader_model = maximum_shader_model
            
            file_name = shader_file_name_array[shader_model]
            shader_file_path = shader_directory + file_name
            self.shader = loader.loadShader(shader_file_path)
            if self.shader:
                pass
            
        
        if self.shader:
            if base.win.getGsg().getShaderModel() == GraphicsStateGuardian.SM20:
                seamodel = loader.loadModel('models/sea/SeaPatch34')
            else:
                seamodel = loader.loadModel('models/sea/SeaPatch31')
            self.patch.seamodel = seamodel
            self.seamodel = self.patch.seamodel
        elif base.options.getTerrainDetailSetting() == 0:
            self.seamodel = loader.loadModel('models/sea/pir_m_are_wld_seaPatch_low')
        else:
            self.seamodel = loader.loadModel('models/sea/SeaPatch31')
        self.seamodel.setScale(2, 1, 1)
        self.seamodel.flattenMedium()
        mask = 0xFFFFFFFFL
        if self.use_water_bin:
            self.seamodel.setBin('water', 0)
            stencil = StencilAttrib.makeWithClear(1, StencilAttrib.SCFAlways, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOReplace, 1, mask, mask, 1, 0)
            self.seamodel.setAttrib(stencil)
        else:
            self.seamodel.setBin('background', 200)
        self.seamodel.hide(OTPRender.MainCameraBitmask)
        self.seamodel.showThrough(OTPRender.EnviroCameraBitmask)
        self.reflectStage = None
        if False:
            self.model = loader.loadModel('models/misc/smiley')
            self.model.reparentTo(render)
            self.model.setPos(0.0, 50.0, 10.0)
            self.model.setHpr(0.0, 180.0, 0.0)
            self.model.setBin('water', 100)
            self.model2 = loader.loadModel('models/misc/smiley')
            self.model2.reparentTo(render)
            self.model2.setPos(10.0, 50.0, 15.0)
            self.model2.setHpr(180.0, 0.0, 0.0)
            self.model2.setBin('water', 50)
            self.model3 = loader.loadModel('models/misc/smiley')
            self.model3.reparentTo(render)
            self.model3.setPos(-10.0, 50.0, 15.0)
            self.model3.setHpr(0.0, 0.0, 0.0)
            self.model3.setBin('water', 50)
            stencil = StencilAttrib.make(1, StencilAttrib.SCFEqual, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOKeep, 1, mask, mask)
            self.model.setAttrib(stencil)
            stencil = StencilAttrib.make(1, StencilAttrib.SCFEqual, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOKeep, 0, mask, mask)
            self.model3.setAttrib(stencil)
        
        self.flatSea = self.seamodel.find('**/flatsea')
        flat2 = self.flatSea.copyTo(self.flatSea)
        flat2.setScale(2, 2, 1)
        flat2.setZ(-4)
        flat4 = self.flatSea.copyTo(self.flatSea)
        flat4.setScale(4, 4, 1)
        flat4.setZ(-8)
        if not self.flatSea.isEmpty():
            self.flatSea.setTag('flat_sea', 'true')
            self.flatSea.setPos(0, 0, -1)
            if False:
                self.flatSea.setScale(1.3)
            
            if self.use_water_bin:
                self.flatSea.setDepthWrite(0)
            
        
        self.flatSea.flattenStrong()
        if self.use_water_bin:
            self.patchNP.setBin('water', 10)
        else:
            self.patchNP.setBin('ground', -10)
        self.todMgr = todMgr
        if self.getTodMgr():
            self.patchNP.setLightOff()
            self.patchNP.setLight(self.getTodMgr().alight)
        
        (seaMin, seaMax) = self.seamodel.getTightBounds()
        seaDelta = seaMax - seaMin
        cp = CollisionPolygon(Point3(-1.0, -1.0, 0), Point3(1.0, -1.0, 0), Point3(1.0, 1.0, 0), Point3(-1.0, 1.0, 0))
        cNode = CollisionNode('seaCollision')
        cNode.setCollideMask(PiratesGlobals.TargetBitmask)
        cNode.addSolid(cp)
        cNodePath = NodePath(cNode)
        cNodePath.reparentTo(self.seamodel)
        cNodePath.setScale(Vec3(seaDelta).length())
        cNodePath.setZ(-3)
        cNodePath.setTag('objType', str(PiratesGlobals.COLL_SEA))
        cNodePath.reparentTo(self.parentNP)
        self.cNodePath = cNodePath
        ccPlane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
        ccNode = CollisionNode('seaCamCollision')
        ccNode.setCollideMask(PiratesGlobals.CameraBitmask)
        ccNode.addSolid(ccPlane)
        ccNodePath = NodePath(ccNode)
        ccNodePath.reparentTo(self.seamodel)
        self.ccNodePath = ccNodePath
        self.seamodel.reparentTo(self.patchNP)
        self.patchNP.flattenLight()
        patchNode.collectGeometry()
        self.enabled = False
        self.enable()
        if self.use_alpha_map:
            if self.enable_alpha_map:
                self.patchNP.setTransparency(1)
                alpha_test_attrib = AlphaTestAttrib.make(RenderAttrib.MAlways, 0)
                self.patchNP.setAttrib(alpha_test_attrib, 100)
            
        
        if self.water_panel != None:
            self.water_panel.setSeaPatch(self)
        
        if self.enable_parameter_keys:
            
            def showSeaPatchPanel():
                SeaPatchPanel = SeaPatchPanel
                import pirates.seapatch
                self.spp = SeaPatchPanel.SeaPatchPanel()
                self.spp.setPatch(self)

            self.accept('shift-5', showSeaPatchPanel)
        
        self.setting_0()
        self.patchNP.setTransparency(0)
        buffer_width = 512
        buffer_height = 512
        self.texture_extension = '.jpg'
        if self.shader:
            self.seamodel.setShader(self.shader)
            self.seamodel.setFogOff()
            if self.use_alpha_map:
                self.patchNP.setTransparency(1)
            
            self.base_texture = loader.loadTexture('maps/oceanWater2' + self.texture_extension)
            self.texture_d = self.base_texture.loadRelated(InternalName.make('-d'))
            self.texture_n = self.base_texture.loadRelated(InternalName.make('-n'))
            self.texture_bb = self.base_texture.loadRelated(InternalName.make('-bb'))
            self.setting_0()
            self.water_r = 77
            self.water_g = 128
            self.water_b = 179
            self.water_a = 255
            self.set_water_color()
            default_water_color_texture_filename = 'maps/ocean_color_1' + self.texture_extension
            default_water_alpha_texture_filename = 'maps/default_inv_alpha' + self.texture_extension
            self.set_water_color_texture(default_water_color_texture_filename)
            self.set_water_alpha_texture(default_water_alpha_texture_filename)
            if self.enable_water_panel:
                self.water_panel.set_texture(default_water_color_texture_filename)
                self.water_panel.set_shader(shader_file_path)
            
        
        if True:
            if reflection:
                self.reflection = reflection
            else:
                self.reflection = Reflection('seapatch', buffer_width, buffer_height, render, Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
            if self.reflection_enabled():
                self.reflection_on()
            else:
                self.reflection_off()
            self.reflection.reflectShowThroughOnly(self.reflect_show_through_only)
            self.seamodel.setShaderInput(self.reflectiontexture_name, self.reflection.reflection_texture)
            OTPRender.renderReflection(False, self.patchNP, 'p_ocean_water', None)
        else:
            self.reflection_factor = 0.0
            self.set_reflection_parameters_np()
        if not self.shader:
            self.accept('timeOfDayChange', self._timeChange)
            if self.reflection:
                self.reflection.createCard('water', 6)
            
            self.setting_0()
            self.reflection_factor = 0.20000000000000001
            self.set_reflection_parameters_np()
            if False:
                default_water_color_texture_filename = 'maps/ocean_color_1' + self.texture_extension
                self.set_water_color_texture(default_water_color_texture_filename)
                self.setup_color_map()
            
        
        self.create_interface()
        self.patchNP.reparentTo(self.parentNP)
        self.accept('grid-detail-changed', self.updateWater)
Exemplo n.º 3
0
    def __init__(self,
                 swamp_model_file_path,
                 parentNP=render,
                 reflection=None,
                 input_swamp_model=None,
                 input_shader_file_path=None,
                 input_water_color=None):
        if input_swamp_model:
            swamp_name = 'Swamp I'
        else:
            swamp_name = 'Swamp'
        Water.__init__(self, swamp_name)
        self.parentNP = parentNP
        self.swamp_model = input_swamp_model
        if input_swamp_model:
            self.seamodel = input_swamp_model
            self.parentNP = input_swamp_model.getParent()
            self.patchNP = NodePath(self.seamodel)
        elif swamp_model_file_path:
            self.seamodel = loader.loadModel(swamp_model_file_path)
        else:
            self.swampmodel = loader.loadModel('models/swamp/SwampA')
            self.swampmodel.reparentTo(self.parentNP)
            self.swampmodel.setPos(0.0, 0.0, -1.0)
            self.seamodel = loader.loadModel('models/swamp/swampA_water')
        self.patchNP = NodePath(self.seamodel)
        self.patchNP.reparentTo(self.parentNP)
        self.hidden = False
        mask = 0xFFFFFFFFL
        if self.use_water_bin:
            self.seamodel.setBin('water', 1)
            stencil = StencilAttrib.make(1, StencilAttrib.SCFAlways,
                                         StencilAttrib.SOKeep,
                                         StencilAttrib.SOKeep,
                                         StencilAttrib.SOReplace, 1, mask,
                                         mask)
            self.seamodel.setAttrib(stencil)
        else:
            self.seamodel.setBin('background', 200)
        self.reflectStage = None
        if False:
            self.model = loader.loadModel('models/misc/smiley')
            self.model.reparentTo(render)
            self.model.setPos(0.0, 50.0, 10.0)
            self.model.setHpr(0.0, 180.0, 0.0)
            self.model.setBin('water', 100)
            self.model2 = loader.loadModel('models/misc/smiley')
            self.model2.reparentTo(render)
            self.model2.setPos(10.0, 50.0, 15.0)
            self.model2.setHpr(180.0, 0.0, 0.0)
            self.model2.setBin('water', 50)
            self.model3 = loader.loadModel('models/misc/smiley')
            self.model3.reparentTo(render)
            self.model3.setPos(-10.0, 50.0, 15.0)
            self.model3.setHpr(0.0, 0.0, 0.0)
            self.model3.setBin('water', 50)
            stencil = StencilAttrib.make(1, StencilAttrib.SCFEqual,
                                         StencilAttrib.SOKeep,
                                         StencilAttrib.SOKeep,
                                         StencilAttrib.SOKeep, 1, mask, mask)
            self.model.setAttrib(stencil)
            stencil = StencilAttrib.make(1, StencilAttrib.SCFEqual,
                                         StencilAttrib.SOKeep,
                                         StencilAttrib.SOKeep,
                                         StencilAttrib.SOKeep, 0, mask, mask)
            self.model3.setAttrib(stencil)

        if self.use_water_bin:
            self.patchNP.setBin('water', 10)
        else:
            self.patchNP.setBin('ground', -10)

        try:
            self.todMgr = base.cr.timeOfDayManager
        except:
            self.todMgr = None

        if self.todMgr:
            self.patchNP.setLightOff()
            self.patchNP.setLight(self.todMgr.alight)

        (seaMin, seaMax) = self.seamodel.getTightBounds()
        seaDelta = seaMax - seaMin
        cp = CollisionPolygon(Point3(-1.0, -1.0, 0), Point3(1.0, -1.0, 0),
                              Point3(1.0, 1.0, 0), Point3(-1.0, 1.0, 0))
        cNode = CollisionNode('seaCollision')
        cNode.setCollideMask(PiratesGlobals.TargetBitmask)
        cNode.addSolid(cp)
        cNodePath = self.parentNP.attachNewNode(cNode)
        cNodePath.reparentTo(self.seamodel)
        cNodePath.setScale(Vec3(seaDelta).length())
        cNodePath.setZ(3)
        cNodePath.setTag('objType', str(PiratesGlobals.COLL_SEA))
        self.cNodePath = cNodePath
        ccPlane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
        ccNode = CollisionNode('seaCamCollision')
        ccNode.setCollideMask(PiratesGlobals.CameraBitmask)
        ccNode.addSolid(ccPlane)
        ccNodePath = self.parentNP.attachNewNode(ccNode)
        ccNodePath.reparentTo(self.seamodel)
        self.ccNodePath = ccNodePath
        self.enabled = False
        self.enable()
        self.setting_0()
        if input_water_color:
            self.water_r = input_water_color[0]
            self.water_g = input_water_color[1]
            self.water_b = input_water_color[2]
            self.water_a = input_water_color[3]
        else:
            self.water_r = 33
            self.water_g = 43
            self.water_b = 38
            self.water_a = 255
        self.set_water_color()
        self.reflection_factor = 0.34000000000000002
        self.set_reflection_parameters_np()
        if self.use_alpha_map:
            if self.enable_alpha_map:
                self.patchNP.setTransparency(1)

        if self.water_panel != None:
            self.water_panel.setSeaPatch(self)

        if input_shader_file_path == None:
            shader_file_path = 'models/swamps/swamp002_2X.cg'
        else:
            shader_file_path = input_shader_file_path
        if base.config.GetBool(
                'want-shaders',
                1) and base.win and base.win.getGsg() and base.win.getGsg(
                ).getShaderModel() >= GraphicsStateGuardian.SM20:
            self.shader = loader.loadShader(shader_file_path)
            if self.shader != None:
                self.seamodel.setShader(self.shader)
                self.seamodel.setFogOff()
                self.setting_0()
                if input_water_color:
                    self.water_r = input_water_color[0]
                    self.water_g = input_water_color[1]
                    self.water_b = input_water_color[2]
                    self.water_a = input_water_color[3]
                else:
                    self.water_r = 33
                    self.water_g = 43
                    self.water_b = 38
                    self.water_a = 255
                self.set_water_color()
                self.reflection_factor = 0.34000000000000002
                self.set_reflection_parameters_np()
                if self.use_alpha_map:
                    self.patchNP.setTransparency(1)

                self.texture_extension = '.jpg'
                default_water_color_texture_filename = 'maps/ocean_color_1' + self.texture_extension
                default_water_alpha_texture_filename = 'maps/default_inv_alpha' + self.texture_extension
                if swamp_model_file_path:
                    if False:
                        self.base_texture = loader.loadTexture(
                            'maps/oceanWater2' + self.texture_extension)
                        self.texture_d = self.base_texture.loadRelated(
                            InternalName.make('-d'))
                        self.texture_n = self.base_texture.loadRelated(
                            InternalName.make('-n'))
                        self.texture_bb = self.base_texture.loadRelated(
                            InternalName.make('-bb'))
                    else:
                        swamp_texture = self.seamodel.findTexture('*')
                        self.set_water_color_texture(
                            default_water_color_texture_filename, True,
                            swamp_texture)
                        if False:
                            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(swamp_texture, 1)
                            card_node_path.node().setBounds(
                                OmniBoundingVolume())
                            card_node_path.node().setFinal(1)
                            card_node_path.reparentTo(render2d)

                        self.texture_d = loader.loadTexture(
                            'maps/oceanWater2-d' + self.texture_extension)
                        self.texture_n = loader.loadTexture(
                            'maps/oceanWater2-n' + self.texture_extension)
                        self.texture_bb = loader.loadTexture(
                            'maps/oceanWater2-bb' + self.texture_extension)
                        self.texture_low2 = loader.loadTexture(
                            'maps/oceanWater2-low2' + self.texture_extension)
                        self.seamodel.setShaderInput('d', self.texture_d)
                        self.seamodel.setShaderInput('n', self.texture_n)
                        self.seamodel.setShaderInput('bb', self.texture_bb)
                        self.seamodel.setShaderInput('low2', self.texture_low2)
                    self.set_water_alpha_texture(
                        default_water_alpha_texture_filename)
                else:
                    self.texture_d = loader.loadTexture('maps/oceanWater2-d' +
                                                        self.texture_extension)
                    self.texture_n = loader.loadTexture('maps/oceanWater2-n' +
                                                        self.texture_extension)
                    self.texture_bb = loader.loadTexture(
                        'maps/oceanWater2-bb' + self.texture_extension)
                    self.texture_low2 = loader.loadTexture(
                        'maps/oceanWater2-low2' + self.texture_extension)
                    self.seamodel.setShaderInput('d', self.texture_d)
                    self.seamodel.setShaderInput('n', self.texture_n)
                    self.seamodel.setShaderInput('bb', self.texture_bb)
                    self.seamodel.setShaderInput('low2', self.texture_low2)
                    self.set_water_color_texture(
                        default_water_color_texture_filename)
                    self.set_water_alpha_texture(
                        default_water_alpha_texture_filename)
                if self.enable_water_panel:
                    self.water_panel.set_texture(
                        default_water_color_texture_filename)
                    self.water_panel.set_shader(shader_file_path)

        buffer_width = 512
        buffer_height = 512
        if True:
            if reflection:
                self.reflection = reflection
            else:
                self.reflection = Reflection(
                    'swamp', buffer_width, buffer_height, render,
                    Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
            if self.reflection_enabled():
                self.reflection_on()
            else:
                self.reflection_off()
            self.seamodel.setShaderInput('reflectiontexture',
                                         self.reflection.reflection_texture)
            OTPRender.renderReflection(False, self.patchNP, 'p_swamp_water',
                                       None)
        else:
            self.reflection_factor = 0.0
            self.set_reflection_parameters()
        if not self.shader:
            if True:
                self.reflection.createCard('water', 6)

            self.setting_0()
            self.reflection_factor = 0.34000000000000002
            self.set_reflection_parameters_np()

        self.create_interface()
Exemplo n.º 4
0
    def __init__(self, swamp_model_file_path, parentNP = render, reflection = None, input_swamp_model = None, input_shader_file_path = None, input_water_color = None):
        if input_swamp_model:
            swamp_name = 'Swamp I'
        else:
            swamp_name = 'Swamp'
        Water.__init__(self, swamp_name)
        self.parentNP = parentNP
        self.swamp_model = input_swamp_model
        if input_swamp_model:
            self.seamodel = input_swamp_model
            self.parentNP = input_swamp_model.getParent()
            self.patchNP = NodePath(self.seamodel)
        elif swamp_model_file_path:
            self.seamodel = loader.loadModel(swamp_model_file_path)
        else:
            self.swampmodel = loader.loadModel('models/swamp/SwampA')
            self.swampmodel.reparentTo(self.parentNP)
            self.swampmodel.setPos(0.0, 0.0, -1.0)
            self.seamodel = loader.loadModel('models/swamp/swampA_water')
        self.patchNP = NodePath(self.seamodel)
        self.patchNP.reparentTo(self.parentNP)
        self.hidden = False
        mask = 0xFFFFFFFFL
        if self.use_water_bin:
            self.seamodel.setBin('water', 1)
            stencil = StencilAttrib.make(1, StencilAttrib.SCFAlways, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOReplace, 1, mask, mask)
            self.seamodel.setAttrib(stencil)
        else:
            self.seamodel.setBin('background', 200)
        self.reflectStage = None
        if False:
            self.model = loader.loadModel('models/misc/smiley')
            self.model.reparentTo(render)
            self.model.setPos(0.0, 50.0, 10.0)
            self.model.setHpr(0.0, 180.0, 0.0)
            self.model.setBin('water', 100)
            self.model2 = loader.loadModel('models/misc/smiley')
            self.model2.reparentTo(render)
            self.model2.setPos(10.0, 50.0, 15.0)
            self.model2.setHpr(180.0, 0.0, 0.0)
            self.model2.setBin('water', 50)
            self.model3 = loader.loadModel('models/misc/smiley')
            self.model3.reparentTo(render)
            self.model3.setPos(-10.0, 50.0, 15.0)
            self.model3.setHpr(0.0, 0.0, 0.0)
            self.model3.setBin('water', 50)
            stencil = StencilAttrib.make(1, StencilAttrib.SCFEqual, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOKeep, 1, mask, mask)
            self.model.setAttrib(stencil)
            stencil = StencilAttrib.make(1, StencilAttrib.SCFEqual, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOKeep, 0, mask, mask)
            self.model3.setAttrib(stencil)
        
        if self.use_water_bin:
            self.patchNP.setBin('water', 10)
        else:
            self.patchNP.setBin('ground', -10)
        
        try:
            self.todMgr = base.cr.timeOfDayManager
        except:
            self.todMgr = None

        if self.todMgr:
            self.patchNP.setLightOff()
            self.patchNP.setLight(self.todMgr.alight)
        
        (seaMin, seaMax) = self.seamodel.getTightBounds()
        seaDelta = seaMax - seaMin
        cp = CollisionPolygon(Point3(-1.0, -1.0, 0), Point3(1.0, -1.0, 0), Point3(1.0, 1.0, 0), Point3(-1.0, 1.0, 0))
        cNode = CollisionNode('seaCollision')
        cNode.setCollideMask(PiratesGlobals.TargetBitmask)
        cNode.addSolid(cp)
        cNodePath = self.parentNP.attachNewNode(cNode)
        cNodePath.reparentTo(self.seamodel)
        cNodePath.setScale(Vec3(seaDelta).length())
        cNodePath.setZ(3)
        cNodePath.setTag('objType', str(PiratesGlobals.COLL_SEA))
        self.cNodePath = cNodePath
        ccPlane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
        ccNode = CollisionNode('seaCamCollision')
        ccNode.setCollideMask(PiratesGlobals.CameraBitmask)
        ccNode.addSolid(ccPlane)
        ccNodePath = self.parentNP.attachNewNode(ccNode)
        ccNodePath.reparentTo(self.seamodel)
        self.ccNodePath = ccNodePath
        self.enabled = False
        self.enable()
        self.setting_0()
        if input_water_color:
            self.water_r = input_water_color[0]
            self.water_g = input_water_color[1]
            self.water_b = input_water_color[2]
            self.water_a = input_water_color[3]
        else:
            self.water_r = 33
            self.water_g = 43
            self.water_b = 38
            self.water_a = 255
        self.set_water_color()
        self.reflection_factor = 0.34000000000000002
        self.set_reflection_parameters_np()
        if self.use_alpha_map:
            if self.enable_alpha_map:
                self.patchNP.setTransparency(1)
            
        
        if self.water_panel != None:
            self.water_panel.setSeaPatch(self)
        
        if input_shader_file_path == None:
            shader_file_path = 'models/swamps/swamp002_2X.cg'
        else:
            shader_file_path = input_shader_file_path
        if base.config.GetBool('want-shaders', 1) and base.win and base.win.getGsg() and base.win.getGsg().getShaderModel() >= GraphicsStateGuardian.SM20:
            self.shader = loader.loadShader(shader_file_path)
            if self.shader != None:
                self.seamodel.setShader(self.shader)
                self.seamodel.setFogOff()
                self.setting_0()
                if input_water_color:
                    self.water_r = input_water_color[0]
                    self.water_g = input_water_color[1]
                    self.water_b = input_water_color[2]
                    self.water_a = input_water_color[3]
                else:
                    self.water_r = 33
                    self.water_g = 43
                    self.water_b = 38
                    self.water_a = 255
                self.set_water_color()
                self.reflection_factor = 0.34000000000000002
                self.set_reflection_parameters_np()
                if self.use_alpha_map:
                    self.patchNP.setTransparency(1)
                
                self.texture_extension = '.jpg'
                default_water_color_texture_filename = 'maps/ocean_color_1' + self.texture_extension
                default_water_alpha_texture_filename = 'maps/default_inv_alpha' + self.texture_extension
                if swamp_model_file_path:
                    if False:
                        self.base_texture = loader.loadTexture('maps/oceanWater2' + self.texture_extension)
                        self.texture_d = self.base_texture.loadRelated(InternalName.make('-d'))
                        self.texture_n = self.base_texture.loadRelated(InternalName.make('-n'))
                        self.texture_bb = self.base_texture.loadRelated(InternalName.make('-bb'))
                    else:
                        swamp_texture = self.seamodel.findTexture('*')
                        self.set_water_color_texture(default_water_color_texture_filename, True, swamp_texture)
                        if False:
                            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(swamp_texture, 1)
                            card_node_path.node().setBounds(OmniBoundingVolume())
                            card_node_path.node().setFinal(1)
                            card_node_path.reparentTo(render2d)
                        
                        self.texture_d = loader.loadTexture('maps/oceanWater2-d' + self.texture_extension)
                        self.texture_n = loader.loadTexture('maps/oceanWater2-n' + self.texture_extension)
                        self.texture_bb = loader.loadTexture('maps/oceanWater2-bb' + self.texture_extension)
                        self.texture_low2 = loader.loadTexture('maps/oceanWater2-low2' + self.texture_extension)
                        self.seamodel.setShaderInput('d', self.texture_d)
                        self.seamodel.setShaderInput('n', self.texture_n)
                        self.seamodel.setShaderInput('bb', self.texture_bb)
                        self.seamodel.setShaderInput('low2', self.texture_low2)
                    self.set_water_alpha_texture(default_water_alpha_texture_filename)
                else:
                    self.texture_d = loader.loadTexture('maps/oceanWater2-d' + self.texture_extension)
                    self.texture_n = loader.loadTexture('maps/oceanWater2-n' + self.texture_extension)
                    self.texture_bb = loader.loadTexture('maps/oceanWater2-bb' + self.texture_extension)
                    self.texture_low2 = loader.loadTexture('maps/oceanWater2-low2' + self.texture_extension)
                    self.seamodel.setShaderInput('d', self.texture_d)
                    self.seamodel.setShaderInput('n', self.texture_n)
                    self.seamodel.setShaderInput('bb', self.texture_bb)
                    self.seamodel.setShaderInput('low2', self.texture_low2)
                    self.set_water_color_texture(default_water_color_texture_filename)
                    self.set_water_alpha_texture(default_water_alpha_texture_filename)
                if self.enable_water_panel:
                    self.water_panel.set_texture(default_water_color_texture_filename)
                    self.water_panel.set_shader(shader_file_path)
                
            
        
        buffer_width = 512
        buffer_height = 512
        if True:
            if reflection:
                self.reflection = reflection
            else:
                self.reflection = Reflection('swamp', buffer_width, buffer_height, render, Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
            if self.reflection_enabled():
                self.reflection_on()
            else:
                self.reflection_off()
            self.seamodel.setShaderInput('reflectiontexture', self.reflection.reflection_texture)
            OTPRender.renderReflection(False, self.patchNP, 'p_swamp_water', None)
        else:
            self.reflection_factor = 0.0
            self.set_reflection_parameters()
        if not self.shader:
            if True:
                self.reflection.createCard('water', 6)
            
            self.setting_0()
            self.reflection_factor = 0.34000000000000002
            self.set_reflection_parameters_np()
        
        self.create_interface()