firtoz / react-three-renderer

Render into a three.js canvas using React.
https://toxicfork.github.com/react-three-renderer-example/
MIT License
1.49k stars 155 forks source link

Foreign prop onMouseDown found in [mesh/react3] #5

Open Amev opened 8 years ago

Amev commented 8 years ago

Hi,

First, thanks for your great job, this lib is really cool !

I'm trying to do some stuff with it but i have a little issue when i try to give a onMouseDown event handler to mesh or react3 components like you did in your examples.

handleClick(event) {
    event.preventDefault();

    this.context.executeAction(changeColorAction, {});
}

render() {
    let window = this.context.getStore(ApplicationStore).getWindow(),
        height = window ? window.innerHeight : 500,
        width = window ? window.innerWidth : 500;

    return (
        <div>
            <React3 mainCamera="camera" width={width} height={height} antialias={true}
                onAnimate={this.handleAnimate} clearColor={0xffffff}>
                <scene>
                    <perspectiveCamera name="camera" fov={75} aspect={width/height}
                        near={0.1} far={1000} position={this.props.cameraPosition} />
                    <mesh rotation={this.props.cubeRotation} ref="mesh" onMouseDown={this.handleClick}>
                        <boxGeometry width={1} height={1} depth={1} />
                        <meshBasicMaterial color={this.props.color} wireframe />
                    </mesh>
                </scene>
            </React3>
        </div>
    );
}

I have a foreign prop onMouseDown found in mesh error when i do this. Am I doing something wrong ? (I just want to change color when i click on cube, this is working perfectly when I assign event handler to parent div)

Thanks

toxicFork commented 8 years ago

Hi, thanks for your interest in the project :D

For these props to work you will need to use the MouseInput module like in this file:

https://github.com/toxicFork/react-three-renderer-example/blob/82b417caef9652453b886684e38801c5bd544d39/src/examples/DraggableCubes/index.js#L209-L212 (search for MouseInput)

Currently it's a bit of a manual process but it's in my TODO list to make the modules easier to set up and use :)