Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #TODO:
- # Set the command name so that DarkRadiant recognises this file
- __commandName__ = 'scaleModel'
- __commandDisplayName__ = 'Scale Model...'
- # The actual algorithm called by DarkRadiant is contained in the execute() function
- def execute():
- script = "Dark Radiant Transform Matrix Widget"
- author = "Richard Bartlett"
- version = "0.1.2"
- # Set default values
- scale = 1
- q3 = False
- # Dialog
- dialog = GlobalDialogManager.createDialog(script + 'v' + version)
- # Add an entry box and remember the handle
- scaleHandle = dialog.addEntryBox("Scale:")
- dialog.setElementValue(scaleHandle, GlobalRegistry.get('user/scripts/scaleModel/recentScale'))
- # Add a checkbox for Q3
- q3Handle = dialog.addCheckbox('Quake 3:')
- dialog.setElementValue(q3Handle, GlobalRegistry.get('user/scripts/scaleModel/recentq3'))
- if dialog.run() == Dialog.OK:
- scale = dialog.getElementValue(scaleHandle)
- q3 = dialog.getElementValue(q3Handle)
- try:
- scale = float(scale)
- if scale <= 0:
- raise ValueError
- except:
- errMsg = GlobalDialogManager.createMessageBox('No scale', 'A numerical value greater than zero is required.', Dialog.ERROR)
- errMsg.run()
- return
- GlobalRegistry.set('user/scripts/scaleModel/recentScale', str(scale))
- GlobalRegistry.set('user/scripts/scaleModel/recentq3', q3)
- # Check if we have a valid selection
- selectionInfo = GlobalSelectionSystem.getSelectionInfo()
- # Don't allow empty selections or selected components only
- if selectionInfo.totalCount == 0 or selectionInfo.totalCount == selectionInfo.componentCount:
- errMsg = GlobalDialogManager.createMessageBox('No selection', 'Nothing selected, cannot run exporter.', Dialog.ERROR)
- errMsg.run()
- return
- selectedNode = GlobalSelectionSystem.ultimateSelected()
- if selectedNode.getNodeType() != 'entity':
- errMsg = GlobalDialogManager.createMessageBox('No entity', 'No entity is selected, cannot apply scale.', Dialog.ERROR)
- errMsg.run()
- return
- selectedEntity = selectedNode.getEntity()
- if selectedEntity.getKeyValue('classname') != 'func_static':
- errMsg = GlobalDialogManager.createMessageBox('No func_static', 'No func_static is selected, cannot apply scale.', Dialog.ERROR)
- errMsg.run()
- return
- if scale:
- tMatrix = selectedEntity.getKeyValue('rotation')
- mScale = selectedEntity.getKeyValue('modelscale')
- if tMatrix == '':
- tMatrix = '1 0 0 0 1 0 0 0 1'
- if mScale == '':
- mScale = '1'
- values = [float(x)*scale for x in tMatrix.split()]
- tMatrix = ' '.join(map(str, values))
- values2 = float(x)*scale
- mScale = str(values2)
- selectedEntity.setKeyValue('rotation', tMatrix)
- if q3:
- selectedEntity.setKeyValue('modelscale', mScale)
- # __executeCommand__ evaluates to true after DarkRadiant has successfully initialised
- if __executeCommand__:
- execute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement