#
luxiaotao1123
2022-01-04 847574e092ed2b348dac7d8b32e314fd35007c03
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
import {MTLLoader} from "../lib/MTLLoader.js";
import {OBJLoader} from "../lib/OBJLoader.js";
import * as THREE from '../three.module.js';
 
function StoreGoods(object, data, shelf) {
    let that = this;
    that.data = data;
    that.object = object;
    that.shelf = shelf;
    let palletList = [];
    let goodsList = [];
 
    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);
        }
    }
 
    const manager = new THREE.LoadingManager();
    new MTLLoader(manager)
        .setPath( '../static/model/obj/' )
        .load( 'pallet.mtl', function ( materials ) {
            materials.preload();
            new OBJLoader( manager )
                .setMaterials( materials )
                .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: 0x2F4F4F
                            });
                        }
                    });
                    obj.scale.set(4, 4, 3.5);
 
                    palletList.map(item => {
                        let clone = obj.clone();
                        let positionX = that.shelf.positionX || 0;
                        let positionY = that.shelf.bottomHight + (item.lev1-1)*that.shelf.binHeight || 0;
                        let positionZ = that.shelf.positionZ || 0;
 
                        clone.position.x = -18 + positionX;
                        clone.position.y = 2 + positionY;
                        clone.position.z = -46 + positionZ;
                        that.object.addObject(clone);
                    })
                }, null, null );
        });
 
}
 
export {StoreGoods}