From ceaf33ffb12e4e2bfc4101ae6d87e15f77bd760d Mon Sep 17 00:00:00 2001 From: HunterBarclay Date: Sun, 22 Sep 2024 14:16:50 -0600 Subject: [PATCH] fix: Added new initial config panel to import local. Also added in a couple cleanups here and there. --- fission/src/mirabuf/MirabufInstance.ts | 2 - fission/src/mirabuf/MirabufSceneObject.ts | 8 ++- .../src/systems/analytics/AnalyticsSystem.ts | 2 - fission/src/systems/scene/GizmoSceneObject.ts | 40 +++++++++++---- fission/src/ui/components/Scene.tsx | 3 -- .../ui/components/TransformGizmoControl.tsx | 50 +++++++++++-------- .../mirabuf/ImportLocalMirabufModal.tsx | 9 ++-- .../ConfigureGamepiecePickupInterface.tsx | 2 +- 8 files changed, 71 insertions(+), 45 deletions(-) diff --git a/fission/src/mirabuf/MirabufInstance.ts b/fission/src/mirabuf/MirabufInstance.ts index 700395611c..f1763a6e92 100644 --- a/fission/src/mirabuf/MirabufInstance.ts +++ b/fission/src/mirabuf/MirabufInstance.ts @@ -234,8 +234,6 @@ class MirabufInstance { } } - console.debug(batchMap) - // Construct batched meshes batchMap.forEach((materialBodyMap, material) => { const count = countMap.get(material)! diff --git a/fission/src/mirabuf/MirabufSceneObject.ts b/fission/src/mirabuf/MirabufSceneObject.ts index 728ef4c92c..30ab817274 100644 --- a/fission/src/mirabuf/MirabufSceneObject.ts +++ b/fission/src/mirabuf/MirabufSceneObject.ts @@ -21,7 +21,6 @@ import { SceneOverlayTag } from "@/ui/components/SceneOverlayEvents" import { ProgressHandle } from "@/ui/components/ProgressNotificationData" import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain" import GizmoSceneObject from "@/systems/scene/GizmoSceneObject" -import { threeMatrix4ToString } from "@/util/debug/DebugPrint" const DEBUG_BODIES = false @@ -176,6 +175,8 @@ class MirabufSceneObject extends SceneObject { this.UpdateScoringZones() setSpotlightAssembly(this) + + this.UpdateBatches() } public Update(): void { @@ -410,10 +411,7 @@ class MirabufSceneObject extends SceneObject { const jBody = World.PhysicsSystem.GetBody(jRootId) const comTransform = JoltMat44_ThreeMatrix4(jBody.GetCenterOfMassTransform()) - gizmo.UpdateGizmoObjectPositionAndRotation(comTransform) - - console.debug(`Source:\n${threeMatrix4ToString(comTransform)}`) - console.debug(`New:\n${threeMatrix4ToString(gizmo.obj.matrix)}`) + gizmo.SetTransform(comTransform) } private getPreferences(): void { diff --git a/fission/src/systems/analytics/AnalyticsSystem.ts b/fission/src/systems/analytics/AnalyticsSystem.ts index 4eb0b9fa27..a7dc4da255 100644 --- a/fission/src/systems/analytics/AnalyticsSystem.ts +++ b/fission/src/systems/analytics/AnalyticsSystem.ts @@ -78,8 +78,6 @@ class AnalyticsSystem extends WorldSystem { betaCode = betaCode.substring(betaCode.indexOf("=") + 1, betaCode.indexOf(";")) this.SetUserProperty("Beta Code", betaCode) - } else { - console.debug("No code match") } if (MOBILE_USER_AGENT_REGEX.test(navigator.userAgent)) { diff --git a/fission/src/systems/scene/GizmoSceneObject.ts b/fission/src/systems/scene/GizmoSceneObject.ts index c98e56fa8f..eb800d46c4 100644 --- a/fission/src/systems/scene/GizmoSceneObject.ts +++ b/fission/src/systems/scene/GizmoSceneObject.ts @@ -7,13 +7,13 @@ import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" import { Object3D, PerspectiveCamera } from "three" import { ThreeQuaternion_JoltQuat, JoltMat44_ThreeMatrix4, ThreeVector3_JoltVec3 } from "@/util/TypeConversions" import { RigidNodeId } from "@/mirabuf/MirabufParser" -import { threeMatrix4ToString } from "@/util/debug/DebugPrint" export type GizmoMode = "translate" | "rotate" | "scale" class GizmoSceneObject extends SceneObject { private _gizmo: TransformControls private _obj: Object3D + private _forceUpdate: boolean = false private _parentObject: MirabufSceneObject | undefined private _relativeTransformations?: Map @@ -66,10 +66,7 @@ class GizmoSceneObject extends SceneObject { if (this._parentObject) { this._relativeTransformations = new Map() - const c = this._obj.matrix.clone() - console.debug(`Clone:\n${threeMatrix4ToString(c)}`) - - const gizmoTransformInv = c.invert() + const gizmoTransformInv = this._obj.matrix.clone().invert() /** Due to the limited math functionality exposed to JS for Jolt, we need everything in ThreeJS. */ this._parentObject.mirabufInstance.parser.rigidNodes.forEach(rn => { @@ -153,7 +150,8 @@ class GizmoSceneObject extends SceneObject { /** Translating the obj changes to the mirabuf scene object */ if (this._parentObject) { this._parentObject.DisablePhysics() - if (this.isDragging) { + if (this.isDragging || this._forceUpdate) { + this._forceUpdate = false this._parentObject.mirabufInstance.parser.rigidNodes.forEach(rn => { this.UpdateNodeTransform(rn.id) }) @@ -167,6 +165,8 @@ class GizmoSceneObject extends SceneObject { this._parentObject?.EnablePhysics() World.SceneRenderer.RemoveObject(this._obj) World.SceneRenderer.RemoveObject(this._gizmo) + + this._relativeTransformations?.clear() } /** changes the mode of the gizmo */ @@ -174,7 +174,11 @@ class GizmoSceneObject extends SceneObject { this._gizmo.setMode(mode) } - /** updates body position and rotation for each body from the parent mirabuf */ + /** + * Updates a given node to follow the gizmo. + * + * @param rnId Target node to update. + */ public UpdateNodeTransform(rnId: RigidNodeId) { if (!this._parentObject || !this._relativeTransformations || !this._relativeTransformations.has(rnId)) return @@ -194,8 +198,13 @@ class GizmoSceneObject extends SceneObject { ) } - /** */ - public UpdateGizmoObjectPositionAndRotation(gizmoTransformation: THREE.Matrix4) { + /** + * Updates the gizmos location. + * + * @param gizmoTransformation Transform for the gizmo to take on. + */ + public SetTransform(gizmoTransformation: THREE.Matrix4) { + // Super hacky, prolly has something to do with how the transform controls update the attached object. const position = new THREE.Vector3(0,0,0) const rotation = new THREE.Quaternion(0,0,0,1) const scale = new THREE.Vector3(1,1,1) @@ -204,6 +213,19 @@ class GizmoSceneObject extends SceneObject { this._obj.position.setFromMatrixPosition(gizmoTransformation) this._obj.rotation.setFromRotationMatrix(gizmoTransformation) + + this._forceUpdate = true + } + + public SetRotation(rotation: THREE.Quaternion) { + const position = new THREE.Vector3(0,0,0) + const scale = new THREE.Vector3(1,1,1) + this._obj.matrix.decompose(position, new THREE.Quaternion(0,0,0,1), scale) + this._obj.matrix.compose(position, rotation, scale) + + this._obj.rotation.setFromQuaternion(rotation) + + this._forceUpdate = true } /** @return true if gizmo is attached to mirabufSceneObject */ diff --git a/fission/src/ui/components/Scene.tsx b/fission/src/ui/components/Scene.tsx index 6ba35ddb6f..034d865503 100644 --- a/fission/src/ui/components/Scene.tsx +++ b/fission/src/ui/components/Scene.tsx @@ -17,8 +17,6 @@ function Scene({ useStats }: SceneProps) { World.InitWorld() if (refContainer.current) { - console.debug("Adding ThreeJs to DOM") - const sr = World.SceneRenderer sr.renderer.domElement.style.width = "100%" sr.renderer.domElement.style.height = "100%" @@ -30,7 +28,6 @@ function Scene({ useStats }: SceneProps) { }) if (useStats && !stats) { - console.log("Adding stat") stats = new Stats() stats.dom.style.position = "absolute" stats.dom.style.top = "0px" diff --git a/fission/src/ui/components/TransformGizmoControl.tsx b/fission/src/ui/components/TransformGizmoControl.tsx index 4360d217ff..c9ea7e8e30 100644 --- a/fission/src/ui/components/TransformGizmoControl.tsx +++ b/fission/src/ui/components/TransformGizmoControl.tsx @@ -3,6 +3,8 @@ import TransformGizmoControlProps from "./TransformGizmoControlProps"; import GizmoSceneObject, { GizmoMode } from "@/systems/scene/GizmoSceneObject"; import { ToggleButton, ToggleButtonGroup } from "./ToggleButtonGroup"; import World from "@/systems/World"; +import Button, { ButtonSize } from "./Button"; +import * as THREE from "three" /** * Creates GizmoSceneObject and gives you a toggle button group to control the modes of the gizmo. @@ -30,8 +32,6 @@ function TransformGizmoControl({ const [gizmo, setGizmo] = useState(undefined) useEffect(() => { - console.debug('Gizmo Recreation') - const gizmo = new GizmoSceneObject( "translate", size, @@ -70,25 +70,35 @@ function TransformGizmoControl({ // If there are no modes enabled, consider the UI pointless. return disableOptions ? (<>) : ( - { - if (v == undefined) return + <> + { + if (v == undefined) return - setMode(v) - gizmo?.SetMode(v) - }} - sx={{ - ...(sx ?? {}), - alignSelf: "center", - }} - > - {/* { translateDisabled ? <> : Move } - { rotateDisabled ? <> : Rotate } - { scaleDisabled ? <> : Scale } */} - { buttons } - + setMode(v) + gizmo?.SetMode(v) + }} + sx={{ + ...(sx ?? {}), + alignSelf: "center", + }} + > + {/* { translateDisabled ? <> : Move } + { rotateDisabled ? <> : Rotate } + { scaleDisabled ? <> : Scale } */} + { buttons } + + {rotateDisabled ? <> :