博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于WebGL(ThingJS)的社区水电燃气管线3D可视化管理演示【三维管线,3D管线,水管可视化】 ...
阅读量:6624 次
发布时间:2019-06-25

本文共 8115 字,大约阅读时间需要 27 分钟。

地下的管线错综复杂如何,图纸并不能完全满足实际需求,我们就用ThingJS平台来模拟一个小区水,电,天然气管线演示。
 
 
 
 
第一步,利用CampusBuilder搭建模拟场景。CampusBuilder的模型库有各种各样的模型,使我们搭建出的场景更逼真。使用CampusBuilde创建层级,之后再给层级加外立面就出现了当前的效果。详情移步:
 
//加载场景代码var app = new THING.App({    // 场景地址    "url": "http://www.thingjs.com/./uploads/wechat/oLX7p05lsWJZUIxnIWsNXAzJ40X8/scene/管线演示2",    //背景设置    "skyBox": "BlueSky"});

  

第二步, 初始化摄像机位置,添加四个按钮,并创建四个方法。
app.on('load', function () {    //摄像机位置初始化    app.camera.position = [0.4374202706634094, 101.92917348318593, 97.06808820543526];    app.camera.target = [52.75056074670042, -18.885239034825123, -20.619558480451797];    new THING.widget.Button('水管演示', water);    new THING.widget.Button('电线演示', electric);    new THING.widget.Button('燃气演示', gas);});function water() {}function electric() {}function gas() {}
 
第三步,创建管线,我们这里写水管线以后的电线,燃气管线同理。这里简单说一下PolygonLine,它继承THING.LineBase,同样有贴图属性,可以自己从本地上传图片至页面资源后使用。
 
var line = null;function buildLine(points, color) {    line = app.create({        type: 'PolygonLine',        points: points,        style: {            color: color,        }    });    line.scrollUV = true;}function water() {    var waterUnderPoints = [];     buildingOpacity(0.3);    app.query(/building_0/).forEach(        function (parentObj) {            var points = [];            points.push(parentObj.selfToWorld([5, -0.8, 0]));            waterUnderPoints.push(points[0]);            for (var i = 3; i <= 24; i += 3) {                points.push(parentObj.selfToWorld([5, i, 0]));                points.push(parentObj.selfToWorld([5, i, 3]));                points.push(parentObj.selfToWorld([-5, i, 3]));                points.push(parentObj.selfToWorld([-5, i, -3]));                points.push(parentObj.selfToWorld([5, i, -3]));                points.push(parentObj.selfToWorld([5, i, 0]));            }            points.push(parentObj.selfToWorld([5, 24, 0]));            buildLine(points, '#0000FF');        }    );    waterUnderPoints.push([15.32711, -0.79, -55.655339999999999]);    buildLine(waterUnderPoints, '#0000FF');    //renderOrder();}function buildingOpacity(num) {    app.query("*").forEach(function (obj) {        obj.style.opacity = num;    });}function renderOrder(){    app.query('.PolygonLine').forEach(        function (obj) {            obj.renderOrder = -10000;        }    );}

  

这里用到了两个方法:
1) buildingOpacity(num);
这个方法的主要作用就是为了将场景虚化,更好的展示我们的管线。
2)renderOrder();
这个我在代码中先注释掉了我们先看一下现在的效果:
 
 
注意:如果没有设置renderOrder();属性的 ,管线的渲染层级没有building高 ,就会导致有被building遮盖的PolygonLine无法正常显示,设置renderOrder();属性后,渲染效果正常
 
 
最后一步,创建出电线以及燃气线
function electric() {    var electricUnderPoints = [];    buildingOpacity(0.3);    app.query(/building_0/).forEach(        function (parentObj) {            var points = [];            points.push(parentObj.selfToWorld([3, -0.8, 0]));            electricUnderPoints.push(points[0]);            for (var i = 3; i <= 24; i += 2.5) {                points.push(parentObj.selfToWorld([3, i, 0]));                points.push(parentObj.selfToWorld([-3, i, 2]));            }            points.push(parentObj.selfToWorld([3, 24, 0]));            buildLine(points, '#00FF00');            console.log(points);        }    );    electricUnderPoints.push([16.690666, -0.79, -55.115203999999999]);    buildLine(electricUnderPoints, '#00FF00');    renderOrder();}function gas() {    var gasUnderPoints = [];    buildingOpacity(0.3);    app.query(/building_0/).forEach(        function (parentObj) {            var points = [];            points.push(parentObj.selfToWorld([-6.2, -0.3, 0]));            gasUnderPoints.unshift(points[0]);            for (var i = 3; i <= 24; i += 3) {                points.push(parentObj.selfToWorld([-6.2, i, 0]));                points.push(parentObj.selfToWorld([-6.2, i, 2]));                points.push(parentObj.selfToWorld([6.2, i, 2]));                points.push(parentObj.selfToWorld([6.2, i, -2]));                points.push(parentObj.selfToWorld([-6.2, i, -2]));                points.push(parentObj.selfToWorld([-6.2, i, 0]));            }            points.push(parentObj.selfToWorld([-6.2, 24, 0]));            buildLine(points, '#FF0000');            console.log(points);        }    );    gasUnderPoints.unshift([22.963023600000003, -0.3, 57.8305784]);    buildLine(gasUnderPoints, '#FF0000');    renderOrder();}
 
 
 附上完整代码,可以直接在平台调试
 
//加载场景代码var app = new THING.App({    // 场景地址    "url": "http://www.thingjs.com/./uploads/wechat/oLX7p05lsWJZUIxnIWsNXAzJ40X8/scene/管线演示2",    //背景设置    "skyBox": "BlueSky"});app.on('load', function () {    //摄像机位置初始化    app.camera.position = [0.4374202706634094, 101.92917348318593, 97.06808820543526];    app.camera.target = [52.75056074670042, -18.885239034825123, -20.619558480451797];    new THING.widget.Button('水管演示', water);    new THING.widget.Button('电线演示', electric);    new THING.widget.Button('燃气演示', gas);});function water() {    var waterUnderPoints = [];     buildingOpacity(0.3);    app.query(/building_0/).forEach(        function (parentObj) {            var points = [];            points.push(parentObj.selfToWorld([5, -0.8, 0]));            waterUnderPoints.push(points[0]);            for (var i = 3; i <= 24; i += 3) {                points.push(parentObj.selfToWorld([5, i, 0]));                points.push(parentObj.selfToWorld([5, i, 3]));                points.push(parentObj.selfToWorld([-5, i, 3]));                points.push(parentObj.selfToWorld([-5, i, -3]));                points.push(parentObj.selfToWorld([5, i, -3]));                points.push(parentObj.selfToWorld([5, i, 0]));            }            points.push(parentObj.selfToWorld([5, 24, 0]));            buildLine(points, '#0000FF');        }    );    waterUnderPoints.push([15.32711, -0.79, -55.655339999999999]);    buildLine(waterUnderPoints, '#0000FF');    renderOrder();}function electric() {    var electricUnderPoints = [];    buildingOpacity(0.3);    app.query(/building_0/).forEach(        function (parentObj) {            var points = [];            points.push(parentObj.selfToWorld([3, -0.8, 0]));            electricUnderPoints.push(points[0]);            for (var i = 3; i <= 24; i += 2.5) {                points.push(parentObj.selfToWorld([3, i, 0]));                points.push(parentObj.selfToWorld([-3, i, 2]));            }            points.push(parentObj.selfToWorld([3, 24, 0]));            buildLine(points, '#00FF00');            console.log(points);        }    );    electricUnderPoints.push([16.690666, -0.79, -55.115203999999999]);    buildLine(electricUnderPoints, '#00FF00');    renderOrder();}function gas() {    var gasUnderPoints = [];    buildingOpacity(0.3);    app.query(/building_0/).forEach(        function (parentObj) {            var points = [];            points.push(parentObj.selfToWorld([-6.2, -0.3, 0]));            gasUnderPoints.unshift(points[0]);            for (var i = 3; i <= 24; i += 3) {                points.push(parentObj.selfToWorld([-6.2, i, 0]));                points.push(parentObj.selfToWorld([-6.2, i, 2]));                points.push(parentObj.selfToWorld([6.2, i, 2]));                points.push(parentObj.selfToWorld([6.2, i, -2]));                points.push(parentObj.selfToWorld([-6.2, i, -2]));                points.push(parentObj.selfToWorld([-6.2, i, 0]));            }            points.push(parentObj.selfToWorld([-6.2, 24, 0]));            buildLine(points, '#FF0000');            console.log(points);        }    );    gasUnderPoints.unshift([22.963023600000003, -0.3, 57.8305784]);    buildLine(gasUnderPoints, '#FF0000');    renderOrder();}/************************************************************************ * common*/function buildingOpacity(num) {    app.query("*").forEach(function (obj) {        obj.style.opacity = num;    });}function renderOrder(){    app.query('.PolygonLine').forEach(        function (obj) {            obj.renderOrder = -10000;        }    );}var line = null;function buildLine(points, color) {    line = app.create({        type: 'PolygonLine',        points: points,        style: {            color: color,        }    });    line.scrollUV = true;}

  

 现实中社区管线远比DEMO中复杂,开发者可以根据自身业务实际,使用开发出更多三维可视化应用。
 

转载地址:http://hotpo.baihongyu.com/

你可能感兴趣的文章
桌面云
查看>>
教大家如何在word 2007中同时打出对齐上下标以及字母头上有波浪线(非编辑器)...
查看>>
Spring Boot五:使用properties配置文件实现多环境配置
查看>>
vim取消高亮显示
查看>>
设计从“心“开始
查看>>
windows7 系统盘 瘦身软件介绍: 冗余文件清理工具
查看>>
SSH整合步骤
查看>>
myeclipse tomcat内存溢出解决方法
查看>>
zabbix之Web网络监控
查看>>
微软SQL Server 2012新特性Silverlight报表客户端 - Power View
查看>>
CentOS 6.2利用drbd+pacemaker实现redis高可用
查看>>
网络安全系列之四十六 在IIS6中配置目录安全性
查看>>
RedHat 5.4 日志服务器学习笔记
查看>>
实例学习SSIS(二)-- 使用迭代
查看>>
自动加入域脚本
查看>>
我的程序人生--语言学习之路
查看>>
inotify+rsync+mutt+msmtp 实现linux文件或者目录自动更新并且实现发邮件给管理员
查看>>
iphone开发之获取系统背光灯亮度
查看>>
Windows Server入门系列40 网络共享权限设置
查看>>
Provisioning Services 7.8 入门系列教程之十四 UEFI支持和BOOTPTAB 编辑器
查看>>