diff --git a/src/modules/Loader_1.8/OctreeDecoderWorker.js b/src/modules/Loader_1.8/OctreeDecoderWorker.js index d62b486f..51460028 100644 --- a/src/modules/Loader_1.8/OctreeDecoderWorker.js +++ b/src/modules/Loader_1.8/OctreeDecoderWorker.js @@ -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, diff --git a/src/modules/Loader_1.8/OctreeLoader_1_8.js b/src/modules/Loader_1.8/OctreeLoader_1_8.js index 59088004..96dd5bbe 100644 --- a/src/modules/Loader_1.8/OctreeLoader_1_8.js +++ b/src/modules/Loader_1.8/OctreeLoader_1_8.js @@ -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; } diff --git a/src/viewer/PropertyPanels/PropertiesPanel.js b/src/viewer/PropertyPanels/PropertiesPanel.js index 2768242d..f34b4d11 100644 --- a/src/viewer/PropertyPanels/PropertiesPanel.js +++ b/src/viewer/PropertyPanels/PropertiesPanel.js @@ -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; diff --git a/src/workers/BinaryDecoderWorker.js b/src/workers/BinaryDecoderWorker.js index cb8c5acd..ae34e1c3 100644 --- a/src/workers/BinaryDecoderWorker.js +++ b/src/workers/BinaryDecoderWorker.js @@ -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, }; }