Skip to content

Commit 7d442a4

Browse files
authored
Merge branch 'dev' into alexey/1938/scene-system-testing
2 parents 13c1d6e + 497de7c commit 7d442a4

File tree

3 files changed

+26
-36
lines changed

3 files changed

+26
-36
lines changed

fission/src/mirabuf/MirabufLoader.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,15 @@ class MirabufCachingService {
115115
*
116116
* @param {string} fetchLocation Location of Mirabuf file.
117117
* @param {MiraType} miraType Type of Mirabuf Assembly.
118+
* @param {string} name Optional display name for the cached file.
118119
*
119120
* @returns {Promise<MirabufCacheInfo | undefined>} Promise with the result of the promise. Metadata on the mirabuf file if successful, undefined if not.
120121
*/
121-
public static async cacheRemote(fetchLocation: string, miraType?: MiraType): Promise<MirabufCacheInfo | undefined> {
122+
public static async cacheRemote(
123+
fetchLocation: string,
124+
miraType?: MiraType,
125+
name?: string
126+
): Promise<MirabufCacheInfo | undefined> {
122127
if (miraType !== undefined) {
123128
const map = MirabufCachingService.getCacheMap(miraType)
124129
const target = map[fetchLocation]
@@ -136,7 +141,7 @@ class MirabufCachingService {
136141
fileSize: miraBuff.byteLength,
137142
})
138143

139-
const cached = await MirabufCachingService.storeInCache(fetchLocation, miraBuff, miraType)
144+
const cached = await MirabufCachingService.storeInCache(fetchLocation, miraBuff, miraType, name)
140145

141146
if (cached) return cached
142147

@@ -148,6 +153,7 @@ class MirabufCachingService {
148153
miraType: miraType ?? (this.assemblyFromBuffer(miraBuff).dynamic ? MiraType.ROBOT : MiraType.FIELD),
149154
cacheKey: fetchLocation,
150155
buffer: miraBuff,
156+
name: name,
151157
}
152158
} catch (e) {
153159
console.warn("Caching failed", e)

fission/src/systems/scene/DragModeSystem.ts

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ import * as THREE from "three"
22
import WorldSystem from "../WorldSystem"
33
import World from "../World"
44
import JOLT from "@/util/loading/JoltSyncLoader"
5-
import { convertThreeVector3ToJoltVec3, convertJoltVec3ToThreeVector3 } from "@/util/TypeConversions"
5+
import { convertJoltVec3ToThreeVector3, convertThreeVector3ToJoltVec3 } from "@/util/TypeConversions"
66
import MirabufSceneObject, { RigidNodeAssociate } from "@/mirabuf/MirabufSceneObject"
77
import {
8-
InteractionStart,
9-
InteractionMove,
108
InteractionEnd,
9+
InteractionMove,
10+
InteractionStart,
1111
PRIMARY_MOUSE_INTERACTION,
1212
} from "./ScreenInteractionHandler"
1313
import { CustomOrbitControls, SphericalCoords } from "./CameraControls"
1414
import Jolt from "@azaleacolburn/jolt-physics"
1515
import { MiraType } from "@/mirabuf/MirabufLoader"
16+
import InputSystem from "@/systems/input/InputSystem.ts"
1617

1718
interface DragTarget {
1819
bodyId: Jolt.BodyID
@@ -59,6 +60,7 @@ class DragModeSystem extends WorldSystem {
5960
// Precision and sensitivity
6061
MINIMUM_DISTANCE_THRESHOLD: 0.02, // Minimum distance to apply forces (smaller = more precision)
6162
WHEEL_SCROLL_SENSITIVITY: -0.01, // Mouse wheel scroll sensitivity for Z-axis
63+
ROTATION_SPEED: 200.0, // speed of arrow key rotation. lower = more precise, higher = more
6264
} as const
6365

6466
private _enabled: boolean = false
@@ -564,25 +566,19 @@ class DragModeSystem extends WorldSystem {
564566
const joltForce = convertThreeVector3ToJoltVec3(forceNeeded)
565567
body.AddForce(joltForce)
566568

567-
// Calculate torque to simulate force applied at the drag point
568-
// Use the current world offset (which rotates with the body)
569-
const leverArm = currentWorldOffset // vector from COM to drag point in world coordinates
570-
const torque = leverArm.cross(forceNeeded) // Cross product gives us the torque
571-
const joltTorque = convertThreeVector3ToJoltVec3(torque)
572-
body.AddTorque(joltTorque)
573-
574-
// Reduce angular damping since we want the natural rotation from the applied force
575-
const angularVel = body.GetAngularVelocity()
576-
const angularDampingStrength = Math.min(
577-
mass * DragModeSystem.DRAG_FORCE_CONSTANTS.ANGULAR_DAMPING_BASE,
578-
DragModeSystem.DRAG_FORCE_CONSTANTS.ANGULAR_DAMPING_MAX
569+
const yawRotation = new JOLT.Vec3(
570+
0,
571+
DragModeSystem.DRAG_FORCE_CONSTANTS.ROTATION_SPEED *
572+
(InputSystem.isKeyPressed("ArrowRight") ? 1 : 0 - (InputSystem.isKeyPressed("ArrowLeft") ? 1 : 0)),
573+
0
579574
)
580-
const angularDampingTorque = new JOLT.Vec3(
581-
-angularVel.GetX() * angularDampingStrength,
582-
-angularVel.GetY() * angularDampingStrength,
583-
-angularVel.GetZ() * angularDampingStrength
575+
const cameraVector = World.sceneRenderer.mainCamera.getWorldDirection(new THREE.Vector3(0, 0, 0))
576+
const pitchRotation = new JOLT.Vec3(cameraVector.z, 0, -cameraVector.x).Mul(
577+
DragModeSystem.DRAG_FORCE_CONSTANTS.ROTATION_SPEED *
578+
(InputSystem.isKeyPressed("ArrowUp") ? 1 : 0 - (InputSystem.isKeyPressed("ArrowDown") ? 1 : 0))
584579
)
585-
body.AddTorque(angularDampingTorque)
580+
body.AddTorque(yawRotation)
581+
body.AddTorque(pitchRotation)
586582
} else {
587583
// When close to target, apply braking forces and gravity compensation
588584
const currentVel = body.GetLinearVelocity()
@@ -602,21 +598,9 @@ class DragModeSystem extends WorldSystem {
602598
const gravityCompensationY = mass * DragModeSystem.DRAG_FORCE_CONSTANTS.GRAVITY_MAGNITUDE
603599
brakingForce.SetY(brakingForce.GetY() + gravityCompensationY)
604600
}
605-
606601
body.AddForce(brakingForce)
607-
608-
const angularVel = body.GetAngularVelocity()
609-
const angularBrakingStrength = Math.min(
610-
mass * DragModeSystem.DRAG_FORCE_CONSTANTS.ANGULAR_BRAKING_BASE,
611-
DragModeSystem.DRAG_FORCE_CONSTANTS.ANGULAR_BRAKING_MAX
612-
)
613-
const angularBrakingTorque = new JOLT.Vec3(
614-
-angularVel.GetX() * angularBrakingStrength,
615-
-angularVel.GetY() * angularBrakingStrength,
616-
-angularVel.GetZ() * angularBrakingStrength
617-
)
618-
body.AddTorque(angularBrakingTorque)
619602
}
603+
body.SetAngularVelocity(new JOLT.Vec3())
620604
}
621605

622606
private handleWheelDuringDrag(event: WheelEvent): void {

fission/src/ui/panels/mirabuf/ImportMirabufPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ const ImportMirabufPanel: React.FC<PanelPropsImpl> = ({ panelId }) => {
250250
const status = new ProgressHandle(info.displayName)
251251
status.update("Downloading from Synthesis...", 0.05)
252252

253-
MirabufCachingService.cacheRemote(info.src, type)
253+
MirabufCachingService.cacheRemote(info.src, type, info.displayName)
254254
.then(cacheInfo => {
255255
if (cacheInfo) {
256256
status.done()

0 commit comments

Comments
 (0)