Pallavi
Pallavi

Reputation: 29

Adding text to a 3d model using sceneform arcore android

I am trying to build a app using arcore and sceneform. For that I want to add text to a 3d model. The text should appear in a particular position in the model.Is that possible using sceneform?

Can anyone give suggestion as to how to proceed?

Upvotes: 2

Views: 2574

Answers (1)

Atul Vasudev A
Atul Vasudev A

Reputation: 463

Text can be added using ViewRenderable, worked with filament version 1.7.0, crashes in some lower versions

Reference

Node tigerTitleNode = new Node();
      tigerTitleNode.setParent(model);
      tigerTitleNode.setEnabled(false);
      tigerTitleNode.setLocalPosition(new Vector3(0.0f, 1.0f, 0.0f));
      ViewRenderable.builder()
              .setView(this, R.layout.tiger_card_view)
              .build()
              .thenAccept(
                      (renderable) -> {
                          tigerTitleNode.setRenderable(renderable);
                          tigerTitleNode.setEnabled(true);
                      })
              .exceptionally(
                      (throwable) -> {
                          throw new AssertionError("Could not load card view.", throwable);
                      }
              );
    });

tiger_card_view.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/rounded_bg"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="6dp"
    android:text="Tiger"
    android:textAlignment="center" />

Upvotes: 2

Related Questions