Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 views
in Technique[技术] by (71.8m points)

augmented reality - Add dots in Augmentedfaces / Render dynamic spheres (mesh) attached to face in sceneform(arcore)

I want to render dots (spheres) which are attached to face mesh vertices from AugmentedFaces module. I know that you can put a mesh texture which imitates this behaviour, however instead of adding a texture on subject's face I'd prefer to render vertices position in real-time.

Based on the simplest AugmentedFaces Sceneform sample app - here. The result that I want to achieve is similar to this:

enter image description here

scene.addOnUpdateListener(
    (FrameTime frameTime) -> {
      if (faceRegionsRenderable == null || faceMeshTexture == null) {
        return;
      }

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

      // Make new AugmentedFaceNodes for any new faces.
      for (AugmentedFace face : faceList) {
        if (!faceNodeMap.containsKey(face)) {
          // SAMPLE CODE FOR ADDING FOX EARS & TEXTURE
        }

        for (int i = 0; i < 460; i++) {
          int finalI = i;
          MaterialFactory.makeOpaqueWithColor(this, new Color(android.graphics.Color.YELLOW))
                  .thenAccept(
                          material -> {
                            modelRenderable =
                                    ShapeFactory.makeSphere(0.0015f, new Vector3(
                                            face.getMeshVertices().get((finalI * 3)),
                                            face.getMeshVertices().get(((finalI * 3) + 1)),
                                            face.getMeshVertices().get(((finalI * 3) + 2))
                                    ), material);
                          });
          AugmentedFaceNode dotOnFaceNode = new AugmentedFaceNode(face);
          dotOnFaceNode.setParent(scene);
          dotOnFaceNode.setFaceRegionsRenderable(modelRenderable);
          faceNodeMap.put(face, dotOnFaceNode);
        }
      }

      // 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();
        }
      }
});

The problem with this approach is PERFORMANCE. I'm not able to add more than 50+ objects to the plane. Is this how the sceneform supposed to work or setFaceRegionsRenderable is just for ADDING ONE or TWO objects at a time - e.g. glasses and adding 460+ objects is a plain misuse of this API?

question from:https://stackoverflow.com/questions/65642674/add-dots-in-augmentedfaces-render-dynamic-spheres-mesh-attached-to-face-in-s

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...