#
luxiaotao1123
2022-03-21 4f7e5d3dc070ea46f4ca243bcbae9eda76d8c8a0
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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/chainConvey.json", function (obj) {
            obj.traverse (function (child) {
                if (child instanceof THREE.Mesh) {
                    child.scale.set(1, 1, 1.6);
                    child.material = new THREE.MeshPhysicalMaterial({
                        color: 0x444444
                    });
                    if (child.name === "Box034" || child.name === "Box035") {
                        child.material = new THREE.MeshPhysicalMaterial({
                            color: 0x1C1C1C
                        });
                    }
                    child.castShadow = true;
                    // child.receiveShadow = true;
                }
            });
 
            chainList.map(item => {
                that.object.addObject(customize(obj.clone(), item));
            })
        });
        new THREE.ObjectLoader().load( "../static/model/json/rollerConvey.json", function (obj) {
            obj.traverse (function (child) {
                if (child instanceof THREE.Mesh) {
                    child.scale.set(0.5, 1, 1);
                    child.material = new THREE.MeshPhysicalMaterial({
                        color: 0x444444
                    });
                    child.castShadow = true;
                    // child.receiveShadow = true;
                }
            });
            rollerList.map(item => {
                that.object.addObject(customize(obj.clone(), item));
            })
        });
        new THREE.ObjectLoader().load( "../static/model/json/transportConvey.json", function (obj) {
            obj.traverse (function (child) {
                if (child instanceof THREE.Mesh) {
                    child.scale.set(1, 1, 1);
                    child.material = new THREE.MeshPhysicalMaterial({
                        color: 0x444444
                    });
                }
            });
            transportList.map(item => {
                that.object.addObject(customize(obj.clone(), item));
            })
        });
    }
 
    function customize(clone, info) {
        let positionX = info.position.x || 0;
        let positionY = info.position.y || 0;
        let positionZ = info.position.z || 0;
        let rotateY = info.rotateY || 0;
 
        clone.position.x = 0 + positionX;
        clone.position.y = 0 + positionY;
        clone.position.z = 0 + positionZ;
        clone.rotateY(rotateY);
        if (info.traverse !== undefined) {
            let traverse = info.traverse;
            clone.traverse (function (child) {
                if (child instanceof THREE.Mesh) {
                    // 拉伸
                    if (traverse.scale !== undefined) {
                        let scaleX = traverse.scale.x || 1;
                        let scaleY = traverse.scale.y || 1;
                        let scaleZ = traverse.scale.z || 1;
                        child.scale.set(scaleX, scaleY, scaleZ);
                    }
                    // 颜色
                    if (traverse.color !== undefined) {
                        child.material = new THREE.MeshLambertMaterial({
                            color: traverse.color
                        });
                    }
                }
            });
        }
        return clone;
    }
 
}
 
export {StoreConvey}