コード例 #1
0
    def generate(self, helperInfo):
        MapHelper.generate(self)

        # Check for a color255 to tint the sprite
        color255Props = self.mapObject.getPropsWithValueType(
            ['color255', 'color1'])
        # If we have a color255 property, select the first one.
        color255Prop = color255Props[0] if len(color255Props) > 0 else None
        if color255Prop:
            color = self.mapObject.getPropertyValue(color255Prop)
            color = LEGlobals.colorFromRGBScalar255(color)
        else:
            color = Vec4(1)

        spritePath = helperInfo['args'][0].replace("\"", "")

        cm = CardMaker("sprite")
        cm.setFrame(-0.75, 0.75, -0.75, 0.75)
        np = NodePath(cm.generate())
        #np.setBSPMaterial(spritePath)
        np.setTexture(base.loader.loadTexture(spritePath))
        np.setColorScale(color)
        np.setLightOff(1)
        np.setFogOff(1)
        np.setBillboardPointEye()
        np.setTransparency(True)
        np.hide(~VIEWPORT_3D_MASK)
        np.reparentTo(self.mapObject.helperRoot)
        self.sprite = np
コード例 #2
0
    def generate(self, helperInfo):
        MapHelper.generate(self)

        args = helperInfo['args']
        modelPath = args[0] if len(args) > 0 else None
        if not modelPath:
            # Model wasn't specified in the class definition,
            # check for a property called "model"
            modelPath = self.mapObject.getPropertyValue(
                "model", default="models/smiley.egg.pz")
        else:
            # For some reason the fgd parser doesn't remove the quotes around the
            # model path string in the game class definition
            modelPath = modelPath.replace("\"", "")
        if not modelPath:
            return

        modelNp = base.loader.loadModel(modelPath, okMissing=True)
        if not modelNp:
            return

        colorScale = LEGlobals.colorFromRGBScalar255(
            self.mapObject.getPropertyValue("color_scale",
                                            default=Vec4(255, 255, 255, 255)))
        castShadows = self.mapObject.getPropertyValue("cast_shadows")
        reflect = self.mapObject.getPropertyValue("reflect")
        lighting = self.mapObject.getPropertyValue("receive_lighting")

        if colorScale != Vec4(1):
            modelNp.setColorScale(colorScale)
        if not lighting:
            modelNp.setLightOff(2)

        # Create a representation in each viewport
        for vp in base.viewportMgr.viewports:
            vpRoot = self.modelRoot.attachNewNode("vpRepr")
            showMask = vp.getViewportFullMask()
            if vp.is3D():
                if not castShadows:
                    showMask &= (~DirectRender.ShadowCameraBitmask)
                if not reflect:
                    showMask &= (~DirectRender.ReflectionCameraBitmask)
            vpRoot.hide(~showMask)
            self.vpRoots.append((vp, vpRoot))

            vpModel = modelNp.instanceTo(vpRoot)

        if self.mapObject.selected:
            self.setSelectedState()
        else:
            self.setUnselectedState()
コード例 #3
0
    def generate(self, helperInfo):
        color = self.mapObject.getPropertyValue("_light",
                                                default=Vec4(
                                                    255, 255, 255, 255))
        color = LEGlobals.colorFromRGBScalar255(color)
        color = LEGlobals.vec3GammaToLinear(color)

        intensity = self.mapObject.getPropertyValue("_intensity", default=1.0)

        color[0] = color[0] * intensity
        color[1] = color[1] * intensity
        color[2] = color[2] * intensity

        csmDistance = self.mapObject.getPropertyValue("_csm_distance")
        sunDistance = self.mapObject.getPropertyValue("_sun_distance")
        csmLogFactor = self.mapObject.getPropertyValue("_csm_log_factor")
        csmBorderBias = self.mapObject.getPropertyValue("_csm_border_bias")
        csmFixedFilmSize = self.mapObject.getPropertyValue(
            "_csm_fixed_film_size")
        numCascades = self.mapObject.getPropertyValue("_num_cascades")
        depthBias = self.mapObject.getPropertyValue("_depth_bias")
        shadowSize = self.mapObject.getPropertyValue("_shadow_map_size")
        shadowCaster = self.mapObject.getPropertyValue("_shadow_caster")
        softnessFactor = self.mapObject.getPropertyValue("_softness_factor")
        normalOffsetScale = self.mapObject.getPropertyValue(
            "_normal_offset_scale")
        normalOffsetUvSpace = self.mapObject.getPropertyValue(
            "_normal_offset_uv_space")

        pl = CascadeLight("lightHelper-light")
        pl.setColor(Vec4(color[0], color[1], color[2], 1.0))
        if shadowCaster:
            pl.setSceneCamera(self.mapObject.doc.get3DViewport().cam)
            pl.setCameraMask(DirectRender.ShadowCameraBitmask)
            pl.setCsmDistance(csmDistance)
            pl.setSunDistance(sunDistance)
            pl.setLogFactor(csmLogFactor)
            pl.setBorderBias(csmBorderBias)
            pl.setUseFixedFilmSize(csmFixedFilmSize)
            pl.setNumCascades(numCascades)
            pl.setDepthBias(depthBias)
            pl.setSoftnessFactor(softnessFactor)
            pl.setNormalOffsetScale(normalOffsetScale)
            pl.setNormalOffsetUvSpace(normalOffsetUvSpace)
            pl.setShadowCaster(True, shadowSize, shadowSize)
        self.light = self.mapObject.helperRoot.attachNewNode(pl)
        if True:  #self.mapObject.doc.numlights < 128:
            self.mapObject.doc.render.setLight(self.light)
            self.mapObject.doc.numlights += 1
            self.hasLight = True
コード例 #4
0
    def generate(self, helperInfo):
        color = self.mapObject.getPropertyValue("_light",
                                                default=Vec4(
                                                    255, 255, 255, 255))
        color = LEGlobals.colorFromRGBScalar255(color)
        color = LEGlobals.vec3GammaToLinear(color)

        intensity = self.mapObject.getPropertyValue("_intensity", default=1.0)

        color[0] = color[0] * intensity
        color[1] = color[1] * intensity
        color[2] = color[2] * intensity

        pl = AmbientLight("lightHelper-ambient-light")
        pl.setColor(Vec4(color[0], color[1], color[2], 1.0))
        self.light = self.mapObject.helperRoot.attachNewNode(pl)
        if True:  #self.mapObject.doc.numlights < 128:
            print("HI ambient light")
            self.mapObject.doc.render.setLight(self.light)
            self.mapObject.doc.numlights += 1
            self.hasLight = True
コード例 #5
0
    def generate(self, helperInfo):
        color = self.mapObject.getPropertyValue("_light",
                                                default=Vec4(
                                                    255, 255, 255, 255))
        color = LEGlobals.colorFromRGBScalar255(color)
        color = LEGlobals.vec3GammaToLinear(color)

        intensity = self.mapObject.getPropertyValue("_intensity", default=1.0)
        innerRadius = self.mapObject.getPropertyValue("_inner_radius",
                                                      default=1.0)
        outerRadius = self.mapObject.getPropertyValue("_outer_radius",
                                                      default=2.0)

        color[0] = color[0] * intensity
        color[1] = color[1] * intensity
        color[2] = color[2] * intensity

        constant = self.mapObject.getPropertyValue("_constant_attn",
                                                   default=0.0)
        linear = self.mapObject.getPropertyValue("_linear_attn", default=0.0)
        quadratic = self.mapObject.getPropertyValue("_quadratic_attn",
                                                    default=1.0)

        depthBias = self.mapObject.getPropertyValue("_depth_bias")
        shadowSize = self.mapObject.getPropertyValue("_shadow_map_size")
        shadowCaster = self.mapObject.getPropertyValue("_shadow_caster")
        softnessFactor = self.mapObject.getPropertyValue("_softness_factor")
        normalOffsetScale = self.mapObject.getPropertyValue(
            "_normal_offset_scale")
        normalOffsetUvSpace = self.mapObject.getPropertyValue(
            "_normal_offset_uv_space")

        pl = PointLight("lightHelper-light")
        pl.setColor(Vec4(color[0], color[1], color[2], 1.0))
        pl.setFalloff(quadratic)
        pl.setInnerRadius(innerRadius)
        pl.setOuterRadius(outerRadius)
        if shadowCaster:
            pl.setCameraMask(DirectRender.ShadowCameraBitmask)
            pl.setShadowCaster(True, shadowSize, shadowSize)
            pl.setDepthBias(depthBias)
            pl.setSoftnessFactor(softnessFactor)
            pl.setNormalOffsetScale(normalOffsetScale)
            pl.setNormalOffsetUvSpace(normalOffsetUvSpace)
        self.light = self.mapObject.helperRoot.attachNewNode(pl)
        if True:  #self.mapObject.doc.numlights < 128:
            self.mapObject.doc.render.setLight(self.light)
            self.mapObject.doc.numlights += 1
            self.hasLight = True

        innerSphere = getUnitCircle().copyTo(self.light)
        innerSphere.setScale(innerRadius)
        innerSphere.setColorScale(InnerColor)
        outerSphere = getUnitCircle().copyTo(self.light)
        outerSphere.setScale(outerRadius)
        outerSphere.setColorScale(OuterColor)

        self.innerSphere = innerSphere
        self.outerSphere = outerSphere

        if not self.mapObject.selected:
            innerSphere.stash()
            outerSphere.stash()
コード例 #6
0
    def generate(self, helperInfo):
        color = self.mapObject.getPropertyValue("_light",
                                                default=Vec4(
                                                    255, 255, 255, 255))
        color = LEGlobals.colorFromRGBScalar255(color)
        color = LEGlobals.vec3GammaToLinear(color)

        intensity = self.mapObject.getPropertyValue("_intensity", default=1.0)
        innerRadius = self.mapObject.getPropertyValue("_inner_radius",
                                                      default=1.0)
        outerRadius = self.mapObject.getPropertyValue("_outer_radius",
                                                      default=2.0)

        color[0] = color[0] * intensity
        color[1] = color[1] * intensity
        color[2] = color[2] * intensity

        constant = self.mapObject.getPropertyValue("_constant_attn",
                                                   default=0.0)
        linear = self.mapObject.getPropertyValue("_linear_attn", default=0.0)
        quadratic = self.mapObject.getPropertyValue("_quadratic_attn",
                                                    default=1.0)

        innerConeDeg = self.mapObject.getPropertyValue("_inner_cone")
        innerConeRad = deg2Rad(innerConeDeg)
        outerConeDeg = self.mapObject.getPropertyValue("_cone")
        outerConeRad = deg2Rad(outerConeDeg)

        depthBias = self.mapObject.getPropertyValue("_depth_bias")
        shadowSize = self.mapObject.getPropertyValue("_shadow_map_size")
        shadowCaster = self.mapObject.getPropertyValue("_shadow_caster")
        softnessFactor = self.mapObject.getPropertyValue("_softness_factor")
        normalOffsetScale = self.mapObject.getPropertyValue(
            "_normal_offset_scale")
        normalOffsetUvSpace = self.mapObject.getPropertyValue(
            "_normal_offset_uv_space")

        pl = Spotlight("lightHelper-light_spot")
        pl.setColor(Vec4(color[0], color[1], color[2], 1.0))
        pl.setFalloff(quadratic)
        pl.setInnerRadius(innerRadius)
        pl.setOuterRadius(outerRadius)
        pl.setExponent(self.mapObject.getPropertyValue("_exponent"))
        pl.setInnerCone(innerConeDeg)
        pl.setOuterCone(outerConeDeg)
        if shadowCaster:
            pl.setCameraMask(DirectRender.ShadowCameraBitmask)
            pl.setShadowCaster(True, shadowSize, shadowSize)
            pl.setDepthBias(depthBias)
            pl.setSoftnessFactor(softnessFactor)
            pl.setNormalOffsetScale(normalOffsetScale)
            pl.setNormalOffsetUvSpace(normalOffsetUvSpace)
        self.light = self.mapObject.helperRoot.attachNewNode(pl)
        if True:  #self.mapObject.doc.numlights < 64:
            self.mapObject.doc.render.setLight(self.light)
            self.mapObject.doc.numlights += 1
            self.hasLight = True

        self.spotlightMdl = base.loader.loadModel(
            "models/misc/spotlight-editor.bam")
        #self.spotlightMdl.setState("materials/spotlight-editor.mat")
        #state = self.spotlightMdl.getState()
        #params = state.getAttrib(ShaderParamAttrib)
        #params = params.setParam("selfillumtint", CKeyValues.toString(color.getXyz()))
        #print(params)
        #self.spotlightMdl.setState(state.setAttrib(params))
        self.spotlightMdl.reparentTo(self.light)
        self.spotlightMdl.setScale(0.5)
        self.spotlightMdl.setH(180)
        self.spotlightMdl.setLightOff(1)
        self.spotlightMdl.setRenderModeWireframe(1)
        self.spotlightMdl.setTextureOff(1)
        self.spotlightMdl.setColor(Vec4(0, 0, 0, 1))
        #self.spotlightMdl.setLightOff(self.light, 1)
        #self.spotlightMdl.ls()

        innerCone = getUnitCone().copyTo(self.light)
        innerCone.setSy(innerRadius)
        innerCone.setSx((innerConeRad / 2) * innerRadius)
        innerCone.setSz((innerConeRad / 2) * innerRadius)
        innerCone.setColorScale(InnerColor)
        self.innerCone = innerCone

        outerCone = getUnitCone().copyTo(self.light)
        outerCone.setSy(outerRadius)
        outerCone.setSx((outerConeRad / 2) * outerRadius)
        outerCone.setSz((outerConeRad / 2) * outerRadius)
        outerCone.setColorScale(OuterColor)
        self.outerCone = outerCone

        if not self.mapObject.selected:
            innerCone.stash()
            outerCone.stash()