Skip to content

Commit

Permalink
WIP: Accumulating friction pairings and fixed gamepiece issue in the
Browse files Browse the repository at this point in the history
exporter.
  • Loading branch information
HunterBarclay committed Sep 5, 2024
1 parent bbc7cda commit 0c39d2e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
6 changes: 5 additions & 1 deletion exporter/SynthesisFusionAddin/src/UI/GamepieceConfigTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
37 changes: 33 additions & 4 deletions fission/src/systems/physics/PhysicsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion fission/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 0c39d2e

Please sign in to comment.