基於WebGL架構的3D可視化平臺—新風系統演示

新風系統是根據在密閉的室內一側用專用設備向室內送新風,再從另外一側由專用設備向室外排出,在室內會造成「新風流動場」,從而知足室內新風換氣的須要。實施方案是:採用高風壓、大流量風機、依靠機械強力由一側向室內送風,由另外一側用專門設計的排風風機向室外排出的方式強迫在系統內造成新風流動場。在送風的同時對進入室內的空氣進過濾、消毒、殺菌、增氧、預熱(冬天)。html

接下來就用ThingJs平臺來搭建一個新風系統數組

第一步,利用CampusBuilder搭建模擬場景。CampusBuilder的模型庫有各類各樣的模型,使咱們搭建出的場景更逼真。
v2-08579a7d34b6108e4c5887f3944e0c7c_hd.jpgapp

//加載場景代碼
var app = new THING.App({
    // 場景地址
    "url": "http://www.thingjs.com/./uploads/wechat/oLX7p05lsWJZUIxnIWsNXAzJ40X8/scene/新風演示2",

});

第二步,建立三個數組來保存每一個風的模型。、ide

var hotWindGroup = [];
var coolWindGroup = [];
var newWindGroup = [];
var wind = null;

第三步,構造一個建立風的函數,爲了方便建立風及其位置,咱們選取排風設備爲風的父物體,將建立出來的風的visiable屬性設置爲false(這裏這個座標問題能夠看一下官網的教程中控制物體中的座標轉換)。函數

function createWind(parent, x, y, angle, localPosition, color, group) {
    rs = app.query(parent)[0];
    wind = app.create({
        type: 'Thing',
        name: 'hotWind',
        url: 'http://model.3dmomoda.cn/models/4da706d8a37047298c0318a5b9546abd/0/gltf/',
        localPosition: localPosition,
        scale: [1, 2, 1],
        angle: angle,
        parent: rs,
    });
    wind.style.color = color;
    wind.visible = false;
    wind.rotateX(x);
    wind.rotateY(y);
    group.push(wind);
}

第四步,開始建立風模型,並調整一下攝像機的角度及位置。ui

app.on('load', function () {
    //攝像機角度
    app.camera.position = [-22.91452445633646, 30.46296743148116, -23.83548169673341];
    app.camera.target = [-13.532807014407252, 5.6565539015865856, -3.3431546399681276];
    //hotWind
    createWind('空調1', 0, 0, 0, [0, -2, 0], '#FF0000', hotWindGroup);
    createWind('空調1', 0, 0, 0, [0, -2, 0.5], '#FF0000', hotWindGroup);
    createWind('空調1', 0, 0, 0, [0, -2, 1], '#FF0000', hotWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 0], '#FF0000', hotWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 0.5], '#FF0000', hotWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 1], '#FF0000', hotWindGroup);
    //coolWind
    createWind('空調1', 0, 0, 0, [0, -2, 0], '#0000FF', coolWindGroup);
    createWind('空調1', 0, 0, 0, [0, -2, 0.5], '#0000FF', coolWindGroup);
    createWind('空調1', 0, 0, 0, [0, -2, 1], '#0000FF', coolWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 0], '#0000FF', coolWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 0.5], '#0000FF', coolWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 1], '#0000FF', coolWindGroup);
    //newWind
    createWind('排風1', -50, 0, 0, [0, -0.5, 2], '#00FF00', newWindGroup);
    createWind('排風1', -50, 0, 0, [0, -0.5, 4], '#00FF00', newWindGroup);
    createWind('排風1', -50, 0, 0, [0, -0.5, 6], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [2, -0.5, 7], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [4, -0.5, 8], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [6, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [8, -0.5, 12], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [10, -0.5, 15], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [12, -0.5, 18], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [10, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [14, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [18, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [22, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [26, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風2', -50, 0, 0, [0, -0.5, 2], '#00FF00', newWindGroup);
    createWind('排風3', -50, 0, 0, [0, -0.5, 2], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 2], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 4], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 6], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 8], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 10], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 12], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 50, [2, -0.6, 12], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 50, [4, -0.7, 12], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 50, [6, -0.8, 13], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 90, [8, -0.8, 11], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 90, [12, -0.8, 9], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 90, [16, -0.8, 7], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 90, [20, -0.8, 5], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 90, [24, -0.8, 3], '#00FF00', newWindGroup);
    createWind('排風4', -90, 0, 90, [8, -0.8, 13], '#00FF00', newWindGroup);
    createWind('排風4', -90, 0, 90, [12, -0.8, 13], '#00FF00', newWindGroup);
    createWind('排風4', -90, 0, 90, [16, -0.7, 13], '#00FF00', newWindGroup);
    createWind('排風4', -90, 0, 90, [20, -0.6, 13], '#00FF00', newWindGroup);
    //createWind('排風4', -90, 0, 90, [24, -0.5, 13], '#00FF00', newWindGroup);

    //熱風演示
    new THING.widget.Button('熱風演示', function () {
        for (let i of coolWindGroup) {
            i.visible = false;
        };
        for (let i of hotWindGroup) {
            i.visible = true;
        };

    });

    //冷風演示
    new THING.widget.Button('冷風演示', function () {
        for (let i of coolWindGroup) {
            i.visible = true;
        };
        for (let i of hotWindGroup) {
            i.visible = false;
        };
    });

    //新風演示
    new THING.widget.Button('新風演示', function () {
        playNewWind();
    });

    function playNewWind() {
        for (var i = 0; i < newWindGroup.length; i++) {
            if(i==newWindGroup.length-1)
            return;
            newWindGroup[i].visible = true;
            newWindGroup[i].moveTo({
                "time": 4000,
                "position": newWindGroup[i+1].position,
            });
        }
});

第五步,運行項目。演示地址url

思考與總結:spa

首先就是空間座標系下轉父物體座標真是弄暈了,看了官網的教程多少理解了一點。剛開始的時候我一直認爲個人子物體以父物體座標下放置的時候,子物體座標軸的問題指向的問題。看了教程發現本身的擔憂多餘了,就好像是人戴鴨舌帽帽子無論戴在誰的頭上都同樣。設計

其次就是讓風動起來,最初是想讓一個模型在空間中運動,發現效果很差用。最後就建立了多個模型他們對應着有各自的點,讓每個模型向他下一個模型的位置移動實現運動。3d

完整代碼

/加載場景代碼
var app = new THING.App({
    // 場景地址
    "url": "http://www.thingjs.com/./uploads/wechat/oLX7p05lsWJZUIxnIWsNXAzJ40X8/scene/新風演示2",

});

var hotWindGroup = [];
var coolWindGroup = [];
var newWindGroup = [];
var wind = null;

function createWind(parent, x, y, angle, localPosition, color, group) {
    rs = app.query(parent)[0];
    wind = app.create({
        type: 'Thing',
        name: 'hotWind',
        url: 'http://model.3dmomoda.cn/models/4da706d8a37047298c0318a5b9546abd/0/gltf/',
        localPosition: localPosition,
        scale: [1, 2, 1],
        angle: angle,
        parent: rs,
    });
    wind.style.color = color;
    wind.visible = false;
    wind.rotateX(x);
    wind.rotateY(y);
    group.push(wind);
}

app.on('load', function () {
    //攝像機角度
    app.camera.position = [-22.91452445633646, 30.46296743148116, -23.83548169673341];
    app.camera.target = [-13.532807014407252, 5.6565539015865856, -3.3431546399681276];
    //hotWind
    createWind('空調1', 0, 0, 0, [0, -2, 0], '#FF0000', hotWindGroup);
    createWind('空調1', 0, 0, 0, [0, -2, 0.5], '#FF0000', hotWindGroup);
    createWind('空調1', 0, 0, 0, [0, -2, 1], '#FF0000', hotWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 0], '#FF0000', hotWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 0.5], '#FF0000', hotWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 1], '#FF0000', hotWindGroup);
    //coolWind
    createWind('空調1', 0, 0, 0, [0, -2, 0], '#0000FF', coolWindGroup);
    createWind('空調1', 0, 0, 0, [0, -2, 0.5], '#0000FF', coolWindGroup);
    createWind('空調1', 0, 0, 0, [0, -2, 1], '#0000FF', coolWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 0], '#0000FF', coolWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 0.5], '#0000FF', coolWindGroup);
    createWind('空調2', 0, 0, 0, [0, -2, 1], '#0000FF', coolWindGroup);

    //newWind
    createWind('排風1', -50, 0, 0, [0, -0.5, 2], '#00FF00', newWindGroup);
    createWind('排風1', -50, 0, 0, [0, -0.5, 4], '#00FF00', newWindGroup);
    createWind('排風1', -50, 0, 0, [0, -0.5, 6], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [2, -0.5, 7], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [4, -0.5, 8], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [6, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [8, -0.5, 12], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [10, -0.5, 15], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [12, -0.5, 18], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [10, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [14, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [18, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [22, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風1', -50, 50, 50, [26, -0.5, 9], '#00FF00', newWindGroup);
    createWind('排風2', -50, 0, 0, [0, -0.5, 2], '#00FF00', newWindGroup);
    createWind('排風3', -50, 0, 0, [0, -0.5, 2], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 2], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 4], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 6], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 8], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 10], '#00FF00', newWindGroup);
    createWind('排風4', -50, 0, 0, [0, -0.5, 12], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 50, [2, -0.6, 12], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 50, [4, -0.7, 12], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 50, [6, -0.8, 13], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 90, [8, -0.8, 11], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 90, [12, -0.8, 9], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 90, [16, -0.8, 7], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 90, [20, -0.8, 5], '#00FF00', newWindGroup);
    createWind('排風4', -90, 50, 90, [24, -0.8, 3], '#00FF00', newWindGroup);
    createWind('排風4', -90, 0, 90, [8, -0.8, 13], '#00FF00', newWindGroup);
    createWind('排風4', -90, 0, 90, [12, -0.8, 13], '#00FF00', newWindGroup);
    createWind('排風4', -90, 0, 90, [16, -0.7, 13], '#00FF00', newWindGroup);
    createWind('排風4', -90, 0, 90, [20, -0.6, 13], '#00FF00', newWindGroup);
    //createWind('排風4', -90, 0, 90, [24, -0.5, 13], '#00FF00', newWindGroup);

    //熱風演示
    new THING.widget.Button('熱風演示', function () {
        for (let i of coolWindGroup) {
            i.visible = false;
        };
        for (let i of hotWindGroup) {
            i.visible = true;
            //playWind(i,[0,-0.6499999999999999,0],[0,-0.7234152255572697,0.46352549156242107],[0,-1.2683221215612903,1.2135254915624212],[0,-2.15,1.5])
        };

    });

    //冷風演示
    new THING.widget.Button('冷風演示', function () {
        for (let i of coolWindGroup) {
            i.visible = true;
        };
        for (let i of hotWindGroup) {
            i.visible = false;
        };
    });

    //新風演示
    new THING.widget.Button('新風演示', function () {
        playNewWind();
    });

    function playNewWind() {
        for (var i = 0; i < newWindGroup.length; i++) {
            if(i==newWindGroup.length-1)
            return;
            newWindGroup[i].visible = true;
            newWindGroup[i].moveTo({
                "time": 4000,
                "position": newWindGroup[i+1].position,
            });
        }
    }

});

做者:extends Thread

相關文章
相關標籤/搜索