Skip to content

Commit

Permalink
God Mode: Physics (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay authored Jun 27, 2024
2 parents 3f1aede + 014dcb0 commit f22f995
Show file tree
Hide file tree
Showing 28 changed files with 526 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ class JointRelationship(enum.Enum):


class DynamicOccurrenceNode(GraphNode):
def __init__(self, occurrence: adsk.fusion.Occurrence, isGround=False, previous=None):
def __init__(
self, occurrence: adsk.fusion.Occurrence, isGround=False, previous=None
):
super().__init__(occurrence)
self.isGround = isGround
self.name = occurrence.name
Expand Down Expand Up @@ -122,7 +124,9 @@ def getConnectedAxisTokens(self) -> list:


class DynamicEdge(GraphEdge):
def __init__(self, relationship: OccurrenceRelationship, node: DynamicOccurrenceNode):
def __init__(
self, relationship: OccurrenceRelationship, node: DynamicOccurrenceNode
):
super().__init__(relationship, node)

# should print all in this class
Expand Down Expand Up @@ -514,7 +518,9 @@ def populateJoint(simNode: SimulationNode, joints: joint_pb2.Joints, progressDia
# print(f"Configuring {proto_joint.info.name}")

# construct body tree if possible
createTreeParts(simNode.data, OccurrenceRelationship.CONNECTION, root, progressDialog)
createTreeParts(
simNode.data, OccurrenceRelationship.CONNECTION, root, progressDialog
)

proto_joint.parts.nodes.append(root)

Expand All @@ -533,7 +539,10 @@ def createTreeParts(
raise RuntimeError("User canceled export")

# if it's the next part just exit early for our own sanity
if relationship == OccurrenceRelationship.NEXT or dynNode.data.isLightBulbOn == False:
if (
relationship == OccurrenceRelationship.NEXT
or dynNode.data.isLightBulbOn == False
):
return

# set the occurrence / component id to reference the part
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ def _jointOrigin(
geometryOrOrigin = (
(
fusionJoint.geometryOrOriginOne
if fusionJoint.geometryOrOriginOne.objectType == "adsk::fusion::JointGeometry"
if fusionJoint.geometryOrOriginOne.objectType
== "adsk::fusion::JointGeometry"
else fusionJoint.geometryOrOriginTwo
)
if fusionJoint.objectType == "adsk::fusion::Joint"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ def _format(self):
# TABS DO NOTHING HALP
out = f"{self.assemblyName} parsing:\n"
out += f"\t Components: \t[ {self.currentCompCount} / {self.componentCount} ]\n"
out += f"\t Occurrences: \t[ {self.currentOccCount} / {self.occurrenceCount} ]\n"
out += (
f"\t Occurrences: \t[ {self.currentOccCount} / {self.occurrenceCount} ]\n"
)
out += f"\t Materials: \t[ {self.currentMatCount} / {self.materialCount} ]\n"
out += f"\t Appearances: \t[ {self.currentAppCount} / {self.appearanceCount} ]\n"
out += (
f"\t Appearances: \t[ {self.currentAppCount} / {self.appearanceCount} ]\n"
)
out += f"{self.currentMessage}"

return out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,18 @@ def export(self) -> bool:

for child in node.children:
if child.value == "ground":
joint_hierarchy_out = f"{joint_hierarchy_out} |---> ground\n"
joint_hierarchy_out = (
f"{joint_hierarchy_out} |---> ground\n"
)
else:
newnode = assembly_out.data.joints.joint_instances[
child.value
]
jointdefinition = assembly_out.data.joints.joint_definitions[
newnode.joint_reference
]
jointdefinition = (
assembly_out.data.joints.joint_definitions[
newnode.joint_reference
]
)
wheel_ = (
" wheel : true"
if (jointdefinition.user_data.data["wheel"] != "")
Expand Down
62 changes: 44 additions & 18 deletions exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ def notify(self, args):
cmd.isAutoExecute = False
cmd.isExecutedWhenPreEmpted = False
cmd.okButtonText = "Export" # replace default OK text with "export"
cmd.setDialogInitialSize(400, 350) # these aren't working for some reason...
cmd.setDialogMinimumSize(400, 350) # these aren't working for some reason...
cmd.setDialogInitialSize(
400, 350
) # these aren't working for some reason...
cmd.setDialogMinimumSize(
400, 350
) # these aren't working for some reason...

global INPUTS_ROOT # Global CommandInputs arg
INPUTS_ROOT = cmd.commandInputs
Expand Down Expand Up @@ -415,7 +419,9 @@ def notify(self, args):
)
jointConfig.isExpanded = False
jointConfig.isVisible = True
jointConfig.tooltip = "Select and define joint occurrences in your assembly."
jointConfig.tooltip = (
"Select and define joint occurrences in your assembly."
)

joint_inputs = jointConfig.children

Expand Down Expand Up @@ -565,7 +571,9 @@ def notify(self, args):
)
weightTableInput_f.tablePresentationStyle = 2 # set to clear background

weight_name_f = gamepiece_inputs.addStringValueInput("weight_name", "Weight")
weight_name_f = gamepiece_inputs.addStringValueInput(
"weight_name", "Weight"
)
weight_name_f.value = "Unit of Mass"
weight_name_f.isReadOnly = True

Expand All @@ -578,7 +586,9 @@ def notify(self, args):
enabled=True,
isCheckBox=False,
)
auto_calc_weight_f.resourceFolder = IconPaths.stringIcons["calculate-enabled"]
auto_calc_weight_f.resourceFolder = IconPaths.stringIcons[
"calculate-enabled"
]
auto_calc_weight_f.isFullWidth = True

weight_unit_f = gamepiece_inputs.addDropDownCommandInput(
Expand Down Expand Up @@ -620,7 +630,9 @@ def notify(self, args):
50,
)

addFieldInput = gamepiece_inputs.addBoolValueInput("field_add", "Add", False)
addFieldInput = gamepiece_inputs.addBoolValueInput(
"field_add", "Add", False
)

removeFieldInput = gamepiece_inputs.addBoolValueInput(
"field_delete", "Remove", False
Expand Down Expand Up @@ -1415,7 +1427,9 @@ def traverseAssembly(
if occ in value:
return [joint, occ] # occurrence that is jointed

if occ.childOccurrences: # if occurrence has children, traverse sub-tree
if (
occ.childOccurrences
): # if occurrence has children, traverse sub-tree
self.traverseAssembly(occ.childOccurrences, jointedOcc)
return None # no jointed occurrence found
except:
Expand Down Expand Up @@ -1488,7 +1502,9 @@ def wheelParent(self, occ: adsk.fusion.Occurrence):
treeParent = parent # each parent that will traverse up in algorithm.

while treeParent != None: # loops until reaches top-level component
returned = self.traverseAssembly(treeParent.childOccurrences, jointedOcc)
returned = self.traverseAssembly(
treeParent.childOccurrences, jointedOcc
)

if returned != None:
for i in range(parentLevel):
Expand Down Expand Up @@ -1960,7 +1976,10 @@ def notify(self, args):
# gm.ui.activeSelections.clear()

addWheelInput.isEnabled = True
if wheelTableInput.selectedRow == -1 or wheelTableInput.selectedRow == 0:
if (
wheelTableInput.selectedRow == -1
or wheelTableInput.selectedRow == 0
):
wheelTableInput.selectedRow = wheelTableInput.rowCount - 1
gm.ui.messageBox("Select a row to delete.")
else:
Expand All @@ -1973,7 +1992,10 @@ def notify(self, args):
addJointInput.isEnabled = True
addWheelInput.isEnabled = True

if jointTableInput.selectedRow == -1 or jointTableInput.selectedRow == 0:
if (
jointTableInput.selectedRow == -1
or jointTableInput.selectedRow == 0
):
jointTableInput.selectedRow = jointTableInput.rowCount - 1
gm.ui.messageBox("Select a row to delete.")
else:
Expand Down Expand Up @@ -2129,7 +2151,9 @@ def notify(self, args):
onSelect.allWheelPreselections.clear()
onSelect.wheelJointList.clear()

for group in gm.app.activeDocument.design.rootComponent.customGraphicsGroups:
for (
group
) in gm.app.activeDocument.design.rootComponent.customGraphicsGroups:
group.deleteMe()

# Currently causes Internal Autodesk Error
Expand Down Expand Up @@ -2198,7 +2222,9 @@ def addJointToTable(joint: adsk.fusion.Joint) -> None:
icon.tooltip = "Ball joint"

# joint name
name = cmdInputs.addTextBoxCommandInput("name_j", "Occurrence name", "", 1, True)
name = cmdInputs.addTextBoxCommandInput(
"name_j", "Occurrence name", "", 1, True
)
name.tooltip = joint.name
name.formattedText = "<p style='font-size:11px'>{}</p>".format(joint.name)

Expand Down Expand Up @@ -2471,9 +2497,9 @@ def removeWheelFromTable(index: int) -> None:
except IndexError:
pass
except:
logging.getLogger("{INTERNAL_ID}.UI.ConfigCommand.removeWheelFromTable()").error(
"Failed:\n{}".format(traceback.format_exc())
)
logging.getLogger(
"{INTERNAL_ID}.UI.ConfigCommand.removeWheelFromTable()"
).error("Failed:\n{}".format(traceback.format_exc()))


def removeJointFromTable(joint: adsk.fusion.Joint) -> None:
Expand Down Expand Up @@ -2509,9 +2535,9 @@ def removeJointFromTable(joint: adsk.fusion.Joint) -> None:
else:
listItems.item(index).deleteMe()
except:
logging.getLogger("{INTERNAL_ID}.UI.ConfigCommand.removeJointFromTable()").error(
"Failed:\n{}".format(traceback.format_exc())
)
logging.getLogger(
"{INTERNAL_ID}.UI.ConfigCommand.removeJointFromTable()"
).error("Failed:\n{}".format(traceback.format_exc()))


def removeGamePieceFromTable(index: int) -> None:
Expand Down
6 changes: 4 additions & 2 deletions exporter/SynthesisFusionAddin/src/UI/CustomGraphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def createTextGraphics(wheel: adsk.fusion.Occurrence, _wheels) -> None:
graphicsText.cullMode = (
adsk.fusion.CustomGraphicsCullModes.CustomGraphicsCullBack
)
graphicsText.color = adsk.fusion.CustomGraphicsShowThroughColorEffect.create(
adsk.core.Color.create(230, 146, 18, 255), 1
graphicsText.color = (
adsk.fusion.CustomGraphicsShowThroughColorEffect.create(
adsk.core.Color.create(230, 146, 18, 255), 1
)
) # orange/synthesis theme
graphicsText.depthPriority = 0

Expand Down
12 changes: 9 additions & 3 deletions exporter/SynthesisFusionAddin/src/UI/HUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,19 @@ def __init__(
cmdDef = gm.ui.commandDefinitions.itemById(self.uid)
if cmdDef:
# gm.ui.messageBox("Looks like you have experienced a crash we will do cleanup.")
self.logger.debug("Looks like there was a crash, doing cleanup in button id")
self.logger.debug(
"Looks like there was a crash, doing cleanup in button id"
)
self.scrub()

# needs to updated with new OString data
self.button = gm.ui.commandDefinitions.addButtonDefinition(
self.uid,
f"{name}",
f"{description}",
OsHelper.getOSPath(".", "src", "Resources", f'{self.name.replace(" ", "")}'),
OsHelper.getOSPath(
".", "src", "Resources", f'{self.name.replace(" ", "")}'
),
)
""" Button Command Definition stored as a member """

Expand Down Expand Up @@ -204,7 +208,9 @@ def deleteMe(self):
self.logger.debug(f"Removing Button {self.uid}")
cmdDef.deleteMe()

ctrl = gm.ui.allToolbarPanels.itemById(self.location).controls.itemById(self.uid)
ctrl = gm.ui.allToolbarPanels.itemById(self.location).controls.itemById(
self.uid
)
if ctrl:
self.logger.debug(f"Removing Button Control {self.location}:{self.uid}")
ctrl.deleteMe()
Expand Down
6 changes: 4 additions & 2 deletions exporter/SynthesisFusionAddin/src/UI/IconPaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
"omni": resources + os.path.join("WheelIcons", "omni-wheel-preview190x24.png"),
"standard": resources
+ os.path.join("WheelIcons", "standard-wheel-preview190x24.png"),
"mecanum": resources + os.path.join("WheelIcons", "mecanum-wheel-preview190x24.png"),
"mecanum": resources
+ os.path.join("WheelIcons", "mecanum-wheel-preview190x24.png"),
}

jointIcons = {
"rigid": resources + os.path.join("JointIcons", "JointRigid", "rigid190x24.png"),
"revolute": resources + os.path.join("JointIcons", "JointRev", "revolute190x24.png"),
"revolute": resources
+ os.path.join("JointIcons", "JointRev", "revolute190x24.png"),
"slider": resources + os.path.join("JointIcons", "JointSlider", "slider190x24.png"),
"cylindrical": resources
+ os.path.join("JointIcons", "JointCyl", "cylindrical190x24.png"),
Expand Down
4 changes: 3 additions & 1 deletion exporter/SynthesisFusionAddin/src/UI/Toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def getPanel(self, name: str, visibility: bool = True) -> str or None:
self.logger.debug(f"Created Panel {panel_uid} in Toolbar {self.uid}")
return panel_uid
else:
self.logger.error(f"Failed to Create Panel {panel_uid} in Toolbar {self.uid}")
self.logger.error(
f"Failed to Create Panel {panel_uid} in Toolbar {self.uid}"
)
return None

@staticmethod
Expand Down
3 changes: 3 additions & 0 deletions fission/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
public/Downloadables


# Logs
logs
*.log
Expand Down
Loading

0 comments on commit f22f995

Please sign in to comment.