viromedia / viro

ViroReact: AR and VR using React Native
MIT License
2.31k stars 483 forks source link

OnClick detected by wrong object #744

Open beauvaisbruno opened 5 years ago

beauvaisbruno commented 5 years ago

Environment

Please provide the following information about your environment:

  1. Development OS: Windows,
  2. Device OS & Version: Android 9
  3. Version: ViroReact 2.16.0, React Native 0.59.3
  4. Device(s): Huawei P20 EML-L09

Description

I have an issue when I click on AR mode an object beside an other one. The click is detetected by the wrong object.

Reproducible Demo

Complete reproducible demo https://github.com/beauvaisbruno/virobugs

import {AppRegistry, View} from 'react-native';
import {Viro3DObject, ViroAmbientLight, ViroARScene, ViroARSceneNavigator} from "react-viro";
import React from "react";

const Navigator = ()=>{
  return  <View style={{ flex:1}}><ViroARSceneNavigator
    initialScene={{scene:  () => {
        return  <ViroARScene>
          <ViroAmbientLight color={"#aaaaaa"} />
          <Viro3DObject
            source={require("./res/outside.glb")}
            type="GLB"
            position={[0, 0, -1]}
            onClick={()=> {
              console.log("Clicked outside");
            }}
          />
          <Viro3DObject
            source={require("./res/inside.glb")}
            type="GLB"
            position={[0, 0, -1]}
            onClick={()=> {
              console.log("Clicked inside");
            }}
          />
        </ViroARScene>;
      }}}
    //https://viromedia.com/signup/
    apiKey={"SOME_API_KEY"} />
  </View>;
}

AppRegistry.registerComponent('virobugs', () => Navigator);

inside.zip outside.zip Screenshot_20191007_111140_com virobugs

tomascg2309 commented 5 years ago

Hey! I have been working for a couple of week with Viro and I could realize what is going on: when you have objects pretty close each other, their hitboxes overlap. You must set the property highAccuracyEvents={true} of the Viro3DObject component to ensure event like clicking will be triggered properly. Remember not to activate this property for all the objects you put on scene due to performance penalty. Cheers!