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

previewScene.py (7176B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\structure\components\previewScene.py
      2 import trinity
      3 import uthread
      4 from carbonui.primitives.container import Container
      5 from carbonui import const as uiconst
      6 from cosmetics.common.structures.const import StructurePaintSlot
      7 from eve.client.script.environment.sofService import GetSofService
      8 from eve.client.script.ui.control.scenecontainer import SceneContainer, SceneContainerBaseNavigation
      9 from eve.client.script.environment.spaceObject.spaceObject import modify_dna
     10 from eve.client.script.ui.cosmetics.structure import paintToolSelections
     11 from evegraphics import utils as gfxutils
     12 from paints.data import dataLoader as paintsDataLoader
     13 import evetypes
     14 from fsdBuiltData.common.graphicIDs import GetAnimationStateObjects
     15 from eve.client.script.environment.spaceObject.structure import STATE_VULNERABLE_ACTIVE
     16 TRANSITION_ZOOM_DEFAULT = 0.3
     17 MINIMUM_ZOOM_DISTANCE_DEFAULT = 5000
     18 ZOOM_RANGE = [1.6, 10.0]
     19 
     20 class PreviewPanel(Container):
     21 
     22     def __init__(self, **kw):
     23         super(PreviewPanel, self).__init__(**kw)
     24         self._construct_layout()
     25         paintToolSelections.SELECTED_STRUCTURE_TYPE.on_change.connect(self._on_structure_selection_changed)
     26         paintToolSelections.SELECTED_STRUCTURE_TYPE.on_change.connect(self._on_structure_selection_changed)
     27         self._on_structure_selection_changed(paintToolSelections.SELECTED_STRUCTURE_TYPE.get())
     28 
     29     def Close(self):
     30         super(PreviewPanel, self).Close()
     31         paintToolSelections.SELECTED_STRUCTURE_TYPE.on_change.disconnect(self._on_structure_selection_changed)
     32 
     33     def _construct_layout(self):
     34         self.preview_container = Container(name='preview_container', parent=self, align=uiconst.TOALL)
     35         self._live_preview = PaintPreviewSceneContainer(name='preview_scene', parent=self.preview_container, align=uiconst.TOALL)
     36         self.sceneNavigation = SceneContainerBaseNavigation(name='preview_navigation', parent=self.preview_container, align=uiconst.TOALL, pos=(0, 0, 0, 0), idx=0, state=uiconst.UI_NORMAL, pickRadius=0)
     37         self.sceneNavigation.Startup(self._live_preview)
     38 
     39     def _on_structure_selection_changed(self, type_id):
     40         self.update(type_id)
     41 
     42     def update(self, type_id, fit_in_view = True):
     43         base_dna = gfxutils.BuildSOFDNAFromTypeID(type_id)
     44         model_dna = modify_dna(base_dna=base_dna, mat1=self._get_material_for_slot(StructurePaintSlot.PRIMARY), mat2=self._get_material_for_slot(StructurePaintSlot.SECONDARY), mat3=self._get_material_for_slot(StructurePaintSlot.DETAILING), isStructure=True)
     45         self._live_preview.preview_type(type_id, model_dna, fit_to_view=fit_in_view)
     46 
     47     def _get_material_for_slot(self, slot_id):
     48         paint_id = paintToolSelections.SELECTED_PAINTWORK.get_slot(slot_id)
     49         if paint_id is None:
     50             return
     51         return paintsDataLoader.get_paint_material_name(paint_id)
     52 
     53 
     54 class PaintPreviewSceneContainer(SceneContainer):
     55     _model_dna = None
     56     _type_id = None
     57     _fit_to_view = True
     58 
     59     def __init__(self, **kwargs):
     60         super(PaintPreviewSceneContainer, self).__init__(**kwargs)
     61         self.PrepareSpaceScene(scenePath='res:/dx9/scene/universe/c05_cube.red')
     62         self.fadeObject = None
     63         if hasattr(self.camera, 'SetAdvancedInspectionMode'):
     64             self.camera.SetAdvancedInspectionMode(True)
     65 
     66     def PrepareSpaceScene(self, scenePath = None):
     67         if scenePath is None:
     68             scenePath = 'res:/dx9/scene/wormholes/wormhole_class_01.red'
     69         super(PaintPreviewSceneContainer, self).PrepareSpaceScene(scenePath=scenePath)
     70         if not self.scene.postprocess:
     71             self.scene.postprocess = trinity.Tr2PostProcess2()
     72         self.scene.sunDirection = (0.6198, -0.1016, -0.7781)
     73         self.scene.nebulaIntensity = 1.25
     74         self.scene.reflectionIntensity = 1.55
     75         self.scene.sunDiffuseColor = (1.0,
     76          205.0 / 255.0,
     77          170.0 / 255.0,
     78          1.0)
     79         self.scene.postprocess.taa = None
     80 
     81     def preview_type(self, type_id, model_dna, fit_to_view = True):
     82         self._type_id = type_id
     83         self._model_dna = model_dna
     84         self._fit_to_view = fit_to_view
     85         uthread.new(self._reload_model)
     86 
     87     def _reload_model(self):
     88         if self.destroyed:
     89             return
     90         with self._reloadLock:
     91             if self.fadeObject is None:
     92                 self.fadeObject = sm.GetService('sceneManager').GetFadeObject(scene=self.scene, create=True)
     93             space_object_factory = GetSofService().spaceObjectFactory
     94             self.model = space_object_factory.BuildFromDNA(self._model_dna)
     95             typeID = paintToolSelections.SELECTED_STRUCTURE_TYPE.get()
     96             graphicsID = evetypes.GetGraphicID(typeID)
     97             state_objects = GetAnimationStateObjects(graphicsID)
     98             dnaToLoad = state_objects[STATE_VULNERABLE_ACTIVE]
     99             self.stateObject = space_object_factory.BuildFromDNA(dnaToLoad)
    100             if self.stateObject is not None:
    101                 self.stateObject.SetControllerVariable('BuildDuration', 0)
    102                 self.stateObject.SetControllerVariable('BuildElapsedTime', 0)
    103                 self.stateObject.SetControllerVariable('IsBuilt', 1)
    104             if self.model is not None:
    105                 self.model.SetControllerVariable('BuildDuration', 0)
    106                 self.model.SetControllerVariable('BuildElapsedTime', 0)
    107                 self.model.SetControllerVariable('IsBuilt', 1)
    108                 self.model.SetControllerVariable('ActivationState', 2)
    109                 self.model.StartControllers()
    110             while len(self.model.observers) > 0:
    111                 self.model.observers.pop()
    112 
    113             self.model.FreezeHighDetailMesh()
    114             trinity.WaitForResourceLoads()
    115             self.ClearScene()
    116             if self._fit_to_view:
    117                 self._fit_model_in_view(self.model)
    118             if self.scene:
    119                 self.AddToScene(self.model)
    120                 self.AddToScene(self.stateObject, clear=0)
    121             self.stateObject.rotationCurve = self.model.rotationCurve
    122             self.stateObject.StartControllers()
    123 
    124     def _fit_model_in_view(self, model):
    125         if model is None:
    126             return
    127         if hasattr(model, 'GetBoundingSphereCenter'):
    128             rad = model.GetBoundingSphereRadius()
    129         else:
    130             rad = MINIMUM_ZOOM_DISTANCE_DEFAULT
    131         maxRenderDist = self.camera.farClip or 400000.0
    132         min_zoom = ZOOM_RANGE[0] * rad
    133         max_zoom = min(ZOOM_RANGE[1] * rad, maxRenderDist - 2 * rad)
    134         self.SetMinMaxZoom(min_zoom, max_zoom)
    135         self.SetZoom(TRANSITION_ZOOM_DEFAULT)
    136         if hasattr(self.camera, 'SetInnerBoundRadius') and self.model.shapeEllipsoidRadius is not None:
    137             self.camera.SetInnerBoundRadius(self.model.shapeEllipsoidRadius)
    138             if hasattr(self.camera, 'SetModelCenter'):
    139                 self.camera.SetModelCenter(self.model.shapeEllipsoidCenter)
    140 
    141     def OrbitParent(self, dx, dy):
    142         self.StopAnimations()
    143         fov = self.camera.fov
    144         cameraSpeed = 0.02
    145         self.camera.Orbit(dx * fov * cameraSpeed, dy * fov * cameraSpeed)