Refactor AssetProperties and TransformControl to improve object position and rotation handling; streamline socket store structure for better maintainability
This commit is contained in:
parent
3a9c41434d
commit
48fc770b51
|
@ -1,11 +1,10 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import InputToggle from "../../../ui/inputs/InputToggle";
|
import InputToggle from "../../../ui/inputs/InputToggle";
|
||||||
import InputWithDropDown from "../../../ui/inputs/InputWithDropDown";
|
import InputWithDropDown from "../../../ui/inputs/InputWithDropDown";
|
||||||
import { RemoveIcon } from "../../../icons/ExportCommonIcons";
|
import { RemoveIcon } from "../../../icons/ExportCommonIcons";
|
||||||
import PositionInput from "../customInput/PositionInputs";
|
import PositionInput from "../customInput/PositionInputs";
|
||||||
import RotationInput from "../customInput/RotationInput";
|
import RotationInput from "../customInput/RotationInput";
|
||||||
import { useSelectedFloorItem } from "../../../../store/store";
|
import { useSelectedFloorItem, useObjectPosition, useObjectRotation } from "../../../../store/store";
|
||||||
import * as THREE from "three";
|
|
||||||
|
|
||||||
interface UserData {
|
interface UserData {
|
||||||
id: number; // Unique identifier for the user data
|
id: number; // Unique identifier for the user data
|
||||||
|
@ -17,6 +16,8 @@ const AssetProperties: React.FC = () => {
|
||||||
const [userData, setUserData] = useState<UserData[]>([]); // State to track user data
|
const [userData, setUserData] = useState<UserData[]>([]); // State to track user data
|
||||||
const [nextId, setNextId] = useState(1); // Unique ID for new entries
|
const [nextId, setNextId] = useState(1); // Unique ID for new entries
|
||||||
const { selectedFloorItem } = useSelectedFloorItem();
|
const { selectedFloorItem } = useSelectedFloorItem();
|
||||||
|
const { objectPosition } = useObjectPosition();
|
||||||
|
const { objectRotation } = useObjectRotation();
|
||||||
// Function to handle adding new user data
|
// Function to handle adding new user data
|
||||||
const handleAddUserData = () => {
|
const handleAddUserData = () => {
|
||||||
const newUserData: UserData = {
|
const newUserData: UserData = {
|
||||||
|
@ -49,17 +50,19 @@ const AssetProperties: React.FC = () => {
|
||||||
{/* Name */}
|
{/* Name */}
|
||||||
<div className="header">{selectedFloorItem.userData.name}</div>
|
<div className="header">{selectedFloorItem.userData.name}</div>
|
||||||
<section>
|
<section>
|
||||||
|
{objectPosition.x && objectPosition.z &&
|
||||||
<PositionInput
|
<PositionInput
|
||||||
onChange={() => {}}
|
onChange={() => { }}
|
||||||
value1={selectedFloorItem.position.x.toFixed(5)}
|
value1={parseFloat(objectPosition.x.toFixed(5))}
|
||||||
value2={selectedFloorItem.position.z.toFixed(5)}
|
value2={parseFloat(objectPosition.z.toFixed(5))}
|
||||||
/>
|
/>
|
||||||
|
}
|
||||||
|
{objectRotation.y &&
|
||||||
<RotationInput
|
<RotationInput
|
||||||
onChange={() => {}}
|
onChange={() => { }}
|
||||||
value={parseFloat(
|
value={parseFloat(objectRotation.y.toFixed(5))}
|
||||||
THREE.MathUtils.radToDeg(selectedFloorItem.rotation.y).toFixed(5)
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
|
}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
|
|
|
@ -167,6 +167,12 @@ export default function TransformControl() {
|
||||||
|
|
||||||
if (selectedFloorItem) {
|
if (selectedFloorItem) {
|
||||||
window.addEventListener("keydown", handleKeyDown);
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
setObjectPosition(selectedFloorItem.position);
|
||||||
|
setObjectRotation({
|
||||||
|
x: THREE.MathUtils.radToDeg(selectedFloorItem.rotation.x),
|
||||||
|
y: THREE.MathUtils.radToDeg(selectedFloorItem.rotation.y),
|
||||||
|
z: THREE.MathUtils.radToDeg(selectedFloorItem.rotation.z),
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
setTransformMode(null);
|
setTransformMode(null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,11 +297,6 @@ export const useObjectPosition = create<any>((set: any) => ({
|
||||||
set({ objectPosition: newObjectPosition }),
|
set({ objectPosition: newObjectPosition }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const useObjectScale = create<any>((set: any) => ({
|
|
||||||
objectScale: { x: undefined, y: undefined, z: undefined },
|
|
||||||
setObjectScale: (newObjectScale: any) => set({ objectScale: newObjectScale }),
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const useObjectRotation = create<any>((set: any) => ({
|
export const useObjectRotation = create<any>((set: any) => ({
|
||||||
objectRotation: { x: undefined, y: undefined, z: undefined },
|
objectRotation: { x: undefined, y: undefined, z: undefined },
|
||||||
setObjectRotation: (newObjectRotation: any) =>
|
setObjectRotation: (newObjectRotation: any) =>
|
||||||
|
@ -411,6 +406,7 @@ export const usePlayAgv = create<any>((set, get) => ({
|
||||||
setPlayAgv: (updateFn: (prev: any[]) => any[]) =>
|
setPlayAgv: (updateFn: (prev: any[]) => any[]) =>
|
||||||
set({ PlayAgv: updateFn(get().PlayAgv) }),
|
set({ PlayAgv: updateFn(get().PlayAgv) }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Define the Asset type
|
// Define the Asset type
|
||||||
type Asset = {
|
type Asset = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
Loading…
Reference in New Issue