#1
luxiaotao1123
2022-04-06 a8b76a8b91cc0034aa05b50520ed8dcf74bedb21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import {MTLLoader} from "../lib/MTLLoader.js";
import {OBJLoader} from "../lib/OBJLoader.js";
import * as THREE from '../three.module.js';
 
const palletX = -18;
const palletY = 2;
const palletZ = -46;
 
const goodsX = -17;
const goodsY = 5;
const goodsZ = -6;
 
function InitPallet(scene, palletList, ref, type) {
    const manager = new THREE.LoadingManager();
    new OBJLoader( manager )
        .setPath( '../static/model/obj/' )
        .load( 'pallet.obj', function ( obj ) {
            obj.traverse (function (child) {
                child.castShadow = true;
                if (child instanceof THREE.Mesh) {
                    child.material = new THREE.MeshLambertMaterial({
                        color: 0x708090
                    });
                }
            });
            obj.scale.set(4, 4, 3.5);
 
            palletList.map(item => {
                let clone = obj.clone();
                let positionX = ref.positionX || 0;
                let positionY = ref.bottomHight + (item.lev1-1)*ref.binHeight || 0;
                let positionZ = (item.bay1-1)*-ref.binHeight || 0;
 
                clone.name = item.loc_no + "-" + "Pallet";
                clone.position.x = palletX + positionX;
                clone.position.y = palletY + positionY;
                clone.position.z = palletZ + positionZ;
                scene.addObject(clone);
            })
        });
}
 
function InitGoods(scene, goodsList, ref, type) {
    const manager = new THREE.LoadingManager();
    const goodsWrapImg = new THREE.TextureLoader( manager ).load( '../static/img/goodsWrap.jpg' );
    const goodsImg = new THREE.TextureLoader( manager ).load( '../static/img/goods.jpg' );
    new OBJLoader( manager ).load( '../static/model/obj/goods.obj', function ( obj ) {
        obj.traverse (function (child) {
            child.castShadow = true;
            if (child instanceof THREE.Mesh) {
                if (child.name === 'goods') {
                    child.material.map = goodsImg;
                } else if (child.name === "goods_wrap") {
                    child.material.map = goodsWrapImg;
                }
            }
        });
        obj.scale.set(1, 1.2, 1.2);
 
        goodsList.map(item => {
            let clone = obj.clone();
            let positionX = ref.positionX || 0;
            let positionY = ref.bottomHight + (item.lev1-1)*ref.binHeight || 0;
            let positionZ = (item.bay1-1)*-ref.binHeight || 0;
 
            clone.name = item.loc_no + "-" + "Goods";
            clone.position.x = goodsX + positionX;
            clone.position.y = goodsY + positionY;
            clone.position.z = goodsZ + positionZ;
            scene.addObject(clone);
        })
    });
}
 
function StoreGoods(object, data, shelf) {
    let that = this;
    that.data = data;
    that.object = object;
    that.shelf = shelf;
    let palletList = [];
    let goodsList = [];
 
    let init = function () {
        for (let i=0;i<that.data.length;i++) {
            let obj = that.data[i];
            if (obj.loc_sts === 'D') {
                palletList.push(obj);
            } else if (obj.loc_sts === 'F') {
                palletList.push(obj);
                goodsList.push(obj);
            }
        }
        if (palletList.length > 0) {
            InitPallet(that.object, palletList, that.shelf);
        }
        if (goodsList.length > 0) {
            InitGoods(that.object, goodsList, that.shelf);
        }
    }
    init();
 
}
 
export {StoreGoods, InitPallet, InitGoods}