0

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 Answers1

0

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.

yakobom
  • 2,681
  • 1
  • 25
  • 33
  • I told you what you need to do in order to solve it, per my experience with such environments. I do not have a specific code for you here, but I see no reason why you cannot do it by yourself... If you have further questions or specific difficulties, go ahead and ask. – yakobom Mar 28 '17 at 13:15
  • I am working with kudan SDK and I am not able to figure out where its making the 3D model inVisible. I went through their documentation but it didnt help me in anyway. The `trackable` object has a listener which has some methods like `onDetect` `onTrack` but I am not able to keep the cube visible –  Mar 29 '17 at 04:44
  • I do not know Kudan specifically, but I can try to take a quick look at the code and see if I can help. Which sample are you using? Provide a link if you can – yakobom Mar 29 '17 at 07:27
  • https://www.kudan.eu/download-kudan-ar-sdk/ for the Android sdk. You can even look for documentation on how to set it up..any issue while setting up. You can ask me –  Mar 30 '17 at 02:43
  • Yeah... although working for you sounds interesting, I'm not going to do that, no time for two jobs... I said I can take a quick look if you have a link to the sample. Otherwise I'll have to pass. Sorry... – yakobom Mar 30 '17 at 03:57
  • I have pasted the code which i have implemented to achieve that output in the screenshot provided. this is the base code I used to achieve this: https://github.com/kudan-eu/Marker-Basics-Android documentation on 3D model: https://wiki.kudan.eu/3D_Models –  Mar 30 '17 at 04:41
  • I'm afraid I have some bad news for you - looking at the sample, it looks like you have no control of the rendering, looks like Kudan are doing this for you. So, you cannot present what you want when you want it. Meaning, you cannot do what you requested - unless there's a feature that allows this (perhaps you should contact their support). There are other AR SDKs that only give you the info on the recognized target, and let you do all the drawing - this is harder but you have more control... – yakobom Mar 30 '17 at 05:20
  • Sure... Sorry I couldn't help more. Good luck. – yakobom Mar 30 '17 at 11:26