update new format loader

This commit is contained in:
m-schuetz 2020-06-14 19:16:13 +02:00
parent 6208769b45
commit 24e9d0877d
4 changed files with 62 additions and 8 deletions

View File

@ -1,7 +1,7 @@
import {Version} from "../../Version.js";
import {PointAttributes, PointAttribute} from "../../loader/PointAttributes.js";
import {PointAttributes, PointAttribute, PointAttributeTypes} from "../../loader/PointAttributes.js";
const typedArrayMapping = {
"int8": Int8Array,
@ -161,6 +161,47 @@ onmessage = function (event) {
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,

View File

@ -59,6 +59,9 @@ export class NodeLoader{
geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(buffer), 3));
}else if(property === "rgba"){
geometry.addAttribute('rgba', new THREE.BufferAttribute(new Uint8Array(buffer), 4, true));
}else if(property === "NORMAL"){
//geometry.addAttribute('rgba', new THREE.BufferAttribute(new Uint8Array(buffer), 4, true));
geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(buffer), 3));
}else if (property === "INDICES") {
let bufferAttribute = new THREE.BufferAttribute(new Uint8Array(buffer), 4);
bufferAttribute.normalized = true;
@ -261,6 +264,22 @@ export class OctreeLoader_1_8{
attributes.add(attribute);
}
{
// check if it has normals
let hasNormals =
attributes.attributes.find(a => a.name === "NormalX") !== undefined &&
attributes.attributes.find(a => a.name === "NormalY") !== undefined &&
attributes.attributes.find(a => a.name === "NormalZ") !== undefined;
if(hasNormals){
let vector = {
name: "NORMAL",
attributes: ["NormalX", "NormalY", "NormalZ"],
};
attributes.addVector(vector);
}
}
return attributes;
}

View File

@ -419,9 +419,8 @@ export class PropertiesPanel{
attribute = pointcloud.getAttribute("intensity");
}
const isIntensity = attribute ? ["intensity", "intensity gradient"].includes(attribute.name) : false;
const isIntensity = ["intensity", "intensity gradient"].includes(attribute.name);
if(isIntensity){
if(pointcloud.material.intensityRange[0] === Infinity){
pointcloud.material.intensityRange = attribute.range;

View File

@ -254,9 +254,6 @@ onmessage = function (event) {
}
{ // handle attribute vectors
let vectors = pointAttributes.vectors;
for(let vector of vectors){
@ -288,8 +285,6 @@ onmessage = function (event) {
attributeBuffers[name] = {
buffer: buffer,
attribute: vecAttribute,
// offset: offset,
// scale: scale,
};
}