stlloadertest.html:

 <!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - STL</title>
<script src="build/three.js"></script>
<script src="js/loaders/STLLoader.js"></script>
<script type="text/javascript" src="js/controls/OrbitControls.js"></script>
<script type="text/javascript" src="stlloadertest.js"></script>
</head> <body onload="init()">
<div>
<canvas id="mainCanvas" width="1000px" height="600px" ></canvas>
</div>
</body>
</html>

stlloadertest.js:

 var camera, cameraTarget, scene, renderer,controlls,loader,material,mesh;

 function init() {

     //camera
camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 0, 0, 500 ); cameraTarget = new THREE.Vector3( 0, 0, 0 );
camera.lookAt( cameraTarget ); //scene
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x72645b );
scene.add(camera); // renderer
renderer = new THREE.WebGLRenderer({
canvas: document.getElementById('mainCanvas')
}); renderer.setSize( window.innerWidth, window.innerHeight ); // a cube in the scene
cube = new THREE.Mesh(new THREE.CubeGeometry(50, 50, 50),
new THREE.MeshBasicMaterial({
color: 0xff0000 //red
})
);
cube.position.set(50,0,0);
scene.add(cube); // ASCII file
//导入dayan.stl
loader = new THREE.STLLoader();
loader.load( 'stl/ascii/dayan.stl', function ( geometry ) { material = new THREE.MeshPhongMaterial( { color: 0xff5533, specular: 0x111111, shininess: 200 } );
mesh = new THREE.Mesh( geometry, material ); mesh.position.set( 1, 0, 0 );
mesh.rotation.set( -Math.PI/2, 0, 0 );
//Math.PI
mesh.scale.set( 1, 1, 1 ); mesh.castShadow = true;
mesh.receiveShadow = true; scene.add( mesh ); render(); } ); // Lights
scene.add( new THREE.HemisphereLight( 0x443333, 0x111122 ) );
addShadowedLight( 1, 1, 1, 0xffffff, 1.35 ); //controlls
controls = new THREE.OrbitControls( camera ,renderer.domElement );
controls.addEventListener( 'change', render ); } 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.shadow.camera.left = -d;
directionalLight.shadow.camera.right = d;
directionalLight.shadow.camera.top = d;
directionalLight.shadow.camera.bottom = -d; directionalLight.shadow.camera.near = 1;
directionalLight.shadow.camera.far = 4; directionalLight.shadow.mapSize.width = 1024;
directionalLight.shadow.mapSize.height = 1024; directionalLight.shadow.bias = -0.005; } function render() {
renderer.render( scene, camera );
}

最新文章

  1. 利用 autoconf 和 automake 生成 Makefile 文件
  2. POJ 2653 Pick-up sticks【线段相交】
  3. 如何自己编写一个easyui插件续
  4. SQL基础(2)-约束
  5. codeforces A. Vasya and Digital Root 解题报告
  6. hdu 2258 优先队列
  7. Java学习之DBUtils工具的学习
  8. Java Socket实现HTTP客户端来理解Session和Cookie的区别和联系
  9. CodeForces 670A Holidays
  10. arm的编译器里已经有C标准库的lib包了,android为啥还要自己再实现呢
  11. gulp+browserSync自动刷新页面
  12. spring boot添加 LocalDateTime 等 java8 时间类序列化和反序列化的支持
  13. 进程,线程,协程,异步IO知识点
  14. 【oacle入门】表空间类型
  15. gulp简介
  16. Python开发 基礎知識 3.類別&amp;方法 (bool &amp; str) (未完待續)
  17. Linux上跑MySQL优化技巧
  18. php面向对象 封装继承多态 接口、重载、抽象类、最终类总结
  19. 使用process_monitor.sh监控hadoop进程的crontab配置
  20. JAVA使用Gecco爬虫 抓取网页内容(附Demo)

热门文章

  1. MySQL 索引性能分析概要
  2. java 子类不能继承父类的static方法
  3. PBR工作流
  4. weal woe
  5. Java保留字和关键字
  6. 在Docker上安装配置Oracle教程
  7. Oracle 11g数据库详解(2)
  8. 判断json格式中是否含有key
  9. 正则表达式 - JavaScript描述
  10. java基础知识框图