def __CreateBakeEffect(self): """ Create and setup a planet's effect file for heightmap baking """ self.effectHeight = trinity.Tr2Effect() if self.effectHeight is None: self.LogError('Could not create effect for planet with id', self.itemID) return mainMesh = self.model.highDetail.children[0].meshLod if mainMesh is None: mainMesh = self.model.highDetail.children[0].mesh errorMsg = 'No LODs found on planet.\n' modelPath = 'modelPath=' + self.modelPath + '\n' presetPath = 'presetPath=' + self.presetPath + '\n' shaderPreset = 'shaderPreset=' + str( self.attributes.shaderPreset) + '\n' self.LogError(errorMsg, modelPath, presetPath, shaderPreset) if len(mainMesh.transparentAreas) > 0: resPath = mainMesh.transparentAreas[0].effect.effectFilePath elif len(mainMesh.opaqueAreas) > 0: resPath = mainMesh.opaqueAreas[0].effect.effectFilePath else: self.LogError('Unexpected program flow! Loading fallback shader.') resPath = 'res:/Graphics/Effect/Managed/Space/Planet/EarthlikePlanet.fx' resPath = resPath.replace('.fx', 'BlitHeight.fx') self.effectHeight.effectFilePath = resPath if self.__GetHeightMap1() is not None and self.__GetHeightMap2( ) is not None: param1 = trinity.TriTexture2DParameter() param1.name = 'NormalHeight1' self.heightMapResPath1 = util.GraphicFile(self.__GetHeightMap1()) self.effectHeight.resources.append(param1) param2 = trinity.TriTexture2DParameter() param2.name = 'NormalHeight2' self.heightMapResPath2 = util.GraphicFile(self.__GetHeightMap2()) self.effectHeight.resources.append(param2) param3 = trinity.Tr2FloatParameter() param3.name = 'Random' param3.value = float(self.itemID % 100) self.effectHeight.parameters.append(param3) param4 = trinity.Tr2FloatParameter() param4.name = 'TargetTextureHeight' param4.value = 2048 self.effectHeight.parameters.append(param4) paramList = self.__GetPlanetShaderParameters( '', 'trinity.Tr2Vector4Parameter') for param in paramList: self.effectHeight.parameters.append(param) paramList = self.__GetPlanetShaderParameters( '', 'trinity.Tr2FloatParameter') for param in paramList: self.effectHeight.parameters.append(param) resList = self.__GetPlanetShaderParameters( '', 'trinity.TriTexture2DParameter') for res in resList: self.effectHeight.resources.append(res)
def __ModifyPlanetShader(self): if self.typeID == const.typePlanetEarthlike or self.typeID == const.typePlanetSandstorm: now = datetime.datetime.now() random.seed(now.year + now.month * 30 + now.day + self.itemID) val = random.randint(1, 5) useDense = val % 5 == 0 if self.typeID == const.typePlanetEarthlike: if useDense: cloudMapIDs = (3857, 3858, 3859, 3860) cloudCapMapIDs = (3861, 3862, 3863, 3864) else: cloudMapIDs = (3848, 3849, 3851, 3852) cloudCapMapIDs = (3853, 3854, 3855, 3856) else: cloudMapIDs = (3956, 3957, 3958, 3959) cloudCapMapIDs = (3960, 3961, 3962, 3963) cloudMapIdx = random.randint(0, 3) cloudCapMapIdx = random.randint(0, 3) cloudCapTexResPath = util.GraphicFile( cloudCapMapIDs[cloudCapMapIdx]) cloudTexResPath = util.GraphicFile(cloudMapIDs[cloudMapIdx]) if self.largeTextures: cloudCapTexResPath = cloudCapTexResPath.replace( '.dds', '_HI.dds') cloudTexResPath = cloudTexResPath.replace('.dds', '_HI.dds') cloudCapParamList = self.__GetPlanetShaderParameters( 'CloudCapTexture', 'trinity.TriTexture2DParameter') for cloudCapParam in cloudCapParamList: cloudCapParam.resourcePath = cloudCapTexResPath cloudParamList = self.__GetPlanetShaderParameters( 'CloudsTexture', 'trinity.TriTexture2DParameter') for cloudParam in cloudParamList: cloudParam.resourcePath = cloudTexResPath cloudsBrightness = random.random() * 0.4 + 0.6 cloudsTransparency = random.random() * 2.0 + 1.0 cloudsFactorsParamList = self.__GetPlanetShaderParameters( 'CloudsFactors', 'trinity.Tr2Vector4Parameter') for cloudsFactorsParam in cloudsFactorsParamList: cloudsFactorsParam.v3 = cloudsTransparency cloudsFactorsParam.v2 = cloudsBrightness if self.typeID is const.typePlanetOcean or self.typeID is const.typePlanetEarthlike: if self.__GetPopulation() == 0: for textureParamName in [ 'CityLight', 'CityDistributionTexture', 'CityDistributionMask' ]: textureParamList = self.__GetPlanetShaderParameters( textureParamName, 'trinity.TriTexture2DParameter') for textureParam in textureParamList: textureParam.resourcePath = '' coverageFactorsParamList = self.__GetPlanetShaderParameters( 'CoverageFactors', 'trinity.Tr2Vector4Parameter') for coverageFactorsParam in coverageFactorsParamList: coverageFactorsParam.v4 = 0.0
def Prepare(self): shipID = self.ballIDs[0] shipBall = self.fxSequencer.GetBall(shipID) if shipBall is None: raise RuntimeError('EMPWave: no ball found') if self.moduleTypeID == 0: self.moduleTypeID = 15957 graphicID = cfg.invtypes.Get(self.moduleTypeID).graphicID if graphicID is None: raise RuntimeError('EMPWave: no graphic ID') gfxString = util.GraphicFile(graphicID) self.gfx = trinity.Load(gfxString) if self.gfx is None: raise RuntimeError('EMPWave: no effect found') entity = audio2.AudEmitter('effect_' + str(shipID)) obs = trinity.TriObserverLocal() obs.observer = entity if self.gfx.__bluetype__ in ('trinity.EveTransform', ): self.gfx.observers.append(obs) for curveSet in self.gfx.curveSets: for curve in curveSet.curves: if curve.__typename__ == 'TriEventCurve' and curve.name == 'audioEvents': curve.eventListener = entity self.gfxModel = trinity.EveRootTransform() radius = self.fxSequencer.GetTypeAttribute( self.moduleTypeID, const.attributeEmpFieldRange) self.gfxModel.scaling = (radius / 1000, radius / 1000, radius / 1000) self.radius = radius self.gfxModel.name = self.__guid__ self.gfxModel.children.append(self.gfx) self.gfxModel.translationCurve = shipBall scene = self.fxSequencer.GetScene() scene.objects.append(self.gfxModel)
def SetupLogo(self, shapes=[None, None, None], colors=[None, None, None]): i = 0 self.sr.layerpics = [] for each in ['layerPic1', 'layerPic2', 'layerPic3']: btn = uiprimitives.Sprite(parent=getattr(self.logopicker, each), pos=(0, 0, 0, 0), align=uiconst.TOALL, color=(1.0, 0.0, 1.0, 0.0)) btn.OnClick = (self.ClickPic, i) self.sr.layerpics.append(btn) texturePath = self.GetLogoLibShape(shapes[i]) btn.LoadTexture(texturePath) btn.SetRGB(1.0, 1.0, 1.0, 1.0) self.corpLogo.SetLayerShapeAndColor(layerNum=i, shapeID=shapes[i], colorID=colors[i]) self.sr.prefs[i] = shapes[i] i += 1 i = 0 self.sr.layercols = [] for each in ['layerStyle1', 'layerStyle2', 'layerStyle3']: btn = uiprimitives.Fill(parent=getattr(self.logopicker, each), pos=(0, 0, 0, 0), align=uiconst.TOALL, color=(1.0, 1.0, 1.0, 0.0), state=uiconst.UI_NORMAL) btn.OnClick = (self.ClickCol, i, btn) self.sr.layercols.append(btn) if colors[i]: newshader = blue.resMan.LoadObject(util.GraphicFile(colors[i])) color, blendMode = self.GetLogoLibColor(colors[i]) btn.SetRGB(*color) self.sr.prefs[i + 3] = colors[i] i = i + 1
def SchedulePrefetchForStation(self, stationId): key = 'station_%d' % stationId if not everesourceprefetch.KeyExists(key): filesToPrefetch = set() npcStation = cfg.mapSolarSystemContentCache.npcStations.get( stationId, None) if npcStation: graphic = util.GraphicFile(npcStation.graphicID) filesToPrefetch.add(graphic.lower()) everesourceprefetch.AddFileset(key, filesToPrefetch) everesourceprefetch.ScheduleFront(key)
def DoModelChange(self): oldModel = self.model if self.level is None or self.level not in self.modelLists: spaceObject.SpaceObject.LoadModel(self) else: modelName = util.GraphicFile(self.modelLists[self.level]) spaceObject.SpaceObject.LoadModel(self, modelName) if self.model is None: spaceObject.SpaceObject.LoadModel(self) self.SetStaticRotation() if oldModel is not None: uthread.pool('CustomsOffice::DelayedRemove', self.DelayedRemove, oldModel, int(1000)) if self.model is not None: self.model.display = True
def DoModelChange(self): """Handle the model change!""" oldModel = self.model if self.level is None or self.level not in self.modelLists: LargeCollidableStructure.LoadModel(self) else: modelName = util.GraphicFile(self.modelLists[self.level]) LargeCollidableStructure.LoadModel(self, modelName) if self.model is None: LargeCollidableStructure.LoadModel(self) self.SetStaticRotation() if oldModel is not None: uthread.pool('CustomsOffice::DelayedRemove', self.DelayedRemove, oldModel, int(1000)) if self.model is not None: self.model.display = True
def LoadRedFiles(self): presetPath = self.modelPath if self.__GetShaderPreset() is not None: presetPath = util.GraphicFile(self.__GetShaderPreset()) if self.largeTextures: presetPath = presetPath.replace('/Template/', '/Template_HI/') planet = trinity.Load(presetPath) if planet is None: self.LogError('No planet was loaded!', presetPath) return False planet.name = 'Planet' self.model.highDetail.children.append(planet) self.model.highDetail.children.append(self.districtContainer) self.model.highDetail.children.append(self.districtExplosions) self.__ModifyPlanetShader() self.__CreateBakeEffect() self.__CollectLargeResources() self.__ApplyPlanetAttributesToDistricts() return True
def GatherFilesForSolarSystem(self, ssid): filesToPrefetch = set() neighborSystemContents = cfg.mapSolarSystemContentCache[ssid] for stargateID, stargateInfo in neighborSystemContents.stargates.iteritems( ): typeID = stargateInfo.typeID graphic = cfg.invtypes.Get(typeID).Graphic().graphicFile filesToPrefetch.add(graphic.lower()) for planetID, planetInfo in neighborSystemContents.planets.iteritems(): pla = planetInfo.planetAttributes self._AddGraphicAttribute(pla, 'heightMap1', filesToPrefetch) self._AddGraphicAttribute(pla, 'heightMap2', filesToPrefetch) self._AddGraphicAttribute(pla, 'shaderPreset', filesToPrefetch) if hasattr(planetInfo, 'npcStations'): for stationID, stationInfo in planetInfo.npcStations.iteritems( ): graphic = util.GraphicFile(stationInfo.graphicID) filesToPrefetch.add(graphic.lower()) return filesToPrefetch
def LoadRedFiles(self): if self.modelPath is None: self.modelPath = self._GetModelPath() if self.largeTextures: self.modelPath = self.modelPath.replace('.red', '_HI.red') if self.rotatePlanet and not self.rotationApplied: self._ApplyPlanetRotation() if self.typeID == const.typeMoon and self.model.zOnlyModel is None: self._ApplyZOnlyModel() if self.attributes is None: self.attributes = self._GetPlanetAttributes(self.itemID) presetPath = self.modelPath if self.__GetShaderPreset() is not None: presetPath = util.GraphicFile(self.__GetShaderPreset()) self.presetPath = presetPath if self.largeTextures: presetPath = presetPath.replace('/Template/', '/Template_HI/') gfx = cfg.invtypes.GetIfExists(self.typeID).Graphic() if hasattr(gfx, 'albedoColor') and gfx.albedoColor: self.model.albedoColor = tuple(gfx.albedoColor) if hasattr(gfx, 'emissiveColor') and gfx.emissiveColor: self.model.emissiveColor = tuple(gfx.emissiveColor) planet = trinity.Load(presetPath) if planet is None: self.LogError('No planet was loaded!', presetPath) return False planet.name = 'Planet' self.model.highDetail.children.append(planet) self.model.highDetail.children.append(self.districtContainer) self.model.highDetail.children.append(self.districtExplosions) self.__ModifyPlanetShader() self.__CreateBakeEffect() self.__CollectLargeResources() self.__ApplyPlanetAttributesToDistricts() if self.isInflightPlanet and not self.audioStarted: self.audioStarted = True self.SetupAmbientAudio() return True
def _AddGraphicAttribute(self, pla, attr, filesToPrefetch): graphic = util.GraphicFile(getattr(pla, attr)) filesToPrefetch.add(graphic.lower())