Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce point cloud data to positional data #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion zine-constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const panelSize = 1024;

export const pointCloudPositionalStride = 4 + 4 + 4;
export const pointCloudFullStride = pointCloudPositionalStride + 1 + 1 + 1;

export const floorNetWorldSize = 100;
export const floorNetWorldDepth = 1000;
export const floorNetResolution = 0.1;
export const floorNetPixelSize = floorNetWorldSize / floorNetResolution;

export const pointcloudStride = 4 + 4 + 4 + 1 + 1 + 1;
export const physicsPixelStride = 8;
46 changes: 36 additions & 10 deletions zine-geometry-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as THREE from 'three';
import {
pointcloudStride,
} from './zine-constants.js';
import { pointCloudPositionalStride } from './zine-constants.js';

//

Expand All @@ -18,9 +16,9 @@ function pointCloudArrayBufferToPositionAttributeArray(
pixelStride = 1,
) { // result in float32Array
const dataView = new DataView(arrayBuffer);
for (let i = 0, j = 0; i < arrayBuffer.byteLength; i += pointcloudStride) {
for (let i = 0, j = 0; i < arrayBuffer.byteLength; i += pointCloudPositionalStride) {
if (pixelStride !== 1) {
const i2 = i / pointcloudStride;
const i2 = i / pointCloudPositionalStride;
const sx = i2 % width;
const sy = Math.floor(i2 / width);
if (sx % pixelStride !== 0 || sy % pixelStride !== 0) { // skip non-stride points
Expand Down Expand Up @@ -138,6 +136,32 @@ export function depthFloat32ArrayToGeometry(

//

export function getDepthFloat32ArrayWorldPositionPx(
depthFloat32Array,
px,
py,
width,
height,
camera,
scale,
target
) {
px = Math.min(Math.max(px, 0), width - 1);
py = Math.min(Math.max(py, 0), height - 1);

let x = px / width;
let y = py / height;

const i = py * width + px;
y = 1 - y;

const viewZ = depthFloat32Array[i];
const worldPoint = setCameraViewPositionFromViewZ(x, y, viewZ, camera, target);
worldPoint.multiply(scale);
worldPoint.applyMatrix4(camera.matrixWorld);
return target;
}

export function getDepthFloat32ArrayWorldPosition(
depthFloat32Array,
x, // 0..1
Expand Down Expand Up @@ -289,8 +313,12 @@ export const snapPointCloudToCamera = (pointCloudArrayBuffer, width, height, cam

const scaleFactor = 1 / width;
const dataView = new DataView(pointCloudArrayBuffer);
for (let i = 0; i < pointCloudArrayBuffer.byteLength; i += pointcloudStride) {
let x = dataView.getFloat32(i + 0, true);
for (
let i = 0;
i < pointCloudArrayBuffer.byteLength;
i += pointCloudPositionalStride
) {
let x = dataView.getFloat32(i , true);
let y = dataView.getFloat32(i + 4, true);
let z = dataView.getFloat32(i + 8, true);

Expand Down Expand Up @@ -413,8 +441,6 @@ export const setCameraViewPositionFromOrthographicViewZ = (x, y, viewZ, camera,
return target;
}

//

export const getDoubleSidedGeometry = geometry => {
const geometry2 = geometry.clone();
// double-side the geometry
Expand Down Expand Up @@ -452,4 +478,4 @@ export const getGeometryHeights = (geometry, width, height, heightfieldScale) =>
}
}
return heights;
};
};
10 changes: 5 additions & 5 deletions zine-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from './zine-camera-utils.js';
import {
floorNetPixelSize,
pointcloudStride,
pointCloudPositionalStride,
physicsPixelStride,
} from './zine-constants.js';

Expand Down Expand Up @@ -218,17 +218,17 @@ class ScenePhysicsMesh extends THREE.Mesh {
// }
const arrayBuffer = pointCloudArrayBuffer;
const pixelStride = physicsPixelStride;
for (let i = 0, j = 0; i < arrayBuffer.byteLength; i += pointcloudStride) {
for (let i = 0, j = 0; i < arrayBuffer.byteLength; i += pointCloudPositionalStride) {
if (pixelStride !== 1) {
const i2 = i / pointcloudStride;
const i2 = i / pointCloudPositionalStride;
const sx = i2 % width;
const sy = Math.floor(i2 / width);
if (sx % pixelStride !== 0 || sy % pixelStride !== 0) { // skip non-stride points
continue;
}
}

const s = segmentSpecs.array[i / pointcloudStride];
const s = segmentSpecs.array[i / pointCloudPositionalStride];
segments[j] = s;

j++;
Expand Down Expand Up @@ -544,4 +544,4 @@ export class ZineRenderer extends EventTarget {
);
targetZineRenderer.camera.updateMatrixWorld();
}
}
}