You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
4.4 KiB

  1. var scene = new THREE.Scene();
  2. var camera = new THREE.PerspectiveCamera(20, window.innerWidth / window.innerHeight, 0.1, 1000);
  3. var renderer = new THREE.WebGLRenderer();
  4. var o1, o2, o3, o4, o5, o6;
  5. var zoom = 1.0;
  6. var fov = camera.fov;
  7. var targetList = [];
  8. renderer.setSize(window.innerWidth, window.innerHeight);
  9. renderer.setClearColor(0xffffff, 1);
  10. document.body.appendChild(renderer.domElement);
  11. /*var geometry = new THREE.BoxGeometry(1, 1, 1);
  12. var material = new THREE.MeshBasicMaterial({
  13. color: 0x00ff00,
  14. transparent:true,
  15. opacity:0.8,
  16. shading: THREE.FlatShading,
  17. vertexColors: THREE.VertexColors
  18. });
  19. var cubeMaterials = [
  20. new THREE.MeshBasicMaterial({color:0xff0000, transparent:true, opacity:0.8, side: THREE.DoubleSide}),
  21. new THREE.MeshBasicMaterial({color:0x00ff00, transparent:true, opacity:0.8, side: THREE.DoubleSide}),
  22. new THREE.MeshBasicMaterial({color:0x0000ff, transparent:true, opacity:0.8, side: THREE.DoubleSide}),
  23. new THREE.MeshBasicMaterial({color:0xffff00, transparent:true, opacity:0.8, side: THREE.DoubleSide}),
  24. new THREE.MeshBasicMaterial({color:0xff00ff, transparent:true, opacity:0.8, side: THREE.DoubleSide}),
  25. new THREE.MeshBasicMaterial({color:0x00ffff, transparent:true, opacity:0.8, side: THREE.DoubleSide}),
  26. ];
  27. var cubeMaterial = new THREE.MeshFaceMaterial(cubeMaterials);
  28. var cube = new THREE.Mesh(geometry, cubeMaterial);
  29. scene.add(cube);*/
  30. //robot
  31. var geometry = new THREE.BoxGeometry( 0.1, 0.1, 0.1 );
  32. var material = new THREE.MeshBasicMaterial( { color: 0xffffff } );
  33. var base = new THREE.Mesh( geometry, material );
  34. scene.add( base );
  35. base.name="base";
  36. /* object 3d exemple */
  37. var mtlLoader = new THREE.MTLLoader();
  38. mtlLoader.setPath( './models3d/bus/' );
  39. mtlLoader.load( 'Ideale 770.mtl', function( materials ) {
  40. materials.preload();
  41. var objLoader = new THREE.OBJLoader();
  42. objLoader.setMaterials( materials );
  43. objLoader.setPath( './models3d/bus/' );
  44. objLoader.load( 'Ideale 770.obj', function ( object ) {
  45. o2=object;
  46. o2.name="o2";
  47. base.add( o2 );
  48. }, onProgress, onError);
  49. });
  50. /* quan tinc 6 peces
  51. var objURL = "./models3d/o1.obj";
  52. var loader = new THREE.OBJLoader();
  53. loader.load(objURL, function ( object ) {
  54. o1=object;
  55. o1.name="o1";
  56. base.add( o1 );
  57. objURL = "./models3d/o2.obj";
  58. loader = new THREE.OBJLoader();
  59. loader.load(objURL, function ( object ) {
  60. o2=object;
  61. o2.name="o2";
  62. o1.add( o2 );
  63. objURL = "./models3d/o3.obj";
  64. loader = new THREE.OBJLoader();
  65. loader.load(objURL, function ( object ) {
  66. o3=object;
  67. o3.name="o3";
  68. o2.add( o3 );
  69. objURL = "./models3d/o4.obj";
  70. loader = new THREE.OBJLoader();
  71. loader.load(objURL, function ( object ) {
  72. o4=object;
  73. o4.name="o4";
  74. o3.add( o4 );
  75. objURL = "./models3d/o5.obj";
  76. loader = new THREE.OBJLoader();
  77. loader.load(objURL, function ( object ) {
  78. o5=object;
  79. o5.name="o5";
  80. o4.add( o5 );
  81. objURL = "./models3d/o6.obj";
  82. loader = new THREE.OBJLoader();
  83. loader.load(objURL, function ( object ) {
  84. o6=object;
  85. o6.name="o6";
  86. o5.add( o6 );
  87. targetList.push(o1);
  88. targetList.push(o2);
  89. targetList.push(o3);
  90. targetList.push(o4);
  91. targetList.push(o5);
  92. targetList.push(o6);
  93. targetList.push(base);
  94. });
  95. });
  96. });
  97. });
  98. });
  99. });
  100. */
  101. //light
  102. var spotLight = new THREE.SpotLight( 0xffffff );
  103. spotLight.position.set( 500, 1000, 500 );
  104. spotLight.castShadow = true;
  105. spotLight.shadow.mapSize.width = 1024;
  106. spotLight.shadow.mapSize.height = 1024;
  107. spotLight.shadow.camera.near = 500;
  108. spotLight.shadow.camera.far = 4000;
  109. spotLight.shadow.camera.fov = 30;
  110. scene.add( spotLight );
  111. //camera
  112. /*camera.position.z=5;
  113. camera.position.y=4;
  114. camera.position.x=0;
  115. camera.rotation.x= -0.62;*/
  116. base.rotation.y = 2;
  117. camera.position.z=5;
  118. camera.position.y=2;
  119. camera.position.x=0;
  120. camera.rotation.x= -0.42;
  121. //render
  122. var render= function (){
  123. requestAnimationFrame(render);
  124. /*cube.rotation.x +=0.1;
  125. cube.rotation.y +=0.1;*/
  126. renderer.render(scene, camera);
  127. };
  128. render();