3D model vanishing when moving the camera away from the marker android (Kudan AR)

539 views Asked by At

I am working on Augmented Reality using Kudan SDK in android. I am trying to generate 3D model when the phone camera is pointing towards the marker. I am able to achieve this. But If I move the camera away from the marker the model is vanishing. I dont want the 3D model to go away until unless the application is close or camera is closed. I want to move the 3D model while I move the camera as well. Here is the code for inserting the marker and the 3D model.

private void addImageTrackable() {

    // Initialise image trackable
    trackable = new ARImageTrackable("Space");
    trackable.loadFromAsset("user_pic.jpg");

    // Get instance of image tracker manager
    ARImageTracker trackableManager = ARImageTracker.getInstance();

    // Add image trackable to image tracker manager
    trackableManager.addTrackable(trackable);
}

private void addModelNode() {
    // Import model
    ARModelImporter modelImporter = new ARModelImporter();
    modelImporter.loadFromAsset("cube.jet");
    ARModelNode modelNode = (ARModelNode) modelImporter.getNode();

    // Load model texture
    ARTexture2D texture2D = new ARTexture2D();
    texture2D.loadFromAsset("cube.png");

    // Apply model texture to model texture material
    ARLightMaterial material = new ARLightMaterial();
    material.setTexture(texture2D);
    material.setAmbient(0.8f, 0.8f, 0.8f);


    // Apply texture material to models mesh nodes
    for (ARMeshNode meshNode : modelImporter.getMeshNodes()) {
        meshNode.setMaterial(material);
    }


    modelNode.rotateByDegrees(10, 1, 0, 0);
    modelNode.scaleByUniform(3f);
    modelNode.setPosition(1, 1, 2000);
    modelNode.play();

    // Add model node to image trackable
    trackable.getWorld().addChild(modelNode);
    modelNode.setVisible(true);

}

Here is the image of the 3D model coming in front of the marker

But I want to keep this 3D model even if I move away my camera away from marker.

1

There are 1 answers

8
yakobom On

The model is vanishing since there is no marker, of course. If you wish to keep drawing the model anyway at the same place, simply save the last position of the model on each frame, and draw the model at that position when the marker detection is lost. If you want to try and draw it at the exact same place in the world (and not the same place on screen), you can try using the device sensors to estimate the phone's movement and update the location of the model accordingly.