added camera view behind 3D view
This commit is contained in:
parent
a4f5cf18d8
commit
fd335ce5cd
31
www/package-lock.json
generated
31
www/package-lock.json
generated
@ -22,6 +22,7 @@
|
|||||||
"@rollup/plugin-typescript": "^8.0.0",
|
"@rollup/plugin-typescript": "^8.0.0",
|
||||||
"@tsconfig/svelte": "^2.0.0",
|
"@tsconfig/svelte": "^2.0.0",
|
||||||
"@types/three": "^0.144.0",
|
"@types/three": "^0.144.0",
|
||||||
|
"@types/w3c-image-capture": "^1.0.7",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"prettier-plugin-svelte": "^2.8.0",
|
"prettier-plugin-svelte": "^2.8.0",
|
||||||
"rollup": "^2.3.4",
|
"rollup": "^2.3.4",
|
||||||
@ -353,6 +354,21 @@
|
|||||||
"@types/webxr": "*"
|
"@types/webxr": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/w3c-image-capture": {
|
||||||
|
"version": "1.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/w3c-image-capture/-/w3c-image-capture-1.0.7.tgz",
|
||||||
|
"integrity": "sha512-BNmjJT+yjwVzB6N5kf1/m9YZMF//e3JAcII+TIuhRkALn7UD9xZX0R1azVGqqyYuQKbQ6UskC+zSQctnsk9zHg==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/webrtc": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/webrtc": {
|
||||||
|
"version": "0.0.33",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/webrtc/-/webrtc-0.0.33.tgz",
|
||||||
|
"integrity": "sha512-xjN6BelzkY3lzXjIjXGqJVDS6XDleEsvp1bVIyNccXCcMoTH3wvUXFew4/qflwJdNqjmq98Zc5VcALV+XBKBvg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/@types/webxr": {
|
"node_modules/@types/webxr": {
|
||||||
"version": "0.5.0",
|
"version": "0.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/webxr/-/webxr-0.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/webxr/-/webxr-0.5.0.tgz",
|
||||||
@ -1986,6 +2002,21 @@
|
|||||||
"@types/webxr": "*"
|
"@types/webxr": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/w3c-image-capture": {
|
||||||
|
"version": "1.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/w3c-image-capture/-/w3c-image-capture-1.0.7.tgz",
|
||||||
|
"integrity": "sha512-BNmjJT+yjwVzB6N5kf1/m9YZMF//e3JAcII+TIuhRkALn7UD9xZX0R1azVGqqyYuQKbQ6UskC+zSQctnsk9zHg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/webrtc": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@types/webrtc": {
|
||||||
|
"version": "0.0.33",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/webrtc/-/webrtc-0.0.33.tgz",
|
||||||
|
"integrity": "sha512-xjN6BelzkY3lzXjIjXGqJVDS6XDleEsvp1bVIyNccXCcMoTH3wvUXFew4/qflwJdNqjmq98Zc5VcALV+XBKBvg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@types/webxr": {
|
"@types/webxr": {
|
||||||
"version": "0.5.0",
|
"version": "0.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/webxr/-/webxr-0.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/webxr/-/webxr-0.5.0.tgz",
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
"@rollup/plugin-typescript": "^8.0.0",
|
"@rollup/plugin-typescript": "^8.0.0",
|
||||||
"@tsconfig/svelte": "^2.0.0",
|
"@tsconfig/svelte": "^2.0.0",
|
||||||
"@types/three": "^0.144.0",
|
"@types/three": "^0.144.0",
|
||||||
|
"@types/w3c-image-capture": "^1.0.7",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"prettier-plugin-svelte": "^2.8.0",
|
"prettier-plugin-svelte": "^2.8.0",
|
||||||
"rollup": "^2.3.4",
|
"rollup": "^2.3.4",
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
import 'papercss/dist/paper.min.css';
|
import 'papercss/dist/paper.min.css';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { Router, Route } from 'svelte-navigator';
|
import { Router, Route } from 'svelte-navigator';
|
||||||
import { currentUser } from './store/user';
|
import { currentUser } from './store/user';
|
||||||
import { read } from './functions/user';
|
import { read } from './functions/user';
|
||||||
|
import ViewAR from './pages/ViewAR.svelte';
|
||||||
import Test3D from './pages/test3D.svelte';
|
|
||||||
import Login from './pages/Login.svelte';
|
import Login from './pages/Login.svelte';
|
||||||
import Profile from './pages/Profile.svelte';
|
import Profile from './pages/Profile.svelte';
|
||||||
|
|
||||||
@ -24,7 +23,7 @@
|
|||||||
|
|
||||||
<Router>
|
<Router>
|
||||||
<Route path="/">
|
<Route path="/">
|
||||||
<Test3D />
|
<ViewAR />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/login">
|
<Route path="/login">
|
||||||
<Login />
|
<Login />
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import NavBar from '../components/NavBar.svelte';
|
|
||||||
import { beforeUpdate, afterUpdate, onMount, onDestroy } from 'svelte';
|
import { beforeUpdate, afterUpdate, onMount, onDestroy } from 'svelte';
|
||||||
import * as Three from 'three';
|
import * as Three from 'three';
|
||||||
|
|
||||||
let container: HTMLElement;
|
export let width: number;
|
||||||
let canvas: HTMLCanvasElement;
|
export let height: number;
|
||||||
let width: number;
|
|
||||||
let height: number;
|
|
||||||
|
|
||||||
//#region variables
|
//#region variables
|
||||||
//let innerWidth: number = 0;
|
let container: HTMLElement;
|
||||||
//let innerHeight: number = 0;
|
let canvas: HTMLCanvasElement;
|
||||||
let maxInnerWidth: number = 0;
|
let maxInnerWidth: number = 0;
|
||||||
let maxInnerHeight: number = 0;
|
let maxInnerHeight: number = 0;
|
||||||
|
|
||||||
@ -18,6 +15,21 @@
|
|||||||
let focalLength: number = 540 / Math.atan((70 * Math.PI) / 180);
|
let focalLength: number = 540 / Math.atan((70 * Math.PI) / 180);
|
||||||
let fov = 75;
|
let fov = 75;
|
||||||
//let baseHorizontalFOV: number = 2.0*Math.atan(baseAspectRation*Math.tan(baseVerticalFOV*0.5));
|
//let baseHorizontalFOV: number = 2.0*Math.atan(baseAspectRation*Math.tan(baseVerticalFOV*0.5));
|
||||||
|
|
||||||
|
let scene: Three.Scene = new Three.Scene();
|
||||||
|
let camera: Three.PerspectiveCamera = new Three.PerspectiveCamera(
|
||||||
|
75,
|
||||||
|
1,
|
||||||
|
0.1,
|
||||||
|
1000,
|
||||||
|
);
|
||||||
|
|
||||||
|
let renderer: Three.WebGLRenderer = new Three.WebGLRenderer();
|
||||||
|
let box: Three.BoxGeometry = new Three.BoxGeometry(1, 1, 1);
|
||||||
|
let mat: Three.MeshBasicMaterial = new Three.MeshBasicMaterial({
|
||||||
|
color: 0x00ff00,
|
||||||
|
});
|
||||||
|
let cube = new Three.Mesh(box, mat);
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region functions
|
//#region functions
|
||||||
@ -50,22 +62,6 @@
|
|||||||
resetMaxDimensions();
|
resetMaxDimensions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//#endregion
|
|
||||||
|
|
||||||
let scene: Three.Scene = new Three.Scene();
|
|
||||||
let camera: Three.PerspectiveCamera = new Three.PerspectiveCamera(
|
|
||||||
75,
|
|
||||||
1,
|
|
||||||
0.1,
|
|
||||||
1000,
|
|
||||||
);
|
|
||||||
|
|
||||||
let renderer: Three.WebGLRenderer = new Three.WebGLRenderer();
|
|
||||||
let box: Three.BoxGeometry = new Three.BoxGeometry(1, 1, 1);
|
|
||||||
let mat: Three.MeshBasicMaterial = new Three.MeshBasicMaterial({
|
|
||||||
color: 0x00ff00,
|
|
||||||
});
|
|
||||||
let cube = new Three.Mesh(box, mat);
|
|
||||||
|
|
||||||
function animate() {
|
function animate() {
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
@ -75,6 +71,7 @@
|
|||||||
|
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
}
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
canvas = container.appendChild(renderer.domElement);
|
canvas = container.appendChild(renderer.domElement);
|
||||||
@ -96,7 +93,7 @@
|
|||||||
camera.setViewOffset(width, height, 0, 0, width, height);
|
camera.setViewOffset(width, height, 0, 0, width, height);
|
||||||
renderer.setSize(width, height);
|
renderer.setSize(width, height);
|
||||||
|
|
||||||
//renderer.setClearColor(0x000000, (innerHeight/(maxInnerHeight))/2 + 0.5);
|
renderer.setClearColor(0x000000, 0.1);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterUpdate(() => {});
|
afterUpdate(() => {});
|
||||||
@ -106,17 +103,15 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div class="Container" bind:this={container} />
|
||||||
id="container"
|
|
||||||
bind:this={container}
|
|
||||||
bind:clientWidth={width}
|
|
||||||
bind:clientHeight={height}
|
|
||||||
/>
|
|
||||||
<NavBar />
|
|
||||||
|
|
||||||
<!--<svelte:window bind:innerWidth bind:innerHeight /> -->
|
|
||||||
<style>
|
<style>
|
||||||
#container {
|
.Container {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
45
www/src/components/CameraHandler.svelte
Normal file
45
www/src/components/CameraHandler.svelte
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import CameraPreview from './CameraPreview.svelte';
|
||||||
|
import { getMediaStream, getImageCapture } from '../helpers/MediaHelper';
|
||||||
|
|
||||||
|
export let width: number;
|
||||||
|
export let height: number;
|
||||||
|
|
||||||
|
let container: HTMLElement;
|
||||||
|
|
||||||
|
let cameraWidth: number = 0;
|
||||||
|
let cameraHeight: number = 0;
|
||||||
|
|
||||||
|
let pictureUrl: string;
|
||||||
|
let imageCapture: ImageCapture;
|
||||||
|
let mediaStreamPromise: Promise<MediaStream>;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
mediaStreamPromise = getMediaStream({ video: true }).then((mediaStream) => {
|
||||||
|
imageCapture = getImageCapture(mediaStream);
|
||||||
|
return mediaStream;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="Container">
|
||||||
|
{#await mediaStreamPromise}
|
||||||
|
<h1>Waiting for camera....</h1>
|
||||||
|
{:then mediaStream}
|
||||||
|
<CameraPreview {mediaStream} {height} {width} />
|
||||||
|
{:catch error}
|
||||||
|
<h1>Error: {error.message}</h1>
|
||||||
|
{/await}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.Container {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
24
www/src/components/cameraPreview.svelte
Normal file
24
www/src/components/cameraPreview.svelte
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let mediaStream: MediaStream;
|
||||||
|
export let width: number;
|
||||||
|
export let height: number;
|
||||||
|
|
||||||
|
function srcObject(node, stream) {
|
||||||
|
node.srcObject = stream;
|
||||||
|
return {
|
||||||
|
update(newStream) {
|
||||||
|
if (node.srcObject != newStream) {
|
||||||
|
node.srcObject = newStream;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<video
|
||||||
|
use:srcObject={mediaStream}
|
||||||
|
width={width}
|
||||||
|
height={height}
|
||||||
|
autoplay
|
||||||
|
playsinline
|
||||||
|
/>
|
10
www/src/helpers/mediaHelper.ts
Normal file
10
www/src/helpers/mediaHelper.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
function getMediaStream(constraints = { video: true }) {
|
||||||
|
return navigator.mediaDevices.getUserMedia(constraints);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getImageCapture(mediaStream) {
|
||||||
|
const track = mediaStream.getVideoTracks()[0];
|
||||||
|
return new ImageCapture(track);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getMediaStream, getImageCapture };
|
26
www/src/pages/ViewAR.svelte
Normal file
26
www/src/pages/ViewAR.svelte
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import View3D from '../components/3DHandler.svelte';
|
||||||
|
import Camera from '../components/CameraHandler.svelte';
|
||||||
|
import NavBar from '../components/NavBar.svelte';
|
||||||
|
|
||||||
|
let containerHeight: number;
|
||||||
|
let containerWidth: number;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="viewAR"
|
||||||
|
bind:clientHeight={containerHeight}
|
||||||
|
bind:clientWidth={containerWidth}
|
||||||
|
>
|
||||||
|
<Camera height={containerHeight} width={containerWidth} />
|
||||||
|
<View3D height={containerHeight} width={containerWidth} />
|
||||||
|
</div>
|
||||||
|
<NavBar />
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.viewAR {
|
||||||
|
position: absolute;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
x
Reference in New Issue
Block a user