parent
f8c8c3f5b7
commit
dabd120f10
|
|
@ -1,5 +1,5 @@
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import type { Character, Scene } from "../types";
|
import type { Character } from "../types";
|
||||||
|
|
||||||
export const CharacterView = observer(function ({ character }: { character: Character }) {
|
export const CharacterView = observer(function ({ character }: { character: Character }) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,19 @@ export const ObjectView = observer(function ({ object }: ObjectViewProps) {
|
||||||
const controls = controlsRef.current;
|
const controls = controlsRef.current;
|
||||||
if (!controls)
|
if (!controls)
|
||||||
return;
|
return;
|
||||||
const onDragChanged = (e: { value: boolean }) => state.worldEditor.setIsDragging(e.value);
|
const onDragChanged = (e: { value: boolean }) => {
|
||||||
|
state.worldEditor.setIsDragging(e.value);
|
||||||
|
if (!e.value) {
|
||||||
|
const group = groupRef.current;
|
||||||
|
if (group)
|
||||||
|
state.worldEditor.setObjectTransform(
|
||||||
|
object.id,
|
||||||
|
group.position.toArray(),
|
||||||
|
group.rotation.toArray().slice(0, 3) as R3,
|
||||||
|
group.scale.toArray(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
controls.addEventListener('dragging-changed', onDragChanged);
|
controls.addEventListener('dragging-changed', onDragChanged);
|
||||||
return () => {
|
return () => {
|
||||||
controls.removeEventListener('dragging-changed', onDragChanged);
|
controls.removeEventListener('dragging-changed', onDragChanged);
|
||||||
|
|
@ -53,25 +65,11 @@ export const ObjectView = observer(function ({ object }: ObjectViewProps) {
|
||||||
state.worldEditor.setSelectedObject(object.id, nextSelectionEditMode(selectionMode));
|
state.worldEditor.setSelectedObject(object.id, nextSelectionEditMode(selectionMode));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleObjectChange = () => {
|
|
||||||
const group = groupRef.current;
|
|
||||||
if (!group)
|
|
||||||
return;
|
|
||||||
|
|
||||||
state.worldEditor.setObjectTransform(
|
|
||||||
object.id,
|
|
||||||
group.position.toArray(),
|
|
||||||
group.rotation.toArray().slice(0, 3) as R3, // chop EulerOrder off array
|
|
||||||
group.scale.toArray(),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (<>
|
return (<>
|
||||||
{
|
{
|
||||||
(isSelected && (selectionMode !== undefined) && groupRef.current) &&
|
(isSelected && (selectionMode !== undefined) && groupRef.current) &&
|
||||||
<TransformControls
|
<TransformControls
|
||||||
object={groupRef as RefObject<Group>}
|
object={groupRef as RefObject<Group>}
|
||||||
onChange={handleObjectChange}
|
|
||||||
mode={selectionMode}
|
mode={selectionMode}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { Canvas } from '@react-three/fiber';
|
import { Canvas } from '@react-three/fiber';
|
||||||
|
import { Stats } from '@react-three/drei';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { state } from '../state';
|
import { state } from '../state';
|
||||||
import { GameView } from './GameView';
|
import { GameView } from './GameView';
|
||||||
|
|
@ -16,6 +17,7 @@ export const ThreeView = observer(function () {
|
||||||
// camera={state.world.character.camera}
|
// camera={state.world.character.camera}
|
||||||
onPointerMissed={() => state.worldEditor.resetSelectedObject()}
|
onPointerMissed={() => state.worldEditor.resetSelectedObject()}
|
||||||
>
|
>
|
||||||
|
<Stats />
|
||||||
{isGame ? <GameView /> : <SceneEditorView />}
|
{isGame ? <GameView /> : <SceneEditorView />}
|
||||||
</Canvas>
|
</Canvas>
|
||||||
<div style={{ position: 'absolute', top: 8, right: 8, display: 'flex', gap: 4 }}>
|
<div style={{ position: 'absolute', top: 8, right: 8, display: 'flex', gap: 4 }}>
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ export class GameState {
|
||||||
this.world.data.state = { playing: false };
|
this.world.data.state = { playing: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
public tick(deltaTime: number): void {
|
public tick(_deltaTime: number): void {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue