react-three-renderer icon indicating copy to clipboard operation
react-three-renderer copied to clipboard

Multiple <scenes />?

Open AndrewRayCode opened this issue 9 years ago • 7 comments

Based on this StackOverflow question there's a strategy to render multiple scenes with the same renderer:

renderer.clear();
renderer.render( scene, camera );
renderer.clearDepth();
renderer.render( scene2, camera );

Is this an abstraction that would worthwhile to explore in this project?

AndrewRayCode avatar Mar 02 '16 23:03 AndrewRayCode

wondering how to implement "clear depth after first scene" :)

toxicFork avatar Mar 02 '16 23:03 toxicFork

But yes, looks like a proper use case!

toxicFork avatar Mar 02 '16 23:03 toxicFork

Hey @toxicFork, are there plans for allowing multiple <scene />s in the near future?

jshor avatar Sep 02 '17 16:09 jshor

@jshor I currently render multiple scenes on top of each other using the <viewport> object

AndrewRayCode avatar Sep 02 '17 16:09 AndrewRayCode

@AndrewRayCode could you provide an example?

jshor avatar Sep 02 '17 17:09 jshor

In my game I overlay the pause screen over the game:

screen shot 2017-09-02 at 11 38 52 am

Viewports are a little confusing, but here's how that's done in a condensed version:

@autobind
clearRendererDepth() {

    const { renderer, } = this;

    if( renderer ) {
        renderer.clearDepth();
    }

}

render() {

    return <React3
        ref="renderer"
        mainCamera="camera"
        width={ gameWidth }
        height={ gameHeight }
    >

        {/* default viewport, required if using viewports. note cameraName
            matches the main scene's camera name */}
        <viewport
            x={ 0 }
            y={ 0 }
            width={ gameWidth }
            height={ gameHeight }
            cameraName="mainCamera"
        />

        {/* paused overlay (same x,y) viewport */}
        { paused ? <viewport
            x={ 0 }
            y={ 0 }
            width={ gameWidth }
            height={ gameHeight }
            cameraName="pausedCamera"
            onBeforeRender={ this.clearRendererDepth }
        /> : null }

        <scene ref="scene">

            {/* group for main scene */}
            <object3D>
                <perspectiveCamera
                    name="mainCamera"
                    ref="camera"
                    fov={ cameraFov }
                    aspect={ cameraAspect }
                    near={ 0.1 }
                    far={ 500 }
                />
                <mesh ... />
            </object3D>

            {/* conditional group for paused scene */}
            { paused ? <object3D>
                <perspectiveCamera
                    name="pausedCamera"
                    ref="camera"
                    fov={ cameraFov }
                    aspect={ cameraAspect }
                    near={ 0.1 }
                    far={ 1000 }
                />
                <mesh ... />
            </object3D> : null }

        </scene>
    </React3>
}

there's also a support channel at https://gitter.im/toxicFork/react-three-renderer

AndrewRayCode avatar Sep 02 '17 18:09 AndrewRayCode

@AndrewRayCode I am attempting to do something similar, but running into this warning:

Warning: Foreign prop onBeforeRender found in viewport.

It looks like ViewportDescriptor doesn't acknowledge the existence of onBeforeRender, even though it's listed in Viewport.

Was there anything special you did to get around this?

Danathus avatar Mar 28 '18 00:03 Danathus