-
Notifications
You must be signed in to change notification settings - Fork 3
/
perlin_noise.html
196 lines (151 loc) · 6.83 KB
/
perlin_noise.html
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE html>
<html lang="en">
<head>
<title>Camp Workshop</title>
<meta charset="utf-8">
<meta property="og:title" content="Camp Workshop"/>
<meta property="og:type" content="website"/>
<meta property="og:image" content=""/>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
margin: 0px;
overflow: hidden;
background-color: #000000;
}
</style>
</head>
<body>
<script src="js/third-party/threejs/three.js"></script>
<script src="js/third-party/threejs/vr/ViveController.js"></script>
<script src="js/third-party/threejs/vr/WebVR.js"></script>
<script src="js/third-party/threejs/loaders/OBJLoader.js"></script>
<script src="js/third-party/threejs/effects/VREffect.js"></script>
<script src="js/third-party/threejs/effects/StereoEffect.js"></script>
<script src="js/third-party/threejs/controls/VRControls.js"></script>
<script src="js/third-party/threejs/controls/DeviceOrientationControls.js"></script>
<script src="js/third-party/threejs/controls/OrbitControls.js"></script>
<script src="js/third-party/TweenMax.min.js"></script>
<script src="js/third-party/perlin.js"></script>
<script src="js/utils/helpers.js"></script>
<script src="js/utils/AudioReactive.js"></script>
<script>
var camera, scene, renderer, effect, controls, vrControls, light;
var controller1, controller2;
var mobile = false;
var vr = false;
var max = 40;
var objects = [];
init();
setup();
render();
function init() {
// audio
//audio = new AudioReactive({});
//audio.playMedia('assets/sound/ritual');
// renderer
renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// scene
scene = new THREE.Scene();
// camera
camera = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight, 0.1, 10000);
camera.position.set(0, 0, 3);
// controls
controls = new THREE.OrbitControls(camera);
//controls.autoRotate = true;
// events
addEvents();
}
function setup() {
var cubeMap = getCubeMap(1);
var cubeShader = THREE.ShaderLib['cube'];
cubeShader.uniforms['tCube'].value = cubeMap;
var skyBoxMaterial = new THREE.ShaderMaterial({
fragmentShader: cubeShader.fragmentShader,
vertexShader: cubeShader.vertexShader,
uniforms: cubeShader.uniforms,
depthWrite: false,
side: THREE.BackSide
});
var skyBox = new THREE.Mesh(new THREE.CubeGeometry(1000, 1000, 1000), skyBoxMaterial);
//scene.add(skyBox);
// lights
light = new THREE.DirectionalLight(0xFFFFFF);
light.position.set(.2, .1, .2);
scene.add(light);
// objects
var material = new THREE.MeshStandardMaterial({
//color:0xFF0000,
metalness: 1,
roughness: 0.6,
envMap: cubeMap,
shading: THREE.FlatShading
});//shading: THREE.FlatShading
var size = .1
for (var _x = 0; _x < max; _x++) {
for (var _y = 0; _y < max; _y++) {
for (var _z = 0; _z < 1; _z++) {
var scale = noise.perlin3(_x * .15, _y * .15, _z * .15) * .5 + .5
console.log(scale)
//console.log(noise.perlin3(.123,1,1))
//var geo = new THREE.TetrahedronGeometry(.1, Math.floor(Math.random()*3));
var geo = new THREE.BoxGeometry(size, size, size)
var mesh = new THREE.Mesh(geo, material);
scene.add(mesh);
objects.push(mesh)
mesh.position.x = (_x - max / 2) * size
mesh.position.y = (_y - max / 2) * size
//mesh.position.z = (_z - max / 2) * size
}
//mesh.rotation.set(Math.random() * Math.PI * 2, Math.random() * Math.PI * 2, Math.random() * Math.PI * 2)
}
}
}
function render() {
var time = Date.now() * 0.001;
//light.position.x = Math.sin(time*10);
//light.position.z = Math.cos(10*time);
/*audio.frequencyData = audio.update();
for (var i = 0; i < objects.length; i++) {
var s = 5 * audio.frequencies[i] / 128
objects[i].scale.set(s, s, s)
}*/
var i = 0
var perlinScale=Math.sin(time*.3)/5
for (var _x = 0; _x < max; _x++) {
for (var _y = 0; _y < max; _y++) {
for (var _z = 0; _z < 1; _z++) {
var mesh = objects[i];
var perlinValue = noise.perlin3(_x * perlinScale + time, _y * perlinScale, _z * perlinScale) * .5 + .5
mesh.scale.set(perlinValue, perlinValue, perlinValue)
//mesh.rotation.y = perlinValue;
i++;
}
}
}
// vr
if (vr) {
vrControls.update();
controller1.update();
controller2.update();
effect.requestAnimationFrame(render);
//camera.position.y-=1;
effect.render(scene, camera);
//camera.position.y+=1;
return;
}
// web and mobile
requestAnimationFrame(render);
controls.update();
if (mobile) {
camera.position.set(0, 0, 0);
camera.translateZ(3);
}
renderer.render(scene, camera);
}
</script>
</body>
</html>