Refactor success notifications to use echo instead of toast; update selection controls and duplication logic
- Changed success notifications from `toast.success` to `echo.success` in copy, duplication, move, rotate, and selection controls. - Updated selection logic in `PostProcessing` to use `flattenChildren` for better performance. - Enhanced `Simulator` component to handle selected product state and execution order more effectively. - Modified `useSelectedItem` state to include `category` and `subCategory` properties for better item classification. - Adjusted `WallItem` interface to standardize type values and added `modelfileID` for improved asset management.
This commit is contained in:
@@ -1,54 +1,102 @@
|
||||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
|
||||
|
||||
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
|
||||
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
|
||||
import * as THREE from 'three';
|
||||
import * as Types from "../../../types/world/worldTypes";
|
||||
import { getWallItems } from '../../../services/factoryBuilder/assest/wallAsset/getWallItemsApi';
|
||||
|
||||
////////// Load the Wall Items's intially of there is any //////////
|
||||
import { retrieveGLTF, storeGLTF } from '../../../utils/indexDB/idbUtils';
|
||||
|
||||
async function loadInitialWallItems(
|
||||
setWallItems: Types.setWallItemSetState,
|
||||
AssetConfigurations: Types.AssetConfigurations
|
||||
): Promise<void> {
|
||||
try {
|
||||
const email = localStorage.getItem('email');
|
||||
if (!email) {
|
||||
throw new Error('No email found in localStorage');
|
||||
}
|
||||
|
||||
const email = localStorage.getItem('email')
|
||||
const organization = (email!.split("@")[1]).split(".")[0];
|
||||
const organization = email.split("@")[1].split(".")[0];
|
||||
const items = await getWallItems(organization);
|
||||
|
||||
const items = await getWallItems(organization);
|
||||
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`;
|
||||
|
||||
localStorage.setItem("WallItems", JSON.stringify(items));
|
||||
if (items.length > 0) {
|
||||
const storedWallItems: Types.wallItems = items;
|
||||
if (!items || items.length === 0) {
|
||||
localStorage.removeItem("WallItems");
|
||||
return;
|
||||
}
|
||||
|
||||
const loadedWallItems = await Promise.all(storedWallItems.map(async (item) => {
|
||||
const loader = new GLTFLoader();
|
||||
localStorage.setItem("WallItems", JSON.stringify(items));
|
||||
|
||||
const loader = new GLTFLoader();
|
||||
const dracoLoader = new DRACOLoader();
|
||||
dracoLoader.setDecoderPath('https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/libs/draco/gltf/');
|
||||
loader.setDRACOLoader(dracoLoader);
|
||||
|
||||
const loadedWallItems = await Promise.all(items.map(async (item: Types.WallItem) => {
|
||||
// Check THREE.js cache first
|
||||
const cachedModel = THREE.Cache.get(item.modelName!);
|
||||
if (cachedModel) {
|
||||
return processModel(cachedModel, item);
|
||||
}
|
||||
|
||||
// Check IndexedDB cache
|
||||
const cachedModelBlob = await retrieveGLTF(item.modelfileID!);
|
||||
if (cachedModelBlob) {
|
||||
const blobUrl = URL.createObjectURL(cachedModelBlob);
|
||||
return new Promise<Types.WallItem>((resolve) => {
|
||||
loader.load(blobUrl, (gltf) => {
|
||||
URL.revokeObjectURL(blobUrl);
|
||||
THREE.Cache.add(item.modelName!, gltf);
|
||||
resolve(processModel(gltf, item));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Load from original URL if not cached
|
||||
const modelUrl = `${url_Backend_dwinzo}/api/v2/AssetFile/${item.modelfileID!}`;
|
||||
return new Promise<Types.WallItem>((resolve) => {
|
||||
loader.load(AssetConfigurations[item.modelName!].modelUrl, (gltf) => {
|
||||
const model = gltf.scene;
|
||||
model.uuid = item.modelUuid!;
|
||||
|
||||
model.children[0].children.forEach((child: any) => {
|
||||
if (child.name !== "CSG_REF") {
|
||||
child.castShadow = true;
|
||||
child.receiveShadow = true;
|
||||
}
|
||||
loader.load(modelUrl, async (gltf) => {
|
||||
try {
|
||||
// Cache the model
|
||||
const modelBlob = await fetch(modelUrl).then((res) => res.blob());
|
||||
await storeGLTF(item.modelName!, modelBlob);
|
||||
THREE.Cache.add(item.modelName!, gltf);
|
||||
resolve(processModel(gltf, item));
|
||||
} catch (error) {
|
||||
console.error('Failed to cache model:', error);
|
||||
resolve(processModel(gltf, item));
|
||||
}
|
||||
});
|
||||
|
||||
resolve({
|
||||
type: item.type,
|
||||
model: model,
|
||||
modelName: item.modelName,
|
||||
scale: item.scale,
|
||||
csgscale: item.csgscale,
|
||||
csgposition: item.csgposition,
|
||||
position: item.position,
|
||||
quaternion: item.quaternion,
|
||||
});
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
setWallItems(loadedWallItems);
|
||||
} catch (error) {
|
||||
console.error('Failed to load wall items:', error);
|
||||
}
|
||||
}
|
||||
|
||||
export default loadInitialWallItems;
|
||||
function processModel(gltf: GLTF, item: Types.WallItem): Types.WallItem {
|
||||
const model = gltf.scene.clone();
|
||||
model.uuid = item.modelUuid!;
|
||||
|
||||
model.children[0]?.children?.forEach((child: THREE.Object3D) => {
|
||||
if (child.name !== "CSG_REF") {
|
||||
child.castShadow = true;
|
||||
child.receiveShadow = true;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
type: item.type,
|
||||
model: model,
|
||||
modelName: item.modelName,
|
||||
modelfileID: item.modelfileID,
|
||||
scale: item.scale,
|
||||
csgscale: item.csgscale,
|
||||
csgposition: item.csgposition,
|
||||
position: item.position,
|
||||
quaternion: item.quaternion,
|
||||
};
|
||||
}
|
||||
|
||||
export default loadInitialWallItems;
|
||||
Reference in New Issue
Block a user