modelDebugFunctions.py (10662B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\menuSvcExtras\modelDebugFunctions.py 2 import log 3 import blue 4 import geo2 5 import trinity 6 import math 7 import eveclientqatools.blueobjectviewer as blueViewer 8 from ballparkCommon.docking import GetUndockDirections 9 from eve.client.script.ui.control.fileDialog import FileDialog 10 from eveclientqatools.textureViewer import TextureWindow 11 UNLOAD_COLLISION_INFO = 0 12 SHOW_COLLISION_DATA = 1 13 SHOW_DESTINY_BALL = 2 14 SHOW_MODEL_SPHERE = 3 15 SHOW_BOUNDING_SPHERE = 4 16 17 def SaveRedFile(ball, graphicFile): 18 dlgRes = FileDialog.SelectFolders(multiSelect=False) 19 if dlgRes is not None: 20 path = dlgRes.Get('folders')[0] 21 graphicFile = graphicFile.split('/')[-1] 22 graphicFile = graphicFile.replace('.blue', '.red') 23 savePath = path + '\\' + graphicFile 24 trinity.Save(ball.model, savePath) 25 log.LogError('GM menu: Saved object as:', savePath) 26 27 28 def GetGMModelInfoMenuItem(itemID = None): 29 30 def GetModelHandler(*args): 31 model = sm.StartService('michelle').GetBall(itemID).GetModel() 32 blueViewer.Show(model) 33 34 return ('Inspect model', GetModelHandler, (None,)) 35 36 37 def GetGMBallsAndBoxesMenu(itemID = None, *args, **kwargs): 38 spaceMgr = sm.StartService('space') 39 partMenu = [('Stop partition box display ', spaceMgr.StopPartitionDisplayTimer, ()), 40 None, 41 ('Start partition box display limit = 0', spaceMgr.StartPartitionDisplayTimer, (0,)), 42 ('Start partition box display limit = 1', spaceMgr.StartPartitionDisplayTimer, (1,)), 43 ('Start partition box display limit = 2', spaceMgr.StartPartitionDisplayTimer, (2,)), 44 ('Start partition box display limit = 3', spaceMgr.StartPartitionDisplayTimer, (3,)), 45 ('Start partition box display limit = 4', spaceMgr.StartPartitionDisplayTimer, (4,)), 46 ('Start partition box display limit = 5', spaceMgr.StartPartitionDisplayTimer, (5,)), 47 ('Start partition box display limit = 6', spaceMgr.StartPartitionDisplayTimer, (6,)), 48 ('Start partition box display limit = 7', spaceMgr.StartPartitionDisplayTimer, (7,)), 49 None, 50 ('Show single level', ChangePartitionLevel, (0,)), 51 ('Show selected level and up', ChangePartitionLevel, (1,))] 52 subMenu = [('Balls & Boxes', [('Hide Collision Info', ShowDestinyBalls, (itemID, UNLOAD_COLLISION_INFO)), 53 ('Show Collision Info', ShowDestinyBalls, (itemID, SHOW_COLLISION_DATA)), 54 None, 55 ('Wireframe Destiny Ball', ShowDestinyBalls, (itemID, SHOW_DESTINY_BALL)), 56 ('Wireframe BoundingSphere', ShowDestinyBalls, (itemID, SHOW_BOUNDING_SPHERE)), 57 None, 58 ('Partition', partMenu), 59 ('Copy Bubble ID', _CopyBubbleID, (itemID,))])] 60 return subMenu 61 62 63 def _CopyBubbleID(itemID): 64 bubbleID = sm.StartService('michelle').AdminGetBubbleID(itemID) 65 blue.pyos.SetClipboardData(str(bubbleID)) 66 67 68 def ChangePartitionLevel(level): 69 settings.user.ui.Set('partition_box_showall', level) 70 71 72 def ShowShieldEllipsoid(itemID): 73 ball = sm.StartService('michelle').GetBall(itemID) 74 model = getattr(ball, 'model', None) 75 if model is not None: 76 impactEffect = getattr(model, 'impactOverlay', None) 77 if impactEffect is not None: 78 if impactEffect.overallShieldImpact < 0.0: 79 impactEffect.overallShieldImpact = 0.1 80 else: 81 impactEffect.overallShieldImpact = -1.0 82 83 84 def ShowUndockLocations(itemID): 85 scene = sm.GetService('sceneManager').GetRegisteredScene('default') 86 name = 'undockingLocators_for_' + str(itemID) 87 for each in scene.objects: 88 if getattr(each, 'name', None) == name: 89 scene.objects.remove(each) 90 return 91 92 ball = sm.StartService('michelle').GetBallpark().GetBall(itemID) 93 locatorTypes = GetUndockDirections(ball.typeID) 94 locators = [] 95 for points in locatorTypes.itervalues(): 96 locators += points 97 98 if len(locators) > 0: 99 graphicObject = CreateLocatorObject(name, ball.radius, locators) 100 graphicObject.translationCurve = ball.model.translationCurve 101 graphicObject.rotationCurve = ball.model.rotationCurve 102 scene.objects.append(graphicObject) 103 104 105 def ShowDestinyBalls(itemID, showType): 106 miniballObject = None 107 scene = sm.GetService('sceneManager').GetRegisteredScene('default') 108 nameOfMiniballs = 'collisionInfo_for_' + str(itemID) 109 for each in scene.objects: 110 if getattr(each, 'name', None) == nameOfMiniballs: 111 miniballObject = each 112 break 113 114 if miniballObject is not None: 115 scene.objects.remove(miniballObject) 116 if miniballObject and showType == UNLOAD_COLLISION_INFO: 117 return 118 ball = sm.StartService('michelle').GetBall(itemID) 119 if showType == SHOW_COLLISION_DATA: 120 graphicObject = CreateMiniCollisionObject(nameOfMiniballs, ball.miniBalls, ball.miniCapsules, ball.miniBoxes) 121 graphicObject.translationCurve = ball 122 graphicObject.rotationCurve = ball 123 scene.objects.append(graphicObject) 124 elif showType == SHOW_DESTINY_BALL: 125 graphicObject = CreateRadiusObject(nameOfMiniballs, ball.radius) 126 graphicObject.translationCurve = ball 127 scene.objects.append(graphicObject) 128 elif showType == SHOW_BOUNDING_SPHERE: 129 graphicObject = CreateRadiusObject(nameOfMiniballs, ball.model.GetBoundingSphereRadius()) 130 pos = ball.model.GetBoundingSphereCenter() 131 graphicObject.translation = (pos[0], pos[1], pos[2]) 132 graphicObject.translationCurve = ball.model.translationCurve 133 graphicObject.rotationCurve = ball.model.rotationCurve 134 scene.objects.append(graphicObject) 135 136 137 def GetTrinityDebugItems(itemID): 138 ball = sm.StartService('michelle').GetBallpark().GetBall(itemID) 139 so = getattr(ball, 'model', None) 140 if so is None: 141 return [] 142 items = [None] 143 debugger = sm.GetService('sceneManager').GetRegisteredScene('default').debugRenderer 144 145 def toggleOption(option): 146 147 def inner(): 148 ball = sm.StartService('michelle').GetBallpark().GetBall(itemID) 149 spaceObject = getattr(ball, 'model', None) 150 scene = sm.GetService('sceneManager').GetRegisteredScene('default') 151 if not scene.debugRenderer: 152 scene.debugRenderer = trinity.Tr2DebugRenderer() 153 options = scene.debugRenderer.GetOptions(spaceObject) 154 if option in options: 155 options.remove(option) 156 else: 157 options.append(option) 158 scene.debugRenderer.SetOptions(spaceObject, options) 159 for each in getattr(spaceObject, 'attachments', []): 160 scene.debugRenderer.SetOptions(each, options) 161 162 return inner 163 164 available = trinity.GetDebugRenderOptions(so) 165 for each in sorted(available): 166 if debugger and each in debugger.GetOptions(so): 167 selected = ' - selected' 168 else: 169 selected = '' 170 items.append((each + selected, toggleOption(each), ())) 171 172 return items 173 174 175 def CreateMiniCollisionObject(name, miniballs, minicapsules, miniboxes): 176 t = trinity.EveRootTransform() 177 sphere = blue.resMan.LoadObject('res:/Model/Global/Miniball.red') 178 capsule = blue.resMan.LoadObject('res:/Model/Global/Minicapsule.red') 179 box = blue.resMan.LoadObject('res:/Model/Global/Minibox.red') 180 if len(miniballs) > 0: 181 for miniball in miniballs: 182 mball = sphere.CopyTo() 183 mball.translation = (miniball.x, miniball.y, miniball.z) 184 r = miniball.radius * 2 185 mball.scaling = (r, r, r) 186 t.children.append(mball) 187 188 for minicapsule in minicapsules: 189 mcapsule = capsule.CopyTo() 190 pointA = (minicapsule.ax, minicapsule.ay, minicapsule.az) 191 pointB = (minicapsule.bx, minicapsule.by, minicapsule.bz) 192 dir = geo2.Vec3Subtract(pointA, pointB) 193 length = geo2.Vec3Length(dir) 194 mcapsule.translation = geo2.Vec3Scale(geo2.Vec3Add(pointA, pointB), 0.5) 195 radius = minicapsule.radius 196 pitch = math.acos(dir[1] / length) 197 yaw = math.atan2(dir[0], dir[2]) 198 quat = geo2.QuaternionRotationSetYawPitchRoll(yaw, pitch, 0) 199 mcapsule.rotation = quat 200 for each in mcapsule.children: 201 if each.name == 'Cylinder': 202 height = length * each.scaling[1] 203 rscaling = geo2.Vec3Scale((each.scaling[0], each.scaling[2]), radius) 204 each.scaling = (rscaling[0], height, rscaling[1]) 205 else: 206 each.scaling = geo2.Vec3Scale(each.scaling, radius) 207 each.translation = geo2.Vec3Scale(each.translation, length) 208 209 t.children.append(mcapsule) 210 211 for minibox in miniboxes: 212 mbox = box.CopyTo() 213 corner = (minibox.c0, minibox.c1, minibox.c2) 214 xAxis = (minibox.x0, minibox.x1, minibox.x2) 215 yAxis = (minibox.y0, minibox.y1, minibox.y2) 216 zAxis = (minibox.z0, minibox.z1, minibox.z2) 217 xyzAxis = geo2.Vec3Add(xAxis, geo2.Vec3Add(yAxis, zAxis)) 218 center = geo2.Vec3Add(corner, geo2.Vec3Scale(xyzAxis, 0.5)) 219 xNormalized = geo2.Vec3Normalize(xAxis) 220 yNormalized = geo2.Vec3Normalize(yAxis) 221 zNormalized = geo2.Vec3Normalize(zAxis) 222 rotationMatrix = ((xNormalized[0], 223 xNormalized[1], 224 xNormalized[2], 225 0), 226 (yNormalized[0], 227 yNormalized[1], 228 yNormalized[2], 229 0), 230 (zNormalized[0], 231 zNormalized[1], 232 zNormalized[2], 233 0), 234 (0, 0, 0, 1)) 235 rot = geo2.QuaternionRotationMatrix(rotationMatrix) 236 mbox.translation = center 237 mbox.scaling = geo2.Vec3Transform((1, 1, 1), geo2.MatrixScaling(geo2.Vec3Length(xAxis), geo2.Vec3Length(yAxis), geo2.Vec3Length(zAxis))) 238 mbox.rotation = geo2.QuaternionNormalize(rot) 239 t.children.append(mbox) 240 241 t.name = name 242 return t 243 244 245 def CreateRadiusObject(name, radius): 246 t = trinity.EveRootTransform() 247 t.name = name 248 s = blue.resMan.LoadObject('res:/model/global/gridSphere.red') 249 radius = radius * 2 250 s.scaling = (radius, radius, radius) 251 t.children.append(s) 252 return t 253 254 255 def CreateLocatorObject(name, radius, locators): 256 t = trinity.EveRootTransform() 257 t.name = name 258 radius = radius / 100 259 for position, rotation in locators: 260 s = blue.resMan.LoadObject('res:/model/global/impactDirection.red') 261 s.scaling = (radius, radius, radius) 262 s.translation = position 263 s.rotation = geo2.QuaternionRotationArc((0.0, 1.0, 0.0), rotation) 264 t.children.append(s) 265 266 return t