#
luxiaotao1123
2021-12-25 2b4aa7fdb59b2656e1281258ebd4a3bccc24958e
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
import {MTLLoader} from "../lib/MTLLoader.js";
import {OBJLoader} from "../lib/OBJLoader.js";
import * as THREE from '../three.module.js';
 
function StoreConvey(object, data) {
    let that = this;
    that.data = null;
    that.object = null;
 
    let chainList = [];
    let rollerList = [];
    let transportList = [];
 
    let init = function () {
        that.data = data;
        that.object = object;
        for (let i=0;i<that.data.length;i++) {
            let conveyObj = that.data[i];
            switch (conveyObj.objectType) {
                case "chain":
                    chainList.push(conveyObj);
                    break;
                case "roller":
                    rollerList.push(conveyObj);
                    break;
                case "transport":
                    transportList.push(conveyObj);
                    break;
                default:
                    break;
            }
        }
    };
    init();
 
    this.load = function () {
        new THREE.ObjectLoader().load( "../static/model/json/链条输送机.json", function (obj) {
            obj.traverse (function (child) {
                if (child instanceof THREE.Mesh) {
                    child.scale.set(1, 1, 1.8);
                    child.material = new THREE.MeshLambertMaterial({
                        color: 0xAAAAAA
                    });
                }
            });
            chainList.map(item => {
                that.object.addObject(customize(obj.clone(), item));
            })
        });
        new THREE.ObjectLoader().load( "../static/model/json/辊筒输送机.json", function (obj) {
            obj.traverse (function (child) {
                if (child instanceof THREE.Mesh) {
                    child.scale.set(1, 1, 1.8);
                    child.material = new THREE.MeshLambertMaterial({
                        color: 0xAAAAAA
                    });
                }
            });
            rollerList.map(item => {
                that.object.addObject(customize(obj.clone(), item));
            })
        });
        new THREE.ObjectLoader().load( "../static/model/json/顶升移栽.json", function (obj) {
            obj.traverse (function (child) {
                if (child instanceof THREE.Mesh) {
                    child.scale.set(1, 1, 1.8);
                    child.material = new THREE.MeshLambertMaterial({
                        color: 0xAAAAAA
                    });
                }
            });
            transportList.map(item => {
                that.object.addObject(customize(obj.clone(), item));
            })
        });
    }
 
    function customize(clone, info) {
        clone.position.x = 0 + info.position.x;
        clone.position.y = 0 + info.position.y;
        clone.position.z = 0 + info.position.z;
        clone.rotateY(info.rotateY);
        if (info.traverse !== undefined) {
            let traverse = info.traverse;
            clone.traverse (function (child) {
                if (child instanceof THREE.Mesh) {
                    child.scale.set(traverse.scale.x, traverse.scale.y, traverse.scale.z);
                    child.material = new THREE.MeshLambertMaterial({
                        color: traverse.color
                    });
                }
            });
        }
        return clone;
    }
 
}
 
export {StoreConvey}