-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointcloud.html
117 lines (96 loc) · 4.25 KB
/
pointcloud.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>BabylonJS Point Cloud</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="babylon4.1.js"></script>
<script src="dudeData.js"></script>
<script src="rabbitData.js"></script>
</head>
<body>
<canvas id="renderCanvas"></canvas>
<script>
if (BABYLON.Engine.isSupported()) {
var canvas = document.getElementById("renderCanvas");
var engine = new BABYLON.Engine(canvas, true);
var createScene = function () {
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera("camera1", 0, 0, 0, new BABYLON.Vector3(0, 40, 0), scene);
camera.setPosition(new BABYLON.Vector3(0, 40, 200));
camera.attachControl(canvas, true);
//Create a custom mesh
var customMesh = new BABYLON.Mesh("custom", scene);
//Set arrays for positions and indices
var vertexData = new BABYLON.VertexData();
var rabbitPositions = rabbitData.points;
var rabbitColors = rabbitData.colors;
var dudePositions = dudeData.points;
var dudeColors = dudeData.colors;
//calculate spiral conditions
var l = rabbitPositions.length / 3;
//Create a custom mesh
var customMesh = new BABYLON.Mesh("custom", scene);
//Assign positions
vertexData.positions = rabbitPositions;
vertexData.colors = rabbitColors;
//Apply vertexData to custom mesh
vertexData.applyToMesh(customMesh, true);
var mat = new BABYLON.StandardMaterial("mat", scene);
mat.emissiveColor = new BABYLON.Color3(1, 1, 1);
mat.disableLighting = true;
mat.pointsCloud = true;
mat.pointSize = 1;
customMesh.material = mat;
var nbFramesToPause = 120;
var iterations = 100;
var direction = 1;
var frameCount = 0;
var positions = [];
var colors = [];
scene.registerAfterRender(function() {
if (frameCount > nbFramesToPause && frameCount < nbFramesToPause + iterations) {
for (var p = 0; p < l; p++) {
positions[3 * p ] = rabbitPositions[3 * p ] + (frameCount - nbFramesToPause) * (dudePositions[3 * p ] - rabbitPositions[3 * p ]) / iterations;
positions[3 * p + 1] = rabbitPositions[3 * p + 1] + (frameCount - nbFramesToPause) * (dudePositions[3 * p + 1] - rabbitPositions[3 * p + 1]) / iterations;
positions[3 * p + 2] = rabbitPositions[3 * p + 2] + (frameCount - nbFramesToPause) * (dudePositions[3 * p + 2] - rabbitPositions[3 * p + 2]) / iterations;
colors[4 * p ] = rabbitColors[4 * p ] + (frameCount - nbFramesToPause) * (dudeColors[4 * p ] - rabbitColors[4 * p ]) / iterations;
colors[4 * p + 1] = rabbitColors[4 * p + 1] + (frameCount - nbFramesToPause) * (dudeColors[4 * p + 1] - rabbitColors[4 * p + 1]) / iterations;
colors[4 * p + 2] = rabbitColors[4 * p + 2] + (frameCount - nbFramesToPause) * (dudeColors[4 * p + 2] - rabbitColors[4 * p + 2]) / iterations;
colors[4 * p + 3] = rabbitColors[4 * p + 3] + (frameCount - nbFramesToPause) * (dudeColors[4 * p + 3] - rabbitColors[4 * p + 3]) / iterations;
}
customMesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions);
customMesh.updateVerticesData(BABYLON.VertexBuffer.ColorKind, colors);
}
frameCount += direction;
if (frameCount === 0 || frameCount === (2 * nbFramesToPause + iterations) ) {
direction *= -1;
}
camera.alpha += 0.01;
});
return scene;
}
var scene = createScene();
engine.runRenderLoop(function () {
scene.render();
});
window.addEventListener("resize", function () {
engine.resize();
});
}
</script>
</body>
</html>