Skip to content

Commit

Permalink
Merge branch 'dev' into barclah/ball-socket
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay committed Dec 28, 2024
2 parents 2c5cbcf + 6d87ac2 commit 32948b5
Show file tree
Hide file tree
Showing 112 changed files with 7,970 additions and 1,495 deletions.
4 changes: 2 additions & 2 deletions exporter/SynthesisFusionAddin/Synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def register_ui() -> None:
work_panel,
lambda *_: True, # TODO: Should be redone with various refactors.
ShowAPSAuthCommand.ShowAPSAuthCommandCreatedHandler,
description=f"APS",
description=f"Login to your Autodesk account",
command=True,
)

Expand All @@ -132,7 +132,7 @@ def register_ui() -> None:
work_panel,
lambda *_: True,
ShowWebsiteCommand.ShowWebsiteCommandCreatedHandler,
description=f"Website Test",
description=f"Open our tutorials page",
command=True,
)
gm.elements.append(websiteButton)
3 changes: 2 additions & 1 deletion exporter/SynthesisFusionAddin/src/Parser/ExporterOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ def readFromDesign(self) -> "ExporterOptions":
for field in fields(self):
attribute = designAttributes.itemByName(INTERNAL_ID, field.name)
if attribute:
attrJsonData = makeObjectFromJson(field.type, json.loads(attribute.value))
attrJsonData = makeObjectFromJson(type(field.type), json.loads(attribute.value))
setattr(self, field.name, attrJsonData)

self.visualQuality = TriangleMeshQualityOptions.LowQualityTriangleMesh
return self

@logFailure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ def _ParseBRep(
) -> None:
meshManager = body.meshManager
calc = meshManager.createMeshCalculator()
calc.setQuality(options.visualQuality)
# Disabling for now. We need the user to be able to adjust this, otherwise it gets locked
# into whatever the default was at the time it first creates the export options.
# calc.setQuality(options.visualQuality)
calc.setQuality(adsk.fusion.TriangleMeshQualityOptions.LowQualityTriangleMesh)
# calc.maxNormalDeviation = 3.14159 * (1.0 / 6.0)
# calc.surfaceTolerance = 0.5
mesh = calc.calculate()

fill_info(trimesh, body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,26 @@ def getMaterialAppearance(

properties = fusionAppearance.appearanceProperties

roughnessProp = properties.itemById("surface_roughness")
if roughnessProp:
appearance.roughness = roughnessProp.value

# Thank Liam for this.
modelItem = properties.itemById("interior_model")
if modelItem:
matModelType = modelItem.value
baseColor = None

if matModelType == 0:
reflectanceProp = properties.itemById("opaque_f0")
if reflectanceProp:
appearance.metallic = reflectanceProp.value
baseColor = properties.itemById("opaque_albedo").value
if baseColor:
baseColor.opacity = 255
elif matModelType == 1:
baseColor = properties.itemById("metal_f0").value
appearance.metallic = 0.8
if baseColor:
baseColor.opacity = 255
elif matModelType == 2:
Expand Down
2 changes: 1 addition & 1 deletion exporter/SynthesisFusionAddin/src/Types.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def makeObjectFromJson(objType: type, data: Any) -> Any:
assert is_dataclass(obj) and isinstance(data, dict), "Found unsupported type to decode."
for field in fields(obj):
if field.name in data:
setattr(obj, field.name, makeObjectFromJson(field.type, data[field.name]))
setattr(obj, field.name, makeObjectFromJson(type(field.type), data[field.name]))
else:
setattr(obj, field.name, field.default_factory if field.default_factory is not MISSING else field.default)

Expand Down
2 changes: 1 addition & 1 deletion exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def notify(self, args: adsk.core.CommandEventArgs) -> None:

processedFileName = gm.app.activeDocument.name.replace(" ", "_")
if generalConfigTab.exportLocation == ExportLocation.DOWNLOAD:
savepath = FileDialogConfig.saveFileDialog(defaultPath=exporterOptions.fileLocation)
savepath = FileDialogConfig.saveFileDialog(defaultPath="~/Documents/")

if not savepath:
# save was canceled
Expand Down
3 changes: 2 additions & 1 deletion exporter/SynthesisFusionAddin/src/UI/GamepieceConfigTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from src.Logging import logFailure
from src.Parser.ExporterOptions import ExporterOptions
from src.Parser.SynthesisParser.Utilities import guid_occurrence
from src.Types import Gamepiece, UnitSystem
from src.UI.CreateCommandInputsHelper import (
createBooleanInput,
Expand Down Expand Up @@ -198,7 +199,7 @@ def removeChildOccurrences(childOccurrences: adsk.fusion.OccurrenceList) -> None
def getGamepieces(self) -> list[Gamepiece]:
gamepieces: list[Gamepiece] = []
for row in range(1, self.gamepieceTable.rowCount): # Row is 1 indexed
gamepieceEntityToken = self.selectedGamepieceList[row - 1].entityToken
gamepieceEntityToken = guid_occurrence(self.selectedGamepieceList[row - 1])
gamepieceWeight = convertMassUnitsTo(self.gamepieceTable.getInputAtPosition(row, 1).value)
gamepieceFrictionCoefficient = self.gamepieceTable.getInputAtPosition(row, 2).valueOne
gamepieces.append(Gamepiece(gamepieceEntityToken, gamepieceWeight, gamepieceFrictionCoefficient))
Expand Down
5 changes: 4 additions & 1 deletion fission/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"init": "(bun run assetpack && bun run playwright:install) || (npm run assetpack && npm run playwright:install)",
"host": "vite --open --host",
"dev": "vite --open",
"build": "tsc && vite build",
"build:prod": "tsc && vite build --base=/fission/ --outDir dist/prod",
Expand All @@ -15,7 +16,7 @@
"lint:fix": "eslint . --ext ts,tsx --report-unused-disable-directives --fix",
"prettier": "bun x prettier src --check || npx prettier src --check",
"prettier:fix": "bun x prettier src --write || npx prettier src --write",
"format": "(bun run prettier:fix && bun run lint:fix) || (npm run prettier:fix && npm run lint:fix)",
"format": "bun run prettier:fix && bun run lint:fix || npm run prettier:fix && npm run lint:fix",
"assetpack": "curl -o public/assetpack.zip https://synthesis.autodesk.com/Downloadables/assetpack.zip && tar -xf public/assetpack.zip -C public/",
"playwright:install": "bun x playwright install || npx playwright install"
},
Expand All @@ -29,6 +30,7 @@
"@react-three/fiber": "^8.15.15",
"@vitest/browser": "^1.6.0",
"@vitest/coverage-v8": "^1.6.0",
"@xyflow/react": "^12.3.2",
"async-mutex": "^0.5.0",
"colord": "^2.9.3",
"framer-motion": "^10.13.1",
Expand Down Expand Up @@ -56,6 +58,7 @@
"@types/three": "^0.160.0",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"@vitejs/plugin-basic-ssl": "^1.1.0",
"@vitejs/plugin-react": "^4.0.3",
"@vitejs/plugin-react-swc": "^3.5.0",
"autoprefixer": "^10.4.14",
Expand Down
14 changes: 14 additions & 0 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ import AnalyticsConsent from "./ui/components/AnalyticsConsent.tsx"
import PreferencesSystem from "./systems/preferences/PreferencesSystem.ts"
import APSManagementModal from "./ui/modals/APSManagementModal.tsx"
import ConfigurePanel from "./ui/panels/configuring/assembly-config/ConfigurePanel.tsx"
import WiringPanel from "./ui/panels/simulation/WiringPanel.tsx"
import CameraSelectionPanel from "./ui/panels/configuring/CameraSelectionPanel.tsx"
import ContextMenu from "./ui/components/ContextMenu.tsx"
import GlobalUIComponent from "./ui/components/GlobalUIComponent.tsx"
import InitialConfigPanel from "./ui/panels/configuring/initial-config/InitialConfigPanel.tsx"
import WPILibConnectionStatus from "./ui/components/WPILibConnectionStatus.tsx"
import AutoTestPanel from "./ui/panels/simulation/AutoTestPanel.tsx"

function Synthesis() {
const { openModal, closeModal, getActiveModalElement } = useModalManager(initialModals)
Expand Down Expand Up @@ -156,8 +163,10 @@ function Synthesis() {
closeAllPanels={closeAllPanels}
>
<ToastProvider key="toast-provider">
<GlobalUIComponent />
<Scene useStats={import.meta.env.DEV} key="scene-in-toast-provider" />
<SceneOverlay />
<ContextMenu />
<MainHUD key={"main-hud"} />
{panelElements.length > 0 && panelElements}
{modalElement && (
Expand All @@ -167,6 +176,7 @@ function Synthesis() {
)}
<ProgressNotifications key={"progress-notifications"} />
<ToastContainer key={"toast-container"} />
<WPILibConnectionStatus />

{!consentPopupDisable ? (
<AnalyticsConsent onClose={onDisableConsent} onConsent={onConsent} />
Expand Down Expand Up @@ -222,6 +232,10 @@ const initialPanels: ReactElement[] = [
<WSViewPanel key="ws-view" panelId="ws-view" />,
<DebugPanel key="debug" panelId="debug" />,
<ConfigurePanel key="configure" panelId="configure" />,
<WiringPanel key="wiring" panelId="wiring" />,
<CameraSelectionPanel key="camera-select" panelId="camera-select" />,
<InitialConfigPanel key="initial-config" panelId="initial-config" />,
<AutoTestPanel key="auto-test" panelId="auto-test" />,
]

export default Synthesis
30 changes: 13 additions & 17 deletions fission/src/aps/APS.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import World from "@/systems/World"
import { MainHUD_AddToast } from "@/ui/components/MainHUD"
import { Global_AddToast } from "@/ui/components/GlobalUIControls"
import { Mutex } from "async-mutex"

const APS_AUTH_KEY = "aps_auth"
Expand All @@ -14,7 +14,7 @@ export const ENDPOINT_SYNTHESIS_CHALLENGE = `/api/aps/challenge`

const ENDPOINT_AUTODESK_AUTHENTICATION_AUTHORIZE = "https://developer.api.autodesk.com/authentication/v2/authorize"
const ENDPOINT_AUTODESK_AUTHENTICATION_TOKEN = "https://developer.api.autodesk.com/authentication/v2/token"
const ENDPOINT_AUTODESK_REVOKE_TOKEN = "https://developer.api.autodesk.com/authentication/v2/revoke"
const ENDPOINT_AUTODESK_AUTHENTICATION_REVOKE = "https://developer.api.autodesk.com/authentication/v2/revoke"
const ENDPOINT_AUTODESK_USERINFO = "https://api.userprofile.autodesk.com/userinfo"

export interface APSAuth {
Expand Down Expand Up @@ -163,7 +163,7 @@ class APS {
["client_id", CLIENT_ID],
] as string[][]),
}
const res = await fetch(ENDPOINT_AUTODESK_REVOKE_TOKEN, opts)
const res = await fetch(ENDPOINT_AUTODESK_AUTHENTICATION_REVOKE, opts)
if (!res.ok) {
console.log("Failed to revoke auth token:\n")
return false
Expand Down Expand Up @@ -205,7 +205,7 @@ class APS {
} catch (e) {
console.error(e)
World.AnalyticsSystem?.Exception("APS Login Failure")
MainHUD_AddToast("error", "Error signing in.", "Please try again.")
Global_AddToast?.("error", "Error signing in.", "Please try again.")
}
})
}
Expand Down Expand Up @@ -236,7 +236,7 @@ class APS {
const json = await res.json()
if (!res.ok) {
if (shouldRelog) {
MainHUD_AddToast("warning", "Must Re-signin.", json.userMessage)
Global_AddToast?.("warning", "Must Re-signin.", json.userMessage)
this.auth = undefined
await this.requestAuthCode()
return false
Expand All @@ -249,13 +249,13 @@ class APS {
if (this.auth) {
await this.loadUserInfo(this.auth)
if (APS.userInfo) {
MainHUD_AddToast("info", "ADSK Login", `Hello, ${APS.userInfo.givenName}`)
Global_AddToast?.("info", "ADSK Login", `Hello, ${APS.userInfo.givenName}`)
}
}
return true
} catch (e) {
World.AnalyticsSystem?.Exception("APS Login Failure")
MainHUD_AddToast("error", "Error signing in.", "Please try again.")
Global_AddToast?.("error", "Error signing in.", "Please try again.")
this.auth = undefined
await this.requestAuthCode()
return false
Expand All @@ -281,7 +281,7 @@ class APS {
const json = await res.json()
if (!res.ok) {
World.AnalyticsSystem?.Exception("APS Login Failure")
MainHUD_AddToast("error", "Error signing in.", json.userMessage)
Global_AddToast?.("error", "Error signing in.", json.userMessage)
this.auth = undefined
return
}
Expand All @@ -293,7 +293,7 @@ class APS {
if (auth) {
await this.loadUserInfo(auth)
if (APS.userInfo) {
MainHUD_AddToast("info", "ADSK Login", `Hello, ${APS.userInfo.givenName}`)
Global_AddToast?.("info", "ADSK Login", `Hello, ${APS.userInfo.givenName}`)
}
} else {
console.error("Couldn't get auth data.")
Expand All @@ -306,7 +306,7 @@ class APS {
if (retry_login) {
this.auth = undefined
World.AnalyticsSystem?.Exception("APS Login Failure")
MainHUD_AddToast("error", "Error signing in.", "Please try again.")
Global_AddToast?.("error", "Error signing in.", "Please try again.")
}
}

Expand All @@ -327,7 +327,7 @@ class APS {
const json = await res.json()
if (!res.ok) {
World.AnalyticsSystem?.Exception("APS Failure: User Info")
MainHUD_AddToast("error", "Error fetching user data.", json.userMessage)
Global_AddToast?.("error", "Error fetching user data.", json.userMessage)
this.auth = undefined
await this.requestAuthCode()
return
Expand All @@ -339,15 +339,11 @@ class APS {
email: json.email,
}

if (json.sub) {
World.AnalyticsSystem?.SetUserId(json.sub as string)
}

this.userInfo = info
} catch (e) {
console.error(e)
World.AnalyticsSystem?.Exception("APS Login Failure: User Info")
MainHUD_AddToast("error", "Error signing in.", "Please try again.")
Global_AddToast?.("error", "Error signing in.", "Please try again.")
this.auth = undefined
}
}
Expand All @@ -363,7 +359,7 @@ class APS {
} catch (e) {
console.error(e)
World.AnalyticsSystem?.Exception("APS Login Failure: Code Challenge")
MainHUD_AddToast("error", "Error signing in.", "Please try again.")
Global_AddToast?.("error", "Error signing in.", "Please try again.")
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions fission/src/aps/APSDataManagement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { MainHUD_AddToast } from "@/ui/components/MainHUD"
import { Global_AddToast } from "@/ui/components/GlobalUIControls"
import APS from "./APS"
import TaskStatus from "@/util/TaskStatus"
import { Mutex } from "async-mutex"
Expand Down Expand Up @@ -140,9 +140,9 @@ export async function getHubs(): Promise<Hub[] | undefined> {
console.log(auth)
console.log(APS.userInfo)
if (e instanceof APSDataError) {
MainHUD_AddToast("error", e.title, e.detail)
Global_AddToast?.("error", e.title, e.detail)
} else if (e instanceof Error) {
MainHUD_AddToast("error", "Failed to get hubs.", e.message)
Global_AddToast?.("error", "Failed to get hubs.", e.message)
}
return undefined
}
Expand Down Expand Up @@ -179,7 +179,7 @@ export async function getProjects(hub: Hub): Promise<Project[] | undefined> {
} catch (e) {
console.error("Failed to get hubs")
if (e instanceof Error) {
MainHUD_AddToast("error", "Failed to get hubs.", e.message)
Global_AddToast?.("error", "Failed to get hubs.", e.message)
}
return undefined
}
Expand Down Expand Up @@ -224,7 +224,7 @@ export async function getFolderData(project: Project, folder: Folder): Promise<D
} catch (e) {
console.error("Failed to get folder data")
if (e instanceof Error) {
MainHUD_AddToast("error", "Failed to get folder data.", e.message)
Global_AddToast?.("error", "Failed to get folder data.", e.message)
}
return undefined
}
Expand All @@ -250,7 +250,7 @@ export async function searchFolder(project: Project, folder: Folder, filters?: F
},
})
if (!res.ok) {
MainHUD_AddToast("error", "Error getting cloud files.", "Please sign in again.")
Global_AddToast?.("error", "Error getting cloud files.", "Please sign in again.")
return []
}
const json = await res.json()
Expand Down
6 changes: 1 addition & 5 deletions fission/src/mirabuf/IntakeSensorSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
ThreeVector3_JoltVec3,
} from "@/util/TypeConversions"
import { OnContactPersistedEvent } from "@/systems/physics/ContactEvents"
import InputSystem from "@/systems/input/InputSystem"
import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain"

class IntakeSensorSceneObject extends SceneObject {
private _parentAssembly: MirabufSceneObject
Expand Down Expand Up @@ -44,9 +42,7 @@ class IntakeSensorSceneObject extends SceneObject {
}

this._collision = (event: OnContactPersistedEvent) => {
const brain = this._parentAssembly.brain
const brainIndex = brain instanceof SynthesisBrain ? brain.brainIndex ?? -1 : -1
if (InputSystem.getInput("intake", brainIndex)) {
if (this._parentAssembly.intakeActive) {
if (this._joltBodyId && !World.PhysicsSystem.isPaused) {
const body1 = event.message.body1
const body2 = event.message.body2
Expand Down
Loading

0 comments on commit 32948b5

Please sign in to comment.