Last active
December 20, 2016 19:56
-
-
Save csprance/f40b20098e5a3479da46b5b10e211226 to your computer and use it in GitHub Desktop.
Drop this in editor/Python/plugins/csSimBrush/startup.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @author Chris Sprance | |
# @Description Open the window from Tools->csTools->csSimBrush | |
# select a brush and click Convert Brush To SimBrush and it will sim and fall | |
# Move the object and press simulate again to simualte again | |
# Click Convert SimBrush to Brush to convert the selected simBrush back to a regular brush | |
from CrySide import QtWidgets | |
import SandboxBridge | |
from sandbox import general | |
from sandbox import physics | |
from sandbox import ui_action | |
class CsSimBrushWindow(QtWidgets.QWidget): | |
def __init__(self): | |
super(CsSimBrushWindow, self).__init__() | |
self.setLayout(QtWidgets.QVBoxLayout()) | |
brushSim = QtWidgets.QPushButton("Convert Brush to SimBrush") | |
brushSim.clicked.connect(self.simobj) | |
self.layout().addWidget(brushSim) | |
simMore = QtWidgets.QPushButton("Simulate Again") | |
simMore.clicked.connect(self.simmore) | |
self.layout().addWidget(simMore) | |
simBrush = QtWidgets.QPushButton("Convert SimBrush to Brush") | |
simBrush.clicked.connect(self.setobj) | |
self.layout().addWidget(simBrush) | |
def simmore(self): | |
physics.simulate_selection() | |
def simobj(self): | |
self.objname = general.get_names_of_selected_objects() | |
objpos = general.get_position(self.objname[0]) | |
objrot = general.get_rotation(self.objname[0]) | |
objscale = general.get_scale(self.objname[0]) | |
self.physobj = general.new_object( | |
'Entity', r'RigidBodyEx', r'brush_sim_temp', 0, 0, 0) | |
# set the physobj to be the selected brush object | |
sel_name = str(general.get_entity_geometry_file(self.objname[0])) | |
# general.set_entity_property('brush_sim_temp', 'Model',sel_name) | |
general.set_entity_geometry_file('brush_sim_temp', sel_name) | |
# 3. snap physobj to xform of selected object | |
general.set_position(self.physobj, int(objpos[0]), | |
int(objpos[1]), int(objpos[2])) | |
general.set_rotation(self.physobj, int(objrot[0]), | |
int(objrot[1]), int(objrot[2])) | |
general.set_scale(self.physobj, int(objscale[0]), | |
int(objscale[1]), int(objscale[2])) | |
general.set_entity_property(self.physobj, r'Mass', 45) | |
general.log('hiding ' + self.objname[0]) | |
general.hide_object(self.objname[0]) | |
general.select_object(self.physobj) | |
ui_action.actionPhysics_Simulate_Objects() | |
general.clear_selection() | |
general.select_object(self.objname[0]) | |
def setobj(self): | |
physics.get_state(self.physobj) | |
physpos = general.get_position(self.physobj) | |
physrot = general.get_rotation(self.physobj) | |
physscale = general.get_scale(self.physobj) | |
general.unhide_object(self.objname[0]) | |
general.set_position(self.objname[0], | |
physpos[0], physpos[1], physpos[2]) | |
general.set_rotation(self.objname[0], | |
physrot[0], physrot[1], physrot[2]) | |
general.set_scale(self.objname[0], | |
physscale[0], physscale[1], physscale[2]) | |
general.delete_object(self.physobj) | |
SandboxBridge.register_window( | |
CsSimBrushWindow, "csSimBrush", category="csTools", | |
needs_menu_item=True, menu_path="csTools", | |
unique=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment