NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

patternProjectorGizmo.py (7954B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\ship\pages\studio\patternProjectorGizmo.py
      2 import math
      3 import blue
      4 import geo2
      5 from cosmetics.client.ships.skins.live_data import current_skin_design_signals, current_skin_design
      6 from cosmetics.common.ships.skins.static_data.pattern_attribute import PatternAttribute
      7 from cosmetics.common.ships.skins.static_data.slot_name import SlotID, PATTERN_SLOT_IDS, PATTERN_SLOT_ID_BY_PATTERN_MATERIAL_ID, PATTERN_RELATED_SLOT_IDS
      8 from eve.client.script.ui.cosmetics.ship.const import SkinrPage
      9 from eve.client.script.ui.cosmetics.ship.pages import current_page
     10 from eve.client.script.ui.cosmetics.ship.pages.studio import studioSettings, studioSignals, patternProjectionUtil
     11 
     12 class PatternProjectorGizmo:
     13 
     14     def __init__(self):
     15         self.position = (0.0, 0.0, 0.0)
     16         self.rotation = (0.0, 0.0, 0.0, 1.0)
     17         self.scaling = (1.0, 1.0, 1.0)
     18         self.model = None
     19         self.origin_model = None
     20         self.lineBetweenRoot = None
     21         self.lineBetweenEffect = None
     22         self.scale = 1.0
     23         self._last_scale_value = 0.0
     24 
     25     def connect_signals(self):
     26         current_skin_design_signals.on_component_attribute_changed.connect(self.on_current_skin_design_component_attribute_changed)
     27         current_skin_design_signals.on_slot_selected.connect(self.on_slot_selected)
     28         current_skin_design_signals.on_slot_fitting_changed.connect(self.on_slot_fitting_changed)
     29         studioSignals.on_page_opened.connect(self.on_page_opened)
     30 
     31     def on_page_opened(self, page_id, page_args, last_page_id, animate = True):
     32         if page_id != SkinrPage.STUDIO_DESIGNER:
     33             self.disappear()
     34 
     35     def on_slot_fitting_changed(self, slot_id, component_instance):
     36         self.update_visibility()
     37 
     38     def on_slot_selected(self, slot_id):
     39         self.update_visibility()
     40 
     41     def update_visibility(self):
     42         slot_id = current_skin_design.get_selected_slot_id()
     43         if not slot_id or slot_id not in PATTERN_RELATED_SLOT_IDS:
     44             self.disappear()
     45         else:
     46             slot_id = PATTERN_SLOT_ID_BY_PATTERN_MATERIAL_ID.get(slot_id, slot_id)
     47             if current_skin_design.get().slot_layout.get_component(slot_id):
     48                 self.update_placement(slot_id)
     49                 self.appear()
     50             else:
     51                 self.disappear()
     52 
     53     def load_and_place_in_scene(self, scene):
     54         self.model = blue.resMan.LoadObject('res:/dx9/scene/skinr/Gizmo/Skinr_Gizmo_Crosshair_01a.red')
     55         self.origin_model = blue.resMan.LoadObject('res:/dx9/scene/skinr/skinr_gizmo_pointer_01a.red')
     56         self.lineBetweenRoot = blue.resMan.LoadObject('res:/dx9/scene/skinr/Skinr_Gizmo_Offset_01a.red')
     57         self.connect_signals()
     58         if self.model is not None:
     59             scene.objects.append(self.model)
     60             self.model.StartControllers()
     61         if self.origin_model is not None:
     62             scene.objects.append(self.origin_model)
     63             self.origin_model.StartControllers()
     64         if self.lineBetweenRoot is not None:
     65             scene.objects.append(self.lineBetweenRoot)
     66             self.lineBetweenRoot.StartControllers()
     67             childContainer = self.lineBetweenRoot.effectChildren.FindByName('EveChildLineSet_Base')
     68             if childContainer is not None:
     69                 subChildContainer = childContainer.objects.FindByName('scaler')
     70                 if subChildContainer is not None:
     71                     lineSet = subChildContainer.objects.FindByName('EveChildLineSet_01')
     72                     if lineSet is not None and len(lineSet.lines) > 0:
     73                         self.lineBetweenEffect = lineSet.lines[0]
     74         self.disappear()
     75 
     76     def update_line_between(self, pos1 = (0.0, 0.0, 0.0), pos2 = (0.0, 0.0, 0.0)):
     77         if pos1 is not None and pos2 is not None:
     78             if self.lineBetweenEffect is not None:
     79                 self.lineBetweenEffect.point1 = pos1
     80                 self.lineBetweenEffect.point2 = pos2
     81 
     82     def update_placement(self, slot_id):
     83         c = current_skin_design.get().get_fitted_component_instance(slot_id)
     84         if not c:
     85             return
     86         scale = max(c.ellipsoid_radii)
     87         self.scale = scale / 1000.0
     88         self.model.scaling = (self.scale, self.scale, self.scale)
     89         self.origin_model.scaling = (self.scale, self.scale, self.scale)
     90         position, rotation, userTwist, totalOffsetNormalized = (c.position,
     91          c.rotation,
     92          c.roll,
     93          c.offset_u_ratio ** 2 + c.offset_v_ratio ** 2)
     94         totalAddedGizmoOffset = (-0.5 * scale, 0.0, 0.0)
     95         totalAddedGizmoOffset = geo2.QuaternionTransformVector(rotation, totalAddedGizmoOffset)
     96         projector_pos = patternProjectionUtil.get_projector_position(c.yaw, c.pitch, c.ellipsoid_center, c.ellipsoid_radii)
     97         projector_pos = geo2.Vec3Add(projector_pos, totalAddedGizmoOffset)
     98         position = geo2.Vec3Add(position, totalAddedGizmoOffset)
     99         self.origin_model.translation = projector_pos
    100         self.origin_model.rotation = rotation
    101         offset = (scale * 0.005, 0.0, 0.0)
    102         offset = geo2.QuaternionTransformVector(rotation, offset)
    103         twistQuaternion = geo2.QuaternionRotationSetYawPitchRoll(0.0, userTwist * math.pi, 0.0)
    104         self.model.translation = geo2.Vec3Add(position, offset)
    105         self.model.rotation = geo2.QuaternionMultiply(geo2.QuaternionInverse(twistQuaternion), rotation)
    106         self.model.SetControllerVariable('twistValue', float(userTwist))
    107         self.update_line_between(geo2.Vec3Add(projector_pos, offset), geo2.Vec3Add(position, offset))
    108         self.lineBetweenRoot.SetControllerVariable('offsetBrightness', totalOffsetNormalized)
    109 
    110     def on_current_skin_design_component_attribute_changed(self, slot_id, attribute_id, value):
    111         if slot_id in PATTERN_SLOT_IDS:
    112             self.play_attribute_change_animation(attribute_id, value)
    113             self.update_placement(slot_id)
    114 
    115     def play_attribute_change_animation(self, attribute_id, value):
    116         if attribute_id == PatternAttribute.YAW_RATIO:
    117             self.model.HandleControllerEvent('orbitHorizontal')
    118             self.origin_model.HandleControllerEvent('isMoving')
    119             self.lineBetweenRoot.HandleControllerEvent('isMoving')
    120         elif attribute_id == PatternAttribute.PITCH_RATIO:
    121             self.model.HandleControllerEvent('orbitVertical')
    122             self.origin_model.HandleControllerEvent('isMoving')
    123             self.lineBetweenRoot.HandleControllerEvent('isMoving')
    124         elif attribute_id == PatternAttribute.OFFSET_U_RATIO:
    125             self.model.HandleControllerEvent('offsetHorizontal')
    126             self.lineBetweenRoot.HandleControllerEvent('isMoving')
    127         elif attribute_id == PatternAttribute.OFFSET_V_RATIO:
    128             self.model.HandleControllerEvent('offsetVertical')
    129             self.lineBetweenRoot.HandleControllerEvent('isMoving')
    130         elif attribute_id == PatternAttribute.ROLL_RATIO:
    131             self.model.HandleControllerEvent('twisting')
    132         elif attribute_id == PatternAttribute.SCALE:
    133             if value[0] > self._last_scale_value:
    134                 self.model.HandleControllerEvent('scaleUp')
    135             else:
    136                 self.model.HandleControllerEvent('scaleDown')
    137             self._last_scale_value = value[0]
    138 
    139     def appear(self):
    140         if not self.model:
    141             return
    142         self.model.SetControllerVariable('crosshairVisible', 1.0)
    143         self.lineBetweenRoot.SetControllerVariable('offsetVisible', 1.0)
    144         self.origin_model.SetControllerVariable('pointerVisible', 1.0)
    145 
    146     def disappear(self):
    147         studioSettings.pattern_rotation_follow_camera_setting.disable()
    148         if not self.model:
    149             return
    150         self.model.SetControllerVariable('crosshairVisible', 0.0)
    151         self.lineBetweenRoot.SetControllerVariable('offsetVisible', 0.0)
    152         self.origin_model.SetControllerVariable('pointerVisible', 0.0)