Skip to content

Commit

Permalink
fix: ortho & persp cam need optional envMap, fix text3d segments miss…
Browse files Browse the repository at this point in the history
…ing in usememo deps
  • Loading branch information
drcmda committed Oct 24, 2022
1 parent b46d9a1 commit e76310f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -221,6 +221,8 @@ type Props = Omit<JSX.IntrinsicElements['perspectiveCamera'], 'children'> & {
frames?: number
/** Resolution of the FBO, 256 */
resolution?: number
/** Optional environment map for functional use */
envMap?: THREE.Texture
}
```
Expand Down
9 changes: 8 additions & 1 deletion src/core/OrthographicCamera.tsx
Expand Up @@ -18,10 +18,12 @@ type Props = Omit<JSX.IntrinsicElements['orthographicCamera'], 'children'> & {
frames?: number
/** Resolution of the FBO, 256 */
resolution?: number
/** Optional environment map for functional use */
envMap?: THREE.Texture
}

export const OrthographicCamera = React.forwardRef(
({ resolution = 256, frames = Infinity, children, makeDefault, ...props }: Props, ref) => {
({ envMap, resolution = 256, frames = Infinity, children, makeDefault, ...props }: Props, ref) => {
const set = useThree(({ set }) => set)
const camera = useThree(({ camera }) => camera)
const size = useThree(({ size }) => size)
Expand Down Expand Up @@ -50,14 +52,19 @@ export const OrthographicCamera = React.forwardRef(
}, [cameraRef, makeDefault, set])

let count = 0
let oldEnvMap: THREE.Color | THREE.Texture | null = null
const functional = isFunction(children)
useFrame((state) => {
if (functional && (frames === Infinity || count < frames)) {
groupRef.current.visible = false
state.gl.setRenderTarget(fbo)
oldEnvMap = state.scene.background
if (envMap) state.scene.background = envMap
state.gl.render(state.scene, cameraRef.current)
state.scene.background = oldEnvMap
state.gl.setRenderTarget(null)
groupRef.current.visible = true
count++
}
})

Expand Down
9 changes: 8 additions & 1 deletion src/core/PerspectiveCamera.tsx
Expand Up @@ -18,10 +18,12 @@ type Props = Omit<JSX.IntrinsicElements['perspectiveCamera'], 'children'> & {
frames?: number
/** Resolution of the FBO, 256 */
resolution?: number
/** Optional environment map for functional use */
envMap?: THREE.Texture
}

export const PerspectiveCamera = React.forwardRef(
({ resolution = 256, frames = Infinity, makeDefault, children, ...props }: Props, ref) => {
({ envMap, resolution = 256, frames = Infinity, makeDefault, children, ...props }: Props, ref) => {
const set = useThree(({ set }) => set)
const camera = useThree(({ camera }) => camera)
const size = useThree(({ size }) => size)
Expand All @@ -40,14 +42,19 @@ export const PerspectiveCamera = React.forwardRef(
})

let count = 0
let oldEnvMap: THREE.Color | THREE.Texture | null = null
const functional = isFunction(children)
useFrame((state) => {
if (functional && (frames === Infinity || count < frames)) {
groupRef.current.visible = false
state.gl.setRenderTarget(fbo)
oldEnvMap = state.scene.background
if (envMap) state.scene.background = envMap
state.gl.render(state.scene, cameraRef.current)
state.scene.background = oldEnvMap
state.gl.setRenderTarget(null)
groupRef.current.visible = true
count++
}
})

Expand Down
1 change: 1 addition & 0 deletions src/core/Text3D.tsx
Expand Up @@ -100,6 +100,7 @@ export const Text3D = React.forwardRef<
bevelThickness,
bevelSize,
bevelEnabled,
bevelSegments,
bevelOffset,
curveSegments,
letterSpacing,
Expand Down

1 comment on commit e76310f

@vercel
Copy link

@vercel vercel bot commented on e76310f Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.