| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 | /** * 说明:检测菜单项是否已打开 */function checkBtnActives(arr) {    for (let i = 0; i < arr.length; i++) {        let temp = arr[i];        if ($(temp).hasClass('active')) {            $(temp).removeClass('active');            $(temp).find('.control-menu').removeClass('actives');        }    }}/** * 说明:判断是否全屏 */function checkFull() {    var isFull =        document.fullscreenElement ||        document.mozFullScreenElement ||        document.webkitFullscreenElement;    //to fix : false || undefined == undefined    if (isFull === undefined) isFull = false;    return isFull;}/** * 说明:创建胶囊 */function createBox() {    if (box == null) {        box = app.create({            type: 'Thing',            url: 'https://model.3dmomoda.com/models/9CD08ED91F5C4E0ABB6B0833C86F2942/0/gltf/',            position: [0, 0, 0],            angle: 180,            scale: [1.7, 1.7, 1.7],            style: {                color: '#FF0000'            }        });    }}/** * 说明:第一人称行走 */function enterFps(pos) {    if (fpsCtrl == null) {        app.pauseEvent(THING.EventType.Pick, '*', THING.EventTag.LevelPickOperation);        app.pauseEvent(THING.EventType.KeyUp, null, '空格键切换视角');        app.camera.position = pos;  // 起始位置为鼠标点击时的位置        // 添加第一人称行走控件        fpsCtrl = app.addControl(            new THING.WalkControl({  // 参数可以动态修改                walkSpeed: 0.02,  // 行走速度                turnSpeed: 0.25,  // 右键旋转速度                gravity: 26,  // 物体重量                eyeHeight: 1.6,  // 人高度                jumpSpeed: 10,  // 按空格键 跳跃的速度                enableKeyRotate: false,  // 默认不开启键盘控制旋转                useCollision: true,  // 默认不开启碰撞检测                useGravity: true,  // 默认开启重力                groundObjects: [app.scene],  // 把整个场景都添加,可把楼层或其他需要检测的添加进入碰撞体系里 | 默认值 园区地板,如果园区过大,可取消提升性能                collisionObjects: [app.scene]  // 把整个场景都添加,可把楼层或其他需要检测的添加进入碰撞体系里 | 默认值 园区地板,如果园区过大,可取消提升性能            })        );    }}/** * 说明:退出第一人称行走 */function exitFps() {    app.removeControl(fpsCtrl);    fpsCtrl = null;    cameraFly(cameraInitPos[0], cameraInitPos[1]);    // 恢复默认双击事件    app.resumeEvent(THING.EventType.DBLClick, '*', THING.EventTag.LevelEnterOperation);    // 恢复默认点击事件    app.resumeEvent(THING.EventType.Click, '*', THING.EventTag.LevelBackOperation);    // 恢复默认拾取事件    app.resumeEvent(THING.EventType.Pick, '*', THING.EventTag.LevelPickOperation);    // 恢复默认键盘键抬起事件    app.resumeEvent(THING.EventType.KeyUp, null, '空格键切换视角');    $('#moveByFps').removeClass('active');}/** * 说明:开启小地图 */function createMiniMap() {    if (miniMapCtrl == null) {        // 添加小地图控件        miniMapCtrl = app.addControl(new THING.MiniMapControl({            width: 200,            height: 200,            position: THING.CornerType.LeftBottom,            opacity: 0.8,            scale: 1,            angle: 0,            mousewheel: true,            cameraViewImg: 'http://www.thingjs.com/static/images/minimap1.png',            cameraCenterImg: 'http://www.thingjs.com/static/images/minimap0.png'        }));        $('.minimap').css('border', '1px solid rgba(255, 255, 255, 0.8)');        $('.minimap').css('left', '3px');        $('.minimap').css('bottom', '3px');    } else {        destoryMiniMap();        createMiniMap();    }}/** * 说明:关闭小地图 */function destoryMiniMap() {    if (miniMapCtrl != null) {        app.removeControl(miniMapCtrl);        miniMapCtrl = null;    }}/** * 说明:全屏显示 */function fullScreen() {    let el = document.documentElement;    let rfs = el.requestFullScreen || el.webkitRequestFullScreen;    if (typeof rfs != "undefined" && rfs) {        rfs.call(el);    } else if (typeof window.ActiveXObject != "undefined") {        let wscript = new ActiveXObject("WScript.Shell");        if (wscript != null) {            wscript.SendKeys("{F11}");        }    }}/** * 说明:退出全屏 */function exitFullScreen() {    let el = document;    let cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.exitFullScreen;    if (typeof cfs != "undefined" && cfs) {        cfs.call(el);    } else if (typeof window.ActiveXObject != "undefined") {        let wscript = new ActiveXObject("WScript.Shell");        if (wscript != null) {            wscript.SendKeys("{F11}");        }    }}/** * 说明:摄像机飞行 */function cameraFly(position, target) {    // 摄像机飞行到某位置    app.camera.flyTo({        'position': position,        'target': target,        'time': 1000,        'complete': function () {        }    });}/** * 说明:自动旋转 */function startRotate() {    app.camera.enableRotate = false;  // 关闭默认的旋转操作    app.camera.enablePan = false;  // 关闭默认的平移操作    app.camera.enableZoom = false;  // 关闭默认的缩放操作    // 绕摄像机当前目标点旋转    app.camera.rotateAround({        target: app.camera.target,  // 围绕摄像机当前目标点        // object: obj,  // 环绕的物体 (object 与 target 的设置互斥)        speed: 4,  // 环绕飞行的时间(3min)        yRotateAngle: 360,  // 环绕y轴飞行的旋转角度        loopType: THING.LoopType.Repeat  // 设置循环类型    });}/** * 说明:停止自动旋转 */function stopRotate() {    app.camera.enableRotate = true;  // 开启默认的旋转操作    app.camera.enablePan = true;  // 开启默认的平移操作    app.camera.enableZoom = true;  // 开启默认的缩放操作    app.camera.stopRotateAround();    if (rotateTimer) {        clearTimeout(rotateTimer);        rotateTimer = null;    }}/** * 说明:重新开始转动,未进行任何操作5s后开始自动旋转 */function restarRotate() {    if (fpsCtrl != null || !$('#sceneSetting .control-menu-pane li.autoRotate').hasClass('selected')) {        return;    }    if (rotateTimer == null) {        rotateTimer = setTimeout(function () {            //  startRotate();        }, restartTime);    } else {        clearTimeout(rotateTimer);        rotateTimer = null;        restarRotate();    }}
 |