diff --git a/zine-geometry-utils.js b/zine-geometry-utils.js index cdeefb7..7f0693e 100644 --- a/zine-geometry-utils.js +++ b/zine-geometry-utils.js @@ -145,6 +145,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 @@ -418,4 +444,4 @@ export const setCameraViewPositionFromOrthographicViewZ = (x, y, viewZ, camera, target.y = worldPoint.y; target.z = worldPoint.z; return target; -} \ No newline at end of file +} diff --git a/zine-renderer.js b/zine-renderer.js index 1fb5998..fabaf8d 100644 --- a/zine-renderer.js +++ b/zine-renderer.js @@ -137,11 +137,8 @@ class SceneMesh extends THREE.Mesh { height, ); geometry.setAttribute('segment', new THREE.BufferAttribute(segmentSpecs.array, 1)); - geometry.setAttribute('segmentColor', new THREE.BufferAttribute(segmentSpecs.colorArray, 3)); geometry.setAttribute('plane', new THREE.BufferAttribute(planeSpecs.array, 1)); - geometry.setAttribute('planeColor', new THREE.BufferAttribute(planeSpecs.colorArray, 3)); // geometry.setAttribute('portal', new THREE.BufferAttribute(portalSpecs.array, 1)); - geometry.setAttribute('portalColor', new THREE.BufferAttribute(portalSpecs.colorArray, 3)); const indexedGeometry = geometry; geometry = geometry.toNonIndexed(); decorateGeometryTriangleIds(geometry); @@ -206,11 +203,8 @@ class ScenePhysicsMesh extends THREE.Mesh { physicsPixelStride, ); // geometry.setAttribute('segment', new THREE.BufferAttribute(segmentSpecs.array, 1)); - // geometry.setAttribute('segmentColor', new THREE.BufferAttribute(segmentSpecs.colorArray, 3)); // geometry.setAttribute('plane', new THREE.BufferAttribute(planeSpecs.array, 1)); - // geometry.setAttribute('planeColor', new THREE.BufferAttribute(planeSpecs.colorArray, 3)); // // geometry.setAttribute('portal', new THREE.BufferAttribute(portalSpecs.array, 1)); - // geometry.setAttribute('portalColor', new THREE.BufferAttribute(portalSpecs.colorArray, 3)); // const indexedGeometry = geometry; // geometry = geometry.toNonIndexed(); // decorateGeometryTriangleIds(geometry); @@ -507,4 +501,4 @@ export class ZineRenderer extends EventTarget { ); targetZineRenderer.camera.updateMatrixWorld(); } -} \ No newline at end of file +}