def createMeshAreaParams(self, meshArea, isDecal, isCloth = False, isTranslucent = False): """ Create the effect needed to draw mesh into the shadow map during the depth pass. The effect will use a skinned or non-skinned shader, based on not-cloth or cloth. For opaque vs. decals, only one shader is needed -- a spotlight.x parameter controls if the diffuse alpha should be used or not to do alphatesting. """ shadowEffect = trinity.Tr2Effect() shadowEffect.effectFilePath = SPOTLIGHT_SHADOW_EFFECT if not isCloth else SPOTLIGHT_SHADOW_EFFECT_CLOTH v = trinity.Tr2Vector4Parameter() v.name = 'spotlight' v.value = (float(isDecal), 1.0 / self.shadowResolution, float(isTranslucent), 1) shadowEffect.parameters.append(v) effect = None if hasattr(meshArea, 'effect') and meshArea.effect: effect = meshArea.effect elif hasattr(meshArea, 'effectReversed') and meshArea.effectReversed: effect = meshArea.effectReversed if type(effect) is not trinity.Tr2Effect: return if effect and isDecal: for p in effect.parameters: if p.name == 'TransformUV0': v = trinity.Tr2Vector4Parameter() v.name = p.name v.value = p.value shadowEffect.parameters.append(v) elif p.name == 'CutMaskInfluence': v = trinity.Tr2FloatParameter() v.name = p.name v.value = p.value shadowEffect.parameters.append(v) for r in effect.resources: if r.name == 'DiffuseMap' or r.name == 'CutMaskMap': t = trinity.TriTexture2DParameter() t.name = r.name t.SetResource(r.resource) shadowEffect.resources.append(t) shadowEffect.RebuildCachedData() if effect: pdCcf.AddWeakBlue(self, 'meshAreaShadowEffect', meshArea, shadowEffect) pdCcf.AddWeakBlue(self, 'meshAreaOriginalEffect', meshArea, meshArea.effect)
def CreateEffectParamsForMesh(self, mesh, isClothMesh = False): meshData = self.MeshData(self.width, isClothMesh) def IsHair(mesh): if not hasattr(mesh, 'name'): return True if mesh.name.lower().startswith('hair'): return True return False def IsSkin(mesh): if not hasattr(mesh, 'name'): return False skinAreas = ['bottominner', 'topinner', 'hands', 'feet', 'sleeveslower/standard', 'sleevesupper/standard'] for sa in skinAreas: if mesh.name.lower().startswith(sa): return True return False isTranslucent = IsHair(mesh) if not isClothMesh: for areaMesh in mesh.opaqueAreas: if not pdCcf.IsBeard(areaMesh): meshData.createMeshAreaParams(areaMesh, isDecal=False, isTranslucent=isTranslucent or pdCcf.IsGlasses(areaMesh)) else: meshData.inhibitShadows(areaMesh) for areaMesh in mesh.decalAreas: if not pdCcf.IsBeard(areaMesh): meshData.createMeshAreaParams(areaMesh, isDecal=True, isTranslucent=isTranslucent or pdCcf.IsGlasses(areaMesh)) else: meshData.inhibitShadows(areaMesh) for areaMesh in mesh.transparentAreas: if IsHair(mesh): meshData.createMeshAreaParams(areaMesh, isDecal=True, isTranslucent=True) else: meshData.inhibitShadows(areaMesh) else: if hasattr(mesh, 'effect') and mesh.effect and 'clothavatarhair_detailed' in mesh.effect.effectFilePath.lower(): isTranslucent = True meshData.createMeshAreaParams(mesh, isDecal=True, isCloth=True, isTranslucent=isTranslucent) fx = pdCcf.GetEffectsFromMesh(mesh) for f in fx: self.CreateEffectParams(f, meshData) for key in self.meshes.iterkeys(): if key.object == mesh: self.meshes[key] = meshData break else: pdCcf.AddWeakBlue(self, 'meshes', mesh, meshData)
def createMeshAreaParams(self, meshArea, isDecal, isCloth = False, isTranslucent = False): shadowEffect = trinity.Tr2Effect() shadowEffect.effectFilePath = SPOTLIGHT_SHADOW_EFFECT if not isCloth else SPOTLIGHT_SHADOW_EFFECT_CLOTH v = trinity.Tr2Vector4Parameter() v.name = 'spotlight' v.value = (float(isDecal), 1.0 / self.shadowResolution, float(isTranslucent), 1) shadowEffect.parameters.append(v) effect = None if hasattr(meshArea, 'effect') and meshArea.effect: effect = meshArea.effect elif hasattr(meshArea, 'effectReversed') and meshArea.effectReversed: effect = meshArea.effectReversed if type(effect) is not trinity.Tr2Effect: return if effect and isDecal: for p in effect.parameters: if p.name == 'TransformUV0': v = trinity.Tr2Vector4Parameter() v.name = p.name v.value = p.value shadowEffect.parameters.append(v) elif p.name == 'CutMaskInfluence': v = trinity.Tr2FloatParameter() v.name = p.name v.value = p.value shadowEffect.parameters.append(v) for r in effect.resources: if r.name == 'DiffuseMap' or r.name == 'CutMaskMap': t = trinity.TriTextureParameter() t.name = r.name t.SetResource(r.resource) shadowEffect.resources.append(t) shadowEffect.RebuildCachedData() if effect: pdCcf.AddWeakBlue(self, 'meshAreaShadowEffect', meshArea, shadowEffect) pdCcf.AddWeakBlue(self, 'meshAreaOriginalEffect', meshArea, meshArea.effect)
def AddMesh(self, mesh): if mesh is None or self.lightmap is None: return def SetupSkinMap(): for a in itertools.chain(mesh.opaqueAreas, mesh.decalAreas): if a.effect is not None and a.effect.resources is not None: for e in a.effect.resources: if e.name == 'SkinMap': self.skinMapPath = e.resourcePath self.paramSkinMap.resourcePath = self.skinMapPath return if self.skinMapPath is None: SetupSkinMap() m = self.Mesh() if not m.ExtractOrigEffect(mesh): return for areaRef, fx in m.origEffect.iteritems(): if areaRef.object is None: continue if pdCcf.IsBeard(areaRef.object): pdCcf.AddWeakBlue(m, 'lightmapRenderEffect', areaRef.object, None) pdCcf.AddWeakBlue(m, 'lightmapApplyEffect', areaRef.object, fx) pdCcf.AddWeakBlue(m, 'stretchmapRenderEffect', areaRef.object, None) continue wasDouble = 'double' in fx.effectFilePath.lower() singleApply = self.LIGHTMAP_APPLICATION_EFFECT doubleApply = self.LIGHTMAP_APPLICATION_DOUBLE_EFFECT lightmapRenderEffect = SkinLightmapRenderer.DuplicateEffect(fx, self.LIGHTMAP_RENDERER_DOUBLE_EFFECT if wasDouble else self.LIGHTMAP_RENDERER_EFFECT) lightmapApplyEffect = SkinLightmapRenderer.DuplicateEffect(fx, doubleApply if wasDouble else singleApply) pdCcf.AddWeakBlue(m, 'lightmapRenderEffect', areaRef.object, lightmapRenderEffect) pdCcf.AddWeakBlue(m, 'lightmapApplyEffect', areaRef.object, lightmapApplyEffect) stretchmapRenderEffect = trinity.Tr2Effect() stretchmapRenderEffect.effectFilePath = self.STRETCHMAP_RENDERER_EFFECT stretchmapRenderEffect.parameters = fx.parameters pdCcf.AddWeakBlue(m, 'stretchmapRenderEffect', areaRef.object, stretchmapRenderEffect) m.liveParameters.append(filter(lambda r: r[0].name.startswith('WrinkleNormalStrength') or r[0].name.startswith('spotLight'), zip(fx.parameters, lightmapRenderEffect.parameters, lightmapApplyEffect.parameters))) self.CreateExtraMaps(lightmapApplyEffect) stretchmapRenderEffect.PopulateParameters() stretchmapRenderEffect.RebuildCachedData() if False: self.DebugPrint('lightmapRenderEffect resources:') for p in lightmapRenderEffect.resources: self.DebugPrint(p.name) self.DebugPrint('lightmapApplyEffect resources:') for p in lightmapApplyEffect.resources: self.DebugPrint(p.name) pdCcf.AddWeakBlue(self, 'meshes', mesh, m)
def inhibitShadows(self, meshArea): pdCcf.AddWeakBlue(self, 'meshAreaShadowEffect', meshArea, None) pdCcf.AddWeakBlue(self, 'meshAreaOriginalEffect', meshArea, meshArea.effect)
def ExtractOrigEffect(self, mesh): for area in itertools.chain(mesh.opaqueAreas, mesh.decalAreas): pdCcf.AddWeakBlue(self, 'origEffect', area, area.effect) return len(self.origEffect) > 0
def AddMesh(self, mesh): """ Add a mesh to the list of items that need to be scattered. It must be from the visual model that was previous set with setSkinnedObject(). We don't actually support multiple objects, since they each require their own rendertarget and renderjobs. What we support however is a multiple opaque areas in the same mesh, eg head[1..5] and such. The needed setup for a mesh is - set them up with the same resources as the original effect - set up for resources they need (scattermap, specular lookup table, etc) """ if mesh is None or self.lightmap is None: return def SetupSkinMap(): for a in itertools.chain(mesh.opaqueAreas, mesh.decalAreas): if a.effect is not None and a.effect.resources is not None: for e in a.effect.resources: if e.name == 'SkinMap': self.skinMapPath = e.resourcePath self.paramSkinMap.resourcePath = self.skinMapPath return if self.skinMapPath is None: SetupSkinMap() m = self.Mesh() if not m.ExtractOrigEffect(mesh): return for areaRef, fx in m.origEffect.iteritems(): if areaRef.object is None: continue if pdCcf.IsBeard(areaRef.object): pdCcf.AddWeakBlue(m, 'lightmapRenderEffect', areaRef.object, None) pdCcf.AddWeakBlue(m, 'lightmapApplyEffect', areaRef.object, fx) pdCcf.AddWeakBlue(m, 'stretchmapRenderEffect', areaRef.object, None) continue wasDouble = 'double' in fx.effectFilePath.lower() singleApply = self.LIGHTMAP_APPLICATION_EFFECT doubleApply = self.LIGHTMAP_APPLICATION_DOUBLE_EFFECT lightmapRenderEffect = SkinLightmapRenderer.DuplicateEffect( fx, self.LIGHTMAP_RENDERER_DOUBLE_EFFECT if wasDouble else self.LIGHTMAP_RENDERER_EFFECT) lightmapApplyEffect = SkinLightmapRenderer.DuplicateEffect( fx, doubleApply if wasDouble else singleApply) pdCcf.AddWeakBlue(m, 'lightmapRenderEffect', areaRef.object, lightmapRenderEffect) pdCcf.AddWeakBlue(m, 'lightmapApplyEffect', areaRef.object, lightmapApplyEffect) stretchmapRenderEffect = trinity.Tr2Effect() stretchmapRenderEffect.effectFilePath = self.STRETCHMAP_RENDERER_EFFECT stretchmapRenderEffect.parameters = fx.parameters pdCcf.AddWeakBlue(m, 'stretchmapRenderEffect', areaRef.object, stretchmapRenderEffect) m.liveParameters.append( filter( lambda r: r[0].name.startswith('WrinkleNormalStrength') or r[0].name.startswith('spotLight'), zip(fx.parameters, lightmapRenderEffect.parameters, lightmapApplyEffect.parameters))) self.CreateExtraMaps(lightmapApplyEffect) stretchmapRenderEffect.PopulateParameters() stretchmapRenderEffect.RebuildCachedData() if False: self.DebugPrint('lightmapRenderEffect resources:') for p in lightmapRenderEffect.resources: self.DebugPrint(p.name) self.DebugPrint('lightmapApplyEffect resources:') for p in lightmapApplyEffect.resources: self.DebugPrint(p.name) pdCcf.AddWeakBlue(self, 'meshes', mesh, m)