three.js 如何用webgl搭建一个3D库房,3D仓库3D码头,3D集装箱,车辆定位,叉车定位可视化孪生系统——第十五课( 六 )

 2.1.2、创建室内库房模型

three.js 如何用webgl搭建一个3D库房,3D仓库3D码头,3D集装箱,车辆定位,叉车定位可视化孪生系统——第十五课

文章插图
这里的模型通过代码实现,篇幅过长 , 不便展示 。
 2.1.3、创建箱子模型
three.js 如何用webgl搭建一个3D库房,3D仓库3D码头,3D集装箱,车辆定位,叉车定位可视化孪生系统——第十五课

文章插图
{ "show": true, "uuid": "", "name": name, "objType": "ExtrudeGeometry", "position": { "x": position.x, "y": position.y, "z": position.z }, "style": { "skinColor": 16711680, "skin": { "skin_up": { "skinColor": color1, "side": 1, "opacity": 1, "imgurl": imgurl1, "repeatx": true, "width": 0.01, "repeaty": true, "height": 0.01 }, "skin_down": { "skinColor": 16777215, "side": 1, "opacity": 1 }, "skin_side": { "skinColor": color2, "opacity": 1, "imgurl": imgurl2, "repeatx": true, "width": 0.01, "repeaty": true, "height": 0.01 } } }, "scale": { "x": size.x / 100, "y": size.y / 100, "z": size.z / 100 }, "shapeParm": { "points": [{ "x": 0, "y": 0, "type": "nomal" }, { "x": 0, "y": 100, "type": "nomal" }, { "x": 100, "y": 100, "type": "nomal" }, { "x": 100, "y": 0, "type": "nomal" }], "holes": [] }, "extrudeSettings": { "amount": 100, "curveSegments": 1, "steps": 1, "bevelEnabled": false, "bevelThickness": 1, "bevelSize": 1, "bevelSegments": 1, "extrudePathPoints": [] }, "showSortNub": 100, "customType1": "", "customType2": "", "animation": null, "dbclickEvents": null, "rotation": [{ "direction": "x", "degree": 0 }, { "direction": "y", "degree": 0 }, { "direction": "z", "degree": 0 }], "BindDevId": null, "BindDevName": null, "devInfo": null, "BindMeteId": null, "BindMeteName": null }2.1.4、创建集装箱模型
three.js 如何用webgl搭建一个3D库房,3D仓库3D码头,3D集装箱,车辆定位,叉车定位可视化孪生系统——第十五课

文章插图
[{"show":true,"uuid":"","name":"cube2_6","objType":"cube2","length":400,"width":200,"height":200,"x":0,"y":200,"z":0,"style":{"skinColor":16777215,"skin":{"skin_up":{"skinColor":2531071,"side":1,"opacity":1,"imgurl":"../img/3dImg/cbjysfk2.jpg"},"skin_down":{"skinColor":2531071,"side":1,"opacity":1,"imgurl":"../img/3dImg/cbjysfk2.jpg"},"skin_fore":{"skinColor":2531071,"side":1,"opacity":1,"imgurl":"../img/3dImg/cbjysfk2.jpg"},"skin_behind":{"skinColor":2531071,"side":1,"opacity":1,"imgurl":"../img/3dImg/cbjysfk2.jpg"},"skin_left":{"skinColor":2531071,"side":1,"opacity":1,"imgurl":"../img/3dImg/cbjysfk2.jpg"},"skin_right":{"skinColor":2531071,"side":1,"opacity":1,"imgurl":"../img/3dImg/cbjysfk2.jpg"}}},"showSortNub":6,"customType1":"","customType2":"","animation":null,"dbclickEvents":null,"rotation":[{"direction":"x","degree":0},{"direction":"y","degree":0},{"direction":"z","degree":0}],"thick":null,"scale":{"x":1,"y":1,"z":1},"BindDevId":null,"BindDevName":null,"devInfo":null,"BindMeteId":null,"BindMeteName":null}]2.1.5、车辆模型
three.js 如何用webgl搭建一个3D库房,3D仓库3D码头,3D集装箱,车辆定位,叉车定位可视化孪生系统——第十五课

文章插图
{ "name": _name, "objType": "objmodel", "position": _position, "scale": _scale, "visible": true, "rotation": [{ "direction": "x", "degree": _rotation.x }, { "direction": "y", "degree": _rotation.y-Math.PI/2 }, { "direction": "z", "degree": _rotation.z }], "filePath": "../js/models/car/", "mtlFileName": "car03.mtl", "objFileName": "car03.obj", "mtlIsPublic": false, "showSortNub": 7, "show": true, "customType1": "", "customType2": "", "animation": null, "dbclickEvents": null, "BindDevId": null, "BindDevName": null, "devInfo": null, "BindMeteId": null, "BindMeteName": null }2.2、数据载入
通过数据生成模型,画出库位,载入车辆等
/* type:1://集装箱2://箱子3://筒状color://颜色id :设备id 唯一必填position :设备位置必填 格式 { x: 0, y: 0, z: 0} 这里矢量单位size:尺寸 默认值 { x: 1, y: 1, z: 1 };*/function createModelJsonByType(type,color, id, position, size) {if (!scale) {scale = { x: 1, y: 1, z: 1 };}var modeljson = null;switch (type) {case 1:{modeljson = {....};}break;case 2:modeljson = {.... 。};break;case 3:modeljson = {....};break;}modeljson.name = "dev_T_" + type + "_ID_" + id;if (config && config.name) {modeljson.name = config.name;}if (modeljson.children) {$.each(modeljson.children, function (_i, _o) {_o.name = "dev_T_" + type + "_ID_" + id + "OBJCREN" + _i;});}if (modeljson.position) {modeljson.position.x = position.x;if (position.y || position.y == 0) {modeljson.position.y = position.y;}modeljson.position.z = position.z;}return modeljson;}/*创建车*/function createCarModel(_name, _position, _rotation, _scale, carType) {var model = ...model;// 1.集卡(带集装箱的) 2.集卡(空车) 3.散卡(带箱的小货车) 4.正面吊 5.小铲车 6 板车if (carType) {switch (carType) {case 1: {model.filePath = "../js/models/jika/";model.mtlFileName = "jika.mtl";model.objFileName = "jika.obj";model.scale = {x: 4.200,y: 4.200,z: 4.200}}break;case 2: {model.filePath = "../js/models/jika_nocube/";model.mtlFileName = "jika_nocube.mtl";model.objFileName = "jika_nocube.obj";model.scale = {x: 4.200,y: 4.200,z: 4.200}}break;case 3: {model.filePath = "../js/models/sanka/";model.mtlFileName = "sanka.mtl";model.objFileName = "sanka.obj";model.scale = {x: 0.080,y: 0.080,z: 0.080}model.rotation[1].degree -= Math.PI / 2;}break;case 4: {model.filePath = "../js/models/diaoche/";model.mtlFileName = "dc.mtl";model.objFileName = "dc.obj";model.scale = {x: 1.150,y: 1.150,z: 1.150}}break;case 5: {model.filePath = "../js/models/canche/";model.mtlFileName = "canche.mtl";model.objFileName = "canche.obj";model.scale = {x: 0.1,y: 0.1,z: 0.1}}break;case 6: {model.filePath = "../js/models/banche/";model.mtlFileName = "banche.mtl";model.objFileName = "banche.obj";model.scale = {x: 4.200,y: 4.200,z: 4.200}}break;}}//model.scale.x *= 0.8;//model.scale.y *= 0.8;//model.scale.z *= 0.8;return model;}

推荐阅读