Advertisement
Guest User

Untitled

a guest
Sep 26th, 2015
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.14 KB | None | 0 0
  1. #TODO:
  2.  
  3. # Set the command name so that DarkRadiant recognises this file
  4. __commandName__ = 'scaleModel'
  5. __commandDisplayName__ = 'Scale Model...'
  6.  
  7.  
  8. # The actual algorithm called by DarkRadiant is contained in the execute() function
  9. def execute():
  10.     script = "Dark Radiant Transform Matrix Widget"
  11.     author = "Richard Bartlett"
  12.     version = "0.1.2"
  13.    
  14.     # Set default values
  15.     scale = 1
  16.     q3 = False
  17.    
  18.     # Dialog
  19.     dialog = GlobalDialogManager.createDialog(script + 'v' + version)
  20.    
  21.     # Add an entry box and remember the handle
  22.     scaleHandle = dialog.addEntryBox("Scale:")
  23.     dialog.setElementValue(scaleHandle, GlobalRegistry.get('user/scripts/scaleModel/recentScale'))
  24.    
  25.     # Add a checkbox for Q3
  26.     q3Handle = dialog.addCheckbox('Quake 3:')
  27.     dialog.setElementValue(q3Handle, GlobalRegistry.get('user/scripts/scaleModel/recentq3'))
  28.    
  29.     if dialog.run() == Dialog.OK:
  30.         scale = dialog.getElementValue(scaleHandle)
  31.         q3 = dialog.getElementValue(q3Handle)
  32.         try:
  33.             scale = float(scale)
  34.             if scale <= 0:
  35.                 raise ValueError
  36.         except:
  37.             errMsg = GlobalDialogManager.createMessageBox('No scale', 'A numerical value greater than zero is required.', Dialog.ERROR)
  38.             errMsg.run()
  39.             return
  40.         GlobalRegistry.set('user/scripts/scaleModel/recentScale', str(scale))
  41.         GlobalRegistry.set('user/scripts/scaleModel/recentq3', q3)
  42.  
  43.     # Check if we have a valid selection
  44.     selectionInfo = GlobalSelectionSystem.getSelectionInfo()
  45.  
  46.     # Don't allow empty selections or selected components only
  47.     if selectionInfo.totalCount == 0 or selectionInfo.totalCount == selectionInfo.componentCount:
  48.         errMsg = GlobalDialogManager.createMessageBox('No selection', 'Nothing selected, cannot run exporter.', Dialog.ERROR)
  49.         errMsg.run()
  50.         return
  51.  
  52.     selectedNode = GlobalSelectionSystem.ultimateSelected()
  53.     if selectedNode.getNodeType() != 'entity':
  54.         errMsg = GlobalDialogManager.createMessageBox('No entity', 'No entity is selected, cannot apply scale.', Dialog.ERROR)
  55.         errMsg.run()
  56.         return
  57.  
  58.     selectedEntity = selectedNode.getEntity()
  59.     if selectedEntity.getKeyValue('classname') != 'func_static':
  60.         errMsg = GlobalDialogManager.createMessageBox('No func_static', 'No func_static is selected, cannot apply scale.', Dialog.ERROR)
  61.         errMsg.run()
  62.         return
  63.  
  64.     if scale:
  65.         tMatrix = selectedEntity.getKeyValue('rotation')
  66.         mScale = selectedEntity.getKeyValue('modelscale')
  67.        
  68.         if tMatrix == '':
  69.             tMatrix = '1 0 0 0 1 0 0 0 1'
  70.        
  71.         if mScale == '':
  72.             mScale = '1'
  73.  
  74.         values = [float(x)*scale for x in tMatrix.split()]
  75.         tMatrix = ' '.join(map(str, values))
  76.        
  77.         values2 = float(x)*scale
  78.         mScale = str(values2)
  79.  
  80.         selectedEntity.setKeyValue('rotation', tMatrix)        
  81.         if q3:
  82.             selectedEntity.setKeyValue('modelscale', mScale)
  83.  
  84. # __executeCommand__ evaluates to true after DarkRadiant has successfully initialised
  85. if __executeCommand__:
  86.     execute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement