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

metadata.py (6129B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\iconrendering2\metadata.py
      2 from __future__ import print_function
      3 import os
      4 import yamlext
      5 from .const import IconStyle, IconViewMode
      6 DEFAULT_SUN_DIRECTION = (-1.0, -1.0, 0.5)
      7 DEFAULT_NEAR = 1.0
      8 DEFAULT_FAR = 1000000.0
      9 
     10 def BuildBaseIconMetadata():
     11     dict = {}
     12     dict['sunDirection'] = DEFAULT_SUN_DIRECTION
     13     dict['viewMode'] = IconViewMode.FREE
     14     dict['view'] = {'eye': (1000, 1000, 1000),
     15      'at': (0, 0, 0),
     16      'up': (0, 1, 0)}
     17     dict['projection'] = {'aspectRatio': 1.0,
     18      'fov': 1.0,
     19      'zn': DEFAULT_NEAR,
     20      'zf': DEFAULT_FAR,
     21      'left': None,
     22      'right': None,
     23      'top': None,
     24      'bottom': None}
     25     dict['stateControllerVariables'] = {}
     26     dict['animationOffset'] = 0
     27     dict['playCurveSets'] = False
     28     dict['scaleFactor'] = 1.0
     29     return dict
     30 
     31 
     32 def BuildDefaultIconDict():
     33     dict = {}
     34     dict['skip'] = False
     35     dict[IconStyle.STANDARD] = BuildBaseIconMetadata()
     36     return dict
     37 
     38 
     39 def CompareIconData(data1, data2):
     40     t1 = data1.get('sunDirection', None) == data2.get('sunDirection', None)
     41     t2 = True
     42     if 'view' in data1 and 'view' in data2:
     43         t2 = t2 and data1['view'].get('eye', None) == data2['view'].get('eye', None)
     44         t2 = t2 and data1['view'].get('at', None) == data2['view'].get('at', None)
     45         t2 = t2 and data1['view'].get('up', None) == data2['view'].get('up', None)
     46     t3 = True
     47     if 'view' in data1 and 'view' in data2:
     48         t3 = t3 and data1['projection'].get('aspectRatio', None) == data2['projection'].get('aspectRatio', None)
     49         t3 = t3 and data1['projection'].get('fov', None) == data2['projection'].get('fov', None)
     50         t3 = t3 and data1['projection'].get('zn', None) == data2['projection'].get('zn', None)
     51         t3 = t3 and data1['projection'].get('zf', None) == data2['projection'].get('zf', None)
     52         t3 = t3 and data1['projection'].get('left', None) == data2['projection'].get('left', None)
     53         t3 = t3 and data1['projection'].get('right', None) == data2['projection'].get('right', None)
     54         t3 = t3 and data1['projection'].get('bottom', None) == data2['projection'].get('bottom', None)
     55         t3 = t3 and data1['projection'].get('top', None) == data2['projection'].get('top', None)
     56     t4 = data1.get('stateControllerVariables', None) == data2.get('stateControllerVariables', None)
     57     t5 = data1.get('animationOffset', 0) == data2.get('animationOffset', 0)
     58     t6 = data1.get('playCurveSets', False) == data2.get('playCurveSets', False)
     59     t7 = data1.get('viewMode', IconViewMode.FREE) == data2.get('viewMode', IconViewMode.FREE)
     60     t8 = data1.get('scaleFactor', 1.0) == data2.get('scaleFactor', 1.0)
     61     return t1 and t2 and t3 and t4 and t5 and t6 and t7 and t8
     62 
     63 
     64 def UpdateIconDataFromScene(data, scene, camera):
     65     if 'sunDirection' in data:
     66         data['sunDirection'] = scene.sunDirection
     67     if 'view' in data:
     68         data['view']['eye'] = camera.GetPosition()
     69         data['view']['at'] = camera.GetPointOfInterest()
     70         data['view']['up'] = camera.GetUpVector()
     71     if 'projection' in data:
     72         data['projection']['zn'] = DEFAULT_NEAR
     73         data['projection']['zf'] = DEFAULT_FAR
     74         poc = camera.GetPerspectiveOffCenter()
     75         data['projection']['left'] = poc[0]
     76         data['projection']['right'] = poc[1]
     77         data['projection']['top'] = poc[2]
     78         data['projection']['bottom'] = poc[3]
     79     return data
     80 
     81 
     82 def UpdateSceneFromIconData(data, scene, camera):
     83     if 'sunDirection' not in data:
     84         data['sunDirection'] = (0, 0, 0)
     85     scene.sunDirection = data['sunDirection']
     86     if 'view' not in data:
     87         data['view'] = {}
     88         data['view']['eye'] = (0, 0, 0)
     89         data['view']['up'] = (0, 0, 0)
     90         data['view']['at'] = (0, 0, 0)
     91     camera.SetPosition(data['view']['eye'])
     92     camera.SetUpVector(data['view']['up'])
     93     camera.LookAt(data['view']['at'], data['view']['up'])
     94     if 'projection' not in data:
     95         data['projection'] = {}
     96         data['projection']['aspectRatio'] = 1.0
     97         data['projection']['fov'] = 1.0
     98         data['projection']['zn'] = DEFAULT_NEAR
     99         data['projection']['zf'] = DEFAULT_FAR
    100         data['projection']['left'] = None
    101         data['projection']['right'] = None
    102         data['projection']['top'] = None
    103         data['projection']['bottom'] = None
    104     camera.SetPerspectiveOffCenter(data['projection']['left'], data['projection']['right'], data['projection']['top'], data['projection']['bottom'], data['projection']['zn'], data['projection']['zf'])
    105     camera.Update()
    106 
    107 
    108 def UpdateIconDataFromStateControllers(data, obj):
    109     ClearStateControllerVariables(data)
    110     try:
    111         variables = obj.Find('trinity.Tr2ControllerFloatVariable')
    112         for var in variables:
    113             if var.value != var.defaultValue:
    114                 SetStateControllerVariable(data, var.name, var.value)
    115 
    116     except:
    117         print("Couldn't retrieve state controller variables for %s" % (obj.name if hasattr(obj, 'name') else obj))
    118 
    119     return data
    120 
    121 
    122 def UpdateStateControllersFromIconData(data, obj):
    123     try:
    124         for key, val in data['stateControllerVariables'].iteritems():
    125             obj.SetControllerVariable(key, val)
    126 
    127         obj.StartControllers()
    128     except:
    129         pass
    130 
    131 
    132 def ClearStateControllerVariables(data):
    133     data['stateControllerVariables'] = {}
    134 
    135 
    136 def SetStateControllerVariable(data, variableName, value):
    137     if variableName not in data['stateControllerVariables']:
    138         data['stateControllerVariables'][variableName] = None
    139     data['stateControllerVariables'][variableName] = value
    140 
    141 
    142 def LoadMetaDataForSpaceObject(resPath, hullName):
    143     metaDataPath = os.path.abspath(os.path.dirname(resPath) + '\\\\metadata\\\\%s_icon.yml' % hullName)
    144     if not os.path.exists(metaDataPath):
    145         return None
    146     return yamlext.loadfile(metaDataPath)
    147 
    148 
    149 def AppendControllerOverrides(metadata, overrides):
    150     if 'stateControllerVariables' not in metadata:
    151         metadata['stateControllerVariables'] = {}
    152     for name, value in overrides.iteritems():
    153         SetStateControllerVariable(metadata, name, value)