Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change Position of ModelRenderable in AugmentedFace Api in AR core Android #120

Open
Adityavj2601 opened this issue Jun 12, 2020 · 0 comments

Comments

@Adityavj2601
Copy link

i want to change the postion of obj in real time based on node.getWorldPosition() here is my code i want to change the position of Model Renderable here is my code :

MaterialFactory
.makeOpaqueWithColor(this, new Color(android.graphics.Color.BLUE))
.thenAccept(material -> {
modelRenderable =
ShapeFactory.makeCube(new Vector3(0.01f , 0.01f , 0.01f) ,new Vector3(0f , 0f , 0.1f) ,
material);

            });



    ArSceneView sceneView = customARFragment.getArSceneView();
    sceneView.setCameraStreamRenderPriority(Renderable.RENDER_PRIORITY_FIRST);


    Scene scene = sceneView.getScene();

    scene.addOnUpdateListener(
            (FrameTime frameTime) -> {
                /*if (modelRenderable == null) {
                    return;
                }

*/

                Collection<AugmentedFace> faceList =
                        sceneView.getSession().getAllTrackables(AugmentedFace.class);

                // Make new AugmentedFaceNodes for any new faces.
                for (AugmentedFace face : faceList) {



                    FloatBuffer buffer = face.getMeshVertices();
                    Vector3 vectorLeftEyeLeft = new Vector3(buffer.get(33 * 3), buffer.get((33 * 3) + 1), buffer.get((33 * 3) + 2));
                    Vector3 vectorLeftEyeRight = new Vector3(buffer.get(133 * 3),buffer.get((133 * 3) + 1), buffer.get((133 * 3) + 2));
                    Node node = new Node();
                    node.setLocalPosition(new Vector3((vectorLeftEyeLeft.x + vectorLeftEyeRight.x) / 2, (vectorLeftEyeLeft.y + vectorLeftEyeRight.y) / 2, (vectorLeftEyeLeft.z + vectorLeftEyeRight.z) / 2));
                    node.setParent(faceNodeMap.get(face));
                    Vector3 vector3 =  node.getWorldPosition();








                    AugmentedFaceNode faceNode = new AugmentedFaceNode(face);
                    faceNode.setParent(scene);
                    faceNode.setFaceRegionsRenderable(modelRenderable);
                    faceNodeMap.put(face, faceNode);

                }



                // Remove any AugmentedFaceNodes associated with an AugmentedFace that stopped tracking.
                Iterator<Map.Entry<AugmentedFace, AugmentedFaceNode>> iter =
                        faceNodeMap.entrySet().iterator();
                while (iter.hasNext()) {
                    Map.Entry<AugmentedFace, AugmentedFaceNode> entry = iter.next();
                    AugmentedFace face = entry.getKey();
                    if (face.getTrackingState() == TrackingState.STOPPED) {
                        AugmentedFaceNode faceNode = entry.getValue();
                        faceNode.setParent(null);
                        iter.remove();
                    }
                }
            });

i want to set modelrenderable on position of vector3 . if you know then let me know and help it's urgent ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant