feat: Integrate upsertProductOrEventApi in Simulations and Products components; adjust loadInitialFloorItems to accept renderDistance parameter; update material handling in addAssetModel and Vehicles components

This commit is contained in:
Jerald-Golden-B 2025-04-25 18:29:01 +05:30
parent d7a22f5bfb
commit 81b353307b
10 changed files with 34 additions and 24 deletions
app/src
components/layout/sidebarRight/simulation
modules
builder
simulation
services/simulation
types

View File

@ -12,6 +12,7 @@ import { useProductStore } from "../../../../store/simulation/useProductStore";
import { generateUUID } from "three/src/math/MathUtils"; import { generateUUID } from "three/src/math/MathUtils";
import RenderOverlay from "../../../templates/Overlay"; import RenderOverlay from "../../../templates/Overlay";
import EditWidgetOption from "../../../ui/menu/EditWidgetOption"; import EditWidgetOption from "../../../ui/menu/EditWidgetOption";
import { upsertProductOrEventApi } from "../../../../services/simulation/UpsertProductOrEventApi";
interface Event { interface Event {
pathName: string; pathName: string;
@ -75,6 +76,11 @@ const Simulations: React.FC = () => {
const handleAddEventToProduct = () => { const handleAddEventToProduct = () => {
if (selectedAsset) { if (selectedAsset) {
addEvent(selectedProduct.productId, selectedAsset); addEvent(selectedProduct.productId, selectedAsset);
// upsertProductOrEventApi({
// productName: selectedProduct.productName,
// productId: selectedProduct.productId,
// eventDatas: selectedAsset
// });
clearSelectedAsset(); clearSelectedAsset();
} }
}; };

View File

@ -14,6 +14,7 @@ async function loadInitialFloorItems(
itemsGroup: Types.RefGroup, itemsGroup: Types.RefGroup,
setFloorItems: Types.setFloorItemSetState, setFloorItems: Types.setFloorItemSetState,
addEvent: (event: EventsSchema) => void, addEvent: (event: EventsSchema) => void,
renderDistance: number
): Promise<void> { ): Promise<void> {
if (!itemsGroup.current) return; if (!itemsGroup.current) return;
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`; let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`;
@ -65,7 +66,7 @@ async function loadInitialFloorItems(
const cameraPosition = new THREE.Vector3(storedPosition.x, storedPosition.y, storedPosition.z); const cameraPosition = new THREE.Vector3(storedPosition.x, storedPosition.y, storedPosition.z);
if (cameraPosition.distanceTo(itemPosition) < 50) { if (cameraPosition.distanceTo(itemPosition) < renderDistance) {
await new Promise<void>(async (resolve) => { await new Promise<void>(async (resolve) => {
// Check Three.js Cache // Check Three.js Cache
@ -210,7 +211,6 @@ function processLoadedModel(
actionUuid: THREE.MathUtils.generateUUID(), actionUuid: THREE.MathUtils.generateUUID(),
actionName: "Vehicle Action", actionName: "Vehicle Action",
actionType: "travel", actionType: "travel",
material: null,
unLoadDuration: 5, unLoadDuration: 5,
loadCapacity: 10, loadCapacity: 10,
pickUpPoint: null, pickUpPoint: null,

View File

@ -202,7 +202,7 @@ async function handleModelLoad(
actionUuid: THREE.MathUtils.generateUUID(), actionUuid: THREE.MathUtils.generateUUID(),
actionName: `Action ${index}`, actionName: `Action ${index}`,
actionType: 'default', actionType: 'default',
material: 'inherit', material: 'Default Material',
delay: 0, delay: 0,
spawnInterval: 5, spawnInterval: 5,
spawnCount: 1, spawnCount: 1,
@ -226,9 +226,8 @@ async function handleModelLoad(
rotation: [0, 0, 0], rotation: [0, 0, 0],
action: { action: {
actionUuid: THREE.MathUtils.generateUUID(), actionUuid: THREE.MathUtils.generateUUID(),
actionName: "Vehicle Action", actionName: "Action 1",
actionType: "travel", actionType: "travel",
material: null,
unLoadDuration: 5, unLoadDuration: 5,
loadCapacity: 10, loadCapacity: 10,
pickUpPoint: null, pickUpPoint: null,
@ -254,11 +253,11 @@ async function handleModelLoad(
actions: [ actions: [
{ {
actionUuid: THREE.MathUtils.generateUUID(), actionUuid: THREE.MathUtils.generateUUID(),
actionName: "Pick and Place", actionName: "Action 1",
actionType: "pickAndPlace", actionType: "pickAndPlace",
process: { process: {
startPoint: [0, 0, 0], startPoint: null,
endPoint: [0, 0, 0] endPoint: null
}, },
triggers: [] triggers: []
} }
@ -280,10 +279,10 @@ async function handleModelLoad(
rotation: [0, 0, 0], rotation: [0, 0, 0],
action: { action: {
actionUuid: THREE.MathUtils.generateUUID(), actionUuid: THREE.MathUtils.generateUUID(),
actionName: "Process Action", actionName: "Action 1",
actionType: "process", actionType: "process",
processTime: 10, processTime: 10,
swapMaterial: "material-id", swapMaterial: "Default Material",
triggers: [] triggers: []
} }
} }

View File

@ -75,7 +75,7 @@ const FloorItemsGroup = ({ itemsGroup, hoveredDeletableFloorItem, AttachedObject
gltfLoaderWorker.postMessage({ floorItems: data }); gltfLoaderWorker.postMessage({ floorItems: data });
} else { } else {
gltfLoaderWorker.postMessage({ floorItems: [] }); gltfLoaderWorker.postMessage({ floorItems: [] });
loadInitialFloorItems(itemsGroup, setFloorItems, addEvent); loadInitialFloorItems(itemsGroup, setFloorItems, addEvent, renderDistance);
updateLoadingProgress(100); updateLoadingProgress(100);
} }
}); });
@ -94,7 +94,7 @@ const FloorItemsGroup = ({ itemsGroup, hoveredDeletableFloorItem, AttachedObject
updateLoadingProgress(progress); updateLoadingProgress(progress);
if (loadedAssets === totalAssets) { if (loadedAssets === totalAssets) {
loadInitialFloorItems(itemsGroup, setFloorItems, addEvent); loadInitialFloorItems(itemsGroup, setFloorItems, addEvent, renderDistance);
updateLoadingProgress(100); updateLoadingProgress(100);
} }
}); });

View File

@ -2,6 +2,8 @@ import React, { useEffect } from 'react'
import { useProductStore } from '../../../store/simulation/useProductStore' import { useProductStore } from '../../../store/simulation/useProductStore'
import * as THREE from 'three'; import * as THREE from 'three';
import { useSelectedProduct } from '../../../store/simulation/useSimulationStore'; import { useSelectedProduct } from '../../../store/simulation/useSimulationStore';
import { upsertProductOrEventApi } from '../../../services/simulation/UpsertProductOrEventApi';
import { getAllProductsApi } from '../../../services/simulation/getallProductsApi';
function Products() { function Products() {
const { products, addProduct } = useProductStore(); const { products, addProduct } = useProductStore();
@ -12,10 +14,22 @@ function Products() {
const id = THREE.MathUtils.generateUUID(); const id = THREE.MathUtils.generateUUID();
const name = 'Product 1'; const name = 'Product 1';
addProduct(name, id); addProduct(name, id);
// upsertProductOrEventApi({ productName: name, productId: id }).then((data) => {
// console.log('data: ', data);
// });
setSelectedProduct(id, name); setSelectedProduct(id, name);
} }
}, [products]) }, [products])
useEffect(() => {
// const email = localStorage.getItem('email')
// const organization = (email!.split("@")[1]).split(".")[0];
// console.log(organization);
// getAllProductsApi(organization).then((data) => {
// console.log('data: ', data);
// })
}, [])
return ( return (
<> <>
</> </>

View File

@ -5,7 +5,6 @@ import { useArmBotStore } from '../../../../store/simulation/useArmBotStore';
function RoboticArmInstances() { function RoboticArmInstances() {
const { armBots } = useArmBotStore(); const { armBots } = useArmBotStore();
return ( return (
<> <>

View File

@ -3,15 +3,11 @@ import RoboticArmInstances from "./instances/roboticArmInstances";
import { useArmBotStore } from "../../../store/simulation/useArmBotStore"; import { useArmBotStore } from "../../../store/simulation/useArmBotStore";
function RoboticArm() { function RoboticArm() {
const { armBots, addArmBot, addCurrentAction } = useArmBotStore(); const { armBots, addArmBot, removeArmBot, addCurrentAction } = useArmBotStore();
const armBotStatusSample: RoboticArmEventSchema[] = [ const armBotStatusSample: RoboticArmEventSchema[] = [
{ {
state: "idle", state: "idle",
// currentAction: {
// actionUuid: "action-001",
// actionName: "Pick Component",
// },
modelUuid: "armbot-xyz-001", modelUuid: "armbot-xyz-001",
modelName: "ArmBot-X200", modelName: "ArmBot-X200",
position: [0, 0, 0], position: [0, 0, 0],
@ -80,6 +76,7 @@ function RoboticArm() {
]; ];
useEffect(() => { useEffect(() => {
removeArmBot(armBotStatusSample[0].modelUuid);
addArmBot('123', armBotStatusSample[0]); addArmBot('123', armBotStatusSample[0]);
// addCurrentAction('armbot-xyz-001', 'action-001'); // addCurrentAction('armbot-xyz-001', 'action-001');
}, []); }, []);
@ -94,8 +91,6 @@ function RoboticArm() {
<RoboticArmInstances /> <RoboticArmInstances />
<></>
</> </>
); );
} }

View File

@ -24,7 +24,6 @@ function Vehicles() {
actionUuid: "action-456", actionUuid: "action-456",
actionName: "Deliver to Zone A", actionName: "Deliver to Zone A",
actionType: "travel", actionType: "travel",
material: "crate",
unLoadDuration: 15, unLoadDuration: 15,
loadCapacity: 5, loadCapacity: 5,
pickUpPoint: { x: 5, y: 0, z: 3 }, pickUpPoint: { x: 5, y: 0, z: 3 },
@ -68,7 +67,6 @@ function Vehicles() {
actionUuid: "action-456", actionUuid: "action-456",
actionName: "Deliver to Zone A", actionName: "Deliver to Zone A",
actionType: "travel", actionType: "travel",
material: "crate",
unLoadDuration: 15, unLoadDuration: 15,
loadCapacity: 5, loadCapacity: 5,
pickUpPoint: { x: 5, y: 0, z: 3 }, pickUpPoint: { x: 5, y: 0, z: 3 },

View File

@ -1,6 +1,6 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const addProductOrEventApi = async (body: any) => { export const upsertProductOrEventApi = async (body: any) => {
try { try {
const response = await fetch(`${url_Backend_dwinzo}/api/v2/UpsertProductOrEvent`, { const response = await fetch(`${url_Backend_dwinzo}/api/v2/UpsertProductOrEvent`, {
method: "POST", method: "POST",

View File

@ -42,7 +42,6 @@ interface VehiclePointSchema {
actionUuid: string; actionUuid: string;
actionName: string; actionName: string;
actionType: "travel"; actionType: "travel";
material: string | null;
unLoadDuration: number; unLoadDuration: number;
loadCapacity: number; loadCapacity: number;
pickUpPoint: { x: number; y: number, z: number } | null; pickUpPoint: { x: number; y: number, z: number } | null;