-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
107 lines (81 loc) · 2.74 KB
/
main.js
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
var scene, camera, renderer;
var mousePos;
var figure;
var sun;
var game;
var deltaTime = 0;
var newTime = new Date().getTime();
var oldTime = new Date().getTime();
var Colors = {
red: 0xf25346,
white: 0xd8d0d1,
brown: 0x59332e,
pink: 0xF5986E,
brownDark: 0x23190f,
blue: 0x68c3c0,
};
init();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.z = 10;
camera.position.y = 2;
var ambientLight = new THREE.AmbientLight(0x404040); // soft white light
scene.add(ambientLight);
var geomSun = new THREE.BoxGeometry(1, 1, 1, 1, 1, 1);
var matSun = new THREE.MeshPhongMaterial({ color: Colors.red, shading: THREE.FlatShading })
sun = new THREE.Mesh(geomSun, matSun);
sun.position.set(5, 5, -1);
scene.add(sun);
var light = new THREE.DirectionalLight(Colors.red, 1, 10);
light.position.set(sun.position);
light.position.set(0, 1, 0); //default; light shining from top
scene.add(light);
var listener = new THREE.AudioListener();
camera.add(listener);
// // create a global audio source
// var sound = new THREE.Audio(listener);
// var audioLoader = new THREE.AudioLoader();
// //Load a sound and set it as the Audio object's buffer
// audioLoader.load('sounds/ambient.ogg', function(buffer) {
// sound.setBuffer(buffer);
// sound.setLoop(true);
// sound.setVolume(0.5);
// sound.play();
// });
var loader = new THREE.TextureLoader();
// var groundMesh = new THREEx.GrassGround();
// scene.add(groundMesh);
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
// renderer.setClearColor(0xEEEEEE);
var loader = new THREE.OBJLoader();
loader.load('models/Stick_Figure_by_Swp.OBJ',
function(object) {
object.position.set(1, 1, 0);
object.rotation.set(1, 1, 180);
figure = object;
scene.add(figure);
}
);
window.onload = function() {
document.body.appendChild(renderer.domElement);
render();
}
document.addEventListener("mousemove", handleMouseMove, false);
}
function render() {
// camera.rotation.z -= 0.1;
// figure.position.z += 0.01;
if (sun) figure.position.z -= 0.01;
if (figure) figure.position.set(mousePos.x * 10, mousePos.y * 10, 1);
renderer.render(scene, camera);
requestAnimationFrame(render);
}
function handleMouseMove(event) {
var tx = -1 + (event.clientX / window.innerWidth) * 2;
var ty = 1 - (event.clientY / window.innerHeight) * 2;
mousePos = { x: tx, y: ty };
}
function procGenerateCubes() {
}