#
luxiaotao1123
2022-04-06 0a6e149ec5684f243bdadb0b8ef780cb71000ace
static/js/object/StoreGoods.js
@@ -2,60 +2,145 @@
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;
/**
 * 初始化托盘模型
 * @param scene 场景
 * @param palletList 托盘数据列表
 * @param ref 参照物
 * @param type 参照物类型:1 - 货架;    2 - 输送线
 */
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;
                let positionY;
                let positionZ;
                switch (type) {
                    case 1:
                        positionX = ref.positionX || 0;
                        positionY = ref.bottomHight + (item.lev1-1)*ref.binHeight || 0;
                        positionZ = (item.bay1-1)*-ref.binHeight || 0;
                        clone.name = item.loc_no + "-" + "Pallet";
                        break;
                    case 2:
                        break;
                    default:
                        console.error("InitPallet param[type] error ===>> " + type);
                }
                clone.position.x = palletX + positionX;
                clone.position.y = palletY + positionY;
                clone.position.z = palletZ + positionZ;
                scene.addObject(clone);
            })
        });
}
/**
 * 初始化货物模型
 * @param scene 场景
 * @param goodsList 货物数据列表
 * @param ref 参照物
 * @param type 参照物类型:1 - 货架;    2 - 输送线
 */
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;
            let positionY;
            let positionZ;
            switch (type) {
                case 1:
                    positionX = ref.positionX || 0;
                    positionY = ref.bottomHight + (item.lev1-1)*ref.binHeight || 0;
                    positionZ = (item.bay1-1)*-ref.binHeight || 0;
                    clone.name = item.loc_no + "-" + "Goods";
                    break;
                case 2:
                    break;
                default:
                    console.error("InitGoods param[type] error ===>> " + type);
            }
            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 = [];
    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);
    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, 1);
        }
        if (goodsList.length > 0) {
            InitGoods(that.object, goodsList, that.shelf, 1);
        }
    }
    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);
                    obj.position.x = -1;
                    obj.position.y = 22;
                    obj.position.z = -46;
                    palletList.map(item => {
                        var clone = obj.clone();
                        let positionX = that.shelf.positionX || 0;
                        let positionY = that.shelf.positionY || 0;
                        let positionZ = that.shelf.positionZ || 0;
                        clone.position.x = -18 + positionX;
                        clone.position.y = 22 + positionY;
                        clone.position.z = -46 + positionZ;
                        that.object.addObject(clone);
                    })
                }, null, null );
        });
    init();
}
export {StoreGoods}
export {StoreGoods, InitPallet, InitGoods}