Как разместить объект в определенном месте в ARcore? - PullRequest
0 голосов
/ 16 октября 2019

Я пытаюсь разместить объект в определенном месте, не нажимая , есть ли прямой способ поместить объект в местоположение в реальном мире.

1 Ответ

0 голосов
/ 28 октября 2019

Конечно, вы могли бы сделать это.

  1. Поиск плоской поверхности.
    2. переопределить onUpdate метод.
  2. циклически просматривайте отслеживаемые объекты, и ваша модель была спроецирована без нажатия.

    Я просто даю вам представление о том, как выглядит метод onUpdate, это псевдокод

       frame = arFragment.getArSceneView().getArFrame();
        if (frame != null) {
            //get the trackables 
            Iterator<Plane> var3 = frame.getUpdatedTrackables(Plane.class).iterator();
            while (var3.hasNext()) {
                Plane plane = var3.next();
    
                //If a plane has been detected & is being tracked by ARCore
                if (plane.getTrackingState() == TrackingState.TRACKING) {
    
                    //Hide the plane discovery helper animation
                    arFragment.getPlaneDiscoveryController().hide();
    
    
                    //Get all added anchors to the frame
                    Iterator<Anchor> iterableAnchor = frame.getUpdatedAnchors().iterator();
    
                    //place the first object only if no previous anchors were added
                    if (!iterableAnchor.hasNext()) {
                        //Perform a hit test at the center of the screen to place an object without tapping
                        List<HitResult> hitTest = frame.hitTest(getScreenVector3().x, getScreenVector3().y);
    
                        //iterate through all hits
                        Iterator<HitResult> hitTestIterator = hitTest.iterator();
                        while (hitTestIterator.hasNext()) {
                            HitResult hitResult = hitTestIterator.next();
    
                            //Create an anchor at the plane hit
    
                                Anchor modelAnchor = plane.createAnchor(hitResult.getHitPose());
    
                                //Attach a node to this anchor with the scene as the parent
                                anchorNode = new AnchorNode(modelAnchor);
                                anchorNode.setParent(arFragment.getArSceneView().getScene());
    
                                **create a new TranformableNode that will carry our model**
                                }
    
    
                        }
                    }
                }
            }
    
        } 
    
...