reactjs - react three fiber and react drei causing all componnents not to render - Stack Overflow

I'm trying to learn and work with react and threejs specifically react-threefiber. I'm runni

I'm trying to learn and work with react and threejs specifically react-three/fiber. I'm running react and three 19 and @react-three/fiber 9.0.4 and react-three/drei 10.0.1. The scene renders fine as long as there is no tag being rendered at all. Regardless of whether it's in the same component or not or whether there it is populated by a mesh or any settings. I am getting no errors and it saves perfectly fine, other than the fact that it doesn't render when there is a tag. when run my app, it just shows me a blank page of my background color. no error shows on console. can someone help to debug

    import React, {Suspense} from 'react';     
    import Button from '../components/Button';
    import { Canvas } from '@react-three/fiber';
    // import CanvasLoader from '../components/CanvasLoader';
    import { Model } from '../components/Model';
    // import { AmbientLight, BoxGeometry, DirectionalLight, Mesh, MeshLambertMaterial } from 'three';  
    import { OrbitControls, PresentationControls, Stage } from '@react-three/drei';

      const HeroSec = () => {
      const handleClick = () => {}
      return (
       <section className='hero flex flex-col justify-center items-center text-white text-md'>
        <div className='flex flex-col sm:flex-row my-16 justify-center items-center h-full w- 
     [80vw]'>
            <div>
                <h3 className='text-purple-700 text-2xl font-bold py-3'>Hi!</h3>
                <h1 className='text-4xl sm:text-5xl font-semibold py-3'>I AM OSES</h1>
                <p className='py-3'>A Web developer with extensive knowlege in developing full 
    stack web application</p>
                <Button  design={"bg-purple-700 p-1.5 rounded-2xl cursor-pointer"} text={"View 
    Work"}
                 handleClick={handleClick}/>
                <Button  design={"bg-purple-700 p-1.5 rounded-2xl cursor-pointer ml-5"} text= 
    {"Hire Me"}
                 handleClick={handleClick}/>
            </div>
            <div>
              
            <Canvas>
              <AmbientLight args={[2,2,5]} intensity={1} color="#fffff"/>
              <DirectionalLight args={[0,0,10]} intensity={1} color="#fffff"/>
              <OrbitControls /> 
                  <Model />
                <Mesh>
                  <BoxGeometry args={[2,2,2]} scale={1} />
                  <MeshLambertMaterial color="#ff0357"/>
                </Mesh>
                <Stage />
            </Canvas>
        </div>
        </div>
    </section>
  )
}

export default HeroSec

I'm trying to learn and work with react and threejs specifically react-three/fiber. I'm running react and three 19 and @react-three/fiber 9.0.4 and react-three/drei 10.0.1. The scene renders fine as long as there is no tag being rendered at all. Regardless of whether it's in the same component or not or whether there it is populated by a mesh or any settings. I am getting no errors and it saves perfectly fine, other than the fact that it doesn't render when there is a tag. when run my app, it just shows me a blank page of my background color. no error shows on console. can someone help to debug

    import React, {Suspense} from 'react';     
    import Button from '../components/Button';
    import { Canvas } from '@react-three/fiber';
    // import CanvasLoader from '../components/CanvasLoader';
    import { Model } from '../components/Model';
    // import { AmbientLight, BoxGeometry, DirectionalLight, Mesh, MeshLambertMaterial } from 'three';  
    import { OrbitControls, PresentationControls, Stage } from '@react-three/drei';

      const HeroSec = () => {
      const handleClick = () => {}
      return (
       <section className='hero flex flex-col justify-center items-center text-white text-md'>
        <div className='flex flex-col sm:flex-row my-16 justify-center items-center h-full w- 
     [80vw]'>
            <div>
                <h3 className='text-purple-700 text-2xl font-bold py-3'>Hi!</h3>
                <h1 className='text-4xl sm:text-5xl font-semibold py-3'>I AM OSES</h1>
                <p className='py-3'>A Web developer with extensive knowlege in developing full 
    stack web application</p>
                <Button  design={"bg-purple-700 p-1.5 rounded-2xl cursor-pointer"} text={"View 
    Work"}
                 handleClick={handleClick}/>
                <Button  design={"bg-purple-700 p-1.5 rounded-2xl cursor-pointer ml-5"} text= 
    {"Hire Me"}
                 handleClick={handleClick}/>
            </div>
            <div>
              
            <Canvas>
              <AmbientLight args={[2,2,5]} intensity={1} color="#fffff"/>
              <DirectionalLight args={[0,0,10]} intensity={1} color="#fffff"/>
              <OrbitControls /> 
                  <Model />
                <Mesh>
                  <BoxGeometry args={[2,2,2]} scale={1} />
                  <MeshLambertMaterial color="#ff0357"/>
                </Mesh>
                <Stage />
            </Canvas>
        </div>
        </div>
    </section>
  )
}

export default HeroSec
Share Improve this question edited Mar 10 at 13:31 Łukasz Daniel Mastalerz 2,4482 gold badges7 silver badges28 bronze badges asked Mar 9 at 18:16 Oguogho Oguogho 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

The scene renders fine as long as there is no tag being rendered at all.

This is a little bit unclear...

Generally, is there any specific reason for importing Mesh, BoxGeometry, and MeshLambertMaterial from Three.js and trying to use them directly, instead using primitives provided by R3F (i.e.<mesh>, <boxGeometry>, <meshLambertMaterial>)?

Pay attention to the capitalization of the letters in the components...

https://r3f.docs.pmnd.rs/getting-started/your-first-scene#the-result

This template should works fine, if you still get issues, please provide sandbox.

import React, {Suspense} from 'react';     
// import Button from '../components/Button';
import { Canvas } from '@react-three/fiber';
// import CanvasLoader from '../components/CanvasLoader';
// import { Model } from '../components/Model';
import { OrbitControls } from '@react-three/drei';

const HeroSec = () => { 
  return (
    <Canvas>
      <ambientLight args={[2, 2, 5]} intensity={1} color="#ffffff" />
      <directionalLight args={[0, 0, 10]} intensity={1} color="#ffffff" />
      <OrbitControls /> 
      
      <mesh>
        <boxGeometry args={[2, 2, 2]} />
        <meshLambertMaterial color="#ff0357" />
      </mesh>
    </Canvas>
  );
}
export default HeroSec

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744863784a4597858.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信