【verge3D】为web3D开启陀螺仪功能

我想要实现在v3d中通过陀螺仪控制相机的方向,在v3d的示例中,我找到了misc_controls_deviceorientation.html,这是官方实现这个功能的示例。示例在SDK中,由于v3d是基于three.js的,在three.js官网的示例中有对应的演示:

https://threejs.org/examples/#misc_controls_deviceorientation

阅读代码发现,关键是调用一个DeviceOrientationControls.js的库。由于我想要以后继续使用拼图创建交互,所以我需要在player的基础上增加这个功能。实现步骤如下。

1.通过app管理器创建一个应用“my_awesome_app”。

2.在生成的my_awesome_app.html中引入DeviceOrientationControls.js,这个文件的位置在verge3d/examples/js/controls下面,把它拷贝到你的程序目录下。

<script src="DeviceOrientationControls.js"></script>

3.在生成的my_awesome_app.js中runCode函数中加入如下代码:


function runCode(app) {
// add your code here, e.g. console.log('Hello, World!');
// 陀螺仪控制方向
var camera, scene, renderer, controls;
camera = app.camera;
scene = app.scene;
renderer = app.renderer;
controls = new v3d.DeviceOrientationControls( camera );
animate();
function animate() {
window.requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );
}
}
});

视频演示:https://www.bilibili.com/video/av28704507/

360全景图示例:

扫码在手机上打开

http://zjbcool.com/static/assets/gyro/gyro.html

发布了15 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/zjbcool/article/details/81750456