auto-git:
[unlink] playwright.config.js [unlink] src/app/App.js [unlink] src/app/editor-store.js [unlink] src/app/use-editor-store.js [unlink] src/assets/audio-assets.js [unlink] src/assets/gltf-model-import.js [unlink] src/assets/image-assets.js [unlink] src/assets/model-instance-labels.js [unlink] src/assets/model-instance-rendering.js [unlink] src/assets/model-instances.js [unlink] src/assets/project-asset-storage.js [unlink] src/assets/project-assets.js [unlink] src/commands/brush-command-helpers.js [unlink] src/commands/command-history.js [unlink] src/commands/command.js [unlink] src/commands/commit-transform-session-command.js [unlink] src/commands/create-box-brush-command.js [unlink] src/commands/delete-box-brush-command.js [unlink] src/commands/delete-entity-command.js [unlink] src/commands/delete-interaction-link-command.js [unlink] src/commands/delete-model-instance-command.js [unlink] src/commands/duplicate-selection-command.js [unlink] src/commands/import-audio-asset-command.js [unlink] src/commands/import-background-image-asset-command.js [unlink] src/commands/import-model-asset-command.js [unlink] src/commands/move-box-brush-command.js [unlink] src/commands/resize-box-brush-command.js [unlink] src/commands/rotate-box-brush-command.js [unlink] src/commands/set-box-brush-face-material-command.js [unlink] src/commands/set-box-brush-face-uv-state-command.js [unlink] src/commands/set-box-brush-name-command.js [unlink] src/commands/set-box-brush-transform-command.js [unlink] src/commands/set-box-brush-volume-settings-command.js [unlink] src/commands/set-entity-name-command.js [unlink] src/commands/set-model-instance-name-command.js [unlink] src/commands/set-player-start-command.js [unlink] src/commands/set-scene-name-command.js [unlink] src/commands/set-world-settings-command.js [unlink] src/commands/upsert-entity-command.js [unlink] src/commands/upsert-interaction-link-command.js [unlink] src/commands/upsert-model-instance-command.js [unlink] src/core/ids.js [unlink] src/core/selection.js [unlink] src/core/tool-mode.js [unlink] src/core/transform-session.js [unlink] src/core/vector.js [unlink] src/core/whitebox-selection-feedback.js [unlink] src/core/whitebox-selection-mode.js [unlink] src/document/brushes.js [unlink] src/document/migrate-scene-document.js [unlink] src/document/scene-document-validation.js [unlink] src/document/scene-document.js [unlink] src/document/world-settings.js [unlink] src/entities/entity-instances.js [unlink] src/entities/entity-labels.js [unlink] src/geometry/box-brush-components.js [unlink] src/geometry/box-brush-mesh.js [unlink] src/geometry/box-brush.js [unlink] src/geometry/box-face-uvs.js [unlink] src/geometry/grid-snapping.js [unlink] src/geometry/model-instance-collider-debug-mesh.js [unlink] src/geometry/model-instance-collider-generation.js [unlink] src/interactions/interaction-links.js [unlink] src/main.js [unlink] src/materials/starter-material-library.js [unlink] src/materials/starter-material-textures.js [unlink] src/rendering/advanced-rendering.js [unlink] src/rendering/fog-material.js [unlink] src/rendering/planar-reflection.js [unlink] src/rendering/water-material.js [unlink] src/runner-web/RunnerCanvas.js [unlink] src/runtime-three/first-person-navigation-controller.js [unlink] src/runtime-three/navigation-controller.js [unlink] src/runtime-three/orbit-visitor-navigation-controller.js [unlink] src/runtime-three/player-collision.js [unlink] src/runtime-three/rapier-collision-world.js [unlink] src/runtime-three/runtime-audio-system.js [unlink] src/runtime-three/runtime-host.js [unlink] src/runtime-three/runtime-interaction-system.js [unlink] src/runtime-three/runtime-scene-build.js [unlink] src/runtime-three/runtime-scene-validation.js [unlink] src/runtime-three/underwater-fog.js [unlink] src/serialization/local-draft-storage.js [unlink] src/serialization/scene-document-json.js [unlink] src/shared-ui/HierarchicalMenu.js [unlink] src/shared-ui/Panel.js [unlink] src/shared-ui/world-background-style.js [unlink] src/viewport-three/ViewportCanvas.js [unlink] src/viewport-three/ViewportPanel.js [unlink] src/viewport-three/viewport-entity-markers.js [unlink] src/viewport-three/viewport-focus.js [unlink] src/viewport-three/viewport-host.js [unlink] src/viewport-three/viewport-layout.js [unlink] src/viewport-three/viewport-transient-state.js [unlink] src/viewport-three/viewport-view-modes.js [unlink] vite.config.js [unlink] vitest.config.js
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
import { Euler, Matrix4, PerspectiveCamera, Plane, Quaternion, Vector3, Vector4 } from "three";
|
||||
|
||||
const SURFACE_UP = new Vector3(0, 1, 0);
|
||||
const CAMERA_FORWARD = new Vector3(0, 0, -1);
|
||||
|
||||
function createRotationQuaternion(rotationDegrees) {
|
||||
return new Quaternion().setFromEuler(new Euler((rotationDegrees.x * Math.PI) / 180, (rotationDegrees.y * Math.PI) / 180, (rotationDegrees.z * Math.PI) / 180, "XYZ"));
|
||||
}
|
||||
|
||||
export function updatePlanarReflectionCamera(surface, sourceCamera, reflectionCamera, reflectionMatrix, clipBias = 0.003) {
|
||||
const rotation = createRotationQuaternion(surface.rotationDegrees);
|
||||
const surfaceNormal = SURFACE_UP.clone().applyQuaternion(rotation).normalize();
|
||||
const surfaceCenter = new Vector3(surface.center.x, surface.center.y, surface.center.z).add(surfaceNormal.clone().multiplyScalar(surface.size.y * 0.5));
|
||||
const cameraWorldPosition = new Vector3().setFromMatrixPosition(sourceCamera.matrixWorld);
|
||||
const sourceRotationMatrix = new Matrix4().extractRotation(sourceCamera.matrixWorld);
|
||||
const lookAtPosition = CAMERA_FORWARD.clone().applyMatrix4(sourceRotationMatrix).add(cameraWorldPosition);
|
||||
const reflectedViewPosition = surfaceCenter.clone().sub(cameraWorldPosition);
|
||||
if (reflectedViewPosition.dot(surfaceNormal) > 0) {
|
||||
return false;
|
||||
}
|
||||
reflectedViewPosition.reflect(surfaceNormal).negate();
|
||||
reflectedViewPosition.add(surfaceCenter);
|
||||
const reflectedTarget = surfaceCenter.clone().sub(lookAtPosition);
|
||||
reflectedTarget.reflect(surfaceNormal).negate();
|
||||
reflectedTarget.add(surfaceCenter);
|
||||
reflectionCamera.position.copy(reflectedViewPosition);
|
||||
reflectionCamera.up.set(0, 1, 0).applyMatrix4(sourceRotationMatrix).reflect(surfaceNormal);
|
||||
reflectionCamera.near = sourceCamera.near;
|
||||
reflectionCamera.far = sourceCamera.far;
|
||||
reflectionCamera.aspect = sourceCamera.aspect;
|
||||
reflectionCamera.projectionMatrix.copy(sourceCamera.projectionMatrix);
|
||||
reflectionCamera.projectionMatrixInverse.copy(sourceCamera.projectionMatrixInverse);
|
||||
reflectionCamera.lookAt(reflectedTarget);
|
||||
reflectionCamera.updateMatrixWorld();
|
||||
reflectionCamera.matrixWorldInverse.copy(reflectionCamera.matrixWorld).invert();
|
||||
reflectionMatrix.set(0.5, 0, 0, 0.5, 0, 0.5, 0, 0.5, 0, 0, 0.5, 0.5, 0, 0, 0, 1);
|
||||
reflectionMatrix.multiply(reflectionCamera.projectionMatrix);
|
||||
reflectionMatrix.multiply(reflectionCamera.matrixWorldInverse);
|
||||
const clipPlane = new Plane().setFromNormalAndCoplanarPoint(surfaceNormal, surfaceCenter).applyMatrix4(reflectionCamera.matrixWorldInverse);
|
||||
const clipVector = new Vector4(clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.constant);
|
||||
const projectionElements = reflectionCamera.projectionMatrix.elements;
|
||||
const q = new Vector4((Math.sign(clipVector.x) + projectionElements[8]) / projectionElements[0], (Math.sign(clipVector.y) + projectionElements[9]) / projectionElements[5], -1, (1 + projectionElements[10]) / projectionElements[14]);
|
||||
clipVector.multiplyScalar(2 / clipVector.dot(q));
|
||||
projectionElements[2] = clipVector.x;
|
||||
projectionElements[6] = clipVector.y;
|
||||
projectionElements[10] = clipVector.z + 1 - clipBias;
|
||||
projectionElements[14] = clipVector.w;
|
||||
reflectionCamera.projectionMatrixInverse.copy(reflectionCamera.projectionMatrix).invert();
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user