Skip to content

Commit

Permalink
Format plus some syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay committed Sep 22, 2024
1 parent 269d333 commit b10ccc7
Show file tree
Hide file tree
Showing 19 changed files with 254 additions and 199 deletions.
10 changes: 5 additions & 5 deletions fission/src/mirabuf/MirabufSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class MirabufSceneObject extends SceneObject {
World.SimulationSystem.RegisterMechanism(this._mechanism)
const simLayer = World.SimulationSystem.GetSimulationLayer(this._mechanism)!
this._brain = new SynthesisBrain(this._mechanism, this._assemblyName)
simLayer.SetBrain(this._brain)
simLayer.SetBrain(this._brain)
}

// Intake
Expand All @@ -183,7 +183,7 @@ class MirabufSceneObject extends SceneObject {

const offset = new JOLT.Vec3(
-(bounds.min.x + bounds.max.x) / 2.0,
0.1 + ((bounds.max.y - bounds.min.y) / 2.0) - ((bounds.min.y + bounds.max.y) / 2.0),
0.1 + (bounds.max.y - bounds.min.y) / 2.0 - (bounds.min.y + bounds.max.y) / 2.0,
-(bounds.min.z + bounds.max.z) / 2.0
)

Expand Down Expand Up @@ -420,7 +420,7 @@ class MirabufSceneObject extends SceneObject {

/**
* Once a gizmo is created and attached to this mirabuf object, this will be executed to align the gizmo correctly.
*
*
* @param gizmo Gizmo attached to the mirabuf object
*/
public PostGizmoCreation(gizmo: GizmoSceneObject) {
Expand All @@ -433,9 +433,9 @@ class MirabufSceneObject extends SceneObject {
const jBody = World.PhysicsSystem.GetBody(jRootId)
if (jBody.IsStatic()) {
const aaBox = jBody.GetWorldSpaceBounds()
const mat = new THREE.Matrix4(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)
const mat = new THREE.Matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
const center = aaBox.mMin.Add(aaBox.mMax).Div(2.0)
mat.compose(JoltVec3_ThreeVector3(center), new THREE.Quaternion(0,0,0,1), new THREE.Vector3(1,1,1))
mat.compose(JoltVec3_ThreeVector3(center), new THREE.Quaternion(0, 0, 0, 1), new THREE.Vector3(1, 1, 1))
gizmo.SetTransform(mat)
} else {
gizmo.SetTransform(JoltMat44_ThreeMatrix4(jBody.GetCenterOfMassTransform()))
Expand Down
9 changes: 7 additions & 2 deletions fission/src/systems/physics/PhysicsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class PhysicsSystem extends WorldSystem {
* Releases a pause.
*
* @param ref String to reference your hold.
*
*
* @returns Whether or not your hold was successfully removed.
*/
public ReleasePause(ref: string): boolean {
Expand Down Expand Up @@ -1080,7 +1080,12 @@ class PhysicsSystem extends WorldSystem {
)
}

public SetBodyPositionAndRotation(id: Jolt.BodyID, position: Jolt.RVec3, rotation: Jolt.Quat, activate: boolean = true): void {
public SetBodyPositionAndRotation(
id: Jolt.BodyID,
position: Jolt.RVec3,
rotation: Jolt.Quat,
activate: boolean = true
): void {
if (!this.IsBodyAdded(id)) {
return
}
Expand Down
30 changes: 15 additions & 15 deletions fission/src/systems/scene/GizmoSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GizmoSceneObject extends SceneObject {
size: number,
obj?: THREE.Mesh,
parentObject?: MirabufSceneObject,
postGizmoCreation?: (gizmo: GizmoSceneObject) => void,
postGizmoCreation?: (gizmo: GizmoSceneObject) => void
) {
super()

Expand All @@ -63,7 +63,7 @@ class GizmoSceneObject extends SceneObject {
World.SceneRenderer.RegisterGizmoSceneObject(this)

postGizmoCreation?.(this)

if (this._parentObject) {
this._relativeTransformations = new Map<RigidNodeId, THREE.Matrix4>()
const gizmoTransformInv = this._obj.matrix.clone().invert()
Expand All @@ -72,7 +72,7 @@ class GizmoSceneObject extends SceneObject {
this._parentObject.mirabufInstance.parser.rigidNodes.forEach(rn => {
const jBodyId = this._parentObject!.mechanism.GetBodyByNodeId(rn.id)
if (!jBodyId) return

const worldTransform = JoltMat44_ThreeMatrix4(World.PhysicsSystem.GetBody(jBodyId).GetWorldTransform())
const relativeTransform = worldTransform.premultiply(gizmoTransformInv)
this._relativeTransformations!.set(rn.id, relativeTransform)
Expand Down Expand Up @@ -176,7 +176,7 @@ class GizmoSceneObject extends SceneObject {

/**
* Updates a given node to follow the gizmo.
*
*
* @param rnId Target node to update.
*/
public UpdateNodeTransform(rnId: RigidNodeId) {
Expand All @@ -187,27 +187,27 @@ class GizmoSceneObject extends SceneObject {

const relativeTransform = this._relativeTransformations.get(rnId)!
const worldTransform = relativeTransform.clone().premultiply(this._obj.matrix)
const position = new THREE.Vector3(0,0,0)
const rotation = new THREE.Quaternion(0,0,0,1)
worldTransform.decompose(position, rotation, new THREE.Vector3(1,1,1))
const position = new THREE.Vector3(0, 0, 0)
const rotation = new THREE.Quaternion(0, 0, 0, 1)
worldTransform.decompose(position, rotation, new THREE.Vector3(1, 1, 1))

World.PhysicsSystem.SetBodyPositionAndRotation(
jBodyId,
ThreeVector3_JoltVec3(position),
ThreeQuaternion_JoltQuat(rotation),
ThreeQuaternion_JoltQuat(rotation)
)
}

/**
* 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)
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)
gizmoTransformation.decompose(position, rotation, scale)
this._obj.matrix.compose(position, rotation, scale)

Expand All @@ -218,9 +218,9 @@ class GizmoSceneObject extends SceneObject {
}

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)
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)
Expand Down
8 changes: 4 additions & 4 deletions fission/src/ui/components/GlobalUIComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { setAddToast, setOpenModal, setOpenPanel } from "./GlobalUIControls"
* So this is Hunter's kinda cursed approach to de-react-ifying some of our UI controls.
* Essentially, this component will expose context controls for our UI, which allows
* non-UI components (such as APSDataManagement) to use UI controls (such as addToast).
*
*
* Stored in a component to ensure a lifetime is followed with this handles.
*
*
* @returns Global UI Component
*/
function GlobalUIComponent() {
Expand Down Expand Up @@ -42,7 +42,7 @@ function GlobalUIComponent() {
}
}, [addToast])

return (<></>)
return <></>
}

export default GlobalUIComponent
export default GlobalUIComponent
14 changes: 10 additions & 4 deletions fission/src/ui/components/GlobalUIControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
* See GlobalUIComponent.tsx for explanation of this madness.
*/

import { ToastType } from "@/ui/ToastContext";
import { ToastType } from "@/ui/ToastContext"

export let Global_AddToast: ((type: ToastType, title: string, description: string) => void) | undefined = undefined
export let Global_OpenPanel: ((panelId: string) => void) | undefined = undefined
export let Global_OpenModal: ((modalId: string) => void) | undefined = undefined

export function setAddToast(func: typeof Global_AddToast) { Global_AddToast = func }
export function setOpenPanel(func: typeof Global_OpenPanel) { Global_OpenPanel = func }
export function setOpenModal(func: typeof Global_OpenModal) { Global_OpenModal = func}
export function setAddToast(func: typeof Global_AddToast) {
Global_AddToast = func
}
export function setOpenPanel(func: typeof Global_OpenPanel) {
Global_OpenPanel = func
}
export function setOpenModal(func: typeof Global_OpenModal) {
Global_OpenModal = func
}
85 changes: 48 additions & 37 deletions fission/src/ui/components/TransformGizmoControl.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { useEffect, useState } from "react";
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 { useEffect, useState } from "react"
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.
* The lifetime of the gizmo is entirely handles within this component and will be recreated depending
* on the updates made to the parameters provided. You can setup initial properties of the gizmo with
* the `postGizmoCreation` handle.
*
*
* @param param0 Transform Gizmo Controls.
* @returns TransformGizmoControl component.
*/
Expand All @@ -25,23 +25,16 @@ function TransformGizmoControl({
rotateDisabled,
scaleDisabled,
sx,
postGizmoCreation
postGizmoCreation,
}: TransformGizmoControlProps) {

const [mode, setMode] = useState<GizmoMode>(defaultMode)
const [gizmo, setGizmo] = useState<GizmoSceneObject | undefined>(undefined)

useEffect(() => {
const gizmo = new GizmoSceneObject(
"translate",
size,
defaultMesh,
parent,
(gizmo: GizmoSceneObject) => {
parent?.PostGizmoCreation(gizmo)
postGizmoCreation?.(gizmo)
}
)
const gizmo = new GizmoSceneObject("translate", size, defaultMesh, parent, (gizmo: GizmoSceneObject) => {
parent?.PostGizmoCreation(gizmo)
postGizmoCreation?.(gizmo)
})

if (gizmoRef) gizmoRef.current = gizmo

Expand All @@ -58,18 +51,32 @@ function TransformGizmoControl({
}
}, [gizmoRef])

const disableOptions = 2 <=
((translateDisabled ? 1 : 0)
+ (rotateDisabled ? 1 : 0)
+ (scaleDisabled ? 1 : 0))
const disableOptions = 2 <= (translateDisabled ? 1 : 0) + (rotateDisabled ? 1 : 0) + (scaleDisabled ? 1 : 0)

const buttons = []
if (!translateDisabled) buttons.push((<ToggleButton key="translate-button" value={"translate"}>Move</ToggleButton>))
if (!rotateDisabled) buttons.push((<ToggleButton key="rotate-button" value={"rotate"}>Rotate</ToggleButton>))
if (!scaleDisabled) buttons.push((<ToggleButton key="scale-button" value={"scale"}>Scale</ToggleButton>))
if (!translateDisabled)
buttons.push(
<ToggleButton key="translate-button" value={"translate"}>
Move
</ToggleButton>
)
if (!rotateDisabled)
buttons.push(
<ToggleButton key="rotate-button" value={"rotate"}>
Rotate
</ToggleButton>
)
if (!scaleDisabled)
buttons.push(
<ToggleButton key="scale-button" value={"scale"}>
Scale
</ToggleButton>
)

// If there are no modes enabled, consider the UI pointless.
return disableOptions ? (<></>) : (
return disableOptions ? (
<></>
) : (
<>
<ToggleButtonGroup
value={mode}
Expand All @@ -88,18 +95,22 @@ function TransformGizmoControl({
{/* { translateDisabled ? <></> : <ToggleButton value={"translate"}>Move</ToggleButton> }
{ rotateDisabled ? <></> : <ToggleButton value={"rotate"}>Rotate</ToggleButton> }
{ scaleDisabled ? <></> : <ToggleButton value={"scale"}>Scale</ToggleButton> } */}
{ buttons }
{buttons}
</ToggleButtonGroup>
{rotateDisabled ? <></> : <Button
value={"Reset Orientation"}
size={ButtonSize.Small}
className="self-center"
onClick={() => {
gizmo?.SetRotation(new THREE.Quaternion(0,0,0,1))
}}
/>}
{rotateDisabled ? (
<></>
) : (
<Button
value={"Reset Orientation"}
size={ButtonSize.Small}
className="self-center"
onClick={() => {
gizmo?.SetRotation(new THREE.Quaternion(0, 0, 0, 1))
}}
/>
)}
</>
)
}

export default TransformGizmoControl;
export default TransformGizmoControl
32 changes: 16 additions & 16 deletions fission/src/ui/components/TransformGizmoControlProps.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import MirabufSceneObject from "@/mirabuf/MirabufSceneObject";
import GizmoSceneObject, { GizmoMode } from "@/systems/scene/GizmoSceneObject";
import { SxProps, Theme } from "@mui/material";
import { MutableRefObject } from "react";
import * as THREE from 'three';
import MirabufSceneObject from "@/mirabuf/MirabufSceneObject"
import GizmoSceneObject, { GizmoMode } from "@/systems/scene/GizmoSceneObject"
import { SxProps, Theme } from "@mui/material"
import { MutableRefObject } from "react"
import * as THREE from "three"

interface TransformGizmoControlProps {
defaultMesh?: THREE.Mesh,
gizmoRef?: MutableRefObject<GizmoSceneObject | undefined>,
size: number,
parent?: MirabufSceneObject,
defaultMode: GizmoMode,
translateDisabled?: boolean,
rotateDisabled?: boolean,
scaleDisabled?: boolean,
sx?: SxProps<Theme>,
postGizmoCreation?: (gizmo: GizmoSceneObject) => void;
defaultMesh?: THREE.Mesh
gizmoRef?: MutableRefObject<GizmoSceneObject | undefined>
size: number
parent?: MirabufSceneObject
defaultMode: GizmoMode
translateDisabled?: boolean
rotateDisabled?: boolean
scaleDisabled?: boolean
sx?: SxProps<Theme>
postGizmoCreation?: (gizmo: GizmoSceneObject) => void
}

export default TransformGizmoControlProps;
export default TransformGizmoControlProps
5 changes: 4 additions & 1 deletion fission/src/ui/modals/mirabuf/ImportLocalMirabufModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ const ImportLocalMirabufModal: React.FC<ModalPropsImpl> = ({ modalId }) => {

Global_OpenPanel?.("initial-config")
}
}).finally(() => setTimeout(() => World.PhysicsSystem.ReleasePause(PAUSE_REF_ASSEMBLY_SPAWNING), 500))
})
.finally(() =>
setTimeout(() => World.PhysicsSystem.ReleasePause(PAUSE_REF_ASSEMBLY_SPAWNING), 500)
)
}
}}
>
Expand Down
Loading

0 comments on commit b10ccc7

Please sign in to comment.