Я добавил несколько разных изображений в мой файл imgdb, и они отлично распознаются с помощью arcore sceneform. Тем не менее, я хочу отобразить разные 3D-объекты для каждого изображения, которое находится в файле imgdb. Я считаю, что это возможно с помощью функции getIndex, но я не знаю, как использовать то же самое, так как я новичок.
В приведенном ниже коде как назначить индекс обнаруженного в данный момент изображения переменной 'value'?
public class AugmentedImageNode extends AnchorNode {
private static final String TAG = "AugmentedImageNode";
// The augmented image represented by this node.
private AugmentedImage image;
private static CompletableFuture<ModelRenderable> ulCorner;
public AugmentedImageNode(Context context) {
if (value == 0) {
// Upon construction, start loading the models for the corners of the frame.
if (ulCorner == null) {
ulCorner =
ModelRenderable.builder()
.setSource(context, Uri.parse("models/tinker.sfb"))
//.setSource(context, Uri.parse("models/borderfence-small2.sfb"))
.build();
}
}
if (value == 1) {
// Upon construction, start loading the models for the corners of the frame.
if (ulCorner == null) {
ulCorner =
ModelRenderable.builder()
.setSource(context, Uri.parse("models/borderfence-small.sfb"))
//.setSource(context, Uri.parse("models/borderfence-small2.sfb"))
.build();
}
}
}
/**
* Called when the AugmentedImage is detected and should be rendered. A Sceneform node tree is
* created based on an Anchor created from the image. The corners are then positioned based on the
* extents of the image. There is no need to worry about world coordinates since everything is
* relative to the center of the image, which is the parent node of the corners.
*/
@SuppressWarnings({"AndroidApiChecker", "FutureReturnValueIgnored"})
public void setImage(AugmentedImage image) {
this.image = image;
// If any of the models are not loaded, then recurse when all are loaded.
if (!ulCorner.isDone())// || !urCorner.isDone() || !llCorner.isDone() || !lrCorner.isDone())
{
CompletableFuture.allOf(ulCorner)//, urCorner, llCorner, lrCorner)
.thenAccept((Void aVoid) -> setImage(image))
.exceptionally(
throwable -> {
Log.e(TAG, "Exception loading", throwable);
return null;
});
}
// Set the anchor based on the center of the image.
setAnchor(image.createAnchor(image.getCenterPose()));
// Make the 4 corner nodes.
Vector3 localPosition = new Vector3();
Node cornerNode;
// Upper left corner.
//localPosition.set(-0.5f * image.getExtentX(), 0.0f, -0.5f * image.getExtentZ());
localPosition.set(-0.0f * image.getExtentX(), 0.1f, +0.5f * image.getExtentZ());
cornerNode = new Node();
cornerNode.setParent(this);
cornerNode.setLocalPosition(localPosition);
cornerNode.setLocalRotation(Quaternion.axisAngle(new Vector3(-1f, 0, 0), 90f));
cornerNode.setRenderable(ulCorner.getNow(null));
}
private void setLocalRotation() {
}
public AugmentedImage getImage() {
return image;
}
}