使用ThreeJs从零开始构建3D智能仓库——第五章
写在前面创建货架对象创建货架、货位类根据配置添加货架
添加货物添加信息侧边栏结束语
写在前面
本章我们来讲解下如何添加货架货物和显示各类信息的侧边栏。效果如下图所示: 2019.11.26 更新:我最近建立了个人网站,大家可以访问下面的链接查看演示 3D仓库演示 2019.11.28 更新:代码和图片资源等已上传至GitHub https://github.com/xiao149/ThreeJsDemo 其中货架的层数和每层的货位数量是可以自定义的,比如我这边就是三层每层两个货位。方便起见我在每个货位上都放置了货物,大家当然可以自行选择。左上角的侧边栏使用了ThreeJs官方的dat.gui,这里为了演示也只是随便列了几个信息,当点击货物时相关信息便会显示出来。
创建货架对象
创建货架、货位类
因为我本身主要从事JAVA后台的开发,对前台一知半解,所以这部分写得不好也请各位轻喷,或许是受JAVA对象类的影响,我想在JS中也创建对象,比如货架的对象,货位的对象。奈何我水平有限,不知如何在JS中创建对象,只能用一些比较“愚蠢”的方式实现:
//创建货架对象
function shelf(storageZoneId, shelfId, shelfName,
planeLength , planeWidth , planeHeight ,
holderLength , holderWidth , holderHeight ,
positionX , positionY , positionZ ,
layerNum , columnNum)
{
this.storageZoneId=storageZoneId;
this.shelfId=shelfId;
this.shelfName=shelfName;
this.planeLength=planeLength;
this.planeWidth=planeWidth;
this.planeHeight=planeHeight;
this.holderLength=holderLength;
this.holderWidth=holderWidth;
this.holderHeight=holderHeight;
this.positionX=positionX;
this.positionY=positionY;
this.positionZ=positionZ;
this.layerNum=layerNum;
this.columnNum=columnNum;
}
//根据货架编码获取货架对象
function getShelfById(shelfId) {
for(var i = 0; i |