From 059270c12f452fcc3344b826f35295fd7c20906e Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期二, 21 三月 2023 08:31:37 +0800 Subject: [PATCH] # --- static/js/object/StoreConvey.js | 146 +++++++++++++++++++++++++++++++++++------------- 1 files changed, 106 insertions(+), 40 deletions(-) diff --git a/static/js/object/StoreConvey.js b/static/js/object/StoreConvey.js index 2548bce..e844b24 100644 --- a/static/js/object/StoreConvey.js +++ b/static/js/object/StoreConvey.js @@ -2,55 +2,121 @@ import {OBJLoader} from "../lib/OBJLoader.js"; import * as THREE from '../three.module.js'; - -function StoreConvey(object) { +function StoreConvey(object, data) { let that = this; - that.no = 0; - that.objectType = null; - that.position = null; + that.data = null; + that.object = null; + + let chainList = []; + let rollerList = []; + let transportList = []; let init = function () { - that.no = object.no; - that.objectType = object.objectType; - that.position = object.position; + 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(); - that.create = function (scene) { - switch (that.objectType) { - case "chain": - 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 - }); - } + 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 }); - obj.position.x = 0 + that.position.x; - obj.position.y = 0 + that.position.y; - obj.position.z = 0 + that.position.z; - scene.addObject( obj ); - scene.conveyTypes.push({type: that.objectType, object: obj}); - } ); - break; - case "roller": - break; - case "transport": - break; - default: - break; - } + 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)); + }) + }); } - this.clone = function (param) { - let goods=param.clone(); - goods.position.set(this.positionX,this.positionY,this.positionZ); - goods.uuid=this.no; - goods.name=this.name; - goods.type="StoreGoods"; - return goods; + 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.name = info.no + "-sta"; + 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; } } -- Gitblit v1.9.1