fix: Update ZoneData interface and streamline loader function calls in loadInitialFloorItems

This commit is contained in:
Jerald-Golden-B 2025-04-09 10:59:43 +05:30
parent 937241d28b
commit d4e0358f4b
2 changed files with 23 additions and 29 deletions
app/src
components/ui/list
modules/scene/IntialLoad

View File

@ -52,7 +52,7 @@ const DropDownList: React.FC<DropDownListProps> = ({
interface ZoneData { interface ZoneData {
id: string; id: string;
name: string; name: string;
assets: { id: string; name: string; position?: [] ;rotation?:{}}[]; assets: { id: string; name: string; position?: []; rotation?: {} }[];
} }
const [zoneDataList, setZoneDataList] = useState<ZoneData[]>([]); const [zoneDataList, setZoneDataList] = useState<ZoneData[]>([]);
const { floorItems, setFloorItems } = useFloorItems(); const { floorItems, setFloorItems } = useFloorItems();
@ -70,6 +70,7 @@ const DropDownList: React.FC<DropDownListProps> = ({
} }
return inside; return inside;
}; };
useEffect(() => { useEffect(() => {
const updatedZoneList: ZoneData[] = zones.map((zone: Zone) => { const updatedZoneList: ZoneData[] = zones.map((zone: Zone) => {
@ -84,7 +85,7 @@ const DropDownList: React.FC<DropDownListProps> = ({
id: item.modeluuid, id: item.modeluuid,
name: item.modelname, name: item.modelname,
position: item.position, position: item.position,
rotation:item.rotation rotation: item.rotation
})); }));
return { return {
@ -96,9 +97,6 @@ const DropDownList: React.FC<DropDownListProps> = ({
setZoneDataList(updatedZoneList); setZoneDataList(updatedZoneList);
}, [zones, floorItems]); }, [zones, floorItems]);
return ( return (
<div className="dropdown-list-container"> <div className="dropdown-list-container">
<div className="head"> <div className="head">

View File

@ -12,7 +12,7 @@ import { getFloorAssets } from '../../../services/factoryBuilder/assest/floorAss
async function loadInitialFloorItems( async function loadInitialFloorItems(
itemsGroup: Types.RefGroup, itemsGroup: Types.RefGroup,
setFloorItems: Types.setFloorItemSetState, setFloorItems: Types.setFloorItemSetState,
setSimulationStates: (paths: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema | Types.StaticMachineEventsSchema)[]) => void setSimulationStates: (paths: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema | Types.StaticMachineEventsSchema | Types.ArmBotEventsSchema)[]) => void
): 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}`;
@ -82,16 +82,14 @@ async function loadInitialFloorItems(
if (indexedDBModel) { if (indexedDBModel) {
// console.log(`[IndexedDB] Fetching ${item.modelname}`); // console.log(`[IndexedDB] Fetching ${item.modelname}`);
const blobUrl = URL.createObjectURL(indexedDBModel); const blobUrl = URL.createObjectURL(indexedDBModel);
loader.load( loader.load(blobUrl, (gltf) => {
blobUrl, URL.revokeObjectURL(blobUrl);
(gltf) => { THREE.Cache.remove(blobUrl);
URL.revokeObjectURL(blobUrl); THREE.Cache.add(item.modelfileID!, gltf);
THREE.Cache.remove(blobUrl); processLoadedModel(gltf.scene.clone(), item, itemsGroup, setFloorItems, setSimulationStates);
THREE.Cache.add(item.modelfileID!, gltf); modelsLoaded++;
processLoadedModel(gltf.scene.clone(), item, itemsGroup, setFloorItems, setSimulationStates); checkLoadingCompletion(modelsLoaded, modelsToLoad, dracoLoader, resolve);
modelsLoaded++; },
checkLoadingCompletion(modelsLoaded, modelsToLoad, dracoLoader, resolve);
},
undefined, undefined,
(error) => { (error) => {
toast.error(`[IndexedDB] Error loading ${item.modelname}:`); toast.error(`[IndexedDB] Error loading ${item.modelname}:`);
@ -105,16 +103,14 @@ async function loadInitialFloorItems(
// Fetch from Backend // Fetch from Backend
// console.log(`[Backend] Fetching ${item.modelname}`); // console.log(`[Backend] Fetching ${item.modelname}`);
const modelUrl = `${url_Backend_dwinzo}/api/v1/AssetFile/${item.modelfileID!}`; const modelUrl = `${url_Backend_dwinzo}/api/v1/AssetFile/${item.modelfileID!}`;
loader.load( loader.load(modelUrl, async (gltf) => {
modelUrl, const modelBlob = await fetch(modelUrl).then((res) => res.blob());
async (gltf) => { await storeGLTF(item.modelfileID!, modelBlob);
const modelBlob = await fetch(modelUrl).then((res) => res.blob()); THREE.Cache.add(item.modelfileID!, gltf);
await storeGLTF(item.modelfileID!, modelBlob); processLoadedModel(gltf.scene.clone(), item, itemsGroup, setFloorItems, setSimulationStates);
THREE.Cache.add(item.modelfileID!, gltf); modelsLoaded++;
processLoadedModel(gltf.scene.clone(), item, itemsGroup, setFloorItems, setSimulationStates); checkLoadingCompletion(modelsLoaded, modelsToLoad, dracoLoader, resolve);
modelsLoaded++; },
checkLoadingCompletion(modelsLoaded, modelsToLoad, dracoLoader, resolve);
},
undefined, undefined,
(error) => { (error) => {
toast.error(`[Backend] Error loading ${item.modelname}:`); toast.error(`[Backend] Error loading ${item.modelname}:`);
@ -137,7 +133,7 @@ async function loadInitialFloorItems(
}, },
]); ]);
if (item.eventData || item.modelfileID === '67e3db95c2e8f37134526fb2') { if (item.eventData) {
processEventData(item, setSimulationStates); processEventData(item, setSimulationStates);
} }
@ -157,7 +153,7 @@ function processLoadedModel(
item: Types.EventData, item: Types.EventData,
itemsGroup: Types.RefGroup, itemsGroup: Types.RefGroup,
setFloorItems: Types.setFloorItemSetState, setFloorItems: Types.setFloorItemSetState,
setSimulationStates: (paths: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema | Types.StaticMachineEventsSchema)[]) => void setSimulationStates: (paths: (Types.ConveyorEventsSchema | Types.VehicleEventsSchema | Types.StaticMachineEventsSchema | Types.ArmBotEventsSchema)[]) => void
) { ) {
const model = gltf; const model = gltf;
model.uuid = item.modeluuid; model.uuid = item.modeluuid;
@ -192,7 +188,7 @@ function processLoadedModel(
}, },
]); ]);
if (item.eventData || item.modelfileID === '67e3db5ac2e8f37134526f40') { if (item.eventData) {
processEventData(item, setSimulationStates); processEventData(item, setSimulationStates);
} }