three.js加载obj模型
来源:互联网 发布:北京天际网络 编辑:程序博客网 时间:2024/05/29 09:50
其实在我们工作中用three.js最大的功能是:加载模型,然后展示在浏览器端,支持鼠标事件和键盘事件,标注等,以后的文章会详细对每个进行讲解。
今天主要给大家分享一下怎么加载obj模型(如果模型太大的话,建议转换为json然后再加载后面的文章会分享怎么加载json格式的),加载模型还是离不开那五大步骤不知道的可以查看three.js入门基础这里就不说了,也可以看下面的代码注释:
if (!Detector.webgl) Detector.addGetWebGLMessage();var container, stats;var camera, cameraTarget, scene, renderer;var mouseX = 0, mouseY = 0;var threeModel = document.getElementById('show3dmodel');var windowHalfX = window.innerWidth / 2;var windowHalfY = window.innerHeight / 2;function init() { //初始化场景、相机、光、模型 var threeModel = document.getElementById('show3dmodel'); container = document.createElement('div'); threeModel.appendChild(container); camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 10000); camera.position.set(8, 10, 8); //设置场景 scene = new THREE.Scene(); // 设置网格 var helper = new THREE.GridHelper(20,2,'#18B756','#B38BB0'); scene.add(helper); // 设置纹理 var manager = new THREE.LoadingManager(); manager.onProgress = function (item, loaded, total) { console.log(item, loaded, total); }; //加载模型 var loader = new THREE.OBJMTLLoader(); loader.load('./files/location_skybox.obj', './files/location_skybox.mtl', function (object) { scene.add(object); camera.lookAt(object.position); }, onProgress, onError); // 追加环境光 scene.add(new THREE.AmbientLight(0x777777,1.0,0)); addShadowedLight(1, 1, 1, 0xffffff, 1.35); addShadowedLight(0.5, 1, -1, 0xffaa00, 1); //生成渲染器对象 renderer = new THREE.WebGLRenderer(); renderer.setPixelRatio(window.devicePixelRatio); renderer.setSize(window.innerWidth, window.innerHeight); container.appendChild(renderer.domElement); // stats 性能检测器 stats = new Stats(); stats.domElement.style.position = 'absolute'; stats.domElement.style.top = '0px'; container.appendChild(stats.domElement); window.addEventListener('resize', onWindowResize, false);}function onWindowResize() { windowHalfX = window.innerWidth / 2; windowHalfY = window.innerHeight / 2; camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); controls.handleResize();}//追加阴影function addShadowedLight(x, y, z, color, intensity) { var directionalLight = new THREE.DirectionalLight(color, intensity); directionalLight.position.set(x, y, z) scene.add(directionalLight); directionalLight.castShadow = true; var d = 1; directionalLight.shadowCameraLeft = -d; directionalLight.shadowCameraRight = d; directionalLight.shadowCameraTop = d; directionalLight.shadowCameraBottom = -d; directionalLight.shadowCameraNear = 1; directionalLight.shadowCameraFar = 4; directionalLight.shadowMapWidth = 1024; directionalLight.shadowMapHeight = 1024; directionalLight.shadowBias = -0.005; directionalLight.shadowDarkness = 0.15;} //循环调用function animate() { requestAnimationFrame(animate); render(); stats.update();} // 为以后鼠标事件和键盘事件重新定位相机位置和重新渲染function render() { camera.lookAt(scene.position); renderer.render(scene, camera);}
阅读全文
0 0
- three.js加载obj模型
- three.js加载obj模型
- three.js加载obj模型
- three.js加载obj模型 键盘控制模型局部动作
- three.js学习笔记 obj模型加载问题
- three.js学习笔记 obj模型加载问题 (转)
- three.js 如何加载obj
- Three.js学习笔记——3dsmax 加载obj模型
- three.js加载vtk模型
- three.js 外部模型加载json
- opengl加载obj模型
- OpenGL---加载obj模型
- OpenGL -- OBJ 模型加载
- HTML5 WebGL Three.js 加载 3D模型文件
- 解决three.js加载外部obj文件在chrome浏览器中无法显示的问题
- Three.js MMDLoader.js Mmd模型的加载 pmx模型加载测试
- three.js加载纹理
- DirectX-3d中.x模型转换成three.js可用的obj文件或者js文件
- Simple Strings CodeForces
- NSData NSString格式相互转换
- 安卓四大组件之activity笔记
- 用Python调度数据在Mysql及Hive间进行计算2例
- python数据分析
- three.js加载obj模型
- python with语句
- 一行代码实现Okhttp,Retrofit,Glide下载上传进度监听
- 中式装修木雕花格有哪些特点, 中式装修木雕花格寓意
- configure配置安装详解
- android开发,如何实现通过上拉由一个activity切换到另一个activity
- umeng(友盟)实现第三方登录和分享详解之分享
- Eclipse 常用快捷键
- Ubuntu16.04LTS安装zsh+oh-my-zsh+autojump