标签: drei

无法在react-三/drei/native中使用远程url加载纹理

我正在尝试使用加载图像纹理useTexture并将其应用到meshStandardMaterial我的反应本机应用程序中。当我从本地资源文件夹导入图像时,纹理工作正常。但是,当我将图像更改为远程 URL 时,纹理不会被应用,材质会呈现黑色。我添加了下面的代码

import React, { Suspense, useRef } from 'react';
import { View } from 'react-native';
import { Canvas } from '@react-three/fiber/native';
import { useTexture } from '@react-three/drei/native';
import useWindowDimensions from 'react-native/Libraries/Utilities/useWindowDimensions';
import localTexturePath from './assets/duck_texture.png'

function Plane() {
  const ref = useRef();
  // THIS DOESN'T WORK
  const textureUrl = 'https://cdntest.metatube.studio/public/Texture.png'
  // THIS WORKS
  // const textureUrl = localTexturePath
  useTexture(textureUrl, (t) => {
    ref.current.map = t
    ref.current.needsUpdate = true
  })
  return(
    <mesh>
      <planeBufferGeometry attach="geometry" args={[3, …
Run Code Online (Sandbox Code Playgroud)

three.js react-native react-three-fiber drei react-three-drei

5
推荐指数
0
解决办法
353
查看次数