Comments (5)
@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.
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.
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.
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.
@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)
- How to render text on top of material from list of materials? HOT 1
- Invalidate is not behaving as expected HOT 5
- Can we modify useLoader to accept an empty string or null? HOT 1
- XRFrame type resolving incorrectly HOT 2
- Error loading OBJ model in React Native HOT 2
- Help: TypeError in is.equ HOT 4
- Primitive with children mounting / unmounting + documentation HOT 4
- This sandbox doesn't work HOT 1
- Canvas eventHandler: onWebGLContextLost, onWebGLContextRestored HOT 2
- Cannot catch error HOT 1
- Is it possible to use react-three-fiber with React-Native CLI application? HOT 1
- help: using the onPointerDown event of a` <group/>` and the event.handlers of `useThree()` together HOT 1
- Types: Removed classes from three.js are still available at R3F HOT 3
- Rendering `<Context.Consumer.Provider>` is not supported HOT 1
- R3F & StereoCamera
- Breaking changes in React experimental branch HOT 1
- Cannot read properties of undefined (reading 'boundingSphere') HOT 1
- Forced landscape HOT 1
- load gltb file show error `Uncaught Invalid typed array length: 64548` HOT 1
- Updating from 8.15.19 to 8.16.1 causes 'demand' frameloop issues with @react-spring/three HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-three-fiber.