-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjloader.js
More file actions
109 lines (77 loc) · 2.63 KB
/
objloader.js
File metadata and controls
109 lines (77 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// 1. Creation of scene, camera and renderer objects
// scene object
var scene = new THREE.Scene;
// Camera object
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
// Renderer object
var renderer = new THREE.WebGLRenderer();
// size which we want to render for is given the bracket
renderer.setSize(window.innerWidth, window.innerHeight);
// add renderer element to canvas
document.body.appendChild(renderer.domElement);
// Adding controls to the window
var controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.25;
controls.enableZoom = true;
// Adding light parameters to the window
var keyLight = new THREE.DirectionalLight(new THREE.Color('hsl(30, 100%, 75%)'), 1.0);
keyLight.position.set(-100, 0, 100);
var fillLight = new THREE.DirectionalLight(new THREE.Color('hsl(240, 100%, 75%)'), 0.75);
fillLight.position.set(100, 0, 100);
var backLight = new THREE.DirectionalLight(0xffffff, 1.0);
backLight.position.set(100, 0, -100).normalize();
scene.add(keyLight);
scene.add(fillLight);
scene.add(backLight);
// var ambiLight = new THREE.AmbientLight(0x404040);
// ambiLight.position.set(100, 100, 100)
// scene.add(ambiLight);
// Loading material (MTLLoader) properties
// var mtlLoader = new THREE.MTLLoader();
// mtlLoader.setResourcePath('http://0.0.0.0:8000/obj%20data/');
// mtlLoader.setPath('http://0.0.0.0:8000/obj%20data/');
// mtlLoader.load('mesh.mtl', function (materials) {
// materials.preload();
// var objLoader = new THREE.OBJLoader();
// objLoader.setMaterials(materials);
// objLoader.setPath('http://0.0.0.0:8000/obj%20data/');
// objLoader.load('mesh.obj', function (object) {
// scene.add(object);
// // object.position.y -= 60;
// console.log('loaded done')
// },
// function(xhr){
// console.log('ongoing')
// },
// function(error){
// console.log('fail')
// });
// });
var loader = new THREE.OBJLoader();
// load a resource
loader.load(
// resource URL
'http://0.0.0.0:8000/obj%20data/mesh.obj',
// called when resource is loaded
function ( object ) {
// object.position.y -=60;
scene.add( object );
},
// called when loading is in progresses
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
// Updating the frame everytime we change the frame
var animate = function(){
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
};
animate();