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