Coder Social home page Coder Social logo

Comments (5)

ryanking1809 avatar ryanking1809 commented on May 16, 2024 1

@jak2030 Oh sorry, that's a mobx function to re-render components on state change. I think don't it is required here, I'll remove it.

from react-three-fiber.

drcmda avatar drcmda commented on May 16, 2024

Resize has to do with webGL, there's a resize command that needs to called on canvas context. If you don't do this your canvas is static, it won't ever adhere to percentages or changes. If you want objects to be cropped, then your view should be responsive, useThree for instance gives you size and a viewport function.

I will making auto-measuring optional otherwise. Then it would be totally up to you. There's already a bulletpoint for it in the roadmap. If you like, a PR would speed this up, currently i still have other priorities, mainly interaction.

from react-three-fiber.

ryanking1809 avatar ryanking1809 commented on May 16, 2024

Great, I'll look into it!
I like the auto measure - I just need to keep my dimensions consistent on resize.
Thanks!

from react-three-fiber.

ryanking1809 avatar ryanking1809 commented on May 16, 2024

I'll add this here in case anyone finds this in the future.

This will scale the camera fov so the dimensions of the plane at planeDistance are kept at a particular pixel ratio when the viewport changes dimensions. So here the plane at z=0 is scaled so 1 three.js unit = 1 pixel no matter what the viewport size is (it's hard to explain without a diagram)

const Camera = () => {
  const camera = useRef()
  const { aspect, size, setDefaultCamera } = useThree()
  const pixelToThreeUnitRatio = 1
  const planeDistance = 0
  const cameraDistance = 500
  const distance = cameraDistance - planeDistance
  const height = size.height / pixelToThreeUnitRatio
  const halfFovRadians = Math.atan((height / 2) / distance)
  const fov = 2 * halfFovRadians * (180/Math.PI)
  useEffect(() => void setDefaultCamera(camera.current), [])
  return <perspectiveCamera
    ref={camera}
    aspect={aspect}
    fov={fov}
    position={[0, 0, cameraDistance]}
    onUpdate={self => self.updateProjectionMatrix()}
  />
}

from react-three-fiber.

jak2030 avatar jak2030 commented on May 16, 2024

@ryanking1809 I was looking into a similar problem and this looks like a nice solution - would you mind explaining or pointing me to what the observer() method here refers to?

from react-three-fiber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.