This is almost all the logic but here is the rest
the App component:
export default function App() {
const { width, height } = Dimensions.get("window");
const { cameraRef, points, ...rest } = useCaptureImage();
return (
<>
<Canvas
camera={{ position: [0, 0, 0], fov: 90, aspect: width / height }}
style={{
position: "absolute",
left: 0,
top: 0,
right: 0,
bottom: 0,
}}
>
<PanoramaCapture points={points} cameraRef={cameraRef} {...rest} />
</Canvas>
<CameraView
animateShutter={false}
style={{
flex: 1,
zIndex: -1,
}}
ref={cameraRef}
/>
</>
);
}
here is the panorama capture component:
function PanoramaCapture(props: {
points: PhotoPoint[];
targetPoint: THREE.Vector3 | undefined;
handleCapture: (camera: CameraType) => Promise<void>;
cameraRef: React.RefObject<CameraView>;
}) {
// const [capturedPoints, setCapturedPoints] = useState<THREE.Vector3[]>([]);
// const [nextPoint, setNextPoint] = useState<THREE.Vector3>();
const sensor = useAnimatedSensor(SensorType.ROTATION, { interval: "auto" });
const [isReadyToCapture, setIsReadyToCapture] = useState(false);
const CAPTURE_ANGLE = 30 * (Math.PI / 180); // 30° in radians
const { camera } = useThree();
const { points, targetPoint, handleCapture } = props;
// const { getPoints } = useGetTargetPosition();
const { getCameraVectors } = useRotateObject({ object: camera });
useFrame(({ camera }) => {
const { forward, up } = getCameraVectors();
// Option 1: Look in the direction
const target = new THREE.Vector3().copy(camera.position).add(forward);
camera.up.copy(up);
camera.lookAt(target);
});
return (
<>
<axesHelper position={[0, 0, -1]} args={[5]} />
<mesh
onClick={async () => {
await handleCapture(camera);
}}
position={[0, 0, 0]}
>
<sphereGeometry args={[5, 32, 16]} />
<meshBasicMaterial
color="#ffff00"
side={THREE.DoubleSide}
transparent={true}
opacity={0.8}
/>
</mesh>
{points.map((p, i) => (
<Suspense key={i}>
<group position={p.position}>
{p.imageUri && <ImageT src={p.imageUri} />}
</group>
</Suspense>
))}
</>
);
}
we basically capture the point which trigger an image capture and pass the image uri to the Image component to render it as texture but it displays a black texture, we can even try to pass the base64 string and it will still not work.
PS: if I pass the image uri to the normal react native image component the image will be displayed so there is no problem with the image.