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

Can't load some glb file in ReactNaitve project #2691

Closed
Okay6 opened this issue Jan 1, 2023 · 2 comments
Closed

Can't load some glb file in ReactNaitve project #2691

Okay6 opened this issue Jan 1, 2023 · 2 comments

Comments

@Okay6
Copy link

Okay6 commented Jan 1, 2023

  • Description
    I created a RN project by Expo and integrated react-three-fiber. Everything works well, i can load glb files provided from office examples and here. But a error was thrown when i download a glb file from Window's 3d resources libray and try to load it.
  • Development Environment
    Windows10 & Vs Code
  • My Mobie Phone
    Xiaomi6 & Android9
  • Code
    My Project
  • Screenshots
    • Work normally
      20230101114905
    • Work broken
      微信图片_20230101115444
  • App.js
import { Canvas, useFrame } from '@react-three/fiber/native'
import React, { useRef, useState, Suspense } from 'react'
import { HStack, Center, NativeBaseProvider } from 'native-base'
import { useGLTF, Environment } from '@react-three/drei/native'
import { Text, StyleSheet } from 'react-native'
import parrotModel from './assets/Parrot.glb'
import iphoneModelPath from './assets/iphone.glb'
import storkeModelPath from './assets/Stork.glb'
function Model({ url, ...rest }) {
  const { scene } = useGLTF(url)
  useFrame(() => (scene.rotation.y += 0.01))
  return <primitive {...rest} object={scene} />
}

function MBox(props) {
  const mesh = useRef(null)
  const [hovered, setHover] = useState(false)
  const [active, setActive] = useState(false)
  useFrame((state, delta) => (mesh.current.rotation.x += 0.01))
  return (
    <mesh
      {...props}
      ref={mesh}
      scale={active ? 1.5 : 1}
      onClick={(event) => setActive(!active)}
      onPointerOver={(event) => setHover(true)}
      onPointerOut={(event) => setHover(false)}
    >
      <boxGeometry args={[1, 1, 1]} />
      <meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
    </mesh>
  )
}
function ModelScene({ url }) {
  return (
    <Canvas
      gl={{ physicallyCorrectLights: true }}
      camera={{ position: [-6, 0, 16], fov: 36 }}
    >
      <color attach="background" args={[0xe2f4df]} />
      <ambientLight />
      <directionalLight intensity={1.1} position={[0.5, 0, 0.866]} />
      <directionalLight intensity={0.8} position={[-6, 2, 2]} />
      <Suspense>
        <Environment preset="park" />
        <Model url={url} />
      </Suspense>
    </Canvas>
  )
}
export default function App() {
  return (
    <NativeBaseProvider>
      <HStack space={3} justifyContent="center">
        <Canvas style={styles.squere}>
          <color attach="background" args={[0xfafe77]} />
          <ambientLight />
          <pointLight position={[10, 10, 10]} />
          <MBox position={[0, 0, 1]} />
        </Canvas>
        <ModelScene url={parrotModel} />
        <ModelScene url={iphoneModelPath} />
        <ModelScene url={storkeModelPath} />
        <Center
          style={styles.rect}
          h="40"
          w="20"
          bg="primary.500"
          rounded="md"
          shadow={3}
        >
          <Text>Native Base</Text>
        </Center>
      </HStack>
      <Text style={styles.text}>React Native 3D Experiment</Text>
    </NativeBaseProvider>
  )
}
const styles = StyleSheet.create({
  text: {
    marginLeft: 5,
    color: 'green',
  },
  squere: {
    marginLeft: 5,
  },
  rect: {
    marginRight: 7,
  },
})
  • My Thoughts
    I thought that maybe the glb file should be processed before loaded, but i couldn't find any solution, so someone can provide help,thanks.
@Okay6 Okay6 changed the title Can't load some glb file on RN Can't load some glb file in ReactNaitve project Jan 1, 2023
@CodyJasonBennett
Copy link
Member

The issue here might stem from #1972 where GLTFLoader can't unpack embedded textures due to missing implementation in react-native.

@CodyJasonBennett
Copy link
Member

CodyJasonBennett commented Jan 21, 2023

I'll redirect this to #1972 as that seems to be the issue. I have a work-around outlined in #1972 (comment), but nobody has championed it across the line upstream to react-native. It is possible to apply locally though. I'll take some time to create an example or investigate championing it myself in that issue if nobody beats me to it.

@CodyJasonBennett CodyJasonBennett closed this as not planned Won't fix, can't repro, duplicate, stale Jan 21, 2023
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

2 participants