add initial components and utility functions for simulation and builder modules

This commit is contained in:
2025-03-25 14:00:03 +05:30
parent 61b3c4ee2c
commit 2303682a15
164 changed files with 13967 additions and 52 deletions

View File

@@ -0,0 +1,23 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`;
export const getAssetImages = async (cursor?: string) => {
try {
const response = await fetch(
`${url_Backend_dwinzo}/api/v3/AssetDatas?limit=10${cursor ? `&cursor=${cursor}` : ""}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
if (!response.ok) {
throw new Error("Failed to fetch assets");
}
return await response.json();
} catch (error: any) {
throw new Error(error.message);
}
};

View File

@@ -0,0 +1,25 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`;
export const getAssetModel = async (modelId: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/AssetFile/${modelId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
throw new Error("Failed to fetch model");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const deleteFloorItem = async (organization: string, modeluuid: string, modelname: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/deletefloorItem`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, modeluuid, modelname }),
});
if (!response.ok) {
throw new Error("Failed to delete Floor Item");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,25 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const getFloorItems = async (organization: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/findfloorItems/${organization}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
throw new Error("Failed to get Floor Items");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const setFloorItemApi = async (organization: string, modeluuid: string, modelname: string, position: Object, rotation: Object, modelfileID: string, isLocked: boolean, isVisible: boolean) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/setFloorItems`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, modeluuid, modelname, position, rotation, modelfileID, isLocked, isVisible }),
});
if (!response.ok) {
throw new Error("Failed to set or update Floor Item");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const deleteWallItem = async (organization: string, modeluuid: string, modelname: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/deleteWallItem`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, modeluuid, modelname }),
});
if (!response.ok) {
throw new Error("Failed to delete Wall Item");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,25 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const getWallItems = async (organization: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/findWallItems/${organization}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
throw new Error("Failed to get Wall Items");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,36 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const setWallItem = async (
organization: string,
modeluuid: string,
modelname: string,
type: string,
csgposition: Object,
csgscale: Object,
position: Object,
quaternion: Object,
scale: Object
) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/setWallItems`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, modeluuid, modelname, position, type, csgposition, csgscale, quaternion, scale }),
});
if (!response.ok) {
throw new Error("Failed to set or update Wall Item");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,32 @@
import { setCamera } from './setCameraApi';
import * as THREE from 'three';
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const getCamera = async (organization: string, userId: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/getCamera/${organization}/${userId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
throw new Error("Failed to get Camera position and target");
}
const result = await response.json();
if (result === "user not found") {
return null;
} else {
return result;
}
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const setCamera = async (organization: string, userId: string, position: Object, target: Object, rotation: Object) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/setCamera`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, userId, position, target, rotation }),
});
if (!response.ok) {
throw new Error("Failed to set Camera Position and Target");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,32 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export default async function getActiveUsersData(organization: string) {
const apiUrl = `${url_Backend_dwinzo}/api/v1/activeCameras/${organization}`;
try {
const response = await fetch(apiUrl, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
});
if (!response.ok) {
throw new Error(`Error: ${response.status} - ${response.statusText}`);
}
if (!response.ok) {
throw new Error("Failed to get active cameras ");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,32 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export default async function fetchShareUsers(organization: string) {
const apiUrl = `${url_Backend_dwinzo}/api/v1/findshareUsers?organization=${organization}`;
try {
const response = await fetch(apiUrl, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
});
if (!response.ok) {
throw new Error(`Error: ${response.status} - ${response.statusText}`);
}
if (!response.ok) {
throw new Error("Failed to get users ");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export default async function giveCollabAccess(email: string, isShare: boolean, organization: string) {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/shareUser`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email, isShare, organization }),
});
if (!response.ok) {
throw new Error("Failed to set Camera Position and Target");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,32 @@
import { setEnvironment } from './setEnvironment';
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const findEnvironment = async (organization: string, userId: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/findEnvironments/${organization}/${userId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
throw new Error("Failed to get wall and roof visibility");
}
const result = await response.json();
if (result === "user not found") {
const userpos = setEnvironment(organization, userId, false, false, false);
return userpos;
} else {
return result;
}
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const setEnvironment = async (organization: string, userId: string, wallVisibility: Boolean, roofVisibility: Boolean, shadowVisibility: Boolean) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/setEvironments`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, userId, wallVisibility, roofVisibility, shadowVisibility }),
});
if (!response.ok) {
throw new Error("Failed to set wall and roof visibility");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const deleteLayer = async (organization: string, layer: number) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/deleteLayer`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, layer }),
});
if (!response.ok) {
throw new Error("Failed to delete line");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const deleteLineApi = async (organization: string, line: Object) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/deleteLine`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, line }),
});
if (!response.ok) {
throw new Error("Failed to delete line");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const deletePointApi = async (organization: string, uuid: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/deletePoint`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, uuid }),
});
if (!response.ok) {
throw new Error("Failed to delete point");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,25 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const getLines = async (organization: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/findLines/${organization}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
throw new Error("Failed to get Lines");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const setLine = async (organization: string, layer: number, line: Object, type: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/setLine`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, layer, line, type }),
});
if (!response.ok) {
throw new Error("Failed to set line");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const updatePoint = async (organization: string, position: Object, uuid: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/updatePoint`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, position, uuid }),
});
if (!response.ok) {
throw new Error("Failed to update point");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,48 @@
import React, { useEffect } from "react";
import mqtt from "mqtt";
import { useDrieUIValue } from "../../../store/store";
const MqttEvents = () => {
const { setTouch, setTemperature, setHumidity } = useDrieUIValue();
useEffect(() => {
const client = mqtt.connect("ws://192.168.0.192:1884", {
username: "gabby",
password: "gabby"
});
client.subscribe("touch");
client.subscribe("temperature");
client.subscribe("humidity");
const handleMessage = (topic: string, message: any) => {
const value = message.toString();
if (topic === "touch") {
setTouch(value);
} else if (topic === "temperature") {
setTemperature(parseFloat(value));
} else if (topic === "humidity") {
setHumidity(parseFloat(value));
}
};
client.on("message", handleMessage);
client.on("error", (err) => {
console.error("MQTT Connection Error:", err);
});
client.on("close", () => {
console.log("MQTT Connection Closed");
});
return () => {
client.end();
};
}, [setTouch, setTemperature, setHumidity]);
return null;
};
export default MqttEvents;

View File

@@ -0,0 +1,22 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const signIn = async (email: string, password: Object, organization: Object) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/login`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email, password, organization }),
});
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
return { error: error.message };
} else {
return { error: "An unknown error occurred" };
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const signUp = async (userName: string, email: string, password: Object, organization: Object) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/signup`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ userName, email, password, organization }),
});
if (!response.ok) {
throw new Error("Failed to signUp");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,51 @@
import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
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);
onmessage = (event) => {
const { floorItems, cameraPosition, uuids, renderDistance } = event.data;
if (!floorItems) return
const toAdd = [];
const toRemove = [];
const cameraPos = new THREE.Vector3(cameraPosition.x, cameraPosition.y, cameraPosition.z);
// Check for items to be added
floorItems.forEach((item) => {
const itemPosition = new THREE.Vector3(...item.position);
const distance = cameraPos.distanceTo(itemPosition);
if (distance <= renderDistance && !uuids.includes(item.modeluuid)) {
toAdd.push(item);
}
});
// Sort the toAdd array based on distance (closest first)
toAdd.sort((a, b) => {
const aDistance = cameraPos.distanceTo(new THREE.Vector3(...a.position));
const bDistance = cameraPos.distanceTo(new THREE.Vector3(...b.position));
return aDistance - bDistance;
});
// Check for items to be removed
uuids.forEach((uuid) => {
const floorItem = floorItems.find((item) => item.modeluuid === uuid);
if (floorItem) {
const itemPosition = new THREE.Vector3(...floorItem.position);
const distance = cameraPos.distanceTo(itemPosition);
if (distance > renderDistance) {
toRemove.push(uuid);
}
}
});
// Send the result back to the main thread
postMessage({ toAdd, toRemove });
};

View File

@@ -0,0 +1,38 @@
import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
import { retrieveGLTF, storeGLTF } from '../../../components/scene/indexDB/idbUtils';
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);
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`;
onmessage = async (event) => {
const { floorItems } = event.data;
const uniqueItems = floorItems.filter((item, index, self) =>
index === self.findIndex((t) => t.modelfileID === item.modelfileID)
);
for (const item of uniqueItems) {
const modelID = item.modelfileID;
const indexedDBModel = await retrieveGLTF(modelID);
let modelBlob;
if (indexedDBModel) {
modelBlob = indexedDBModel;
const message = "gltfLoaded";
postMessage({ message, modelID, modelBlob });
} else {
const modelUrl = `${url_Backend_dwinzo}/api/v1/AssetFile/${modelID}`;
const modelBlob = await fetch(modelUrl).then((res) => res.blob());
await storeGLTF(modelID, modelBlob);
const message = "gltfLoaded";
postMessage({ message, modelID, modelBlob });
}
}
postMessage({ message: 'done' })
};

View File

@@ -0,0 +1,11 @@
import * as THREE from 'three';
onmessage = (event) => {
const { controlsTarget, sunPosition, offsetDistance } = event.data;
const lightPosition = new THREE.Vector3()
.copy(controlsTarget)
.addScaledVector(new THREE.Vector3().copy(sunPosition).normalize(), offsetDistance);
postMessage({ lightPosition, controlsTarget });
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const deleteZonesApi = async (userId: string, organization: string, zoneId: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/setLine`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ userId, organization, zoneId }),
});
if (!response.ok) {
throw new Error("Failed to delete zone");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,25 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const getZonesApi = async (organization: string) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v2/findZones/${organization}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
// if (!response.ok) {
// throw new Error("Failed to get Zones");
// }
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@@ -0,0 +1,26 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
export const setZonesApi = async (userId: string, organization: string, zoneData: any) => {
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v1/setLine`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ userId, organization, zoneData }),
});
if (!response.ok) {
throw new Error("Failed to set zone");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};