From 0c39d2e378f46802d5a7fa915c9294ed1fa2c8df Mon Sep 17 00:00:00 2001 From: HunterBarclay Date: Thu, 5 Sep 2024 00:45:35 -0600 Subject: [PATCH] WIP: Accumulating friction pairings and fixed gamepiece issue in the exporter. --- .../src/UI/GamepieceConfigTab.py | 6 ++- fission/src/systems/physics/PhysicsSystem.ts | 37 +++++++++++++++++-- fission/vite.config.ts | 2 +- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/exporter/SynthesisFusionAddin/src/UI/GamepieceConfigTab.py b/exporter/SynthesisFusionAddin/src/UI/GamepieceConfigTab.py index c28f6c60f..819f352e8 100644 --- a/exporter/SynthesisFusionAddin/src/UI/GamepieceConfigTab.py +++ b/exporter/SynthesisFusionAddin/src/UI/GamepieceConfigTab.py @@ -3,6 +3,9 @@ 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, @@ -198,7 +201,8 @@ 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 + occ = self.selectedGamepieceList[row - 1] + gamepieceEntityToken = guid_occurrence(occ) gamepieceWeight = convertMassUnitsTo(self.gamepieceTable.getInputAtPosition(row, 1).value) gamepieceFrictionCoefficient = self.gamepieceTable.getInputAtPosition(row, 2).valueOne gamepieces.append(Gamepiece(gamepieceEntityToken, gamepieceWeight, gamepieceFrictionCoefficient)) diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index f0e84a638..463d3d4c3 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -62,6 +62,8 @@ const FLOOR_FRICTION = 0.7 const SUSPENSION_MIN_FACTOR = 0.1 const SUSPENSION_MAX_FACTOR = 0.3 +const DEFAULT_PHYSICAL_MATERIAL_KEY = "default" + // Motor constant const VELOCITY_DEFAULT = 30 @@ -660,7 +662,14 @@ class PhysicsSystem extends WorldSystem { let shapesAdded = 0 let totalMass = 0 - let frictionOverride = 0 + + type FrictionPairing = { + dynamic: number, + static: number, + weight: number + } + const frictionAccum: FrictionPairing[] = [] + const comAccum = new mirabuf.Vector3() const minBounds = new JOLT.Vec3(1000000.0, 1000000.0, 1000000.0) @@ -701,8 +710,14 @@ class PhysicsSystem extends WorldSystem { JOLT.destroy(transform) // Set friction override once to any of the parts' values - if (!frictionOverride && partDefinition?.frictionOverride) - frictionOverride = partDefinition.frictionOverride + const physicalMaterial = parser.assembly.data!.materials!.physicalMaterials![partInstance.physicalMaterial ?? DEFAULT_PHYSICAL_MATERIAL_KEY] + const frictionPairing: FrictionPairing = { + dynamic: partDefinition?.frictionOverride ?? physicalMaterial.dynamicFriction!, + static: partDefinition?.frictionOverride ?? physicalMaterial.staticFriction!, + weight: partDefinition.physicalData?.area ?? 1.0 + } + frictionAccum.push(frictionPairing) + // console.debug(`(${frictionPairing.dynamic.toFixed(3), frictionPairing.static.toFixed(3)}) [${frictionPairing.weight.toFixed(3)}]`) if (!partDefinition.physicalData?.com || !partDefinition.physicalData.mass) return @@ -741,7 +756,21 @@ class PhysicsSystem extends WorldSystem { rnToBodies.set(rn.id, body.GetID()) // Set Friction Here - if (frictionOverride) body.SetFriction(frictionOverride) + let staticFriction = 0.0 + let dynamicFriction = 0.0 + let weightSum = 0.0 + frictionAccum.forEach(pairing => { + staticFriction += pairing.static * pairing.weight + dynamicFriction += pairing.dynamic * pairing.weight + weightSum += pairing.weight + }) + staticFriction /= weightSum == 0.0 ? 1.0 : weightSum + dynamicFriction /= weightSum == 0.0 ? 1.0 : weightSum + + // I guess this is an okay substitute. + const friction = (staticFriction + dynamicFriction) / 2.0 + body.SetFriction(friction) + console.debug(`Friction: ${friction}`) // Little testing components this._bodies.push(body.GetID()) diff --git a/fission/vite.config.ts b/fission/vite.config.ts index 967c978ca..050892e31 100644 --- a/fission/vite.config.ts +++ b/fission/vite.config.ts @@ -7,7 +7,7 @@ const basePath = "/fission/" const serverPort = 3000 const dockerServerPort = 80 -const useLocal = true +const useLocal = false // https://vitejs.dev/config/ export default defineConfig({