Using AlloyTouch to control three.js 3D model
As you can see, the above cube rotation, acceleration, deceleration stop all through the AlloyTouch to achieve.
Demo(Mobile)
Code
<script src="asset/three.js"></script>
<script src="../../alloy_touch.js"></script>
<script>
var camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 500;
var scene = new THREE.Scene();
var texture = new THREE.TextureLoader().load( 'asset/crate.gif' );
var geometry = new THREE.BoxBufferGeometry( 200, 200, 200 );
var material = new THREE.MeshBasicMaterial( { map: texture } );
var mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
var renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
}
animate();
new AlloyTouch({
touch: document, //touch the whole document
vertical: false, //monitor horizontal touch
target: mesh.rotation, //animate mesh.rotation's y property
property: "y",
factor: 0.08, //friction coefficient
moveFactor: 0.2 //touch move friction coefficient
})
</script>
factor need to continue to debug the best value for the speed and time of inertial motion let go after the best effect.
moveFactor need to continue to debug the best value, is to let the lateral drag distance map to achieve the rotation angle.
If you don't need an inertial motion. For example, the king of glory in the task rotation is not inertia, the finger left the screen will immediately stop moving. Such as:
You only need to set the AlloyTouch inertia to false.
Non inertia demo
Code
<script src="asset/three.js"></script>
<script src="../../alloy_touch.js"></script>
<script>
...
...
...
animate();
new AlloyTouch({
touch: document,
vertical: false,
target: mesh.rotation,
property: "y",
factor: 0.08,
moveFactor: 0.2 ,
inertia: false //disable the inertia animation
})
</script>
AlloyTouch
Github:https://github.com/AlloyTeam/AlloyTouch
Any question, please let me know:https://github.com/AlloyTeam/AlloyTouch/issues
Using AlloyTouch to control three.js 3D model的更多相关文章
- three.js 3d三维网页代码加密的实现方法
http://www.jiamisoft.com/blog/17827-three-js-3dsanweiwangyejiami.html https://www.html5tricks.com/ta ...
- 排名前10的H5、Js 3D游戏引擎和框架
由于很多人都在用JavaScript.HTML5和WebGL技术创建基于浏览器的3D游戏,所有JavaScript 3D游戏引擎是一个人们主题.基于浏览器的游戏最棒的地方是平台独立,它们能在iOS.A ...
- Make3D Convert your image into 3d model
Compiling and Running Make3D on your own computer source: http://make3d.cs.cornell.edu/code_linux.ht ...
- 3d模型 手办制作 3d model manual production
3d模型 手办制作 3d model manual production 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱:313134555@qq.com E-mail: 313 ...
- QT Graphics-View 3D编程例子- 3D Model Viewer
学习在Graphics-View框架中使用opengl进行3D编程,在网上找了一个不错的例子“3D Model Viewer”,很值得学习. 可以在http://www.oyonale.com/acc ...
- Backbone.js之model篇(一)
Backbone.js之model篇(一) Backbone 是一个前端 JS 代码 MVC 框架,它不可取代 Jquery,不可取代现有的 template 库.而是和这些结合起来构建复杂的 web ...
- WPF 3D model - Sphere, Cone, and Cylinder
原文:WPF 3D model - Sphere, Cone, and Cylinder Extending Visual3D - Sphere, Cone, and Cylinder http: ...
- ShapeNet: An Information-Rich 3D Model Repository 阅读笔记
ShapeNet: An Information-Rich 3D Model Repository 注:本论文只是讲述数据库建立方法 摘要 ShapeNet是一个有丰富注释的大型形状存储库,由对象的3 ...
- AlloyTouch与three.js 3D模型交互
如你所见,上面的cube的旋转.加速.减速停止都是通过AlloyTouch去实现的. 演示 代码 <script src="asset/three.js"></s ...
随机推荐
- OpenGL ES 3.0: 图元重启(Primitive restart)
[TOC] 背景概述 在OpenGL绘制图形时,可能需要绘制多个并不相连的图形.这样的情况下这几个图形没法被当做一个图形来处理.也就需要多次调用 DrawArrays 或 DrawElements. ...
- BZOJ 3894: 文理分科 [最小割]
3894: 文理分科 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 674 Solved: 392[Submit][Status][Discuss] ...
- 面向未来的友好设计:Future Friendly
一年前翻译了本文的一部分,最近终于翻译完成.虽然此设计思想的提出已经好几年了,但是还是觉得应该在国内推广一下,让大家知道“内容策略”,“移动优先”,“响应式设计”,“原子设计”等设计思想和技术的根源. ...
- 如何从本地导入.nupkg文件
买了本asp.net mvc4高级编程 里面的源码下载下来是.nupkg后缀的文件,不知道怎么引入到项目中, baidu无果,只好google,可怜我英语四级都难的人,不过所幸还是找到了方法: htt ...
- ABP框架 - 依赖注入
文档目录 本节内容: 什么是依赖注入 传统方式的问题 解决方案 构造器注入模式 属性注入模式 依赖注入框架 ABP 依赖注入基础 注册依赖 约定注入 辅助接口 自定义/直接 注册 使用IocManag ...
- 设置Fn键 笔记本直接按F1-F12 无须按Fn键 Fn+F12改F12(联想小新300为例)
最近公司给配的笔记本联想小新300 80RT i7-6500U 4G内存 500G机械,后加装120G固态+4G内存 这样就感觉还不错了. 在使用这本子的时候,去了Win10,强行装了Win7.无线 ...
- springmvc注解事例
注解有简化 ,灵活性增强的功能 1.引入jar包 com.springsource.javax.validation-1.0.0.GA.jarcom.springsource.org.aopallia ...
- mongoose - 让node.js高效操作mongodb
Mongoose库简而言之就是在node环境中操作MongoDB数据库的一种便捷的封装,一种对象模型工具,类似ORM,Mongoose将数据库中的数据转换为JavaScript对象以供你在应用中使用. ...
- $(document).ready() 与window.onload的区别
1.执行时间 window.onload必须等到页面内包括图片的所有元素加载完毕后才能执行. $(document).ready()是DOM结构绘制完毕后就执行,不必等到加载完毕. 2.编写个数不同 ...
- Hadoop的数据管理
Hadoop的数据管理,主要包括Hadoop的分布式文件系统HDFS.分布式数据库HBase和数据仓库工具Hive的数据管理. 1.HDFS的数据管理 HDFS是分布式计算的存储基石,Hadoop分布 ...