-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTestScene.js
More file actions
104 lines (89 loc) · 2.6 KB
/
TestScene.js
File metadata and controls
104 lines (89 loc) · 2.6 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
var LightProbe = require('threejs-light-probe'),
CheckerRoom = require('threejs-checkerroom');
function TestScene() {
this.camera = new THREE.PerspectiveCamera();
this.scene = new THREE.Scene();
//dolly
this.dolly = new THREE.Object3D();
this.scene.add(this.dolly);
this.camera.position.z = 8;
this.camera.position.y = 4;
this.camera.lookAt(new THREE.Vector3(0, 1, 0));
this.dolly.add(this.camera);
//skip frames
this.skipFramesCounter = 0;
this.skipFrames = 0;
//lights
var light = new THREE.PointLight(0xffffff, .5);
light.position.x = 5;
light.position.y = 30;
this.scene.add(light);
var hemisphereLight = new THREE.HemisphereLight(0x7f6f5f, 0x7f0000);
this.scene.add(hemisphereLight);
//something to reflect
this.lightMesh = new THREE.Mesh(
new THREE.SphereGeometry(2, 16, 8),
new THREE.MeshBasicMaterial({
color: new THREE.Color(140, 120, 100),
emissive: new THREE.Color(10, 3, 1)
})
)
this.lightMesh.position.copy(light.position);
this.scene.add(this.lightMesh);
var checkerRoom = new CheckerRoom(20, 20, 4);
this.scene.add(checkerRoom);
//test mirror ball
var distance = 2;
this.totalBalls = 6;
this.lightProbes = [];
var colors = [
0xef7f7f,
0xefef7f,
0x7fef7f,
0x7fefef,
0x7f7fef,
0xef7fef
]
for (var i = this.totalBalls; i > 0; i--) {
var ratio = i / this.totalBalls;
var angle = ratio * Math.PI * 2;
var pos = new THREE.Vector3(Math.cos(angle) * distance, 1, Math.sin(angle) * distance);
var lightProbe = new LightProbe();
this.scene.add(lightProbe);
// lightProbe.update(this.renderer, this.scene);
var mirrorBall = new THREE.Mesh(
new THREE.SphereGeometry(1, 32, 16),
new THREE.MeshPhongMaterial({
color: colors[i-1],
// color: new THREE.Color(-.15, -.35, -4),
// emissive: colors[i-1],
// wireframe: true,
combine: THREE.MultiplyOperation,
envMap : lightProbe.getCubeMap(64, 1 * ratio * ratio * ratio, 3, false)
})
)
this.scene.add(mirrorBall);
mirrorBall.position.copy(pos);
lightProbe.position.copy(pos);
this.lightProbes.push(lightProbe);
};
this.onEnterFrame = this.onEnterFrame.bind(this);
}
TestScene.prototype = {
bindRenderer: function(renderer) {
this.renderer = renderer;
},
onEnterFrame: function() {
if(this.skipFramesCounter > 0) {
this.skipFramesCounter--;
} else {
this.skipFramesCounter = this.skipFrames;
this.dolly.rotation.y += .005;
this.lightMesh.position.y = 10 * Math.sin((new Date()).getTime() * .001) + 11;
for (var i = this.lightProbes.length - 1; i >= 0; i--) {
this.lightProbes[i].update(this.renderer, this.scene);
};
}
}
}
module.exports = TestScene;