首页 > 解决方案 > 球体不考虑平面几何外的重力

问题描述

我有一个带有球体和平面的简单环境。这两个对象都包裹在一个物理组件中,并且物理工作,如果我移除平面,球体将会下降。但是当我在平面外运行球体时,球体不会下落。我不知道我是否误解了一些琐碎的事情,也许飞机比它看起来更宽?

我认为没有办法设置网格的宽度/深度,所以我认为它是 planeBufferGeometry 的宽度/深度重要吗?

在此处输入图像描述 主.js:

import { Canvas } from '@react-three/fiber'
import { Sky, PointerLockControls } from '@react-three/drei'
import { Physics } from '@react-three/cannon'
import { Ground, Sphere } from '../components/'

export default function Game(props) {
  return (
    <>
      <Canvas shadows colorManagement camera={{ fov: 45 }}>
        <Sky sunPosition={[100, 10, 100]} />
        <ambientLight intensity={0.3} />
        <pointLight castShadow intensity={2.8} position={[100, 100, 100]} />
        <Physics gravity={[0, -106, 0]}>
          <Ground />
          <Sphere />
        </Physics>
        <PointerLockControls />
      </Canvas>
    </>
  )
}

Ground.js:

import { usePlane } from '@react-three/cannon'
import { useNormalTexture } from '@react-three/drei'

export default function Ground(props) {
  const [ref] = usePlane(() => ({ rotation: [-Math.PI / 2, 0, 0], ...props }))

  const [normalMap] = useNormalTexture(32, {
    offset: [0, 0],
    repeat: [100, 100],
    anisotropy: 8
  })

  return (
    <mesh ref={ref} receiveShadow>
      <planeBufferGeometry attach="geometry" args={[50, 50]} />
      <meshStandardMaterial
        attach="material"
        normalMap={normalMap}
        color="#dadb84"
      />
    </mesh>
  )
}

标签: react-three-fiber

解决方案


推荐阅读