Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Friction Data Export #1014

Merged
merged 26 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e0c28d9
added friction override to exporter options
azaleacolburn Jun 28, 2024
1a11e52
added friction override to exporter options
azaleacolburn Jul 1, 2024
3e8054c
added friction options exportation to config command
azaleacolburn Jul 1, 2024
7ee0684
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Jul 2, 2024
393f618
upload broken code for brandon to debug (tysm)
azaleacolburn Jul 3, 2024
4a3337d
tested and fixed friction override exportation from config command
azaleacolburn Jul 3, 2024
d4d118a
added friction override to mirabuf assembly
azaleacolburn Jul 4, 2024
01aa9dd
added export location
azaleacolburn Jul 5, 2024
4b92b61
Revert "added export location"
azaleacolburn Jul 5, 2024
4cff486
ran formatter
azaleacolburn Jul 8, 2024
64567e7
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Jul 11, 2024
be4426c
move friction override serialization
azaleacolburn Jul 12, 2024
0f29963
move friction override to materials
azaleacolburn Jul 12, 2024
ddac7fe
pass in options correctly
azaleacolburn Jul 12, 2024
85ddf0b
export aps auth from strings
azaleacolburn Jul 12, 2024
363438c
add curr_time to another place it was missing
azaleacolburn Jul 12, 2024
0b49cd2
added friction override to parsing
azaleacolburn Jul 18, 2024
c622a42
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Jul 22, 2024
9a6cbeb
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Jul 24, 2024
42154ce
fixed double button and physical material misnaming
azaleacolburn Jul 24, 2024
c777ef9
ran formatter
azaleacolburn Jul 24, 2024
3b17c5a
fix friction override
azaleacolburn Jul 25, 2024
78fab85
Fixed bug with fusion material overrides
BrandonPacewic Jul 25, 2024
361e25f
Merge `dev`
BrandonPacewic Jul 25, 2024
8c9bb18
General cleanups
BrandonPacewic Jul 25, 2024
b32c9f5
Did not mean to add this
BrandonPacewic Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions exporter/SynthesisFusionAddin/src/APS/APS.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from ..general_imports import (
APP_NAME,
APS_AUTH,
DESCRIPTION,
INTERNAL_ID,
gm,
Expand All @@ -20,10 +21,8 @@
CLIENT_ID = "GCxaewcLjsYlK8ud7Ka9AKf9dPwMR3e4GlybyfhAK2zvl3tU"
auth_path = os.path.abspath(os.path.join(my_addin_path, "..", ".aps_auth"))

APS_AUTH = None
APS_USER_INFO = None


@dataclass
class APSAuth:
access_token: str
Expand Down Expand Up @@ -65,7 +64,8 @@ def getCodeChallenge() -> str | None:
return data["challenge"]


def getAuth() -> APSAuth:
def getAuth() -> APSAuth | None:
curr_time = int(time.time() * 1000)
global APS_AUTH
if APS_AUTH is not None:
return APS_AUTH
Expand All @@ -76,12 +76,13 @@ def getAuth() -> APSAuth:
access_token=p["access_token"],
refresh_token=p["refresh_token"],
expires_in=p["expires_in"],
expires_at=int(p["expires_in"] * 1000),
expires_at=int(curr_time + (p["expires_in"] * 1000)),
token_type=p["token_type"],
)
except:
raise Exception("Need to sign in!")
curr_time = int(time.time() * 1000)
gm.ui.messageBox("Need to sign in!")
return None

if curr_time >= APS_AUTH.expires_at:
refreshAuthToken()
if APS_USER_INFO is None:
Expand All @@ -94,11 +95,13 @@ def convertAuthToken(code: str):
authUrl = f'http://localhost:80/api/aps/code/?code={code}&redirect_uri={urllib.parse.quote_plus("http://localhost:80/api/aps/exporter/")}'
res = urllib.request.urlopen(authUrl)
data = _res_json(res)["response"]
curr_time = time.time() * 1000
logging.getLogger("curr_time{}".format(curr_time))
APS_AUTH = APSAuth(
access_token=data["access_token"],
refresh_token=data["refresh_token"],
expires_in=data["expires_in"],
expires_at=int(data["expires_in"] * 1000),
expires_at=curr_time + data["expires_in"] * 1000,
token_type=data["token_type"],
)
with open(auth_path, "wb") as f:
Expand Down Expand Up @@ -130,14 +133,15 @@ def refreshAuthToken():
req = urllib.request.Request("https://developer.api.autodesk.com/authentication/v2/token", data=body)
req.method = "POST"
req.add_header(key="Content-Type", val="application/x-www-form-urlencoded")
curr_time = time.time() * 1000
try:
res = urllib.request.urlopen(req)
data = _res_json(res)
APS_AUTH = APSAuth(
access_token=data["access_token"],
refresh_token=data["refresh_token"],
expires_in=data["expires_in"],
expires_at=int(data["expires_in"] * 1000),
expires_at=int(curr_time + data["expires_in"] * 1000),
token_type=data["token_type"],
)
except urllib.request.HTTPError as e:
Expand Down
3 changes: 3 additions & 0 deletions exporter/SynthesisFusionAddin/src/Parser/ExporterOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class ExporterOptions:
# Always stored in kg regardless of 'preferredUnits'
robotWeight: float = field(default=0.0)

frictionOverride: bool = field(default=False)
frictionOverrideCoeff: float | None = field(default=None)

compressOutput: bool = field(default=True)
exportAsPart: bool = field(default=False)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from proto.proto_out import material_pb2

from ...general_imports import INTERNAL_ID
from .. import ExporterOptions
from ..ExporterOptions import ExporterOptions
from .PDMessage import PDMessage
from .Utilities import *

Expand All @@ -21,7 +21,7 @@ def _MapAllPhysicalMaterials(
options: ExporterOptions,
progressDialog: PDMessage,
) -> None:
setDefaultMaterial(materials.physicalMaterials["default"])
setDefaultMaterial(materials.physicalMaterials["default"], options)

for material in physicalMaterials:
progressDialog.addMaterial(material.name)
Expand All @@ -33,12 +33,16 @@ def _MapAllPhysicalMaterials(
getPhysicalMaterialData(material, newmaterial, options)


def setDefaultMaterial(physical_material: material_pb2.PhysicalMaterial):
def setDefaultMaterial(physical_material: material_pb2.PhysicalMaterial, options: ExporterOptions):
construct_info("default", physical_material)

physical_material.description = "A default physical material"
physical_material.dynamic_friction = 0.5
physical_material.static_friction = 0.5
if options.frictionOverride:
physical_material.dynamic_friction = options.frictionOverrideCoeff
physical_material.static_friction = options.frictionOverrideCoeff
else:
physical_material.dynamic_friction = 0.5
physical_material.static_friction = 0.5
physical_material.restitution = 0.5
physical_material.deformable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ def export(self) -> bool:

# Physical Props here when ready

# ts = time()

progressDialog = app.userInterface.createProgressDialog()
progressDialog.cancelButtonText = "Cancel"
progressDialog.isBackgroundTranslucent = False
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 50 additions & 45 deletions exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import logging
import os
import platform

# import platform
import traceback
from enum import Enum

Expand Down Expand Up @@ -622,11 +623,13 @@ def notify(self, args):
"""
Creates the advanced tab, which is the parent container for internal command inputs
"""
advancedSettings = INPUTS_ROOT.addTabCommandInput("advanced_settings", "Advanced")
advancedSettings: adsk.core.TabCommandInput = INPUTS_ROOT.addTabCommandInput(
"advanced_settings", "Advanced"
)
advancedSettings.tooltip = (
"Additional Advanced Settings to change how your model will be translated into Unity."
)
a_input = advancedSettings.children
a_input: adsk.core.CommandInputs = advancedSettings.children

# ~~~~~~~~~~~~~~~~ EXPORTER SETTINGS ~~~~~~~~~~~~~~~~
"""
Expand Down Expand Up @@ -661,55 +664,38 @@ def notify(self, args):
"""
Physics settings group command
"""
physicsSettings = a_input.addGroupCommandInput("physics_settings", "Physics Settings")
physicsSettings: adsk.core.GroupCommandInput = a_input.addGroupCommandInput(
"physics_settings", "Physics Settings"
)

physicsSettings.isExpanded = False
physicsSettings.isExpanded = True
physicsSettings.isEnabled = True
physicsSettings.tooltip = "tooltip" # TODO: update tooltip
physics_settings = physicsSettings.children

# AARD-1687
# Should also be commented out / removed?
# This would cause problems elsewhere but I can't tell i f
# this is even being used.
frictionOverrideTable = self.createTableInput(
"friction_override_table",
"",
physics_settings,
2,
"1:2",
1,
columnSpacing=25,
)
frictionOverrideTable.tablePresentationStyle = 2
# frictionOverrideTable.isFullWidth = True
physicsSettings.tooltip = "Settings relating to the custom physics of the robot, like the wheel friction"
physics_settings: adsk.core.CommandInputs = physicsSettings.children

frictionOverride = self.createBooleanInput(
frictionOverrideInput = self.createBooleanInput(
"friction_override",
"",
"Friction Override",
physics_settings,
checked=False,
checked=exporterOptions.frictionOverride, # object is missing attribute
tooltip="Manually override the default friction values on the bodies in the assembly.",
enabled=True,
isCheckBox=False,
)
frictionOverride.resourceFolder = IconPaths.stringIcons["friction_override-enabled"]
frictionOverride.isFullWidth = True
frictionOverrideInput.resourceFolder = IconPaths.stringIcons["friction_override-enabled"]
frictionOverrideInput.isFullWidth = True

valueList = [1]
for i in range(20):
valueList.append(i / 20)

frictionCoeff = physics_settings.addFloatSliderListCommandInput(
"friction_coeff_override", "Friction Coefficient", "", valueList
frictionCoeffSlider: adsk.core.FloatSliderCommandInput = physics_settings.addFloatSliderListCommandInput(
"friction_override_coeff", "Friction Coefficient", "", valueList
)
frictionCoeff.isVisible = False
frictionCoeff.valueOne = 0.5
frictionCoeff.tooltip = "Friction coefficient of field element."
frictionCoeff.tooltipDescription = "<i>Friction coefficients range from 0 (ice) to 1 (rubber).</i>"

frictionOverrideTable.addCommandInput(frictionOverride, 0, 0)
frictionOverrideTable.addCommandInput(frictionCoeff, 0, 1)
frictionCoeffSlider.isVisible = True
frictionCoeffSlider.valueOne = 0.5
frictionCoeffSlider.tooltip = "Friction coefficient of field element."
frictionCoeffSlider.tooltipDescription = "<i>Friction coefficients range from 0 (ice) to 1 (rubber).</i>"

# ~~~~~~~~~~~~~~~~ JOINT SETTINGS ~~~~~~~~~~~~~~~~
"""
Expand Down Expand Up @@ -1008,12 +994,6 @@ def notify(self, args):
self.log.error("Could not execute configuration due to failure")
return

export_as_part_boolean = (
eventArgs.command.commandInputs.itemById("advanced_settings")
.children.itemById("exporter_settings")
.children.itemById("export_as_part")
).value

processedFileName = gm.app.activeDocument.name.replace(" ", "_")
dropdownExportMode = INPUTS_ROOT.itemById("mode")
if dropdownExportMode.selectedItem.index == 0:
Expand Down Expand Up @@ -1176,13 +1156,36 @@ def notify(self, args):
elif dropdownExportMode.selectedItem.index == 1:
_mode = ExportMode.FIELD

"""
Advanced Settings
"""
global compress
compress = (
eventArgs.command.commandInputs.itemById("advanced_settings")
.children.itemById("exporter_settings")
.children.itemById("compress")
).value

export_as_part_boolean = (
eventArgs.command.commandInputs.itemById("advanced_settings")
.children.itemById("exporter_settings")
.children.itemById("export_as_part")
).value

frictionOverrideButton: adsk.core.BoolValueCommandInput = (
eventArgs.command.commandInputs.itemById("advanced_settings")
.children.itemById("physics_settings")
.children.itemById("friction_override")
)
frictionSlider: adsk.core.FloatSliderCommandInput = (
eventArgs.command.commandInputs.itemById("advanced_settings")
.children.itemById("physics_settings")
.children.itemById("friction_override_coeff")
)

frictionOverrideCoeff = frictionSlider.valueOne
frictionOverride = frictionSlider.isVisible

exporterOptions = ExporterOptions(
savepath,
name,
Expand All @@ -1196,9 +1199,11 @@ def notify(self, args):
exportMode=_mode,
compressOutput=compress,
exportAsPart=export_as_part_boolean,
frictionOverride=frictionOverride,
frictionOverrideCoeff=frictionOverrideCoeff,
)

Parser(exporterOptions).export()
_: bool = Parser(exporterOptions).export()
exporterOptions.writeToDesign()
except:
if gm.ui:
Expand Down Expand Up @@ -1637,7 +1642,7 @@ def notify(self, args):
inputs = cmdInput.commandInputs
onSelect = gm.handlers[3]

frictionCoeff = INPUTS_ROOT.itemById("friction_coeff_override")
frictionCoeff = INPUTS_ROOT.itemById("friction_override_coeff")

wheelSelect = inputs.itemById("wheel_select")
jointSelect = inputs.itemById("joint_select")
Expand Down
8 changes: 4 additions & 4 deletions exporter/SynthesisFusionAddin/src/UI/ShowAPSAuthCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def notify(self, args):
command.execute.add(onExecute)
gm.handlers.append(onExecute)
except:
gm.ui.messageBox("Failed:\n{}".format(traceback.format_exc()))
logging.getLogger(f"{INTERNAL_ID}").error("Failed:\n{}".format(traceback.format_exc()))
gm.ui.messageBox("Failed:\n{}Here".format(traceback.format_exc()))
logging.getLogger(f"{INTERNAL_ID}").error("Failed:\n{}Here".format(traceback.format_exc()))
if palette:
palette.deleteMe()

Expand Down Expand Up @@ -139,7 +139,7 @@ def notify(self, args):

convertAuthToken(data["code"])
except:
gm.ui.messageBox("Failed:\n".format(traceback.format_exc()))
logging.getLogger(f"{INTERNAL_ID}").error("Failed:\n".format(traceback.format_exc()))
gm.ui.messageBox("Failed:\n{}".format(traceback.format_exc()))
logging.getLogger(f"{INTERNAL_ID}").error("Failed:\n{}".format(traceback.format_exc()))
if palette:
palette.deleteMe()
5 changes: 3 additions & 2 deletions exporter/SynthesisFusionAddin/src/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .strings import INTERNAL_ID
from .Types.OString import OString
from typing import Any

try:
config = ConfigParser()
Expand Down Expand Up @@ -49,7 +50,7 @@ def setAnalytics(enabled: bool):
return True


def get_value(key: str, section="main") -> any:
def get_value(key: str, section="main") -> Any:
"""Gets a value from the config file

Args:
Expand All @@ -62,7 +63,7 @@ def get_value(key: str, section="main") -> any:
return config.get(section, key)


def write_configuration(section: str, key: str, value: any):
def write_configuration(section: str, key: str, value: Any):
"""Write a configuration flag to the ini file

Args:
Expand Down
1 change: 1 addition & 0 deletions exporter/SynthesisFusionAddin/src/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
APP_TITLE = "Synthesis Robot Exporter"
DESCRIPTION = "Exports files from Fusion into the Synthesis Format"
INTERNAL_ID = "synthesis"
APS_AUTH: None | str = None
8 changes: 8 additions & 0 deletions fission/src/mirabuf/MirabufParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ class MirabufParser {
directedRecursive(this._rigidNodes[0].id)
}
this._directedGraph = directedGraph

const partDefinitions: { [k: string]: mirabuf.IPartDefinition } | null | undefined =
this.assembly.data?.parts?.partDefinitions
if (!partDefinitions) {
console.log("Failed to get part definitions")
return
}
console.log(partDefinitions)
}

private NewRigidNode(suffix?: string): RigidNode {
Expand Down
Loading