关于VR技术
一分钟VR简史
关于A-Frame
结合three.js和WebGL的力量
通过自定义标签创建WebVR,标签具有可读性
具有跨平台性,支持PC端、Mobile端以及头戴设备Oculus Rift和HTC Vive
减少开发成本,降低初学者与牛人之间学习曲线
底层模块化和可扩展性
A-Frame功能
A-Frame实例
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>demo</title>
<script src="aframe-v0.3.0.js"></script>
</head>
<body>
<a-scene>
</a-scene>
</body></html>
创建画布,渲染器以及渲染循环
默认的相机和光影
创建WebVR Polyfill,VREffect
添加用户界面进入VR,调用WebVR API
<a-scene>
<a-assets>
<img id="lake" src="lake.jpg">
</a-assets>
<a-sky src="#lake"></a-sky></a-scene>
<a-scene>
<a-entity position="0 0 3.8">
<a-camera></a-camera>
</a-entity></a-scene>
<a-scene>
<!-- 球面 -->
<a-sphere position="0 1.25 -1" radius="1.25" color="#ef2d5e"></a-sphere>
<!-- 立方体 -->
<a-box position="-1 0.5 1" rotation="0 45 0" width="1" height="1" depath="1" color="#4cc3d9"></a-box>
<!-- 圆柱 -->
<a-cylinder position="1 0.75 1" radius="0.5" height="1.5" color="#ffc65d"></a-cylinder>
<!-- 平面 -->
<a-plane rotation="-90 0 0" width="4" height="4" color="#7bc8a4"></a-plane></a-scene>
position
定位实体x、y、z轴的位置rotation
调整实体x、y、z轴的旋转角度color
改变实体的颜色depth
景深width
、height
设置实体的宽高radius
圆角半径数值是以“米”为单位
<a-scene>
<a-sphere position="0 1.25 -1" radius="1.25" color="#ef2d5e">
<!-- 缩放 -->
<a-animation attribute="scale" from="1 1 1" to="1.2 1.2 1.2" repeat="indefinite" direction="alternate" dur="2000"></a-animation>
</a-sphere>
<a-box position="-1 0.5 1" rotation="0 45 0" width="1" height="1" depath="1" color="#4cc3d9">
<!-- 旋转 -->
<a-animation attribute="rotation" from="0 45 0" to="0 360 0" repeat="indefinite" direction="alternate"></a-animation>
</a-box>
<a-cylinder position="1 0.75 1" radius="0.5" height="1.5" color="#ffc65d">
<!-- 改变高度 -->
<a-animation attribute="height" from="1.5" to="0" repeat="indefinite" direction="alternate"></a-animation>
</a-cylinder></a-scene>
attribute
定义要执行的动画属性from
动画的起始to
动画的结束repeat
定义了要循环的次数,可以是一个数字或indefinite表示无限循环dur
动画的时长direction
动画轮流反向播放
<a-scene>
<a-box cursor-listener position="-1 0.5 1" rotation="0 45 0" width="1" height="1" depath="1" color="#4cc3d9">
<a-animation attribute="rotation" from="0 45 0" to="0 360 0" repeat="indefinite" direction="alternate"></a-animation>
</a-box>
<a-entity position="0 0 3.8">
<a-camera>
<!-- 创建光标 -->
<a-cursor color="#000"></a-cursor>
</a-camera>
</a-entity></a-scene>
// 添加光标监听器AFRAME.registerComponent("cursor-listener", {
init: function() {
var COLORS = ["#6c8cbf", "#e4f0ff", "#6c70e1"];
// 点击随机改变立方体颜色
this.el.addEventListener("click", function() {
var randomIndex = Math.floor(Math.random() * COLORS.length);
this.setAttribute("color", COLORS[randomIndex]);
});
}});
A-Frame社区
A-Frame资源
参考资料:
http://en.wikipedia.org/wiki/Virtual_reality
https://en.wikipedia.org/wiki/Sensorama
https://en.wikipedia.org/wiki/Sega_VR
https://en.wikipedia.org/wiki/Virtual_Boy
https://en.wikipedia.org/wiki/Oculus_Rift
http://aframe.io/
https://github.com/aframevr/aframe
https://twitter.com/aframevr
感谢您的阅读,本文由 凹凸实验室 版权所有。如若转载,请注明出处:凹凸实验室
本文分享自微信公众号 - 凹凸实验室(AOTULabs)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。