support brotli compression
This commit is contained in:
parent
57f71cc265
commit
a4b887ef72
43
libs/brotli/BUILD
Normal file
43
libs/brotli/BUILD
Normal file
@ -0,0 +1,43 @@
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
licenses(["notice"]) # MIT
|
||||
|
||||
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
|
||||
|
||||
# Not a real polyfill. Do NOT use for anything, but tests.
|
||||
closure_js_library(
|
||||
name = "polyfill",
|
||||
srcs = ["polyfill.js"],
|
||||
suppress = [
|
||||
"JSC_INVALID_OPERAND_TYPE",
|
||||
"JSC_MISSING_JSDOC",
|
||||
"JSC_STRICT_INEXISTENT_PROPERTY",
|
||||
"JSC_TYPE_MISMATCH",
|
||||
"JSC_UNKNOWN_EXPR_TYPE",
|
||||
],
|
||||
)
|
||||
|
||||
# Do NOT use this artifact; it is for test purposes only.
|
||||
closure_js_library(
|
||||
name = "decode",
|
||||
srcs = ["decode.js"],
|
||||
suppress = [
|
||||
"JSC_DUP_VAR_DECLARATION",
|
||||
"JSC_USELESS_BLOCK",
|
||||
],
|
||||
deps = [":polyfill"],
|
||||
)
|
||||
|
||||
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_test")
|
||||
|
||||
closure_js_test(
|
||||
name = "all_tests",
|
||||
srcs = ["decode_test.js"],
|
||||
deps = [
|
||||
":decode",
|
||||
":polyfill",
|
||||
"@io_bazel_rules_closure//closure/library:testing",
|
||||
],
|
||||
)
|
||||
19
libs/brotli/LICENSE
Normal file
19
libs/brotli/LICENSE
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
12
libs/brotli/WORKSPACE
Normal file
12
libs/brotli/WORKSPACE
Normal file
@ -0,0 +1,12 @@
|
||||
workspace(name = "org_brotli_js")
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
|
||||
|
||||
git_repository(
|
||||
name = "io_bazel_rules_closure",
|
||||
commit = "29ec97e7c85d607ba9e41cab3993fbb13f812c4b",
|
||||
remote = "https://github.com/bazelbuild/rules_closure.git",
|
||||
)
|
||||
|
||||
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
|
||||
closure_repositories()
|
||||
2031
libs/brotli/decode.js
Normal file
2031
libs/brotli/decode.js
Normal file
File diff suppressed because one or more lines are too long
2
libs/brotli/decode.min.js
vendored
Normal file
2
libs/brotli/decode.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
79
libs/brotli/decode_test.js
Normal file
79
libs/brotli/decode_test.js
Normal file
@ -0,0 +1,79 @@
|
||||
goog.require('goog.testing.asserts');
|
||||
goog.require('goog.testing.jsunit');
|
||||
|
||||
/**
|
||||
* @param {!Int8Array} bytes
|
||||
* @return {string}
|
||||
*/
|
||||
function bytesToString(bytes) {
|
||||
return String.fromCharCode.apply(null, new Uint16Array(bytes));
|
||||
}
|
||||
|
||||
function testMetadata() {
|
||||
assertEquals("", bytesToString(BrotliDecode(Int8Array.from([1, 11, 0, 42, 3]))));
|
||||
}
|
||||
|
||||
function testEmpty() {
|
||||
assertEquals("", bytesToString(BrotliDecode(Int8Array.from([6]))));
|
||||
assertEquals("", bytesToString(BrotliDecode(Int8Array.from([0x81, 1]))));
|
||||
}
|
||||
|
||||
function testBaseDictWord() {
|
||||
var input = Int8Array.from([
|
||||
0x1b, 0x03, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe3, 0xb4, 0x0d, 0x00, 0x00,
|
||||
0x07, 0x5b, 0x26, 0x31, 0x40, 0x02, 0x00, 0xe0, 0x4e, 0x1b, 0x41, 0x02
|
||||
]);
|
||||
/** @type {!Int8Array} */
|
||||
var output = BrotliDecode(input);
|
||||
assertEquals("time", bytesToString(output));
|
||||
}
|
||||
|
||||
function testBlockCountMessage() {
|
||||
var input = Int8Array.from([
|
||||
0x1b, 0x0b, 0x00, 0x11, 0x01, 0x8c, 0xc1, 0xc5, 0x0d, 0x08, 0x00, 0x22,
|
||||
0x65, 0xe1, 0xfc, 0xfd, 0x22, 0x2c, 0xc4, 0x00, 0x00, 0x38, 0xd8, 0x32,
|
||||
0x89, 0x01, 0x12, 0x00, 0x00, 0x77, 0xda, 0x04, 0x10, 0x42, 0x00, 0x00, 0x00
|
||||
]);
|
||||
/** @type {!Int8Array} */
|
||||
var output = BrotliDecode(input);
|
||||
assertEquals("aabbaaaaabab", bytesToString(output));
|
||||
}
|
||||
|
||||
function testCompressedUncompressedShortCompressedSmallWindow() {
|
||||
var input = Int8Array.from([
|
||||
0x21, 0xf4, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x1c, 0xa7, 0x6d, 0x00, 0x00,
|
||||
0x38, 0xd8, 0x32, 0x89, 0x01, 0x12, 0x00, 0x00, 0x77, 0xda, 0x34, 0x7b,
|
||||
0xdb, 0x50, 0x80, 0x02, 0x80, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x31,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x4e, 0xdb, 0x00, 0x00, 0x70, 0xb0,
|
||||
0x65, 0x12, 0x03, 0x24, 0x00, 0x00, 0xee, 0xb4, 0x11, 0x24, 0x00
|
||||
]);
|
||||
/** @type {!Int8Array} */
|
||||
var output = BrotliDecode(input);
|
||||
assertEquals(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaabbbbbbbbbb", bytesToString(output));
|
||||
}
|
||||
|
||||
function testIntactDistanceRingBuffer0() {
|
||||
var input = Int8Array.from([
|
||||
0x1b, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe3, 0xb4, 0x0d, 0x00, 0x00,
|
||||
0x07, 0x5b, 0x26, 0x31, 0x40, 0x02, 0x00, 0xe0, 0x4e, 0x1b, 0xa1, 0x80,
|
||||
0x20, 0x00
|
||||
]);
|
||||
/** @type {!Int8Array} */
|
||||
var output = BrotliDecode(input);
|
||||
assertEquals("himselfself", bytesToString(output));
|
||||
}
|
||||
65
libs/brotli/polyfill.js
Normal file
65
libs/brotli/polyfill.js
Normal file
@ -0,0 +1,65 @@
|
||||
if (!Int32Array.__proto__.from) {
|
||||
Object.defineProperty(Int32Array.__proto__, 'from', {
|
||||
value: function(obj) {
|
||||
obj = Object(obj);
|
||||
if (!obj['length']) {
|
||||
return new this(0);
|
||||
}
|
||||
var typed_array = new this(obj.length);
|
||||
for(var i = 0; i < typed_array.length; i++) {
|
||||
typed_array[i] = obj[i];
|
||||
}
|
||||
return typed_array;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!Array.prototype.copyWithin) {
|
||||
Array.prototype.copyWithin = function(target, start, end) {
|
||||
var O = Object(this);
|
||||
var len = O.length >>> 0;
|
||||
var to = target | 0;
|
||||
var from = start | 0;
|
||||
var count = Math.min(Math.min(end | 0, len) - from, len - to);
|
||||
var direction = 1;
|
||||
if (from < to && to < (from + count)) {
|
||||
direction = -1;
|
||||
from += count - 1;
|
||||
to += count - 1;
|
||||
}
|
||||
while (count > 0) {
|
||||
O[to] = O[from];
|
||||
from += direction;
|
||||
to += direction;
|
||||
count--;
|
||||
}
|
||||
return O;
|
||||
};
|
||||
}
|
||||
|
||||
if (!Array.prototype.fill) {
|
||||
Object.defineProperty(Array.prototype, 'fill', {
|
||||
value: function(value, start, end) {
|
||||
end = end | 0;
|
||||
var O = Object(this);
|
||||
var k = start | 0;
|
||||
while (k < end) {
|
||||
O[k] = value;
|
||||
k++;
|
||||
}
|
||||
return O;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!Int8Array.prototype.copyWithin) {
|
||||
Int8Array.prototype.copyWithin = Array.prototype.copyWithin;
|
||||
}
|
||||
|
||||
if (!Int8Array.prototype.fill) {
|
||||
Int8Array.prototype.fill = Array.prototype.fill;
|
||||
}
|
||||
|
||||
if (!Int32Array.prototype.fill) {
|
||||
Int32Array.prototype.fill = Array.prototype.fill;
|
||||
}
|
||||
@ -17,9 +17,17 @@ export default [
|
||||
sourcemap: false
|
||||
}
|
||||
},{
|
||||
input: 'src/modules/Loader_1.8/OctreeDecoderWorker.js',
|
||||
input: 'src/modules/loader/2.0/DecoderWorker.js',
|
||||
output: {
|
||||
file: 'build/potree/workers/OctreeDecoderWorker.js',
|
||||
file: 'build/potree/workers/2.0/DecoderWorker.js',
|
||||
format: 'es',
|
||||
name: 'Potree',
|
||||
sourcemap: false
|
||||
}
|
||||
},{
|
||||
input: 'src/modules/loader/2.0/DecoderWorker_brotli.js',
|
||||
output: {
|
||||
file: 'build/potree/workers/2.0/DecoderWorker_brotli.js',
|
||||
format: 'es',
|
||||
name: 'Potree',
|
||||
sourcemap: false
|
||||
|
||||
@ -32,7 +32,7 @@ export * from "./materials/NormalizationMaterial.js";
|
||||
export * from "./materials/PointCloudMaterial.js";
|
||||
|
||||
export * from "./loader/POCLoader.js";
|
||||
export * from "./modules/Loader_1.8/OctreeLoader_1_8.js";
|
||||
export * from "./modules/loader/2.0/OctreeLoader.js";
|
||||
export * from "./loader/EptLoader.js";
|
||||
export * from "./loader/ept/BinaryLoader.js";
|
||||
export * from "./loader/ept/LaszipLoader.js";
|
||||
@ -67,7 +67,7 @@ export * from "./modules/OrientedImages/OrientedImages.js";
|
||||
export * from "./modules/Images360/Images360.js";
|
||||
export * from "./modules/CameraAnimation/CameraAnimation.js";
|
||||
|
||||
export * from "./modules/Loader_1.8/OctreeLoader_1_8.js";
|
||||
export * from "./modules/loader/2.0/OctreeLoader.js";
|
||||
|
||||
export {OrbitControls} from "./navigation/OrbitControls.js";
|
||||
export {FirstPersonControls} from "./navigation/FirstPersonControls.js";
|
||||
@ -80,7 +80,7 @@ import "./extensions/PerspectiveCamera.js";
|
||||
import "./extensions/Ray.js";
|
||||
|
||||
import {LRU} from "./LRU.js";
|
||||
import {OctreeLoader_1_8} from "./modules/Loader_1.8/OctreeLoader_1_8.js";
|
||||
import {OctreeLoader} from "./modules/loader/2.0/OctreeLoader.js";
|
||||
import {POCLoader} from "./loader/POCLoader.js";
|
||||
import {EptLoader} from "./loader/EptLoader.js";
|
||||
import {PointCloudOctree} from "./PointCloudOctree.js";
|
||||
@ -162,7 +162,7 @@ export function loadPointCloud(path, name, callback){
|
||||
}
|
||||
});
|
||||
} else if (path.indexOf('metadata.json') > 0) {
|
||||
Potree.OctreeLoader_1_8.load(path).then(e => {
|
||||
Potree.OctreeLoader.load(path).then(e => {
|
||||
let geometry = e.geometry;
|
||||
|
||||
if(!geometry){
|
||||
@ -183,7 +183,7 @@ export function loadPointCloud(path, name, callback){
|
||||
}
|
||||
});
|
||||
|
||||
OctreeLoader_1_8.load(path, function (geometry) {
|
||||
OctreeLoader.load(path, function (geometry) {
|
||||
if (!geometry) {
|
||||
//callback({type: 'loading_failed'});
|
||||
console.error(new Error(`failed to load point cloud from URL: ${path}`));
|
||||
|
||||
@ -335,6 +335,12 @@ export function updateVisibility(pointclouds, camera, renderer){
|
||||
} else if (!pointcloud.showBoundingBox && node.boundingBoxNode) {
|
||||
node.boundingBoxNode.visible = false;
|
||||
}
|
||||
|
||||
// if(node.boundingBoxNode !== undefined && exports.debug.allowedNodes !== undefined){
|
||||
// if(!exports.debug.allowedNodes.includes(node.name)){
|
||||
// node.boundingBoxNode.visible = false;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// add child nodes to priorityQueue
|
||||
|
||||
@ -1,221 +1,225 @@
|
||||
|
||||
|
||||
import {Version} from "../../Version.js";
|
||||
import {PointAttributes, PointAttribute, PointAttributeTypes} from "../../loader/PointAttributes.js";
|
||||
|
||||
const typedArrayMapping = {
|
||||
"int8": Int8Array,
|
||||
"int16": Int16Array,
|
||||
"int32": Int32Array,
|
||||
"int64": Float64Array,
|
||||
"uint8": Uint8Array,
|
||||
"uint16": Uint16Array,
|
||||
"uint32": Uint32Array,
|
||||
"uint64": Float64Array,
|
||||
"float": Float32Array,
|
||||
"double": Float64Array,
|
||||
};
|
||||
|
||||
Potree = {};
|
||||
|
||||
onmessage = function (event) {
|
||||
|
||||
let {buffer, pointAttributes, scale, name, min, max, size, offset} = event.data;
|
||||
|
||||
let numPoints = buffer.byteLength / pointAttributes.byteSize;
|
||||
let view = new DataView(buffer);
|
||||
|
||||
let attributeBuffers = {};
|
||||
let attributeOffset = 0;
|
||||
|
||||
let bytesPerPoint = 0;
|
||||
for (let pointAttribute of pointAttributes.attributes) {
|
||||
bytesPerPoint += pointAttribute.byteSize;
|
||||
}
|
||||
|
||||
let gridSize = 32;
|
||||
let grid = new Uint32Array(gridSize ** 3);
|
||||
let toIndex = (x, y, z) => {
|
||||
// let dx = gridSize * (x - min.x) / size.x;
|
||||
// let dy = gridSize * (y - min.y) / size.y;
|
||||
// let dz = gridSize * (z - min.z) / size.z;
|
||||
|
||||
// min is already subtracted
|
||||
let dx = gridSize * x / size.x;
|
||||
let dy = gridSize * y / size.y;
|
||||
let dz = gridSize * z / size.z;
|
||||
|
||||
let ix = Math.min(parseInt(dx), gridSize - 1);
|
||||
let iy = Math.min(parseInt(dy), gridSize - 1);
|
||||
let iz = Math.min(parseInt(dz), gridSize - 1);
|
||||
|
||||
let index = ix + iy * gridSize + iz * gridSize * gridSize;
|
||||
|
||||
return index;
|
||||
};
|
||||
|
||||
let numOccupiedCells = 0;
|
||||
for (let pointAttribute of pointAttributes.attributes) {
|
||||
|
||||
if(["POSITION_CARTESIAN", "position"].includes(pointAttribute.name)){
|
||||
let buff = new ArrayBuffer(numPoints * 4 * 3);
|
||||
let positions = new Float32Array(buff);
|
||||
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
|
||||
let pointOffset = j * bytesPerPoint;
|
||||
|
||||
let x = (view.getInt32(pointOffset + attributeOffset + 0, true) * scale[0]) + offset[0] - min.x;
|
||||
let y = (view.getInt32(pointOffset + attributeOffset + 4, true) * scale[1]) + offset[1] - min.y;
|
||||
let z = (view.getInt32(pointOffset + attributeOffset + 8, true) * scale[2]) + offset[2] - min.z;
|
||||
|
||||
let index = toIndex(x, y, z);
|
||||
let count = grid[index]++;
|
||||
if(count === 0){
|
||||
numOccupiedCells++;
|
||||
}
|
||||
|
||||
positions[3 * j + 0] = x;
|
||||
positions[3 * j + 1] = y;
|
||||
positions[3 * j + 2] = z;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
}else if(["RGBA", "rgba"].includes(pointAttribute.name)){
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let colors = new Uint8Array(buff);
|
||||
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
let pointOffset = j * bytesPerPoint;
|
||||
|
||||
let r = view.getUint16(pointOffset + attributeOffset + 0, true);
|
||||
let g = view.getUint16(pointOffset + attributeOffset + 2, true);
|
||||
let b = view.getUint16(pointOffset + attributeOffset + 4, true);
|
||||
|
||||
colors[4 * j + 0] = r > 255 ? r / 256 : r;
|
||||
colors[4 * j + 1] = g > 255 ? g / 256 : g;
|
||||
colors[4 * j + 2] = b > 255 ? b / 256 : b;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
}else{
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let f32 = new Float32Array(buff);
|
||||
|
||||
let TypedArray = typedArrayMapping[pointAttribute.type.name];
|
||||
preciseBuffer = new TypedArray(numPoints);
|
||||
|
||||
let [offset, scale] = [0, 1];
|
||||
|
||||
const getterMap = {
|
||||
"int8": view.getInt8,
|
||||
"int16": view.getInt16,
|
||||
"int32": view.getInt32,
|
||||
// "int64": view.getInt64,
|
||||
"uint8": view.getUint8,
|
||||
"uint16": view.getUint16,
|
||||
"uint32": view.getUint32,
|
||||
// "uint64": view.getUint64,
|
||||
"float": view.getFloat32,
|
||||
"double": view.getFloat64,
|
||||
};
|
||||
const getter = getterMap[pointAttribute.type.name].bind(view);
|
||||
|
||||
// compute offset and scale to pack larger types into 32 bit floats
|
||||
if(pointAttribute.type.size > 4){
|
||||
let [amin, amax] = pointAttribute.range;
|
||||
offset = amin;
|
||||
scale = 1 / (amax - amin);
|
||||
}
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
let pointOffset = j * bytesPerPoint;
|
||||
let value = getter(pointOffset + attributeOffset, true);
|
||||
|
||||
f32[j] = (value - offset) * scale;
|
||||
preciseBuffer[j] = value;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = {
|
||||
buffer: buff,
|
||||
preciseBuffer: preciseBuffer,
|
||||
attribute: pointAttribute,
|
||||
offset: offset,
|
||||
scale: scale,
|
||||
};
|
||||
}
|
||||
|
||||
attributeOffset += pointAttribute.byteSize;
|
||||
|
||||
|
||||
}
|
||||
|
||||
let occupancy = parseInt(numPoints / numOccupiedCells);
|
||||
// console.log(`${name}: #points: ${numPoints}: #occupiedCells: ${numOccupiedCells}, occupancy: ${occupancy} points/cell`);
|
||||
|
||||
{ // add indices
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let indices = new Uint32Array(buff);
|
||||
|
||||
for (let i = 0; i < numPoints; i++) {
|
||||
indices[i] = i;
|
||||
}
|
||||
|
||||
attributeBuffers["INDICES"] = { buffer: buff, attribute: PointAttribute.INDICES };
|
||||
}
|
||||
|
||||
|
||||
{ // handle attribute vectors
|
||||
let vectors = pointAttributes.vectors;
|
||||
|
||||
for(let vector of vectors){
|
||||
|
||||
let {name, attributes} = vector;
|
||||
let numVectorElements = attributes.length;
|
||||
let buffer = new ArrayBuffer(numVectorElements * numPoints * 4);
|
||||
let f32 = new Float32Array(buffer);
|
||||
|
||||
let iElement = 0;
|
||||
for(let sourceName of attributes){
|
||||
let sourceBuffer = attributeBuffers[sourceName];
|
||||
let {offset, scale} = sourceBuffer;
|
||||
let view = new DataView(sourceBuffer.buffer);
|
||||
|
||||
const getter = view.getFloat32.bind(view);
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
let value = getter(j * 4, true);
|
||||
|
||||
f32[j * numVectorElements + iElement] = (value / scale) + offset;
|
||||
}
|
||||
|
||||
iElement++;
|
||||
}
|
||||
|
||||
let vecAttribute = new PointAttribute(name, PointAttributeTypes.DATA_TYPE_FLOAT, 3);
|
||||
|
||||
attributeBuffers[name] = {
|
||||
buffer: buffer,
|
||||
attribute: vecAttribute,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
let message = {
|
||||
buffer: buffer,
|
||||
attributeBuffers: attributeBuffers,
|
||||
density: occupancy,
|
||||
};
|
||||
|
||||
let transferables = [];
|
||||
for (let property in message.attributeBuffers) {
|
||||
transferables.push(message.attributeBuffers[property].buffer);
|
||||
}
|
||||
transferables.push(buffer);
|
||||
|
||||
postMessage(message, transferables);
|
||||
};
|
||||
|
||||
|
||||
// import {Version} from "../../Version.js";
|
||||
import {PointAttributes, PointAttribute, PointAttributeTypes} from "../../../loader/PointAttributes.js";
|
||||
|
||||
const typedArrayMapping = {
|
||||
"int8": Int8Array,
|
||||
"int16": Int16Array,
|
||||
"int32": Int32Array,
|
||||
"int64": Float64Array,
|
||||
"uint8": Uint8Array,
|
||||
"uint16": Uint16Array,
|
||||
"uint32": Uint32Array,
|
||||
"uint64": Float64Array,
|
||||
"float": Float32Array,
|
||||
"double": Float64Array,
|
||||
};
|
||||
|
||||
Potree = {};
|
||||
|
||||
onmessage = function (event) {
|
||||
|
||||
let {buffer, pointAttributes, scale, name, min, max, size, offset} = event.data;
|
||||
|
||||
let tStart = performance.now();
|
||||
|
||||
let numPoints = buffer.byteLength / pointAttributes.byteSize;
|
||||
let view = new DataView(buffer);
|
||||
|
||||
let attributeBuffers = {};
|
||||
let attributeOffset = 0;
|
||||
|
||||
let bytesPerPoint = 0;
|
||||
for (let pointAttribute of pointAttributes.attributes) {
|
||||
bytesPerPoint += pointAttribute.byteSize;
|
||||
}
|
||||
|
||||
let gridSize = 32;
|
||||
let grid = new Uint32Array(gridSize ** 3);
|
||||
let toIndex = (x, y, z) => {
|
||||
// let dx = gridSize * (x - min.x) / size.x;
|
||||
// let dy = gridSize * (y - min.y) / size.y;
|
||||
// let dz = gridSize * (z - min.z) / size.z;
|
||||
|
||||
// min is already subtracted
|
||||
let dx = gridSize * x / size.x;
|
||||
let dy = gridSize * y / size.y;
|
||||
let dz = gridSize * z / size.z;
|
||||
|
||||
let ix = Math.min(parseInt(dx), gridSize - 1);
|
||||
let iy = Math.min(parseInt(dy), gridSize - 1);
|
||||
let iz = Math.min(parseInt(dz), gridSize - 1);
|
||||
|
||||
let index = ix + iy * gridSize + iz * gridSize * gridSize;
|
||||
|
||||
return index;
|
||||
};
|
||||
|
||||
let numOccupiedCells = 0;
|
||||
for (let pointAttribute of pointAttributes.attributes) {
|
||||
|
||||
if(["POSITION_CARTESIAN", "position"].includes(pointAttribute.name)){
|
||||
let buff = new ArrayBuffer(numPoints * 4 * 3);
|
||||
let positions = new Float32Array(buff);
|
||||
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
|
||||
let pointOffset = j * bytesPerPoint;
|
||||
|
||||
let x = (view.getInt32(pointOffset + attributeOffset + 0, true) * scale[0]) + offset[0] - min.x;
|
||||
let y = (view.getInt32(pointOffset + attributeOffset + 4, true) * scale[1]) + offset[1] - min.y;
|
||||
let z = (view.getInt32(pointOffset + attributeOffset + 8, true) * scale[2]) + offset[2] - min.z;
|
||||
|
||||
let index = toIndex(x, y, z);
|
||||
let count = grid[index]++;
|
||||
if(count === 0){
|
||||
numOccupiedCells++;
|
||||
}
|
||||
|
||||
positions[3 * j + 0] = x;
|
||||
positions[3 * j + 1] = y;
|
||||
positions[3 * j + 2] = z;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
}else if(["RGBA", "rgba"].includes(pointAttribute.name)){
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let colors = new Uint8Array(buff);
|
||||
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
let pointOffset = j * bytesPerPoint;
|
||||
|
||||
let r = view.getUint16(pointOffset + attributeOffset + 0, true);
|
||||
let g = view.getUint16(pointOffset + attributeOffset + 2, true);
|
||||
let b = view.getUint16(pointOffset + attributeOffset + 4, true);
|
||||
|
||||
colors[4 * j + 0] = r > 255 ? r / 256 : r;
|
||||
colors[4 * j + 1] = g > 255 ? g / 256 : g;
|
||||
colors[4 * j + 2] = b > 255 ? b / 256 : b;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
}else{
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let f32 = new Float32Array(buff);
|
||||
|
||||
let TypedArray = typedArrayMapping[pointAttribute.type.name];
|
||||
preciseBuffer = new TypedArray(numPoints);
|
||||
|
||||
let [offset, scale] = [0, 1];
|
||||
|
||||
const getterMap = {
|
||||
"int8": view.getInt8,
|
||||
"int16": view.getInt16,
|
||||
"int32": view.getInt32,
|
||||
// "int64": view.getInt64,
|
||||
"uint8": view.getUint8,
|
||||
"uint16": view.getUint16,
|
||||
"uint32": view.getUint32,
|
||||
// "uint64": view.getUint64,
|
||||
"float": view.getFloat32,
|
||||
"double": view.getFloat64,
|
||||
};
|
||||
const getter = getterMap[pointAttribute.type.name].bind(view);
|
||||
|
||||
// compute offset and scale to pack larger types into 32 bit floats
|
||||
if(pointAttribute.type.size > 4){
|
||||
let [amin, amax] = pointAttribute.range;
|
||||
offset = amin;
|
||||
scale = 1 / (amax - amin);
|
||||
}
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
let pointOffset = j * bytesPerPoint;
|
||||
let value = getter(pointOffset + attributeOffset, true);
|
||||
|
||||
f32[j] = (value - offset) * scale;
|
||||
preciseBuffer[j] = value;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = {
|
||||
buffer: buff,
|
||||
preciseBuffer: preciseBuffer,
|
||||
attribute: pointAttribute,
|
||||
offset: offset,
|
||||
scale: scale,
|
||||
};
|
||||
}
|
||||
|
||||
attributeOffset += pointAttribute.byteSize;
|
||||
|
||||
|
||||
}
|
||||
|
||||
let occupancy = parseInt(numPoints / numOccupiedCells);
|
||||
// console.log(`${name}: #points: ${numPoints}: #occupiedCells: ${numOccupiedCells}, occupancy: ${occupancy} points/cell`);
|
||||
|
||||
{ // add indices
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let indices = new Uint32Array(buff);
|
||||
|
||||
for (let i = 0; i < numPoints; i++) {
|
||||
indices[i] = i;
|
||||
}
|
||||
|
||||
attributeBuffers["INDICES"] = { buffer: buff, attribute: PointAttribute.INDICES };
|
||||
}
|
||||
|
||||
|
||||
{ // handle attribute vectors
|
||||
let vectors = pointAttributes.vectors;
|
||||
|
||||
for(let vector of vectors){
|
||||
|
||||
let {name, attributes} = vector;
|
||||
let numVectorElements = attributes.length;
|
||||
let buffer = new ArrayBuffer(numVectorElements * numPoints * 4);
|
||||
let f32 = new Float32Array(buffer);
|
||||
|
||||
let iElement = 0;
|
||||
for(let sourceName of attributes){
|
||||
let sourceBuffer = attributeBuffers[sourceName];
|
||||
let {offset, scale} = sourceBuffer;
|
||||
let view = new DataView(sourceBuffer.buffer);
|
||||
|
||||
const getter = view.getFloat32.bind(view);
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
let value = getter(j * 4, true);
|
||||
|
||||
f32[j * numVectorElements + iElement] = (value / scale) + offset;
|
||||
}
|
||||
|
||||
iElement++;
|
||||
}
|
||||
|
||||
let vecAttribute = new PointAttribute(name, PointAttributeTypes.DATA_TYPE_FLOAT, 3);
|
||||
|
||||
attributeBuffers[name] = {
|
||||
buffer: buffer,
|
||||
attribute: vecAttribute,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let duration = performance.now() - tStart;
|
||||
let pointsPerMs = numPoints / duration;
|
||||
console.log(`duration: ${duration.toFixed(1)}ms, #points: ${numPoints}, points/ms: ${pointsPerMs.toFixed(1)}`);
|
||||
|
||||
let message = {
|
||||
buffer: buffer,
|
||||
attributeBuffers: attributeBuffers,
|
||||
density: occupancy,
|
||||
};
|
||||
|
||||
let transferables = [];
|
||||
for (let property in message.attributeBuffers) {
|
||||
transferables.push(message.attributeBuffers[property].buffer);
|
||||
}
|
||||
transferables.push(buffer);
|
||||
|
||||
postMessage(message, transferables);
|
||||
};
|
||||
419
src/modules/loader/2.0/DecoderWorker_brotli.js
Normal file
419
src/modules/loader/2.0/DecoderWorker_brotli.js
Normal file
@ -0,0 +1,419 @@
|
||||
|
||||
|
||||
// import {Version} from "../../Version.js";
|
||||
import {PointAttributes, PointAttribute, PointAttributeTypes} from "../../../loader/PointAttributes.js";
|
||||
import {BrotliDecode} from "../../../../libs/brotli/decode.js";
|
||||
|
||||
const typedArrayMapping = {
|
||||
"int8": Int8Array,
|
||||
"int16": Int16Array,
|
||||
"int32": Int32Array,
|
||||
"int64": Float64Array,
|
||||
"uint8": Uint8Array,
|
||||
"uint16": Uint16Array,
|
||||
"uint32": Uint32Array,
|
||||
"uint64": Float64Array,
|
||||
"float": Float32Array,
|
||||
"double": Float64Array,
|
||||
};
|
||||
|
||||
Potree = {};
|
||||
|
||||
function dealign24b(mortoncode){
|
||||
// see https://stackoverflow.com/questions/45694690/how-i-can-remove-all-odds-bits-in-c
|
||||
|
||||
// input alignment of desired bits
|
||||
// ..a..b..c..d..e..f..g..h..i..j..k..l..m..n..o..p
|
||||
let x = mortoncode;
|
||||
|
||||
// ..a..b..c..d..e..f..g..h..i..j..k..l..m..n..o..p ..a..b..c..d..e..f..g..h..i..j..k..l..m..n..o..p
|
||||
// ..a.....c.....e.....g.....i.....k.....m.....o... .....b.....d.....f.....h.....j.....l.....n.....p
|
||||
// ....a.....c.....e.....g.....i.....k.....m.....o. .....b.....d.....f.....h.....j.....l.....n.....p
|
||||
x = ((x & 0b001000001000001000001000) >> 2) | ((x & 0b000001000001000001000001) >> 0);
|
||||
// ....ab....cd....ef....gh....ij....kl....mn....op ....ab....cd....ef....gh....ij....kl....mn....op
|
||||
// ....ab..........ef..........ij..........mn...... ..........cd..........gh..........kl..........op
|
||||
// ........ab..........ef..........ij..........mn.. ..........cd..........gh..........kl..........op
|
||||
x = ((x & 0b000011000000000011000000) >> 4) | ((x & 0b000000000011000000000011) >> 0);
|
||||
// ........abcd........efgh........ijkl........mnop ........abcd........efgh........ijkl........mnop
|
||||
// ........abcd....................ijkl............ ....................efgh....................mnop
|
||||
// ................abcd....................ijkl.... ....................efgh....................mnop
|
||||
x = ((x & 0b000000001111000000000000) >> 8) | ((x & 0b000000000000000000001111) >> 0);
|
||||
// ................abcdefgh................ijklmnop ................abcdefgh................ijklmnop
|
||||
// ................abcdefgh........................ ........................................ijklmnop
|
||||
// ................................abcdefgh........ ........................................ijklmnop
|
||||
x = ((x & 0b000000000000000000000000) >> 16) | ((x & 0b000000000000000011111111) >> 0);
|
||||
|
||||
// sucessfully realigned!
|
||||
//................................abcdefghijklmnop
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
let mask_b0 = new Uint8Array([0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3]);
|
||||
|
||||
onmessage = function (event) {
|
||||
|
||||
let {pointAttributes, scale, name, min, max, size, offset, numPoints} = event.data;
|
||||
|
||||
let tStart = performance.now();
|
||||
|
||||
let buffer = BrotliDecode(new Int8Array(event.data.buffer));
|
||||
let view = new DataView(buffer.buffer);
|
||||
|
||||
let attributeBuffers = {};
|
||||
let attributeOffset = 0;
|
||||
|
||||
let bytesPerPoint = 0;
|
||||
for (let pointAttribute of pointAttributes.attributes) {
|
||||
bytesPerPoint += pointAttribute.byteSize;
|
||||
}
|
||||
|
||||
let gridSize = 32;
|
||||
let grid = new Uint32Array(gridSize ** 3);
|
||||
let toIndex = (x, y, z) => {
|
||||
|
||||
// min is already subtracted
|
||||
let dx = gridSize * x / size.x;
|
||||
let dy = gridSize * y / size.y;
|
||||
let dz = gridSize * z / size.z;
|
||||
|
||||
let ix = Math.min(parseInt(dx), gridSize - 1);
|
||||
let iy = Math.min(parseInt(dy), gridSize - 1);
|
||||
let iz = Math.min(parseInt(dz), gridSize - 1);
|
||||
|
||||
let index = ix + iy * gridSize + iz * gridSize * gridSize;
|
||||
|
||||
return index;
|
||||
};
|
||||
|
||||
let numOccupiedCells = 0;
|
||||
let byteOffset = 0;
|
||||
for (let pointAttribute of pointAttributes.attributes) {
|
||||
|
||||
|
||||
if(["POSITION_CARTESIAN", "position"].includes(pointAttribute.name)){
|
||||
|
||||
// let tStart = performance.now();
|
||||
|
||||
let buff = new ArrayBuffer(numPoints * 4 * 3);
|
||||
let positions = new Float32Array(buff);
|
||||
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
|
||||
|
||||
let mc_0 = view.getUint32(byteOffset + 4, true);
|
||||
let mc_1 = view.getUint32(byteOffset + 0, true);
|
||||
let mc_2 = view.getUint32(byteOffset + 12, true);
|
||||
let mc_3 = view.getUint32(byteOffset + 8, true);
|
||||
|
||||
byteOffset += 16;
|
||||
|
||||
let X = dealign24b((mc_3 & 0x00FFFFFF) >>> 0)
|
||||
| (dealign24b(((mc_3 >>> 24) | (mc_2 << 8)) >>> 0) << 8);
|
||||
|
||||
let Y = dealign24b((mc_3 & 0x00FFFFFF) >>> 1)
|
||||
| (dealign24b(((mc_3 >>> 24) | (mc_2 << 8)) >>> 1) << 8)
|
||||
|
||||
|
||||
let Z = dealign24b((mc_3 & 0x00FFFFFF) >>> 2)
|
||||
| (dealign24b(((mc_3 >>> 24) | (mc_2 << 8)) >>> 2) << 8)
|
||||
|
||||
|
||||
if(mc_1 != 0 || mc_2 != 0){
|
||||
X = X | (dealign24b((mc_1 & 0x00FFFFFF) >>> 0) << 16)
|
||||
| (dealign24b(((mc_1 >>> 24) | (mc_0 << 8)) >>> 0) << 24);
|
||||
|
||||
Y = Y | (dealign24b((mc_1 & 0x00FFFFFF) >>> 1) << 16)
|
||||
| (dealign24b(((mc_1 >>> 24) | (mc_0 << 8)) >>> 1) << 24);
|
||||
|
||||
Z = Z | (dealign24b((mc_1 & 0x00FFFFFF) >>> 2) << 16)
|
||||
| (dealign24b(((mc_1 >>> 24) | (mc_0 << 8)) >>> 2) << 24);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// VERIFY AGAINST LOOP VERSION
|
||||
// =======================
|
||||
// let reference;
|
||||
// { // correct reference
|
||||
|
||||
// let mc_upper = view.getBigUint64(byteOffset + 0, true);
|
||||
// let mc_lower = view.getBigUint64(byteOffset + 8, true);
|
||||
|
||||
// let X = 0n;
|
||||
// let Y = 0n;
|
||||
// let Z = 0n;
|
||||
|
||||
// for(let k = 0n; k < 16n; k++){
|
||||
// let mask_lower = (mc_lower >> (3n * k)) & 0b111n;
|
||||
// let mask_upper = (mc_upper >> (3n * k)) & 0b111n;
|
||||
|
||||
// X = X | (((mask_lower >> 0n) & 0b001n) << k);
|
||||
// X = X | ((((mask_upper >> 0n) & 0b001n) << k) << 16n);
|
||||
|
||||
// Y = Y | (((mask_lower >> 1n) & 0b001n) << k);
|
||||
// Y = Y | ((((mask_upper >> 1n) & 0b001n) << k) << 16n);
|
||||
|
||||
// Z = Z | (((mask_lower >> 2n) & 0b001n) << k);
|
||||
// Z = Z | ((((mask_upper >> 2n) & 0b001n) << k) << 16n);
|
||||
// }
|
||||
|
||||
// reference = [X, Y, Z];
|
||||
// }
|
||||
// //dbgad += parseInt(reference[2]);
|
||||
// let [rX, rY, rZ] = reference;
|
||||
|
||||
// if(X !== parseInt(rX)){
|
||||
// debugger;
|
||||
// }
|
||||
// if(Y !== parseInt(rY)){
|
||||
// debugger;
|
||||
// }
|
||||
// if(Z !== parseInt(rZ)){
|
||||
// debugger;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
// let mc_upper = view.getBigUint64(byteOffset + 0, true);
|
||||
// let mc_lower = view.getBigUint64(byteOffset + 8, true);
|
||||
// byteOffset += 16;
|
||||
|
||||
// =======================
|
||||
// MAGIC NUMBERS 32BIT
|
||||
// =======================
|
||||
// let mc0 = parseInt((mc_lower >> 0n) & 0x00FFFFFFn);
|
||||
// let mc1 = parseInt((mc_lower >> 24n) & 0x00FFFFFFn);
|
||||
// let mc2 = parseInt((mc_lower >> 48n) & 0x00FFFFFFn);
|
||||
|
||||
// let X = dealign24b(mc0 >> 0) | (dealign24b(mc1 >> 0) << 8) | (dealign24b(mc2 >> 0) << 16);
|
||||
// let Y = dealign24b(mc0 >> 1) | (dealign24b(mc1 >> 1) << 8) | (dealign24b(mc2 >> 1) << 16);
|
||||
// let Z = dealign24b(mc0 >> 2) | (dealign24b(mc1 >> 2) << 8) | (dealign24b(mc2 >> 2) << 16);
|
||||
|
||||
|
||||
// =======================
|
||||
// MAGIC NUMBERS BIGINT
|
||||
// =======================
|
||||
// let X = dealign(mc_lower >> 0n);// | (dealign(mc_upper >> 0n) << 16n);
|
||||
// let Y = dealign(mc_lower >> 1n);// | (dealign(mc_upper >> 1n) << 16n);
|
||||
// let Z = dealign(mc_lower >> 2n);// | (dealign(mc_upper >> 2n) << 16n);
|
||||
|
||||
// =======================
|
||||
// LOOP
|
||||
// =======================
|
||||
// let X = 0n;
|
||||
// let Y = 0n;
|
||||
// let Z = 0n;
|
||||
|
||||
// for(let k = 0n; k < 16n; k++){
|
||||
// let mask_lower = (mc_lower >> (3n * k)) & 0b111n;
|
||||
// let mask_upper = (mc_upper >> (3n * k)) & 0b111n;
|
||||
|
||||
// X = X | (((mask_lower >> 0n) & 0b001n) << k);
|
||||
// X = X | ((((mask_upper >> 0n) & 0b001n) << k) << 16n);
|
||||
|
||||
// Y = Y | (((mask_lower >> 1n) & 0b001n) << k);
|
||||
// Y = Y | ((((mask_upper >> 1n) & 0b001n) << k) << 16n);
|
||||
|
||||
// Z = Z | (((mask_lower >> 2n) & 0b001n) << k);
|
||||
// Z = Z | ((((mask_upper >> 2n) & 0b001n) << k) << 16n);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
let x = parseInt(X) * scale[0] + offset[0] - min.x;
|
||||
let y = parseInt(Y) * scale[1] + offset[1] - min.y;
|
||||
let z = parseInt(Z) * scale[2] + offset[2] - min.z;
|
||||
|
||||
let index = toIndex(x, y, z);
|
||||
let count = grid[index]++;
|
||||
if(count === 0){
|
||||
numOccupiedCells++;
|
||||
}
|
||||
|
||||
positions[3 * j + 0] = x;
|
||||
positions[3 * j + 1] = y;
|
||||
positions[3 * j + 2] = z;
|
||||
}
|
||||
|
||||
// let duration = performance.now() - tStart;
|
||||
// console.log(`xyz: ${duration.toFixed(1)}ms`);
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
}else if(["RGBA", "rgba"].includes(pointAttribute.name)){
|
||||
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let colors = new Uint8Array(buff);
|
||||
|
||||
// for (let j = 0; j < numPoints; j++) {
|
||||
// let r = view.getUint16(byteOffset + 0, true);
|
||||
// let g = view.getUint16(byteOffset + 2, true);
|
||||
// let b = view.getUint16(byteOffset + 4, true);
|
||||
// byteOffset += 6;
|
||||
|
||||
// colors[4 * j + 0] = r > 255 ? r / 256 : r;
|
||||
// colors[4 * j + 1] = g > 255 ? g / 256 : g;
|
||||
// colors[4 * j + 2] = b > 255 ? b / 256 : b;
|
||||
// }
|
||||
|
||||
// let tStart = performance.now();
|
||||
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
|
||||
let mc_0 = view.getUint32(byteOffset + 4, true);
|
||||
let mc_1 = view.getUint32(byteOffset + 0, true);
|
||||
byteOffset += 8;
|
||||
|
||||
let r = dealign24b((mc_1 & 0x00FFFFFF) >>> 0)
|
||||
| (dealign24b(((mc_1 >>> 24) | (mc_0 << 8)) >>> 0) << 8);
|
||||
|
||||
let g = dealign24b((mc_1 & 0x00FFFFFF) >>> 1)
|
||||
| (dealign24b(((mc_1 >>> 24) | (mc_0 << 8)) >>> 1) << 8);
|
||||
|
||||
let b = dealign24b((mc_1 & 0x00FFFFFF) >>> 2)
|
||||
| (dealign24b(((mc_1 >>> 24) | (mc_0 << 8)) >>> 2) << 8);
|
||||
|
||||
// let bits = mask_b0[mc_1 >>> 24];
|
||||
|
||||
// if(((r >> 8) & 0b11) !== bits){
|
||||
// debugger;
|
||||
// }
|
||||
|
||||
// let r = dealign24b(mc0 >> 0) | (dealign24b(mc1 >> 0) << 8);
|
||||
// let g = dealign24b(mc0 >> 1) | (dealign24b(mc1 >> 1) << 8);
|
||||
// let b = dealign24b(mc0 >> 2) | (dealign24b(mc1 >> 2) << 8);
|
||||
|
||||
|
||||
colors[4 * j + 0] = r > 255 ? r / 256 : r;
|
||||
colors[4 * j + 1] = g > 255 ? g / 256 : g;
|
||||
colors[4 * j + 2] = b > 255 ? b / 256 : b;
|
||||
}
|
||||
// let duration = performance.now() - tStart;
|
||||
// console.log(`rgb: ${duration.toFixed(1)}ms`);
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
}else{
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let f32 = new Float32Array(buff);
|
||||
|
||||
let TypedArray = typedArrayMapping[pointAttribute.type.name];
|
||||
preciseBuffer = new TypedArray(numPoints);
|
||||
|
||||
let [offset, scale] = [0, 1];
|
||||
|
||||
const getterMap = {
|
||||
"int8": view.getInt8,
|
||||
"int16": view.getInt16,
|
||||
"int32": view.getInt32,
|
||||
// "int64": view.getInt64,
|
||||
"uint8": view.getUint8,
|
||||
"uint16": view.getUint16,
|
||||
"uint32": view.getUint32,
|
||||
// "uint64": view.getUint64,
|
||||
"float": view.getFloat32,
|
||||
"double": view.getFloat64,
|
||||
};
|
||||
const getter = getterMap[pointAttribute.type.name].bind(view);
|
||||
|
||||
// compute offset and scale to pack larger types into 32 bit floats
|
||||
if(pointAttribute.type.size > 4){
|
||||
let [amin, amax] = pointAttribute.range;
|
||||
offset = amin;
|
||||
scale = 1 / (amax - amin);
|
||||
}
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
// let pointOffset = j * bytesPerPoint;
|
||||
let value = getter(byteOffset, true);
|
||||
byteOffset += pointAttribute.byteSize;
|
||||
|
||||
f32[j] = (value - offset) * scale;
|
||||
preciseBuffer[j] = value;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = {
|
||||
buffer: buff,
|
||||
preciseBuffer: preciseBuffer,
|
||||
attribute: pointAttribute,
|
||||
offset: offset,
|
||||
scale: scale,
|
||||
};
|
||||
}
|
||||
|
||||
// attributeOffset += pointAttribute.byteSize;
|
||||
|
||||
|
||||
}
|
||||
|
||||
let occupancy = parseInt(numPoints / numOccupiedCells);
|
||||
// console.log(`${name}: #points: ${numPoints}: #occupiedCells: ${numOccupiedCells}, occupancy: ${occupancy} points/cell`);
|
||||
|
||||
{ // add indices
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let indices = new Uint32Array(buff);
|
||||
|
||||
for (let i = 0; i < numPoints; i++) {
|
||||
indices[i] = i;
|
||||
}
|
||||
|
||||
attributeBuffers["INDICES"] = { buffer: buff, attribute: PointAttribute.INDICES };
|
||||
}
|
||||
|
||||
|
||||
{ // handle attribute vectors
|
||||
let vectors = pointAttributes.vectors;
|
||||
|
||||
for(let vector of vectors){
|
||||
|
||||
let {name, attributes} = vector;
|
||||
let numVectorElements = attributes.length;
|
||||
let buffer = new ArrayBuffer(numVectorElements * numPoints * 4);
|
||||
let f32 = new Float32Array(buffer);
|
||||
|
||||
let iElement = 0;
|
||||
for(let sourceName of attributes){
|
||||
let sourceBuffer = attributeBuffers[sourceName];
|
||||
let {offset, scale} = sourceBuffer;
|
||||
let view = new DataView(sourceBuffer.buffer);
|
||||
|
||||
const getter = view.getFloat32.bind(view);
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
let value = getter(j * 4, true);
|
||||
|
||||
f32[j * numVectorElements + iElement] = (value / scale) + offset;
|
||||
}
|
||||
|
||||
iElement++;
|
||||
}
|
||||
|
||||
let vecAttribute = new PointAttribute(name, PointAttributeTypes.DATA_TYPE_FLOAT, 3);
|
||||
|
||||
attributeBuffers[name] = {
|
||||
buffer: buffer,
|
||||
attribute: vecAttribute,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
let duration = performance.now() - tStart;
|
||||
let pointsPerMs = numPoints / duration;
|
||||
// console.log(`duration: ${duration.toFixed(1)}ms, #points: ${numPoints}, points/ms: ${pointsPerMs.toFixed(1)}`);
|
||||
|
||||
let message = {
|
||||
buffer: buffer,
|
||||
attributeBuffers: attributeBuffers,
|
||||
density: occupancy,
|
||||
};
|
||||
|
||||
let transferables = [];
|
||||
for (let property in message.attributeBuffers) {
|
||||
transferables.push(message.attributeBuffers[property].buffer);
|
||||
}
|
||||
// transferables.push(buffer);
|
||||
|
||||
postMessage(message, transferables);
|
||||
};
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
import {PointAttribute, PointAttributes, PointAttributeTypes} from "../../loader/PointAttributes.js";
|
||||
import {PointAttribute, PointAttributes, PointAttributeTypes} from "../../../loader/PointAttributes.js";
|
||||
import {OctreeGeometry, OctreeGeometryNode} from "./OctreeGeometry.js";
|
||||
|
||||
export class NodeLoader{
|
||||
@ -17,13 +17,13 @@ export class NodeLoader{
|
||||
node.loading = true;
|
||||
Potree.numNodesLoading++;
|
||||
|
||||
if(node.nodeType === 2){
|
||||
await this.loadHierarchy(node);
|
||||
}
|
||||
|
||||
let {byteOffset, byteSize} = node;
|
||||
|
||||
try{
|
||||
if(node.nodeType === 2){
|
||||
await this.loadHierarchy(node);
|
||||
}
|
||||
|
||||
let {byteOffset, byteSize} = node;
|
||||
|
||||
|
||||
let urlOctree = `${this.url}/../octree.bin`;
|
||||
|
||||
@ -39,7 +39,13 @@ export class NodeLoader{
|
||||
|
||||
let buffer = await response.arrayBuffer();
|
||||
|
||||
let workerPath = Potree.scriptPath + '/workers/OctreeDecoderWorker.js';
|
||||
let workerPath;
|
||||
if(this.metadata.encoding === "BROTLI"){
|
||||
workerPath = Potree.scriptPath + '/workers/2.0/DecoderWorker_brotli.js';
|
||||
}else{
|
||||
workerPath = Potree.scriptPath + '/workers/2.0/DecoderWorker.js';
|
||||
}
|
||||
|
||||
let worker = Potree.workerPool.getWorker(workerPath);
|
||||
|
||||
worker.onmessage = function (e) {
|
||||
@ -97,6 +103,7 @@ export class NodeLoader{
|
||||
let min = node.octreeGeometry.offset.clone().add(box.min);
|
||||
let size = box.max.clone().sub(box.min);
|
||||
let max = min.clone().add(size);
|
||||
let numPoints = node.numPoints;
|
||||
|
||||
let offset = node.octreeGeometry.loader.offset;
|
||||
|
||||
@ -109,6 +116,7 @@ export class NodeLoader{
|
||||
max: max,
|
||||
size: size,
|
||||
offset: offset,
|
||||
numPoints: numPoints
|
||||
};
|
||||
|
||||
worker.postMessage(message, [message.buffer]);
|
||||
@ -293,7 +301,7 @@ let typenameTypeattributeMap = {
|
||||
"uint64": PointAttributeTypes.DATA_TYPE_UINT64,
|
||||
}
|
||||
|
||||
export class OctreeLoader_1_8{
|
||||
export class OctreeLoader{
|
||||
|
||||
static parseAttributes(jsonAttributes){
|
||||
|
||||
@ -347,7 +355,7 @@ export class OctreeLoader_1_8{
|
||||
let response = await fetch(url);
|
||||
let metadata = await response.json();
|
||||
|
||||
let attributes = OctreeLoader_1_8.parseAttributes(metadata.attributes);
|
||||
let attributes = OctreeLoader.parseAttributes(metadata.attributes);
|
||||
|
||||
let loader = new NodeLoader(url);
|
||||
loader.metadata = metadata;
|
||||
@ -377,7 +385,7 @@ export class OctreeLoader_1_8{
|
||||
octree.boundingSphere = boundingBox.getBoundingSphere(new THREE.Sphere());
|
||||
octree.tightBoundingSphere = boundingBox.getBoundingSphere(new THREE.Sphere());
|
||||
octree.offset = offset;
|
||||
octree.pointAttributes = OctreeLoader_1_8.parseAttributes(metadata.attributes);
|
||||
octree.pointAttributes = OctreeLoader.parseAttributes(metadata.attributes);
|
||||
octree.loader = loader;
|
||||
|
||||
let root = new OctreeGeometryNode("r", octree, boundingBox);
|
||||
@ -391,7 +399,6 @@ export class OctreeLoader_1_8{
|
||||
|
||||
octree.root = root;
|
||||
|
||||
//await OctreeLoader_1_8.loadHierarchy(url, root);
|
||||
await loader.load(root);
|
||||
|
||||
let result = {
|
||||
Loading…
x
Reference in New Issue
Block a user