google-ar / sceneform-android-sdk

Sceneform SDK for Android
https://developers.google.com/sceneform/develop/
Apache License 2.0
1.23k stars 604 forks source link

sceneform is not rendered #489

Open ghost opened 5 years ago

ghost commented 5 years ago

Though it seems personal but spent 3 days but unable to figure why sceneform is not rendered package com.example.onkar.sceneform1;

import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity;

import com.google.ar.sceneform.Node; import com.google.ar.sceneform.Scene; import com.google.ar.sceneform.SceneView; import com.google.ar.sceneform.math.Vector3; import com.google.ar.sceneform.rendering.ModelRenderable;

public class MainActivity extends AppCompatActivity {

//private ModelRenderable earth_ballRenderable;
private ModelRenderable Tex_BengalTigerRenderable;
private SceneView scene_View;
private Scene scene;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    scene_View = findViewById(R.id.sceneView);
    scene = scene_View.getScene();

    ModelRenderable.builder()
            .setSource(this, Uri.parse("Mesh_BengalTiger.sfb"))
            .build()
            .thenAccept(renderable -> Tex_BengalTigerRenderable = renderable)
            .exceptionally(throwable -> {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage(throwable.getMessage())
                        .show();
                return null;
            });
    Node modelNode = new Node();
    modelNode.setRenderable(Tex_BengalTigerRenderable);
    scene.addChild(modelNode);
    modelNode.setLocalPosition(new Vector3(0, 0, 0));
}

@Override
protected void onResume() {
    super.onResume();
}

@Override
public void onPause() {
    super.onPause();
}

} using sceneform 1.6.0

thanks for help in advance

bobekos commented 5 years ago

When you assign your renderable to the node it is null. The ModelRenderable Builder return a future callback wich means the renderable is build async. Just assign the renderable to the node in the 'thenAccept' callback.

claywilkinson commented 5 years ago

You'll also need to forward onPause/onResume to the sceneView which starts and stops the Choreographer which controls the drawing . I implemented the scenview in a fragment, but you can see how I ended up doing it in https://github.com/googlesamples/sceneform-poly-browser/blob/master/app/src/main/java/com/google/devrel/ar/sample/polygallery/SceneformFragment.java

chiragmak10 commented 5 years ago

When you assign your renderable to the node it is null. The ModelRenderable Builder return a future callback wich means the renderable is build async. Just assign the renderable to the node in the 'thenAccept' callback.

can you please elaborate