I'm developing AR android app with using ARCore-Augmented Faces API in Android Studio. For now, I have finish set up the app (5 buttons and its associate 3d model) and it is work well when I click one of those buttons for the first time launched the app. The problem is when I click another button to change the current face mask, it won't replace the current mask with new mask.
However, to fix this problem. I have tried to use restart() method and tried to remove the facenode. But it seems, those solutions don't work at all.
This is partial of my code that currently I work on it (not the fix one) where I still stuck with the problem I encounter.
alchemist_ovalbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alchemistOval();
}
});
scene.addOnUpdateListener(
(FrameTime frameTime) -> {
if (faceRegionsRenderable == 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)) {
AugmentedFaceNode faceNode = new AugmentedFaceNode(face);
faceNode.setParent(scene);
faceNode.setFaceRegionsRenderable(faceRegionsRenderable);
faceNode.setFaceMeshTexture(faceMeshTexture);
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();
}
}
public void alchemistOval() {
ModelRenderable.builder()
.setSource(this, R.raw.alchemist_oval)
.build()
.thenAccept(
modelRenderable -> {
faceRegionsRenderable = modelRenderable;
modelRenderable.setShadowCaster(false);
modelRenderable.setShadowReceiver(false);
});
}
So, I expect that the current face mask will be replace by new mask when user click another button.