Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use CameraControls in react native #468

Open
bbb169 opened this issue Oct 30, 2023 · 2 comments
Open

How to use CameraControls in react native #468

bbb169 opened this issue Oct 30, 2023 · 2 comments

Comments

@bbb169
Copy link

bbb169 commented Oct 30, 2023

Describe the bug

I'm use CameraControls in '@react-three/drei/native', which based on this libary, but it cause this bug
So, it is possible to use CameraControls in react native ?
image

To Reproduce

Steps to reproduce the behavior:

  1. Use expo to build a react-native project
  2. Import CameraControls and use it
  3. See error

Code

import React, { Suspense, useRef, useState } from 'react';
import { View } from 'react-native';
import { BoxGeometry, Color, Vector3 } from 'three';
import { Button } from '@rneui/themed';
import { Canvas, MeshProps } from '@react-three/fiber/native';
import {
  CameraControls,
  CameraShake,
  PerspectiveCamera,
} from '@react-three/drei/native';
import BoxEdges from '../../component/boxEdges';
import XYZGrid from '../../component/XYZGrid';
import { publicStyles } from '../../styles';
import CameraControler from '../../component/cameraControls';

function Rig() {
  return (
    <CameraShake
      maxYaw={0.01}
      maxPitch={0.01}
      maxRoll={0.01}
      yawFrequency={0.5}
      pitchFrequency={0.5}
      rollFrequency={0.4}
    />
  );
}

const Cube = ({ ...props }: MeshProps) => {
  const boxRef = useRef<BoxGeometry>(null);

  return (
    <mesh {...props}>
      <boxGeometry ref={boxRef} args={[1, 1, 1]} />
      <meshBasicMaterial attach="material" color="yellow" />
      {boxRef.current && <BoxEdges boxRef={boxRef} />}
    </mesh>
  );
};

export default function HomePage(): React.JSX.Element {
  const [renderTimes, setRenderTimes] = useState(1);

  return (
    <>
      <Canvas
        key={renderTimes}
        scene={{ background: new Color('black') }}
        camera={{
          position: [10, 10, 10],
          onUpdate: self => {
            self.lookAt(new Vector3(0, 0, 0));
          },
        }}>
        <Suspense fallback={null}>
          <Cube position={[1, 1, 1]} />
          <XYZGrid isX={true} />
          <XYZGrid isY={true} />
          <XYZGrid isZ={true} />
          {/* <Rig /> */}
          <directionalLight />
        </Suspense>
        {/* <PerspectiveCamera makeDefault /> */}
        <CameraControls />
      </Canvas>
      <View>
        <Button
          style={{
            ...publicStyles.displayCenter,
            backgroundColor: 'rgb(38,139,210)',
          }}
          onPress={() => {
            setRenderTimes(pre => pre + 1);
          }}
          title={renderTimes.toString()}
        />
      </View>
    </>
  );
}

Live example

No response

Expected behavior

CameraControls can be used normally in react native

Screenshots or Video

No response

Device

Mobile

OS

Android

Browser

Chrome

@yomotsu
Copy link
Owner

yomotsu commented Nov 8, 2023

Sorry, but I don't know much about React Native...

@MainzerKaiser
Copy link

What is the status here, i am using this package so far but it is missing touch release events:
https://github.com/TiagoCavalcante/r3f-native-orbitcontrols

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants