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

OrbitControls zoom does not work with expo #2067

Closed
suggoooiii opened this issue Aug 16, 2024 · 4 comments
Closed

OrbitControls zoom does not work with expo #2067

suggoooiii opened this issue Aug 16, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@suggoooiii
Copy link

  • three version: 0.167.1
  • @react-three/fiber version: 8.17.5
  • @react-three/drei version: 9.109.5
  • node version: v20.15.0
  • yarn version: 1.22.22
  • expo version: ~51.0.26
  • expo-gl version: ^14.0.2

Problem description:

when i use the zoom feature in OrbitControls it causes my 3d model to disappear from the screen. when i disable it OrbitControls works just fine, what i'm trying to accomplish is to zoom on each part of the model when i click or double click on it and show a short description.

Relevant code:

import { Canvas, useFrame, useThree } from "@react-three/fiber/native";
import { StatusBar } from "expo-status-bar";
import { StyleSheet, View } from "react-native";
import Car from "./assets/models/Model.glb";
import { Center, Gltf, OrbitControls } from "@react-three/drei/native";
import { Suspense, useRef } from "react";


function CarModel({ onPartClick }) {
  const groupRef = useRef();
  const { camera } = useThree();

  useFrame((state, delta) => {
    if (groupRef.current) {
      // groupRef.current.rotation.y += delta * 0.1;
    }
  });

  const handleDoubleClick = (event) => {
    event.stopPropagation();
    if (event.object.name) {
      console.log(event.object.name);
    }
  };
  return (
    <group ref={groupRef} position={[0, 0, 0]} scale={0.3}>
      <mesh onClick={handleDoubleClick}>
        <Gltf src={Car} />
      </mesh>
    </group>
  );
}

export default function App() {
  const orbitControlsRef = useRef();

  return (
    <View style={styles.container}>
      <Canvas
        gl={{
          powerPreference: "high-performance",
          outputColorSpace: "srgb",
        }}
        // camera={{ position: [0, 0, 5], fov: 50 }}
      >
        <color attach="background" args={["#512DA8"]} />
        <ambientLight intensity={2} />
        <pointLight position={[1, 1, 1]} />
        <Suspense fallback={null}>
          <Center>
            <CarModel onPartClick={() => console.log("lol")} />
          </Center>
        </Suspense>
        <OrbitControls ref={orbitControlsRef} enableZoom={false} />
      </Canvas>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});
@suggoooiii suggoooiii added the bug Something isn't working label Aug 16, 2024
@CodyJasonBennett
Copy link
Member

CodyJasonBennett commented Aug 16, 2024

OrbitControls probably sees null or undefined for one of the events used by zoom.

@suggoooiii
Copy link
Author

so should i use a PerspectiveCamera instead ?

@CodyJasonBennett
Copy link
Member

In three.js, the concept of controls and cameras are separate, where controls modify a camera, which is just the view transform. R3F already created a perspective camera for you, although you can tailor one with Drei's <PerspectiveCamera />. This issue seems to be with R3F's polyfills for DOM events not including properties for zoom/multi-touch, and it's integrating null/undefined against the camera, which makes it non-renderable.

@moose96
Copy link

moose96 commented Sep 6, 2024

I've created a PR in react-three-fiber repository which fixes this issue ;). Please look at it and review: pmndrs/react-three-fiber#3347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants