-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
145 lines (121 loc) · 4.73 KB
/
index.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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Simple 3d Dla Viewer</title>
<style>
html, body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#renderCanvas {
width: 100%;
height: 100%;
touch-action: none;
}
</style>
<script src="https://preview.babylonjs.com/babylon.js"></script>
<script src="https://preview.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>
<script src="https://code.jquery.com/pep/0.4.3/pep.js"></script>
<script src="dla.js"></script>
</head>
<body>
<canvas id="renderCanvas" touch-action="none"></canvas>
<script>
function renderDLA() {
var canvas = document.getElementById("renderCanvas");
var engine = new BABYLON.Engine(canvas, true);
var rotate = false;
var createScene = function () {
var scene = new BABYLON.Scene(engine);
var mat = new BABYLON.StandardMaterial("mat1", scene);
mat.diffuseColor = new BABYLON.Color3(0.1, 0.3, 0.1);
var camera = new BABYLON.ArcRotateCamera(
"Camera",
0,0,5,
new BABYLON.Vector3(DLA.camera.look_at.x, DLA.camera.look_at.y, DLA.camera.look_at.z),
scene
);
camera.setPosition(new BABYLON.Vector3(
DLA.camera.position.x,
DLA.camera.position.y,
DLA.camera.position.z,
));
camera.attachControl(canvas, true);
var ssao = new BABYLON.SSAORenderingPipeline("ssao", scene, 1, camera);
ssao.fallOff = 0.000001;
ssao.area = 1;
ssao.radius = 0.0001;
ssao.totalStrength = 1.0;
ssao.base = 0.5;
var lights = [];
for (var i = 0; i < DLA.lights.length; ++i) {
var light = DLA.lights[i];
var pointLight =
new BABYLON.PointLight(
"light" + i,
new BABYLON.Vector3(light.position.x, light.position.y, light.position.z),
scene,
);
pointLight.intensity = light.intensity;
lights.push(pointLight);
}
mat.maxSimultaneousLights = lights.length;
var SPS = new BABYLON.SolidParticleSystem('SPS', scene);
var shape = BABYLON.MeshBuilder.CreateSphere("s", {segments: 4, diameter: 2}, scene);
SPS.addShape(shape, DLA.particles.length);
var mesh = SPS.buildMesh();
mesh.material = mat;
shape.dispose();
SPS.initParticles = function() {
for (var p = 0; p < this.nbParticles; p++) {
var particle = this.particles[p];
particle.id = p;
particle.position.x = DLA.particles[p].x;
particle.position.y = DLA.particles[p].y;
particle.position.z = DLA.particles[p].z;
}
};
scene.registerBeforeRender(function() {
if (!rotate) {
return;
}
SPS.mesh.rotation.y += 0.01;
if (SPS.mesh.rotation.y > Math.PI * 2) {
SPS.mesh.rotation.y -= Math.PI * 2;
}
});
SPS.initParticles();
SPS.setParticles();
return scene;
};
var scene = createScene();
engine.runRenderLoop(function() {
scene.render();
});
window.addEventListener("resize", function() {
engine.resize();
});
window.addEventListener("keydown", function(k) {
if (k.key === 'r') {
rotate = !rotate;
}
});
}
var hasDLA = false;
try {
DLA;
hasDLA = true;
} catch (e) {
alert("Please run the dla generator, save the final scene as js and " +
"put that file in the same directory as this one.");
}
if (hasDLA) {
renderDLA();
}
</script>
</body>
</html>