Start a new topic
Solved

Using ObjectTrackable.drawables.addCamDrawable(drawable)

I'm trying to dynamically add an arrow image to a 3d object. I'm trying to use this code which I found in the documentation of ObjecTrackable. Using the javascript api.


var image = new AR.ImageResource("resource/arrow.jpeg");

    var drawable = new AR.ImageDrawable(image, 1,

        {

            offsetX: 1,

            offsetY: 1,

            rotation: 1

        });

    objectTrackable.drawables.addCamDrawable(drawable);


The code doesn't crash or anything but when the object is recognized the arrow doesn't show up.


Here is the full js code. Everything works except the last function.


AR.logger.activateDebugMode();

var stepnr = 0;

var objectTrackable;

var object


function test(url) {

    AR.logger.debug(url);


    var targetCollectionMouse = new AR.TargetCollectionResource(url, {});


    var mouseTracker = new AR.ObjectTracker(targetCollectionMouse,

        {

            onError: function (errorMessage) {

                alert("big rip");

            }

        });


    objectTrackable = new AR.ObjectTrackable(mouseTracker, "*",

        {

            onObjectRecognized: function (target) {

                AR.logger.debug("found mouse");

                AR.logger.debug(target);

                //AR.platform.sendJSONObject({ "name": target });

                object = target;

            }

        });

}


function NextStep() {

    stepnr++;

    AR.platform.sendJSONObject({ "name": stepnr.toString() });

}


function ShowDash() {

    if (object != null) {

        AR.platform.sendJSONObject({ "name": object });

    }

}


function NextInstruction(offsetx, offsety, rotationn) {

    //AR.platform.sendJSONObject({ "name": offsetx.toString() + ", " + offsety.toString() + ", " + rotation.toString() });


    //objectTrackable.drawables.removeCamDrawable(0);

    var image = new AR.ImageResource("resource/arrow.jpeg");

    var drawable = new AR.ImageDrawable(image, 1,

        {

            offsetX: offsetx,

            offsetY: offsety,

            rotation: rotationn

        });

    objectTrackable.drawables.addCamDrawable(drawable);

}

I have just tried to hardcode a drawable onto the object and it's not showing up either... I have no clue why it's not working. Code below doesnt show up on recognition (it is recognized i can see that in the logger)


ar image = new AR.ImageResource("resource/arrow.jpeg");

    var drawable = new AR.ImageDrawable(image, 5,

        {

            offsetX: 1,

            offsetY: 1,

            rotation: 1

        });


    objectTrackable = new AR.ObjectTrackable(mouseTracker, "*",

        {

            drawables: {

                cam: [drawable]

            },

            onObjectRecognized: function (target) {

                AR.logger.debug("found mouse");

                AR.logger.debug(target);

                object = target;

            }

        });



Turns out i needed a 3d model instead of an image :) 

Login or Signup to post a comment