如果没有设置进入VR时的初始视角,当进入到VR模式时就是之前最后正常模式停留的视角,也许这并不是制作者希望浏览者想看到的角度,因此就需要在进入VR以及VR场景之间切换时设置一下进入VR的初始视角。
下面的代码是通用的,前提是你的webvr插件的name是WebVR,代码粘贴到任意位置即可,只要不是scene的里面就可以。
点击代码窗口最右侧按钮,在新窗口打开后复制代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<!-- 添加到进入VR的onentervr --> <action name="webvrhlookat" autorun="onstart"> txtadd(plugin[WebVR].onentervr,'lookat(view.hlookat,0);setvrlookat();',get(plugin[WebVR].onentervr)); </action> <!-- 0 1 2 对应场景的index序号,是从0开始算的,如果场景较多,也可以直接用scene的name进行判断,resetSensor里面是视角的水平坐标值,相当于view.hlookat --> <action name="setvrlookat" > if(scene[get(xml.scene)].index == 0,webvr.resetSensor(90)); if(scene[get(xml.scene)].index == 1,webvr.resetSensor(135)); if(scene[get(xml.scene)].index == 2,webvr.resetSensor(180)); </action> <events name="setvrhlookat" keep="true" onnewpano="if(webvr.isenabled, if(scene[get(xml.scene)].index == 0,webvr.resetSensor(90);lookat(view.hlookat,0);); if(scene[get(xml.scene)].index == 1,webvr.resetSensor(135);lookat(view.hlookat,0);); if(scene[get(xml.scene)].index == 2,webvr.resetSensor(180);lookat(view.hlookat,0);); )"/> |
点击代码窗口最右侧按钮,在新窗口打开后复制代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<!-- 添加到进入VR的onentervr --> <action name="webvrhlookat" autorun="onstart"> txtadd(plugin[WebVR].onentervr,'lookat(view.hlookat,0);setvrlookat();',get(plugin[WebVR].onentervr)); </action> <!-- 直接用scene的name进行判断,resetSensor里面是视角值 --> <action name="setvrlookat" > if(xml.scene == 'scene_01',webvr.resetSensor(90)); if(xml.scene == 'scene_02',webvr.resetSensor(135)); if(xml.scene == 'scene_03',webvr.resetSensor(180)); </action> <events name="setvrhlookat" keep="true" onnewpano="if(webvr.isenabled, if(xml.scene == 'scene_01',webvr.resetSensor(90);lookat(view.hlookat,0);); if(xml.scene == 'scene_02',webvr.resetSensor(135);lookat(view.hlookat,0);); if(xml.scene == 'scene_03',webvr.resetSensor(180);lookat(view.hlookat,0);); )"/> |