sceneManager.py (11021B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation_new\sceneManager.py 2 import trinity 3 import telemetry 4 import blue 5 import geo2 6 import math 7 import eve.client.script.ui.login.charcreation_new.ccUtil as ccUtil 8 import charactercreator.const as ccConst 9 from eve.client.script.ui.camera.charCreationCamera import CharCreationCamera 10 from fsdBuiltData.common.graphicIDs import GetGraphicFile 11 ccSceneManager = None 12 13 def GetCharacterCreationSceneManager(): 14 global ccSceneManager 15 if ccSceneManager is None: 16 ccSceneManager = CharacterCreationSceneManager() 17 return ccSceneManager 18 19 20 class CharacterCreationSceneManager(object): 21 22 def __init__(self): 23 self.scene = None 24 self.avatarScene = None 25 self.sceneManagerSvc = None 26 self.camera = None 27 self.cameraUpdateJob = None 28 self.storedPortraitCameraSettings = None 29 self.cameraPoi = None 30 self.cameraPos = None 31 self.cameraFov = None 32 self.lightingID = ccConst.LIGHT_SETTINGS_ID[0] 33 self.lightColorID = ccConst.LIGHT_COLOR_SETTINGS_ID[0] 34 self.lightIntensity = 0.5 35 36 def Initialize(self): 37 self.sceneManagerSvc = sm.GetService('sceneManager') 38 39 def TearDown(self): 40 self.scene = None 41 self.avatarScene = None 42 self.cameraUpdateJob = None 43 self.ClearCamera() 44 45 def Cleanup(self): 46 self.scene = None 47 self.sceneManagerSvc.UnregisterScene('characterCreation') 48 self.ClearCamera() 49 50 @telemetry.ZONE_METHOD 51 def SetAvatarScene(self, info): 52 isNewScene = False 53 if self.avatarScene is None: 54 self.SetupScene(ccConst.SCENE_PATH_CUSTOMIZATION) 55 self.avatarScene = self.scene 56 self.floor = trinity.Load(ccConst.CUSTOMIZATION_FLOOR1) 57 self.floor2 = trinity.Load(ccConst.CUSTOMIZATION_FLOOR2) 58 self.scene.dynamics.append(self.floor) 59 self.scene.dynamics.append(self.floor2) 60 trinity.WaitForResourceLoads() 61 if info.genderID: 62 origin1 = self.floor.placeableRes.visualModel.meshes[0].opaqueAreas[0].effect.parameters.FindByName('Origin') 63 origin2 = self.floor2.placeableRes.visualModel.meshes[0].opaqueAreas[0].effect.parameters.FindByName('Origin') 64 origin1_list = list(origin1.value) 65 origin2_list = list(origin2.value) 66 origin1_list[2] = 2.2 67 origin2_list[2] = 2.3 68 origin1.value = tuple(origin1_list) 69 origin2.value = tuple(origin2_list) 70 isNewScene = True 71 else: 72 self.scene = self.avatarScene 73 self.sceneManagerSvc.SetActiveScene(self.scene, sceneKey='characterCreation') 74 return isNewScene 75 76 @telemetry.ZONE_METHOD 77 def SetupScene(self, path): 78 scene = trinity.Load(path) 79 blue.resMan.Wait() 80 if ccUtil.IsSlowMachine(): 81 if hasattr(scene, 'shadowCubeMap'): 82 scene.shadowCubeMap.enabled = False 83 if hasattr(scene, 'ssao') and hasattr(scene.ssao, 'enable'): 84 scene.ssao.enable = False 85 if hasattr(scene, 'ambientColor'): 86 scene.ambientColor = (0.25, 0.25, 0.25) 87 elif scene: 88 if hasattr(scene, 'shadowCubeMap'): 89 scene.shadowCubeMap.enabled = False 90 self.scene = scene 91 self.sceneManagerSvc.RegisterScene(scene, 'characterCreation') 92 self.sceneManagerSvc.SetRegisteredScenes('characterCreation') 93 94 def SetupForPortraitStep(self, avatar): 95 if self.camera is None: 96 self.SetupCamera(avatar, ccConst.CAMERA_MODE_PORTRAIT) 97 else: 98 self.camera.ToggleMode(ccConst.CAMERA_MODE_PORTRAIT, avatar=avatar, transformTime=500.0) 99 if self.cameraPos and self.cameraPoi: 100 self.camera.PlacePortraitCamera(self.cameraPos, self.cameraPoi) 101 xFactor, yFactor = self.camera.GetCorrectCameraXandYFactors(self.cameraPos, self.cameraPoi) 102 self.camera.xFactor = self.camera.xTarget = xFactor 103 self.camera.yFactor = self.camera.yTarget = yFactor 104 self.RestorePortraitCameraSettings() 105 self.UpdateLights() 106 107 def SetupCamera(self, avatar, cameraMode, callback = None, frontClip = None, backClip = None, controlStyle = None): 108 self.camera = CharCreationCamera(avatar, cameraMode) 109 if frontClip is not None: 110 self.camera.frontClip = frontClip 111 if backClip is not None: 112 self.camera.backclip = backClip 113 if controlStyle is not None: 114 self.camera.controlStyle = controlStyle 115 self.SetupCameraUpdateJob() 116 self.camera.SetMoveCallback(callback) 117 118 def SetUpNamingStepCamera(self, avatar): 119 self.SetupCamera(avatar, ccConst.CAMERA_MODE_DEFAULT, frontClip=3.5, backClip=100.0) 120 self.camera.fieldOfView = 0.3 121 self.camera.distance = 8.0 122 self.camera.SetPointOfInterest((0.0, self.camera.avatarEyeHeight / 2.0, 0.0)) 123 124 @telemetry.ZONE_METHOD 125 def SetupCameraUpdateJob(self): 126 self.sceneManagerSvc.RefreshJob(self.camera) 127 if self.cameraUpdateJob is None: 128 self.cameraUpdateJob = trinity.renderJob.CreateRenderJob('cameraUpdate') 129 r = trinity.TriStepPythonCB() 130 r.SetCallback(self.UpdateCamera) 131 self.cameraUpdateJob.steps.append(r) 132 self.sceneManagerSvc.characterRenderJob.SetCameraUpdate(self.cameraUpdateJob) 133 134 @telemetry.ZONE_METHOD 135 def UpdateCamera(self): 136 if self.camera is not None: 137 self.camera.Update() 138 139 @telemetry.ZONE_METHOD 140 def ClearCamera(self): 141 if self.camera is not None: 142 for priority, behavior in self.camera.cameraBehaviors: 143 behavior.camera = None 144 145 del self.camera.cameraBehaviors[:] 146 self.camera.avatar = None 147 self.camera = None 148 149 def ShouldMoveCamera(self, newPos, newPoi): 150 newDirection = geo2.Subtract(newPos, newPoi) 151 distanceDiff = abs(self.camera.distance - geo2.Vec3Length(newDirection)) 152 direction2 = geo2.Vec3Normalize(newDirection) 153 yaw = math.acos(direction2[0]) 154 yawDiff = abs(self.camera.yaw - yaw) 155 pitch = math.asin(direction2[1]) + math.pi / 2.0 156 pitchDiff = math.sqrt(math.pow(self.camera.pitch - pitch, 2)) 157 diffPos = geo2.Vec3Distance(self.camera.GetPosition(), newPos) 158 if distanceDiff < 5e-07 and yawDiff < 5e-05 and pitchDiff < 5e-05 and diffPos < 0.05: 159 return False 160 return True 161 162 @telemetry.ZONE_METHOD 163 def StorePortraitCameraSettings(self): 164 if self.camera is not None: 165 self.storedPortraitCameraSettings = {'poi': self.camera.poi, 166 'pitch': self.camera.pitch, 167 'yaw': self.camera.yaw, 168 'distance': self.camera.distance, 169 'xFactor': self.camera.xFactor, 170 'yFactor': self.camera.yFactor, 171 'fieldOfView': self.camera.fieldOfView} 172 173 def RestorePortraitCameraSettings(self): 174 if self.storedPortraitCameraSettings: 175 self.camera.SetPointOfInterest(self.storedPortraitCameraSettings['poi']) 176 self.camera.pitch = self.storedPortraitCameraSettings['pitch'] 177 self.camera.yaw = self.storedPortraitCameraSettings['yaw'] 178 self.camera.distance = self.storedPortraitCameraSettings['distance'] 179 self.camera.xFactor = self.storedPortraitCameraSettings['xFactor'] 180 self.camera.yFactor = self.storedPortraitCameraSettings['yFactor'] 181 self.camera.fieldOfView = self.storedPortraitCameraSettings['fieldOfView'] 182 183 def GetDoll(self, charID): 184 for obj in self.scene.dynamics: 185 if obj.name == 'doll_%s' % charID: 186 return obj 187 188 @telemetry.ZONE_METHOD 189 def SetLighting(self, lightScenePath): 190 self.SetLightScene(lightScenePath) 191 if ccUtil.IsSlowMachine(): 192 self.ReduceLights() 193 194 def SetSingleDollLighting(self): 195 self.SetLighting('res:/Graphics/Character/Global/PaperdollSettings/LightSettings/Normal.red') 196 197 def SetSingleDollCloseupLighting(self, genderID): 198 self.SetLighting('res:/Graphics/Character/Global/PaperdollSettings/LightSettings/OneDollCloseup.red') 199 light = self.GetLightByName('FrontMain') 200 if light: 201 if genderID: 202 light.coneDirection = (-0.2813, -0.3778, -0.7448) 203 else: 204 light.coneDirection = (-0.2813, -0.59375, -0.7448) 205 206 def SetTwoDollsLighting(self): 207 self.SetLighting('res:/Graphics/Character/Global/PaperdollSettings/LightSettings/Normal_TwoDolls.red') 208 209 @telemetry.ZONE_METHOD 210 def UpdateLights(self): 211 lightsPath = GetGraphicFile(self.lightingID) 212 lightColorPath = GetGraphicFile(self.lightColorID) 213 lightScene = trinity.Load(lightsPath) 214 lightColorScene = trinity.Load(lightColorPath) 215 ccUtil.SetupLighting(self.scene, lightScene, lightColorScene, self.lightIntensity) 216 if ccUtil.IsSlowMachine(): 217 self.ReduceLights() 218 219 @telemetry.ZONE_METHOD 220 def ReduceLights(self): 221 scene = self.scene 222 if hasattr(scene, 'lights'): 223 lightsToRemove = [] 224 for each in scene.lights: 225 if each.name != 'FrontMain': 226 lightsToRemove.append(each) 227 228 for each in lightsToRemove: 229 scene.lights.remove(each) 230 231 @telemetry.ZONE_METHOD 232 def SetLightScene(self, lightPath, scene = None): 233 scene = scene or self.scene 234 lightScene = trinity.Load(lightPath) 235 if scene: 236 lightList = [] 237 for l in scene.lights: 238 lightList.append(l) 239 240 for l in lightList: 241 scene.RemoveLightSource(l) 242 243 for l in lightScene.lights: 244 scene.AddLightSource(l) 245 246 @telemetry.ZONE_METHOD 247 def SetLights(self, lightID): 248 self.lightingID = lightID 249 self.UpdateLights() 250 251 @telemetry.ZONE_METHOD 252 def GetLight(self): 253 return self.lightingID 254 255 def GetLightByName(self, name): 256 if not self.scene: 257 return 258 for light in self.scene.lights: 259 if light.name == name: 260 return light 261 262 @telemetry.ZONE_METHOD 263 def SetLightColor(self, lightID): 264 self.lightColorID = lightID 265 self.UpdateLights() 266 267 @telemetry.ZONE_METHOD 268 def GetLightColor(self): 269 return self.lightColorID 270 271 @telemetry.ZONE_METHOD 272 def SetLightsAndColor(self, lightID, colorID): 273 self.lightingID = lightID 274 self.lightColorID = colorID 275 self.UpdateLights() 276 277 @telemetry.ZONE_METHOD 278 def SetLightIntensity(self, intensity): 279 self.lightIntensity = intensity 280 self.UpdateLights() 281 282 @telemetry.ZONE_METHOD 283 def GetLightIntensity(self): 284 return self.lightIntensity