未捕获的错误:R3F:Div不是THREE命名空间的一部分!您是否忘记扩展

huangapple go评论65阅读模式
英文:

Uncaught Error: R3F: Div is not part of the THREE namespace! Did you forget to extend

问题

R3F: Div is not part of the THREE namespace! Did you forget to extend?

import React, { Suspense, useEffect, useState } from "react";
import { Canvas } from "@react-three/fiber";
import { OrbitControls, Preload, useGLTF } from "@react-three/drei";
import CanvasLoader from '../Loader';

const Computers = () => {
const computer = useGLTF("./desktop_pc/scene.gltf");

return (



)
}

const ComputersCanvas=()=>{
return (
<Canvas
frameloop='demand'
shadows
camera={{ position: [20, 3, 5], fov: 25 }}
gl={{ preserveDrawingBuffer: true }}
>
<Suspense fallback={}>
<OrbitControls
enableZoom={false}
maxPolarAngle={Math.PI / 2}
minPolarAngle={Math.PI / 2}
/>

  <Preload all />
</Canvas>

);
};

export default ComputersCanvas;

I have not use any div inside canvas, and when I do extend({OrbitControls, Preload, useGLTF}) as the documentation says, then also an error comes as "extended is not defined." I am not able to solve the error as I am new to three.js.

英文:

R3F: Div is not part of the THREE namespace! Did you forget to extend?

import React, { Suspense, useEffect, useState } from &quot;react&quot;;
import { Canvas } from &quot;@react-three/fiber&quot;;
import { OrbitControls, Preload, useGLTF } from &quot;@react-three/drei&quot;;
import CanvasLoader from &#39;../Loader&#39;;

const Computers = () =&gt; {
  const computer = useGLTF(&quot;./desktop_pc/scene.gltf&quot;);

   return (
    &lt;mesh&gt;
     &lt;hemisphereLight intensity={0.15} groundColor=&quot;black&quot; /&gt;
     &lt;pointLight intensity={1}/&gt;
     &lt;primitive
       object={computer.scene}
     /&gt;
    &lt;/mesh&gt;
  )
}

const ComputersCanvas=()=&gt;{
  return (
    &lt;Canvas
      frameloop=&#39;demand&#39;
      shadows
      camera={{ position: [20, 3, 5], fov: 25 }}
      gl={{ preserveDrawingBuffer: true }}
    &gt;
      &lt;Suspense fallback={&lt;CanvasLoader /&gt;}&gt;
        &lt;OrbitControls
          enableZoom={false}
          maxPolarAngle={Math.PI / 2}
          minPolarAngle={Math.PI / 2}
        /&gt;
        &lt;Computers  /&gt;
      &lt;/Suspense&gt;

      &lt;Preload all /&gt;
    &lt;/Canvas&gt;
  );
};


export default ComputersCanvas;

i have not use any div inside canvas and when i do extend({OrbitControls, Preload, useGLTF}) as the documention says then also error comes as extended is not defined . i am not able to solve the error as i am new to three.js

答案1

得分: 2

你必须将此代码放入 Loader.jsx 组件中:

import React from 'react';
import { Html, useProgress } from '@react-three/drei';

const Loader = () => {
  const { progress } = useProgress();
  return (
    <Html>
      <span
        className='canvas-load'
      >
      </span>
      <p
        style={{
          fontSize: 14,
          color: '#f1f1f1',
          fontWeight: 800,
          marginTop: 40
        }}
      >
        {progress.toFixed(2)}%
      </p>
    </Html>
  )
}

export default Loader
英文:

hey you have to put this code in the Loader.jsx component:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

import React from &#39;react&#39;;
import { Html, useProgress } from &#39;@react-three/drei&#39;;

const Loader = () =&gt; {
  const {progress} = useProgress();
  return (
    &lt;Html&gt;
      &lt;span
        className=&#39;canvas-load&#39;
      &gt;

      &lt;/span&gt;
      &lt;p
        style={{
          fontSize: 14,
          color: &#39;#f1f1f1&#39;,
          fontWeight: 800,
          marginTop: 40
        }}

      &gt;
        {progress.toFixed(2)}%
      &lt;/p&gt;
    &lt;/Html&gt;
  )
}

export default Loader

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月7日 04:20:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75655481.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定