#
luxiaotao1123
2024-10-16 b20fdb26e9d1d091fd7864de1edcc639e9da01b8
#
6个文件已修改
1个文件已添加
507 ■■■■ 已修改文件
zy-acs-flow/package-lock.json 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-flow/package.json 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-flow/public/model/shelf.fbx 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-flow/src/map/http.js 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-flow/src/map/insight/shelf/ShelfMain.jsx 125 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-flow/src/map/insight/shelf/ShelfThree.js 343 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/MapController.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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",
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": {
zy-acs-flow/public/model/shelf.fbx
Binary files differ
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);
    })
}
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>
    );
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的lookAt
        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);
}
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);
    }