R3F – PerspectiveCamera似乎损坏或对象距离应该更远。

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

R3F - PerspectiveCamera seems broken or objets are further away than they should

问题

我有一个关于R3F的小问题,经过调查和寻找解决方案后,我一无所获,所以我会在这里尝试一下。

问题出在PerspectiveCamera上,我不知道为什么,不知道是与声明相关还是与R3F本身相关,但无论我如何改变网格或相机的位置,都无法将网格靠近相机:

我的场景

我正在按照不同的教程来查找为什么会发生这种情况,但我还没有找到答案,这是场景应该是这样的(基于我找到的最新教程):

教程场景

这是代码,两个场景使用完全相同的代码:

import { Canvas } from '@react-three/fiber'
import { PerspectiveCamera } from '@react-three/drei';
import * as THREE from 'three';

function App() {

    return (
        <Canvas>
            <PerspectiveCamera makeDefault position={[0,1,5]} />
            
            <mesh position={[0,0.5,0]}>
                <sphereGeometry args={[0.5, 32, 32]} />
                <meshStandardMaterial color='#dddddd' />
            </mesh>

            <mesh rotation={[-Math.PI/2,0,0]}>
                <planeGeometry args={[7,7]} />
                <meshStandardMaterial color='#1ea3d8' />
            </mesh>

            <ambientLight args={['#ffffff', 1]} />
        
        </Canvas>
    )
}

export default App;

我是否漏掉了什么?希望问题不是由于我现在没有看到的愚蠢的事情引起的。感谢你的帮助。

英文:

I have a small problem with R3F and after investigating and searching for a solution I end up with nothing, so I'll try here.

The problem is with the PerspectiveCamera, I don't know why, if is something related with the declaration or with R3F itself but no matter how I change positions of the meshes or the camera, there is no way to bring closer the meshes to the camera:

My scene

I'm following different tutorials two see why is happening this but I didn't find an answer yet, this is how the scene should be (based in the last tutorial I've found):

Tutorial scene

This is the code, is exactly the same code for both scenes:

import { Canvas } from &#39;@react-three/fiber&#39;
import { PerspectiveCamera } from &#39;@react-three/drei&#39;;
import * as THREE from &#39;three&#39;

function App() {

    return (
        &lt;Canvas&gt;
            &lt;PerspectiveCamera makeDefault position={[0,1,5]} /&gt;
            
            &lt;mesh position={[0,0.5,0]}&gt;
                &lt;sphereGeometry args={[0.5, 32, 32]} /&gt;
                &lt;meshStandardMaterial color=&#39;#dddddd&#39; /&gt;
            &lt;/mesh&gt;

            &lt;mesh rotation={[-Math.PI/2,0,0]}&gt;
                &lt;planeGeometry args={[7,7]} /&gt;
                &lt;meshStandardMaterial color=&#39;#1ea3d8&#39; /&gt;
            &lt;/mesh&gt;

            &lt;ambientLight args={[&#39;#ffffff&#39;, 1]} /&gt;
        
        &lt;/Canvas&gt;
    )
}

export default App;

Is there something that I'm missing? I hope the problem is not caused by a stupid thing that I'm not seeing right now.. Thanks for your help

答案1

得分: 1

是的... 我忘了渲染器大小

return (
    &lt;div style={{width: window.innerWidth, height: window.innerHeight }}&gt;
        &lt;Canvas&gt;
            &lt;PerspectiveCamera makeDefault position={[0,1,5]} /&gt;
            
            &lt;mesh position={[0,0.5,0]}&gt;
                &lt;sphereGeometry args={[0.5, 32, 32]} /&gt;
                &lt;meshStandardMaterial color=&#39;#dddddd&#39; /&gt;
            &lt;/mesh&gt;

            &lt;mesh rotation={[-Math.PI/2,0,0]}&gt;
                &lt;planeGeometry args={[7,7]} /&gt;
                &lt;meshStandardMaterial color=&#39;#1ea3d8&#39; /&gt;
            &lt;/mesh&gt;

            &lt;ambientLight args={[&#39;#ffffff&#39;, 1]} /&gt;
        &lt;/Canvas&gt;
    &lt;/div&gt;
)
英文:

YES... I forgot the renderer size:

return (
&lt;div style={{width: window.innerWidth, height: window.innerHeight }}&gt;
&lt;Canvas&gt;
&lt;PerspectiveCamera makeDefault position={[0,1,5]} /&gt;
&lt;mesh position={[0,0.5,0]}&gt;
&lt;sphereGeometry args={[0.5, 32, 32]} /&gt;
&lt;meshStandardMaterial color=&#39;#dddddd&#39; /&gt;
&lt;/mesh&gt;
&lt;mesh rotation={[-Math.PI/2,0,0]}&gt;
&lt;planeGeometry args={[7,7]} /&gt;
&lt;meshStandardMaterial color=&#39;#1ea3d8&#39; /&gt;
&lt;/mesh&gt;
&lt;ambientLight args={[&#39;#ffffff&#39;, 1]} /&gt;
&lt;/Canvas&gt;
&lt;/div&gt;
)

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

发表评论

匿名网友

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

确定