Spaces:
Runtime error
Runtime error
Commit
•
a60cb50
1
Parent(s):
2f0f4c5
working on coordinate conversion
Browse files- package-lock.json +5 -0
- package.json +5 -0
- src/app/engines.ts +2 -2
- src/app/render.ts +1 -1
- src/components/business/renderer.tsx +1 -1
- src/components/business/spherical-image.tsx +21 -3
- src/lib/cartesianToSpherical.ts +6 -0
- src/lib/getCoordinatesFromMousePosition.ts +39 -0
- src/lib/sphericalToCartesian.ts +6 -0
package-lock.json
CHANGED
@@ -11,6 +11,10 @@
|
|
11 |
"@gorgonjs/gorgon": "^1.4.1",
|
12 |
"@huggingface/agents": "^0.0.4",
|
13 |
"@huggingface/inference": "^2.6.1",
|
|
|
|
|
|
|
|
|
14 |
"@radix-ui/react-accordion": "^1.1.2",
|
15 |
"@radix-ui/react-avatar": "^1.0.3",
|
16 |
"@radix-ui/react-checkbox": "^1.0.4",
|
@@ -45,6 +49,7 @@
|
|
45 |
"fs-extra": "^11.1.1",
|
46 |
"lucide-react": "^0.260.0",
|
47 |
"next": "13.4.10",
|
|
|
48 |
"pick": "^0.0.1",
|
49 |
"postcss": "8.4.26",
|
50 |
"react": "18.2.0",
|
|
|
11 |
"@gorgonjs/gorgon": "^1.4.1",
|
12 |
"@huggingface/agents": "^0.0.4",
|
13 |
"@huggingface/inference": "^2.6.1",
|
14 |
+
"@photo-sphere-viewer/core": "^5.1.7",
|
15 |
+
"@photo-sphere-viewer/markers-plugin": "^5.1.7",
|
16 |
+
"@photo-sphere-viewer/video-plugin": "^5.1.7",
|
17 |
+
"@photo-sphere-viewer/virtual-tour-plugin": "^5.1.7",
|
18 |
"@radix-ui/react-accordion": "^1.1.2",
|
19 |
"@radix-ui/react-avatar": "^1.0.3",
|
20 |
"@radix-ui/react-checkbox": "^1.0.4",
|
|
|
49 |
"fs-extra": "^11.1.1",
|
50 |
"lucide-react": "^0.260.0",
|
51 |
"next": "13.4.10",
|
52 |
+
"photo-sphere-viewer-lensflare-plugin": "^1.1.1",
|
53 |
"pick": "^0.0.1",
|
54 |
"postcss": "8.4.26",
|
55 |
"react": "18.2.0",
|
package.json
CHANGED
@@ -12,6 +12,10 @@
|
|
12 |
"@gorgonjs/gorgon": "^1.4.1",
|
13 |
"@huggingface/agents": "^0.0.4",
|
14 |
"@huggingface/inference": "^2.6.1",
|
|
|
|
|
|
|
|
|
15 |
"@radix-ui/react-accordion": "^1.1.2",
|
16 |
"@radix-ui/react-avatar": "^1.0.3",
|
17 |
"@radix-ui/react-checkbox": "^1.0.4",
|
@@ -46,6 +50,7 @@
|
|
46 |
"fs-extra": "^11.1.1",
|
47 |
"lucide-react": "^0.260.0",
|
48 |
"next": "13.4.10",
|
|
|
49 |
"pick": "^0.0.1",
|
50 |
"postcss": "8.4.26",
|
51 |
"react": "18.2.0",
|
|
|
12 |
"@gorgonjs/gorgon": "^1.4.1",
|
13 |
"@huggingface/agents": "^0.0.4",
|
14 |
"@huggingface/inference": "^2.6.1",
|
15 |
+
"@photo-sphere-viewer/core": "^5.1.7",
|
16 |
+
"@photo-sphere-viewer/markers-plugin": "^5.1.7",
|
17 |
+
"@photo-sphere-viewer/video-plugin": "^5.1.7",
|
18 |
+
"@photo-sphere-viewer/virtual-tour-plugin": "^5.1.7",
|
19 |
"@radix-ui/react-accordion": "^1.1.2",
|
20 |
"@radix-ui/react-avatar": "^1.0.3",
|
21 |
"@radix-ui/react-checkbox": "^1.0.4",
|
|
|
50 |
"fs-extra": "^11.1.1",
|
51 |
"lucide-react": "^0.260.0",
|
52 |
"next": "13.4.10",
|
53 |
+
"photo-sphere-viewer-lensflare-plugin": "^1.1.1",
|
54 |
"pick": "^0.0.1",
|
55 |
"postcss": "8.4.26",
|
56 |
"react": "18.2.0",
|
src/app/engines.ts
CHANGED
@@ -47,8 +47,8 @@ export const engines: Record<string, Engine> = {
|
|
47 |
label: "Spherical video",
|
48 |
visible: false,
|
49 |
enabled: false,
|
50 |
-
modelName: "",
|
51 |
-
modelUrl: "",
|
52 |
},
|
53 |
|
54 |
spherical_stereogram: {
|
|
|
47 |
label: "Spherical video",
|
48 |
visible: false,
|
49 |
enabled: false,
|
50 |
+
modelName: "Zeroscope",
|
51 |
+
modelUrl: "https://huggingface.co/cerspense/zeroscope_v2_576w",
|
52 |
},
|
53 |
|
54 |
spherical_stereogram: {
|
src/app/render.ts
CHANGED
@@ -29,7 +29,7 @@ export async function newRender({
|
|
29 |
throw new Error(`cannot call the rendering API without actionnables, aborting..`)
|
30 |
}
|
31 |
|
32 |
-
const nbFrames = engine.type
|
33 |
|
34 |
const cacheKey = `render/${JSON.stringify({ prompt, actionnables, nbFrames, type: engine.type })}`
|
35 |
|
|
|
29 |
throw new Error(`cannot call the rendering API without actionnables, aborting..`)
|
30 |
}
|
31 |
|
32 |
+
const nbFrames = engine.type.includes("video") ? 8 : 1
|
33 |
|
34 |
const cacheKey = `render/${JSON.stringify({ prompt, actionnables, nbFrames, type: engine.type })}`
|
35 |
|
src/components/business/renderer.tsx
CHANGED
@@ -194,7 +194,7 @@ export const Renderer = ({
|
|
194 |
onEvent={handleMouseEvent}
|
195 |
debug={debug}
|
196 |
/>
|
197 |
-
: engine.type === "spherical_image"
|
198 |
? <SphericalImage
|
199 |
rendered={rendered}
|
200 |
onEvent={handleMouseEvent}
|
|
|
194 |
onEvent={handleMouseEvent}
|
195 |
debug={debug}
|
196 |
/>
|
197 |
+
: (engine.type === "spherical_image" || engine.type === "spherical_video")
|
198 |
? <SphericalImage
|
199 |
rendered={rendered}
|
200 |
onEvent={handleMouseEvent}
|
src/components/business/spherical-image.tsx
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
-
import {
|
|
|
|
|
2 |
|
3 |
-
import { SceneEventHandler } from "./types"
|
4 |
import { RenderedScene } from "@/app/types"
|
5 |
-
|
|
|
6 |
|
7 |
export function SphericalImage({
|
8 |
rendered,
|
@@ -27,6 +29,7 @@ export function SphericalImage({
|
|
27 |
defaultZoomLvl: 1,
|
28 |
overlay: rendered.maskUrl || undefined,
|
29 |
overlayOpacity: debug ? 0.5 : 0,
|
|
|
30 |
/*
|
31 |
panoData: {
|
32 |
fullWidth: 2000,
|
@@ -71,6 +74,20 @@ export function SphericalImage({
|
|
71 |
task()
|
72 |
}, [sceneConfig, rendered.assetUrl, ref.current])
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
if (!rendered.assetUrl) {
|
75 |
return null
|
76 |
}
|
@@ -84,6 +101,7 @@ export function SphericalImage({
|
|
84 |
//
|
85 |
height="100vh"
|
86 |
width="100%"
|
|
|
87 |
|
88 |
{...options}
|
89 |
|
|
|
1 |
+
import { useEffect, useRef, useState } from "react"
|
2 |
+
import { PluginConstructor } from "@photo-sphere-viewer/core"
|
3 |
+
import { LensflarePlugin, ReactPhotoSphereViewer } from "react-photo-sphere-viewer"
|
4 |
|
|
|
5 |
import { RenderedScene } from "@/app/types"
|
6 |
+
|
7 |
+
import { SceneEventHandler } from "./types"
|
8 |
|
9 |
export function SphericalImage({
|
10 |
rendered,
|
|
|
29 |
defaultZoomLvl: 1,
|
30 |
overlay: rendered.maskUrl || undefined,
|
31 |
overlayOpacity: debug ? 0.5 : 0,
|
32 |
+
fisheye: false, // ..no!
|
33 |
/*
|
34 |
panoData: {
|
35 |
fullWidth: 2000,
|
|
|
74 |
task()
|
75 |
}, [sceneConfig, rendered.assetUrl, ref.current])
|
76 |
|
77 |
+
const plugins: (PluginConstructor | [PluginConstructor, any])[] = [
|
78 |
+
|
79 |
+
// for the lensflare plugin we are also gonna need aw ay to determine the position
|
80 |
+
[LensflarePlugin, {
|
81 |
+
lensflares: [
|
82 |
+
{
|
83 |
+
id: 'sun',
|
84 |
+
position: { yaw: '145deg', pitch: '2deg' },
|
85 |
+
type: 0,
|
86 |
+
}
|
87 |
+
]
|
88 |
+
}]
|
89 |
+
]
|
90 |
+
|
91 |
if (!rendered.assetUrl) {
|
92 |
return null
|
93 |
}
|
|
|
101 |
//
|
102 |
height="100vh"
|
103 |
width="100%"
|
104 |
+
// plugins={plugins}
|
105 |
|
106 |
{...options}
|
107 |
|
src/lib/cartesianToSpherical.ts
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export function cartesianToSpherical(x: number, y: number, width: number, height: number): { yaw: number, pitch: number } {
|
2 |
+
const yaw = (x / width) * 360 - 180;
|
3 |
+
const pitch = (y / height) * 180 - 90;
|
4 |
+
|
5 |
+
return { yaw, pitch };
|
6 |
+
}
|
src/lib/getCoordinatesFromMousePosition.ts
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export function getCoordinatesFromMousePosition({
|
2 |
+
mouseX,
|
3 |
+
mouseY,
|
4 |
+
containerWidth,
|
5 |
+
containerHeight,
|
6 |
+
currentYaw,
|
7 |
+
currentPitch,
|
8 |
+
imageWidth,
|
9 |
+
imageHeight,
|
10 |
+
fov,
|
11 |
+
}: {
|
12 |
+
mouseX: number
|
13 |
+
mouseY: number
|
14 |
+
containerWidth: number
|
15 |
+
containerHeight: number
|
16 |
+
currentYaw: number
|
17 |
+
currentPitch: number
|
18 |
+
imageWidth: number
|
19 |
+
imageHeight: number
|
20 |
+
fov: number
|
21 |
+
}): { x: number; y: number } {
|
22 |
+
// Convert mouse position to relative to the viewer's center
|
23 |
+
const relativeX = 2 * (mouseX / containerWidth) - 1;
|
24 |
+
const relativeY = 2 * (mouseY / containerHeight) - 1;
|
25 |
+
|
26 |
+
// Calculate angle differences (in degrees)
|
27 |
+
const deltaYaw = relativeX * fov / 2;
|
28 |
+
const deltaPitch = relativeY * fov / 2;
|
29 |
+
|
30 |
+
// Calculate new yaw and pitch
|
31 |
+
const newYaw = currentYaw + deltaYaw;
|
32 |
+
const newPitch = currentPitch + deltaPitch;
|
33 |
+
|
34 |
+
// Now convert these yaw, pitch back to (x, y) on the image
|
35 |
+
const x = ((newYaw + 180) / 360) * imageWidth;
|
36 |
+
const y = ((newPitch + 90) / 180) * imageHeight;
|
37 |
+
|
38 |
+
return { x, y };
|
39 |
+
}
|
src/lib/sphericalToCartesian.ts
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
function sphericalToCartesian(yaw: number, pitch: number, width: number, height: number): { x: number, y: number } {
|
2 |
+
const x = ((yaw + 180) / 360) * width;
|
3 |
+
const y = ((pitch + 90) / 180) * height;
|
4 |
+
|
5 |
+
return { x, y };
|
6 |
+
}
|