name and schema chmage for assembly to manufacturer

This commit is contained in:
2025-08-23 10:24:21 +05:30
parent c86509e812
commit 69329dba7a
23 changed files with 327 additions and 353 deletions

View File

@@ -271,7 +271,7 @@ function AssetsGroup({ plane }: { readonly plane: RefMesh }) {
actionName: "Action 1",
actionType: "worker",
loadCount: 1,
assemblyCount: 1,
manufactureCount: 1,
loadCapacity: 1,
processTime: 10,
triggers: []

View File

@@ -389,7 +389,7 @@ async function handleModelLoad(
actionName: "Action 1",
actionType: "worker",
loadCount: 1,
assemblyCount: 1,
manufactureCount: 1,
loadCapacity: 1,
processTime: 10,
triggers: []

View File

@@ -1,13 +1,5 @@
import { useMemo } from "react";
import {
Shape,
Vector2,
DoubleSide,
TextureLoader,
RepeatWrapping,
SRGBColorSpace,
NoColorSpace,
} from "three";
import { Shape, Vector2, DoubleSide, TextureLoader, RepeatWrapping, SRGBColorSpace, NoColorSpace, } from "three";
import { useLoader } from "@react-three/fiber";
import { Extrude } from "@react-three/drei";
import useModuleStore from "../../../../../store/useModuleStore";
@@ -36,212 +28,207 @@ import material4MetalicMap from "../../../../../assets/textures/floor/tex3/metal
import material4NormalMap from "../../../../../assets/textures/floor/tex3/metal_plate_nor_gl_1k.png";
function FloorInstance({ floor }: { floor: Floor }) {
const { togglView } = useToggleView();
const { activeModule } = useModuleStore();
const { selectedFloor, setSelectedFloor, setSelectedDecal } =
useBuilderStore();
const savedTheme = localStorage.getItem("theme");
const { togglView } = useToggleView();
const { activeModule } = useModuleStore();
const { selectedFloor, setSelectedFloor, setSelectedDecal } =
useBuilderStore();
const savedTheme = localStorage.getItem("theme");
const materials: Record<
string,
{
map: string;
roughnessMap?: string;
metalnessMap?: string;
normalMap?: string;
textureTileScale?: [number, number];
const materials: Record<
string,
{
map: string;
roughnessMap?: string;
metalnessMap?: string;
normalMap?: string;
textureTileScale?: [number, number];
}
> = {
"Default Material": {
map: savedTheme === "dark" ? texturePathDark : texturePath,
},
"Material 1": {
map: material1,
},
"Material 2": {
map: material2Map,
roughnessMap: material2MetalicRoughnessMap,
metalnessMap: material2MetalicRoughnessMap,
normalMap: material2NormalMap,
textureTileScale: [0.1, 0.1],
},
"Material 3": {
map: material3Map,
roughnessMap: material3MetalicRoughnessMap,
metalnessMap: material3MetalicRoughnessMap,
normalMap: material3NormalMap,
textureTileScale: [0.35, 0.5],
},
"Material 4": {
map: material4Map,
roughnessMap: material4RoughnessMap,
metalnessMap: material4MetalicMap,
normalMap: material4NormalMap,
},
};
const shape = useMemo(() => {
const shape = new Shape();
const points = floor.points.map(
(p) => new Vector2(p.position[0], p.position[2])
);
if (points.length < 3) return null;
shape.moveTo(points[0].x, points[0].y);
for (let i = 1; i < points.length; i++) {
shape.lineTo(points[i].x, points[i].y);
}
return shape;
}, [floor]);
const textureScale = Constants.floorConfig.textureScale;
// Helper function to handle texture maps and filter out null values
function getMaterialMaps(material: any, defaultMap: any) {
const materialMap = material.map || defaultMap;
const normalMap = material.normalMap || null;
const roughnessMap = material.roughnessMap || null;
const metalnessMap = material.metalnessMap || null;
return [materialMap, normalMap, roughnessMap, metalnessMap].filter(
(texture): texture is string => texture !== null
);
}
> = {
"Default Material": {
map: savedTheme === "dark" ? texturePathDark : texturePath,
},
"Material 1": {
map: material1,
},
"Material 2": {
map: material2Map,
roughnessMap: material2MetalicRoughnessMap,
metalnessMap: material2MetalicRoughnessMap,
normalMap: material2NormalMap,
textureTileScale: [0.1, 0.1],
},
"Material 3": {
map: material3Map,
roughnessMap: material3MetalicRoughnessMap,
metalnessMap: material3MetalicRoughnessMap,
normalMap: material3NormalMap,
textureTileScale: [0.35, 0.5],
},
"Material 4": {
map: material4Map,
roughnessMap: material4RoughnessMap,
metalnessMap: material4MetalicMap,
normalMap: material4NormalMap,
},
};
const shape = useMemo(() => {
const shape = new Shape();
const points = floor.points.map(
(p) => new Vector2(p.position[0], p.position[2])
);
if (points.length < 3) return null;
shape.moveTo(points[0].x, points[0].y);
for (let i = 1; i < points.length; i++) {
shape.lineTo(points[i].x, points[i].y);
}
return shape;
}, [floor]);
// Default material map
const defaultMaterialMap = materials["Default Material"].map;
const textureScale = Constants.floorConfig.textureScale;
// Get top and side material maps
const topMaterial = materials[floor.topMaterial];
const sideMaterial = materials[floor.sideMaterial];
// Helper function to handle texture maps and filter out null values
function getMaterialMaps(material: any, defaultMap: any) {
const materialMap = material.map || defaultMap;
const normalMap = material.normalMap || null;
const roughnessMap = material.roughnessMap || null;
const metalnessMap = material.metalnessMap || null;
// Get the filtered lists for top and side textures
const topTexturesList = getMaterialMaps(topMaterial, defaultMaterialMap);
const sideTexturesList = getMaterialMaps(sideMaterial, defaultMaterialMap);
return [materialMap, normalMap, roughnessMap, metalnessMap].filter(
(texture): texture is string => texture !== null
);
}
// Use loader to load top and side textures
const [topTexture, topNormalTexture, topRoughnessTexture, topMetalicTexture] = useLoader(TextureLoader, topTexturesList);
// Default material map
const defaultMaterialMap = materials["Default Material"].map;
// Get top and side material maps
const topMaterial = materials[floor.topMaterial];
const sideMaterial = materials[floor.sideMaterial];
// Get the filtered lists for top and side textures
const topTexturesList = getMaterialMaps(topMaterial, defaultMaterialMap);
const sideTexturesList = getMaterialMaps(sideMaterial, defaultMaterialMap);
// Use loader to load top and side textures
const [topTexture, topNormalTexture, topRoughnessTexture, topMetalicTexture] =
useLoader(TextureLoader, topTexturesList);
const [
sideTexture,
sideNormalTexture,
sideRoughnessTexture,
sideMetalicTexture,
] = useLoader(TextureLoader, sideTexturesList);
// Early exit if materials are missing
if (!materials[floor.topMaterial] || !materials[floor.sideMaterial])
return null;
// Combine and pair textures with their corresponding material
const textureMaterialMap = [
{
textures: [
topTexture,
topNormalTexture,
topRoughnessTexture,
topMetalicTexture,
],
materialKey: floor.topMaterial,
},
{
textures: [
const [
sideTexture,
sideNormalTexture,
sideRoughnessTexture,
sideMetalicTexture,
],
materialKey: floor.sideMaterial,
},
];
] = useLoader(TextureLoader, sideTexturesList);
// Apply texture settings
textureMaterialMap.forEach(({ textures, materialKey }) => {
const tileScale = materials[materialKey]?.textureTileScale ?? [
textureScale,
textureScale,
// Early exit if materials are missing
if (!materials[floor.topMaterial] || !materials[floor.sideMaterial])
return null;
// Combine and pair textures with their corresponding material
const textureMaterialMap = [
{
textures: [
topTexture,
topNormalTexture,
topRoughnessTexture,
topMetalicTexture,
],
materialKey: floor.topMaterial,
},
{
textures: [
sideTexture,
sideNormalTexture,
sideRoughnessTexture,
sideMetalicTexture,
],
materialKey: floor.sideMaterial,
},
];
textures.forEach((tex, idx) => {
if (!tex) return;
tex.wrapS = tex.wrapT = RepeatWrapping;
tex.repeat.set(tileScale[0], tileScale[1]);
tex.anisotropy = 16;
// First texture is always the color map (use SRGB), others should be linear
tex.colorSpace = idx < 1 ? SRGBColorSpace : NoColorSpace;
// Apply texture settings
textureMaterialMap.forEach(({ textures, materialKey }) => {
const tileScale = materials[materialKey]?.textureTileScale ?? [
textureScale,
textureScale,
];
textures.forEach((tex, idx) => {
if (!tex) return;
tex.wrapS = tex.wrapT = RepeatWrapping;
tex.repeat.set(tileScale[0], tileScale[1]);
tex.anisotropy = 16;
// First texture is always the color map (use SRGB), others should be linear
tex.colorSpace = idx < 1 ? SRGBColorSpace : NoColorSpace;
});
});
});
if (!shape) return null;
if (!shape) return null;
return (
<mesh
castShadow
receiveShadow
name={`Floor-${floor.floorUuid}`}
rotation={[Math.PI / 2, 0, 0]}
position={[
0,
!floor.isBeveled ? floor.floorDepth - 0.1 : floor.floorDepth - 0.2,
0,
]}
userData={floor}
onDoubleClick={(e) => {
if (!togglView && activeModule === "builder") {
if (e.object.userData.floorUuid) {
e.stopPropagation();
setSelectedFloor(e.object);
setSelectedDecal(null);
}
}
}}
onPointerMissed={() => {
if (
selectedFloor &&
selectedFloor.userData.floorUuid === floor.floorUuid
) {
setSelectedFloor(null);
}
}}
>
<Extrude
name={`Floor-${floor.floorUuid}`}
args={[
shape,
{
depth: !floor.isBeveled ? floor.floorDepth : floor.floorDepth - 0.1,
bevelEnabled: floor.isBeveled,
bevelSegments: floor.bevelStrength,
bevelOffset: -0.1,
bevelSize: 0.1,
bevelThickness: 0.1,
},
]}
userData={floor}
>
<meshPhysicalMaterial
attach="material-0"
color={Constants.floorConfig.defaultColor}
map={topTexture}
roughnessMap={topRoughnessTexture}
metalnessMap={topMetalicTexture}
normalMap={topNormalTexture}
roughness={1.5}
metalness={1.0}
side={DoubleSide}
/>
<meshStandardMaterial
attach="material-1"
color={Constants.floorConfig.defaultColor}
map={sideTexture?.clone()}
roughnessMap={sideRoughnessTexture?.clone()}
metalnessMap={sideMetalicTexture?.clone()}
normalMap={sideNormalTexture?.clone()}
side={DoubleSide}
/>
</Extrude>
</mesh>
);
return (
<mesh
castShadow
receiveShadow
name={`Floor-${floor.floorUuid}`}
rotation={[Math.PI / 2, 0, 0]}
position={[0, !floor.isBeveled ? floor.floorDepth - 0.1 : floor.floorDepth - 0.2, 0,]}
userData={floor}
onDoubleClick={(e) => {
if (!togglView && activeModule === "builder") {
if (e.object.userData.floorUuid) {
e.stopPropagation();
setSelectedFloor(e.object);
setSelectedDecal(null);
}
}
}}
onPointerMissed={() => {
if (
selectedFloor &&
selectedFloor.userData.floorUuid === floor.floorUuid
) {
setSelectedFloor(null);
}
}}
>
<Extrude
name={`Floor-${floor.floorUuid}`}
args={[
shape,
{
depth: !floor.isBeveled ? floor.floorDepth : floor.floorDepth - 0.1,
bevelEnabled: floor.isBeveled,
bevelSegments: floor.bevelStrength,
bevelOffset: -0.1,
bevelSize: 0.1,
bevelThickness: 0.1,
},
]}
userData={floor}
>
<meshPhysicalMaterial
attach="material-0"
color={Constants.floorConfig.defaultColor}
map={topTexture}
roughnessMap={topRoughnessTexture}
metalnessMap={topMetalicTexture}
normalMap={topNormalTexture}
roughness={1.5}
metalness={1.0}
side={DoubleSide}
/>
<meshStandardMaterial
attach="material-1"
color={Constants.floorConfig.defaultColor}
map={sideTexture?.clone()}
roughnessMap={sideRoughnessTexture?.clone()}
metalnessMap={sideMetalicTexture?.clone()}
normalMap={sideNormalTexture?.clone()}
side={DoubleSide}
/>
</Extrude>
</mesh>
);
}
export default FloorInstance;

View File

@@ -10,7 +10,7 @@ import { useToggleView, useWallVisibility } from '../../../../../store/builder/s
import { useBuilderStore } from '../../../../../store/builder/useBuilderStore';
import * as Constants from '../../../../../types/world/worldConstants';
// import DecalInstance from '../../../Decal/decalInstance';
import DecalInstance from '../../../Decal/decalInstance';
import defaultMaterial from '../../../../../assets/textures/floor/wall-tex.png';
import material1 from '../../../../../assets/textures/floor/factory wall texture.jpg';
@@ -150,19 +150,6 @@ function Wall({ wall }: { readonly wall: Wall }) {
e.stopPropagation();
setSelectedWall(e.object);
setSelectedDecal(null);
if (wall.decals.length > 0) return;
const decal: Decal = {
decalUuid: THREE.MathUtils.generateUUID(),
decalName: 'Decal',
decalId: 'Default Decal',
decalPosition: [0, 0, wall.wallThickness / 2 + 0.001],
decalRotation: 0,
decalScale: 1,
decalType: { type: 'Wall', wallUuid: wall.wallUuid }
}
addDecal(wall.wallUuid, decal);
}
}
}}
@@ -174,9 +161,9 @@ function Wall({ wall }: { readonly wall: Wall }) {
>
<MeshDiscardMaterial />
{/* {wall.decals.map((decal) => (
{wall.decals.map((decal) => (
<DecalInstance zPosition={wall.wallThickness / 2 + 0.001} visible={visible} key={decal.decalUuid} decal={decal} />
))} */}
))}
</mesh>
</mesh>
);