brianzinn / react-babylonjs

React for Babylon 3D engine
https://brianzinn.github.io/react-babylonjs/
821 stars 105 forks source link

how to apply detachControl() ?? #296

Closed lawplatform closed 1 year ago

lawplatform commented 1 year ago

I know normal way to detachControl

camera.inputs.attached.mouse.detachControl();

however, How to I put the code in the raect-babylonjs ?

    <div style={{ flex: 1, display: 'flex' }}>
        <Engine antialias adaptToDeviceRatio canvasId="babylon-canvas">
            <Scene>

                <freeCamera
                    name="camera1"
                    position={new Vector3(0, 5, -10)}
                    setTarget={[Vector3.Zero()]}
                    detachControl=true
                />

                <hemisphericLight
                    name="light1"
                    intensity={0.7}
                    direction={new Vector3(0, 1, 0)}
                />

                {children}</Scene>
        </Engine>
    </div
lawplatform commented 1 year ago

I found it :)

useEffect(() => { if (scene?.activeCamera != null) { scene.activeCamera.inputs.attached.mouse.detachControl(); } }, [])