Public
Edited
Jul 12, 2023
Paused
1 fork
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ab = fetch(lazUrl).then((res) => res.arrayBuffer())
Insert cell
ab.byteLength
Insert cell
Insert cell
data = {
let start = new Date();
const data = await load(ab, LASWorkerLoader, {
las: {
skip: 4
}
});
let end = new Date();
mutable loadingMS = end - start;
return data;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
index = {
const start = new Date();
const points = data.attributes.POSITION.value;
const index = new Flatbush(points.length / 3);

for (let i = 0; i < points.length; i += 3) {
index.add(points[i], points[i + 1], points[i], points[i + 1]);
}
// perform the indexing
index.finish();
const end = new Date();
mutable indexingMS = end - start;
return index;
}
Insert cell
terrain = {
const start = new Date();
const arr = new Float32Array(gridSize * gridSize);
let ti = 0;
for (let x = 0; x < gridSize; ++x) {
for (let y = 0; y < gridSize; ++y) {
const xPos = bbox.minX + aequidistance[0] * x;
const yPos = bbox.minY + aequidistance[1] * y;
const i = index.neighbors(xPos, yPos, 1)[0];
arr[ti++] = data.attributes.POSITION.value[i * 3 + 2];
}
}
const end = new Date();
mutable terrainMS = end - start;
return arr;
}
Insert cell
geometry = {
const start = new Date();
const error = 0;
const martini = new Martini(gridSize);
const tile = martini.createTile(terrain);
const mesh = tile.getMesh(error);

const geometry = new THREE.BufferGeometry();

const vertices = new Float32Array((mesh.vertices.length / 2) * 3);
const terrainExaggeration = 1;

let index = 0;
for (let i = 0; i < mesh.vertices.length / 2; i++) {
let x = mesh.vertices[i * 2],
y = mesh.vertices[i * 2 + 1];
vertices[index++] = x * aequidistance[0] + bbox.minX;
vertices[index++] = y * aequidistance[1] + bbox.minY;
vertices[index++] = terrain[x * gridSize + y] * terrainExaggeration;
}

geometry.setAttribute("position", new THREE.BufferAttribute(vertices, 3));
geometry.setIndex(new THREE.BufferAttribute(mesh.triangles, 1));
geometry.computeVertexNormals();
geometry.computeBoundingBox();

// calc uvs to correctly position texture
let { min, max } = geometry.boundingBox;

let offset = new THREE.Vector2(0 - min.x, 0 - min.y);
let range = new THREE.Vector2(max.x - min.x, max.y - min.y);

const position = geometry.attributes.position;

const martiniEnd = new Date();
mutable martiniMS = martiniEnd - start;

const uvs = [];

for (let i = 0; i < position.count; i++) {
const v3 = new THREE.Vector3().fromBufferAttribute(position, i);
uvs.push((v3.x + offset.x) / range.x);
uvs.push((v3.y + offset.y) / range.y);
}

geometry.setAttribute(
"uv",
new THREE.BufferAttribute(new Float32Array(uvs), 2)
);
geometry.setAttribute(
"uv2",
new THREE.BufferAttribute(new Float32Array(uvs), 2)
);

geometry.attributes.uv.needsUpdate = true;
geometry.attributes.uv2.needsUpdate = true;
const end = new Date();
console.log("Calculating UVs", end - martiniEnd);
return geometry;
}
Insert cell
Insert cell
scene = {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xffffff);

var light = new THREE.DirectionalLight(0xffffff, 1.5);
light.position.setScalar(100);
scene.add(light);
scene.add(new THREE.AmbientLight(0xffffff, 0.5));

// add geometry

const material = new THREE.MeshNormalMaterial({
flatShading: true,
side: THREE.DoubleSide
});

let threeMesh = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({ map: map, side: THREE.DoubleSide })
);
scene.add(threeMesh);

return scene;
}
Insert cell
map = {
const start = new Date();
const map = await loadTexture(textureWMSUrl);
const end = new Date();
mutable textureMS = end - start;
return map;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more