def BindClothShaders(self, mesh, doll, isHair): if doll.currentLOD <= 0: fx = PD.GetEffectsFromMesh(mesh) for f in iter(fx): isHair = PD.PortraitTools.BindHeroHairShader(f, '.fx') or isHair if doll.currentLOD <= PD.LOD_SKIN: PD.PortraitTools.BindHeroClothShader(f, doll.useDXT5N) return isHair
def SetShaderValue(self, avatar, name, value): for mesh in avatar.visualModel.meshes: for effect in PD.GetEffectsFromMesh(mesh): effect.StartUpdate() for p in effect.parameters: if p.name == name: p.value = value break effect.RebuildCachedData() effect.EndUpdate()
def SetInteriorShader(self, asyncMeshes, mesh, wrinkleFx, doll): fx = PD.GetEffectsFromMesh(mesh) tasklets = [] for f in iter(fx): if type(f) == trinity.Tr2ShaderMaterial: continue t = uthread.new(self.SetInteriorShaderForFx_t, *(f, asyncMeshes, mesh, wrinkleFx, doll)) tasklets.append(t) PD.WaitForAll(tasklets, lambda x: x.alive)
def RebindDXT5ShadersForSM2(meshes): if meshes is None: return for mesh in meshes: effects = PD.GetEffectsFromMesh(mesh) for effect in effects: path = effect.effectFilePath.lower() if '_dxt5n.fx' not in path: continue path = path[:-9] + '.fx' if path not in PD.SHADERS_THAT_CAN_SWITCH_TO_FAST_SHADER_MODE: continue path = path[:-3] + '_fast_dxt5n.fx' effect.effectFilePath = path
def fun(): path = resPath def GetMapResourcePath(map): return path + '/' + PD.MAPNAMES[map] + '.dds' for map in PD.MAPS: texture = self.doll.mapBundle[map] texture.SaveAsync(GetMapResourcePath(map)) texture.WaitForSave() meshGeometryResPaths = {} for modifier in self.doll.buildDataManager.GetSortedModifiers(): meshGeometryResPaths.update(modifier.meshGeometryResPaths) for mesh in self.avatar.visualModel.meshes: mesh.geometryResPath = meshGeometryResPaths.get(mesh.name, '') for fx in PD.GetEffectsFromMesh(mesh): for resource in fx.resources: if resource.name in PD.MAPNAMES: resource.resourcePath = GetMapResourcePath(PD.MAPNAMES.index(resource.name)) trinity.Save(self.avatar, path + '/unique.red') morphTargets = {} for modifier in self.doll.buildDataManager.GetSortedModifiers(): if modifier.categorie in PD.BLENDSHAPE_CATEGORIES: morphTargets[modifier.name] = modifier.weight bsFilePath = blue.paths.ResolvePath(path + '/blendshapes.yaml') f = file(bsFilePath, 'w') yaml.dump(morphTargets, f) f.close() animOffsets = {} for bone in self.doll.boneOffsets: trans = self.doll.boneOffsets[bone]['translation'] animOffsets[bone] = trans aoFilePath = blue.paths.ResolvePath(path + '/animationOffsets.yaml') f = file(aoFilePath, 'w') yaml.dump(animOffsets, f) f.close()
def SetDecal_t(self, avatar, decal, setTexture, setMask): if decal is None: return while self.doingAvatar or decal.BusyLoading(): PD.Yield(frameNice=False) for mesh in iter(avatar.visualModel.meshes): for effect in PD.GetEffectsFromMesh(mesh): effect.StartUpdate() for p in effect.parameters: valuesToSet = None if p.name == 'TattooYawPitchRoll': valuesToSet = decal.GetYPR() elif p.name == 'TattooPosition': valuesToSet = decal.GetPositionAndScale() elif p.name == 'TattooOptions': valuesToSet = decal.GetOptions() elif p.name == 'TattooDimensions': valuesToSet = decal.GetDimensions() elif p.name == 'TattooAspectRatio' and hasattr( decal, 'aspectRatio'): valuesToSet = decal.aspectRatio elif p.name == 'TattooPickingLayer': valuesToSet = decal.layer if type(valuesToSet) == tuple: valLen = len(valuesToSet) if valLen < len(p.value): valuesToSet = valuesToSet + p.value[valLen:] if valuesToSet: p.value = valuesToSet resourceNameFound = False if setTexture: resourceNameFound = self.SetTexture_t( 'TattooTextureMap', decal.textureResource, effect) if setMask and resourceNameFound: resourceNameFound = self.SetTexture_t( 'TattooTextureMask', decal.maskResource, effect) effect.RebuildCachedData() effect.EndUpdate()
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) isInteriorStatic = hasattr(mesh, 'enlightenAreas') if isInteriorStatic: for areaMesh in mesh.enlightenAreas: meshData.createMeshAreaParams(areaMesh, isDecal=False, isTranslucent=False) elif not isClothMesh: for areaMesh in mesh.opaqueAreas: if not PD.IsBeard(areaMesh): meshData.createMeshAreaParams(areaMesh, isDecal=False, isTranslucent=isTranslucent or PD.IsGlasses(areaMesh)) else: meshData.inhibitShadows(areaMesh) for areaMesh in mesh.decalAreas: if not PD.IsBeard(areaMesh): meshData.createMeshAreaParams(areaMesh, isDecal=True, isTranslucent=isTranslucent or PD.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 = PD.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: PD.AddWeakBlue(self, 'meshes', mesh, meshData)
def FindSkinEffect(meshes): for mesh in iter(meshes): fx = PD.GetEffectsFromMesh(mesh) for effect in iter(fx): if effect.name.lower().startswith('c_skin_'): return effect