From b20fdb26e9d1d091fd7864de1edcc639e9da01b8 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 16 十月 2024 15:04:14 +0800
Subject: [PATCH] #

---
 zy-acs-flow/package.json                                                              |    3 
 zy-acs-flow/public/model/shelf.fbx                                                    |    0 
 zy-acs-flow/src/map/http.js                                                           |   20 ++
 zy-acs-flow/package-lock.json                                                         |    6 
 zy-acs-flow/src/map/insight/shelf/ShelfThree.js                                       |  345 +++++++++++++++++++++++++++++--------
 zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/MapController.java |   12 +
 zy-acs-flow/src/map/insight/shelf/ShelfMain.jsx                                       |  125 ++++++++++++-
 7 files changed, 416 insertions(+), 95 deletions(-)

diff --git a/zy-acs-flow/package-lock.json b/zy-acs-flow/package-lock.json
index 448342a..4c03f3e 100644
--- a/zy-acs-flow/package-lock.json
+++ b/zy-acs-flow/package-lock.json
@@ -11,6 +11,7 @@
         "@mui/icons-material": "^5.16.7",
         "@mui/material": "^5.16.7",
         "@mui/x-tree-view": "^7.16.0",
+        "@tweenjs/tween.js": "^21.0.0",
         "axios": "^1.7.4",
         "date-fns": "^3.6.0",
         "papaparse": "^5.4.1",
@@ -1957,6 +1958,11 @@
         "react": "^18.0.0"
       }
     },
+    "node_modules/@tweenjs/tween.js": {
+      "version": "21.1.1",
+      "resolved": "https://registry.npmmirror.com/@tweenjs/tween.js/-/tween.js-21.1.1.tgz",
+      "integrity": "sha512-O2GetAwEC/0MOiRb3lxCLIt/eeugoDPX0nu+1SFWLqGKf835ZdWsfM9RzDpjF+aKkpYMhvOnEhO+SxMnHHjpfw=="
+    },
     "node_modules/@types/babel__core": {
       "version": "7.20.5",
       "resolved": "https://registry.npmmirror.com/@types/babel__core/-/babel__core-7.20.5.tgz",
diff --git a/zy-acs-flow/package.json b/zy-acs-flow/package.json
index 512dc52..a65f9a4 100644
--- a/zy-acs-flow/package.json
+++ b/zy-acs-flow/package.json
@@ -26,6 +26,7 @@
     "react-router-dom": "^6.26.1",
     "react-syntax-highlighter": "^15.5.0",
     "three": "^0.155.0",
+    "@tweenjs/tween.js": "^21.0.0",
     "tweedle.js": "^2.1.0"
   },
   "devDependencies": {
@@ -44,4 +45,4 @@
     "vite": "^5.3.5"
   },
   "name": "cool-admin-flow"
-}
+}
\ No newline at end of file
diff --git a/zy-acs-flow/public/model/shelf.fbx b/zy-acs-flow/public/model/shelf.fbx
new file mode 100644
index 0000000..0f7552c
--- /dev/null
+++ b/zy-acs-flow/public/model/shelf.fbx
Binary files differ
diff --git a/zy-acs-flow/src/map/http.js b/zy-acs-flow/src/map/http.js
index c317224..b329a1f 100644
--- a/zy-acs-flow/src/map/http.js
+++ b/zy-acs-flow/src/map/http.js
@@ -107,3 +107,23 @@
         console.error(error.message);
     })
 }
+
+
+export const getLocGroup = async (row, bay, callback) => {
+    await request.post('/map/shelf/group', {
+        row: row,
+        bay: bay
+    }, {
+        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
+    }).then((res) => {
+        const { code, msg, data } = res.data;
+        if (code === 200) {
+            callback(data)
+        } else {
+            notify.error(msg);
+        }
+    }).catch((error) => {
+        notify.error(error.message);
+        console.error(error.message);
+    })
+}
diff --git a/zy-acs-flow/src/map/insight/shelf/ShelfMain.jsx b/zy-acs-flow/src/map/insight/shelf/ShelfMain.jsx
index e05fec1..db4f07b 100644
--- a/zy-acs-flow/src/map/insight/shelf/ShelfMain.jsx
+++ b/zy-acs-flow/src/map/insight/shelf/ShelfMain.jsx
@@ -12,6 +12,82 @@
     Stack,
 } from '@mui/material';
 import ShelfThree from './ShelfThree';
+import request from '@/utils/request';
+import { getLocGroup } from '../../http';
+
+let shelfThree;
+
+const startThree = (dom) => {
+    shelfThree = new ShelfThree(dom);
+    shelfThree.startup();
+}
+
+const endThree = () => {
+    if (shelfThree) {
+        shelfThree.destroy();
+        shelfThree = null;
+    }
+}
+
+const renderThree = (info, curLocNo) => {
+    if (info && shelfThree) {
+        shelfThree.generateMesh((loader, addObject) => {
+            const promises = [];
+            const singleHeight = 123;
+            for (const item of info) {
+                const { lev } = item;
+                promises.push(new Promise((resolve) => {
+                    loader.load('model/shelf.fbx', (mesh) => {
+                        mesh.position.set(0, singleHeight * (lev - 1), 0);
+                        mesh.scale.set(5, 5, 5);
+                        mesh.name = item.locNo;
+                        mesh.traverse(function (child) {
+                            if (child.isMesh) {
+                                if (child.name === '璐ф灦') {
+                                    child.material.color.set(0x4680BF);
+                                }
+                                let palletVisible = true, cargoVisible = true;
+                                switch (item.locStsEl) {
+                                    case 'STOCK':
+                                        cargoVisible = false;
+                                        break;
+                                    case 'IDLE':
+                                        palletVisible = false;
+                                        cargoVisible = false;
+                                        break;
+                                    default:
+                                        break;
+                                }
+                                if (child.name === '鎵樼洏') {
+                                    child.visible = palletVisible;
+                                    child.material.color.set(0xBEBEBE);
+                                }
+                                if (child.name === '涓嶈鍒�') {
+                                    child.visible = cargoVisible;
+                                    child.material.color.set(0xE8B67E);
+                                }
+                                child.name = item.locNo
+                                child.castShadow = true;
+                                child.receiveShadow = true;
+                            }
+                        });
+                        addObject(mesh);
+                        resolve();
+                    })
+                }));
+
+            }
+
+            Promise.all(promises).then(() => {
+                shelfThree.setNewSelectedMesh(curLocNo);
+                shelfThree.rePerspective(singleHeight * info.length, 500);
+            }).catch(error => {
+                console.error(error);
+            });
+
+        })
+    }
+}
 
 const ShelfMain = (props) => {
     const { data, curLocNo, setCurLocNo } = props;
@@ -20,6 +96,38 @@
     const [loading, setLoading] = useState(true);
     const [shelfThree, setShelfThree] = useState(null);
     const [info, setInfo] = useState(null);
+
+
+
+    useEffect(() => {
+        if (data) {
+            getLocGroup(data.row, data.bay, (response) => {
+                setInfo(response);
+                setCurLocNo(response[0]?.locNo);
+            });
+        }
+    }, [data]);
+
+    useEffect(() => {
+        if (info) {
+            endThree();
+            setLoading(true);
+
+            setTimeout(() => {
+                startThree(containerRef.current);
+                shelfThree.handleClick = (objName) => {
+                    setCurLocNo(objName);
+                };
+                renderThree(info, curLocNo);
+                setLoading(false);
+            }, 300)
+
+        }
+
+        return endThree;
+    }, [info]);
+
+
 
     useEffect(() => {
         const initThree = () => {
@@ -31,7 +139,6 @@
             setShelfThree(shelfThreeInstance);
             setLoading(false);
             // Fetch initial data
-            fetchShelfInfo(curLocNo);
         };
 
         initThree();
@@ -43,19 +150,7 @@
         };
     }, []);
 
-    useEffect(() => {
-        if (curLocNo) {
-            fetchShelfInfo(curLocNo);
-        }
-    }, [curLocNo]);
 
-    const fetchShelfInfo = async (locNo) => {
-        // 鍋囪鏈変竴涓嚱鏁版潵鑾峰彇璐ф灦淇℃伅
-        const res = await fetchShelfData(locNo);
-        if (res?.data) {
-            setInfo(res.data);
-        }
-    };
 
     return (
         <Box display="flex" height="500px">
@@ -78,7 +173,7 @@
                 )}
             </Box>
             <Box width="40%" height="100%" overflow="auto" p={2}>
-                <Paper elevation={3} style={{ padding: '16px' }}>
+                {/* <Paper elevation={3} style={{ padding: '16px' }}>
                     <Typography variant="h6" gutterBottom>
                         {translate('map.loc.no', { defaultMessage: '搴撲綅鍙�' })}: {curLocNo}
                     </Typography>
@@ -118,7 +213,7 @@
                             </Stack>
                         </Grid>
                     </Grid>
-                </Paper>
+                </Paper> */}
             </Box>
         </Box>
     );
diff --git a/zy-acs-flow/src/map/insight/shelf/ShelfThree.js b/zy-acs-flow/src/map/insight/shelf/ShelfThree.js
index a77d3c1..1bb5f34 100644
--- a/zy-acs-flow/src/map/insight/shelf/ShelfThree.js
+++ b/zy-acs-flow/src/map/insight/shelf/ShelfThree.js
@@ -1,88 +1,275 @@
-import * as THREE from 'three';
-import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
+import * as THREE from 'three'
+import Stats from 'three/addons/libs/stats.module.js';
+import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
+import TWEEN from '@tweenjs/tween.js';
+import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer';
+import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass';
+import { OutlinePass } from 'three/examples/jsm/postprocessing/OutlinePass';
+import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass';
+import { FXAAShader } from 'three/examples/jsm/shaders/FXAAShader';
+import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader'
+
+const help = false;
 
 export default class ShelfThree {
-    constructor(container) {
-        this.container = container;
-        this.scene = null;
-        this.camera = null;
-        this.renderer = null;
-        this.controls = null;
-        this.animationFrameId = null;
+
+    constructor(dom) {
+        this.dom = dom;
+
+        this.objects = [];
     }
 
-    startup() {
-        this.initScene();
-        this.initCamera();
-        this.initRenderer();
-        this.initControls();
-        this.addLights();
-        this.addObjects();
+    startup = () => {
+        this.scene = this.initScene();
+        this.camera = this.initCamera();
+        this.renderer = this.initRenderer();
+        this.controls = this.initControls();
+        this.stats = this.initStats();
+        this.composer = this.initComposer();
+        this.windowResize();
+        this.initRaycaster();
+        initLight(this.scene);
+
         this.animate();
-        window.addEventListener('resize', this.onWindowResize, false);
-    }
-
-    initScene() {
-        this.scene = new THREE.Scene();
-        this.scene.background = new THREE.Color(0x7a7a7a);
-    }
-
-    initCamera() {
-        const width = this.container.clientWidth;
-        const height = this.container.clientHeight;
-        this.camera = new THREE.PerspectiveCamera(70, width / height, 0.1, 1000);
-        this.camera.position.set(0, 5, 10);
-    }
-
-    initRenderer() {
-        this.renderer = new THREE.WebGLRenderer({ antialias: true });
-        this.renderer.setSize(this.container.clientWidth, this.container.clientHeight);
-        this.container.appendChild(this.renderer.domElement);
-    }
-
-    initControls() {
-        this.controls = new OrbitControls(this.camera, this.renderer.domElement);
-        this.controls.enableDamping = true;
-    }
-
-    addLights() {
-        const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
-        this.scene.add(ambientLight);
-
-        const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
-        directionalLight.position.set(5, 10, 7.5);
-        this.scene.add(directionalLight);
-    }
-
-    addObjects() {
-        // 鍦ㄨ繖閲屾坊鍔犳偍鐨勮揣鏋舵ā鍨嬫垨鍏朵粬瀵硅薄
-        const geometry = new THREE.BoxGeometry(1, 1, 1);
-        const material = new THREE.MeshStandardMaterial({ color: 0x4680BF });
-        const cube = new THREE.Mesh(geometry, material);
-        this.scene.add(cube);
     }
 
     animate = () => {
-        this.animationFrameId = requestAnimationFrame(this.animate);
-        this.controls.update();
-        this.renderer.render(this.scene, this.camera);
-    };
-
-    onWindowResize = () => {
-        const width = this.container.clientWidth;
-        const height = this.container.clientHeight;
-        this.camera.aspect = width / height;
-        this.camera.updateProjectionMatrix();
-        this.renderer.setSize(width, height);
-    };
-
-    destroy() {
-        cancelAnimationFrame(this.animationFrameId);
-        window.removeEventListener('resize', this.onWindowResize);
-        this.controls.dispose();
-        this.renderer.dispose();
-        this.scene = null;
-        this.camera = null;
-        this.renderer.domElement.remove();
+        this.animationFrame = requestAnimationFrame(this.animate);
+        this.render();
+        TWEEN.update();
     }
-}
+
+    render = () => {
+        // this.renderer.render(this.scene, this.camera);
+        this.composer.render(); // use special effects
+        this.stats.update();
+        // Rotate the scene
+        this.controls.update()
+        this.controls.autoRotateSpeed = 2;
+    }
+
+    getFullWidth = () => {
+        return this.dom?.offsetWidth;
+    }
+
+    getFullHeight = () => {
+        return this.dom?.offsetHeight;
+    }
+
+    addObject = (object) => {
+        this.scene.add(object);
+        this.objects.push(object);
+    }
+
+    initScene = () => {
+        const scene = new THREE.Scene();
+        // scene.background = new THREE.Color(0xf8f8f8);
+        scene.background = new THREE.Color(0x7a7a7a);
+        scene.fog = new THREE.Fog(scene.background, 1, 5000);
+        if (help) {
+            scene.add(new THREE.AxesHelper(1000));
+        }
+        return scene;
+    }
+
+    initCamera = () => {
+        const camera = new THREE.PerspectiveCamera(70, this.getFullWidth() / this.getFullHeight(), 1, 60000);
+        camera.position.set(-400, 400, 400);
+        this.scene.add(camera);
+        return camera;
+    }
+
+    initRenderer = () => {
+        const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
+        renderer.setClearAlpha(0);
+        // renderer.useLegacyLights = false;  // 鏃х増鍏夋簮 閲嶈
+        renderer.shadowMap.enabled = true;
+        // this.renderer.shadowMap.type = THREE.BasicShadowMap;    // 鏈�浣庨槾褰�
+        // renderer.toneMapping = THREE.ReinhardToneMapping;
+        renderer.toneMapping = THREE.ACESFilmicToneMapping;
+        renderer.setPixelRatio(window.devicePixelRatio);
+        renderer.setSize(this.getFullWidth(), this.getFullHeight());
+        this.dom?.appendChild(renderer.domElement);
+        return renderer;
+    }
+
+    initComposer = () => {
+        const composer = new EffectComposer(this.renderer);
+        const renderPass = new RenderPass(this.scene, this.camera);
+        composer.addPass(renderPass);
+        // pixel ratio
+        const pixelRatio = this.renderer.getPixelRatio();
+        const newWidth = Math.floor(this.getFullWidth() * pixelRatio) || 1;
+        const newHeight = Math.floor(this.getFullHeight() * pixelRatio) || 1;
+        composer.setSize(newWidth, newHeight);
+        // antialias
+        const effectFXAA = new ShaderPass(FXAAShader);
+        effectFXAA.uniforms['resolution'].value.set(1 / newWidth, 1 / newHeight);
+        composer.addPass(effectFXAA);
+        // outline
+        this.outlinePass = new OutlinePass(new THREE.Vector2(this.getFullWidth(), this.getFullHeight()), this.scene, this.camera);
+        this.outlinePass.visibleEdgeColor.set('#ffffff'); // outline color
+        this.outlinePass.edgeStrength = 10; // outline weight
+        composer.addPass(this.outlinePass);
+        return composer;
+    }
+
+    initControls = () => {
+        const controls = new OrbitControls(this.camera, this.renderer.domElement);
+        // controls.enableRotate = false; // 绂佺敤鏁翠綋鏃嬭浆鍔熻兘
+        controls.enablePan = false; // 鍏佽骞崇Щ
+        controls.enableDamping = true;   // 寮�鍚樆灏�
+        controls.dampingFactor = 0.08; // 闃诲凹鍥犲瓙
+        controls.enableZoom = true; // 鍏佽缂╂斁
+        // controls.minDistance = 1; // 鏈�灏忕缉鏀捐窛绂�
+        // controls.maxDistance = 30; // 鏈�澶х缉鏀捐窛绂�
+        controls.minPolarAngle = 0; // 鏈�灏忎刊浠拌搴︼紙鍚戜笅鐪嬶級
+        controls.minPolarAngle = Math.PI / 2.1;
+        controls.maxPolarAngle = Math.PI / 2.1; // 鏈�澶т刊浠拌搴︼紙鍚戜笂鐪嬶級
+        controls.rotateSpeed = 0.6; // 瑙嗚绉诲姩閫熷害鍑忔參
+        controls.autoRotate = true; // 鑷姩鏃嬭浆
+
+        controls.target = new THREE.Vector3(0, 250, 0)  // 灞忓箷涓績鐐� 骞虫浛 camera鐨刲ookAt
+        return controls;
+    }
+
+    initStats = () => {
+        const stats = new Stats();
+        this.dom?.appendChild(stats.dom);
+        if (!help) {
+            stats.domElement.style.display = 'none';
+        }
+        return stats;
+    }
+
+    windowResize = () => {
+        this.resizeHandler = () => {
+            this.camera.aspect = this.getFullWidth() / this.getFullHeight();
+            this.camera.updateProjectionMatrix();
+            this.renderer.setSize(this.getFullWidth(), this.getFullHeight());
+        };
+        window.addEventListener('resize', this.resizeHandler, false);
+    }
+
+    initRaycaster = () => {
+        const raycaster = new THREE.Raycaster();
+        const mouse = new THREE.Vector2();
+        this.handleClickEvent = (event) => {
+            let x, y;
+            if (event.changedTouches) {
+                x = event.changedTouches[0].pageX;
+                y = event.changedTouches[0].pageY;
+            } else {
+                x = event.clientX;
+                y = event.clientY;
+            }
+            let rect = this.dom.getBoundingClientRect();
+            mouse.x = ((x - rect.left) / rect.width) * 2 - 1;
+            mouse.y = -((y - rect.top) / rect.height) * 2 + 1;
+            event.preventDefault();
+            raycaster.setFromCamera(mouse, this.camera);
+            let intersects = raycaster.intersectObjects(this.objects, true);
+            if (intersects.length === 0) {
+                return;
+            }
+            let objName = intersects[0].object.name;
+            this.objects.forEach(obj => {
+                if (obj.name === objName) {
+                    this.outlinePass.selectedObjects = [obj];
+                }
+            })
+            if (objName && this.handleClick) {
+                this.handleClick(objName, x, y);
+            }
+        }
+        this.dom?.addEventListener("click", this.handleClickEvent, false);
+    }
+
+    generateMesh = (fn) => {
+        const loader = new FBXLoader();
+        fn(loader, this.addObject);
+    }
+
+    setNewSelectedMesh = (objName) => {
+        for (const mesh of this.objects) {
+            if (mesh.name === objName) {
+                this.outlinePass.selectedObjects = [mesh];
+                break;
+            }
+        }
+    }
+
+    rePerspective = (maxHeight, normalHeight) => {
+        const height = Math.max(maxHeight, normalHeight)
+        const cameraPosScale = 0.7;
+        this.camera.position.set(
+            -height * cameraPosScale,
+            height * cameraPosScale,
+            height * cameraPosScale
+        );
+        this.controls.target = new THREE.Vector3(0, maxHeight * 0.53, 0);
+    }
+
+    destroy = () => {
+        cancelAnimationFrame(this.animationFrame);
+        window.removeEventListener('resize', this.resizeHandler);
+        if (this.scene) {
+            while (this.scene.children.length > 0) {
+                this.removeEntity(this.scene.children[0]);
+            }
+            this.scene = null;
+        }
+        if (this.renderer) {
+            this.renderer.dispose();
+            this.renderer.forceContextLoss();
+            this.renderer.context = null;
+            this.renderer.domElement = null;
+            this.renderer = null;
+        }
+        if (this.composer) {
+            this.composer.passes.forEach(pass => {
+                if (pass.dispose) {
+                    pass.dispose();
+                }
+            });
+            this.composer = null;
+        }
+        if (this.controls) {
+            this.controls.dispose();
+            this.controls = null;
+        }
+        this.dom?.removeEventListener("click", this.handleClickEvent);
+        this.camera = null;
+        this.objects = [];
+        while (this.dom?.firstChild) {
+            this.dom.removeChild(this.dom.firstChild);
+        }
+    }
+
+    removeEntity = (object) => {
+        if (object.material) object.material.dispose();
+        if (object.geometry) object.geometry.dispose();
+        if (object.texture) object.texture.dispose();
+        this.scene.remove(object);
+    }
+};
+
+const initLight = (scene) => {
+    const hemiLight = new THREE.HemisphereLight(0xffffff, 0xffffff, 6);
+    hemiLight.color.setHSL(0.6, 1, 0.6);
+    hemiLight.groundColor.setHSL(0.095, 1, 0.75);
+    hemiLight.position.set(0, 1500, 0);
+    scene.add(hemiLight);
+
+    const dirLight = new THREE.DirectionalLight(0xffffff, 2.5);
+    dirLight.color.setHSL(0.1, 1, 0.95);
+    dirLight.position.set(-10, 10, 10);
+    dirLight.position.multiplyScalar(30);
+    scene.add(dirLight);
+
+    const dirLight1 = new THREE.DirectionalLight(0xffffff, 2.5);
+    dirLight1.color.setHSL(0.1, 1, 0.95);
+    dirLight1.position.set(10, 10, -10);
+    dirLight1.position.multiplyScalar(30);
+    scene.add(dirLight1);
+}
\ No newline at end of file
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/MapController.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/MapController.java
index 3f47a97..aebae1e 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/MapController.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/MapController.java
@@ -58,6 +58,8 @@
     private MapMapper mapMapper;
     @Autowired
     private SnowflakeIdWorker snowflakeIdWorker;
+    @Autowired
+    private LocService locService;
 
     @PreAuthorize("hasAuthority('manager:loc:list')")
     @PostMapping("/data/fetch")
@@ -113,6 +115,16 @@
         return R.ok("Save Success");
     }
 
+    @PostMapping("/shelf/group")
+    public R shelfGroup(@RequestParam(required = false) Integer row, @RequestParam(required = false) Integer bay) {
+        if (null == row || null == bay) {
+            return R.error();
+        }
+        List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getRow, row).eq(Loc::getBay, bay).orderByAsc(Loc::getLev));
+        return R.ok().add(locList);
+    }
+
+
 
 
 

--
Gitblit v1.9.1