Start a new topic
Solved

How to activate animation when model is touched

How can I make my 3d model run its animation whenever I touch the model or the screen of my device. I've been researching and I saw that you can use the "Start() and stop()" but I am not sure where to put these variables. 


var World = {
loaded: false,
rotating: false,
resourcesLoaded: false,

init: function initFn() {
this.createOverlays();
},

createOverlays: function createOverlaysFn() {
/*
First an AR.ImageTracker needs to be created in order to start the recognition engine. It is initialized with a AR.TargetCollectionResource specific to the target collection that should be used. Optional parameters are passed as object in the last argument. In this case a callback function for the onTargetsLoaded trigger is set. Once the tracker loaded all its target images, the function worldLoaded() is called.

Important: If you replace the tracker file with your own, make sure to change the target name accordingly.
Use a specific target name to respond only to a certain target or use a wildcard to respond to any or a certain group of targets.
*/
this.targetCollectionResource = new AR.TargetCollectionResource("assets/tracker.wtc", {
onLoaded: function () {
World.resourcesLoaded = true;
this.loadingStep;
},
onError: function(errorMessage) {
alert(errorMessage);
}
});

this.tracker = new AR.ImageTracker(this.targetCollectionResource, {
onTargetsLoaded: this.loadingStep,
onError: function(errorMessage) {
alert(errorMessage);
}
});

/*
3D content within Wikitude can only be loaded from Wikitude 3D Format files (.wt3). This is a compressed binary format for describing 3D content which is optimized for fast loading and handling of 3D content on a mobile device. You still can use 3D models from your favorite 3D modeling tools (Autodesk® Maya® or Blender) but you'll need to convert them into the wt3 file format. The Wikitude 3D Encoder desktop application (Windows and Mac) encodes your 3D source file. You can download it from our website. The Encoder can handle Autodesk® FBX® files (.fbx) and the open standard Collada (.dae) file formats for encoding to .wt3.

Create an AR.Model and pass the URL to the actual .wt3 file of the model. Additional options allow for scaling, rotating and positioning the model in the scene.

A function is attached to the onLoaded trigger to receive a notification once the 3D model is fully loaded. Depending on the size of the model and where it is stored (locally or remotely) it might take some time to completely load and it is recommended to inform the user about the loading time.
*/
this.modelCar = new AR.Model("assets/birdWithFlower.wt3", {
onLoaded: this.loadingStep,
scale: {
x: 0.045,
y: 0.045,
z: 0.045
},
translate: {
x: 0.0,
y: 0.05,
z: 0.0
},
rotate: {
z: -25
}
});

/*
Similar to 2D content the 3D model is added to the drawables.cam property of an AR.ImageTrackable.
*/
var trackable = new AR.ImageTrackable(this.tracker, "*", {
drawables: {
cam: [this.modelCar]
},
onImageRecognized: this.removeLoadingBar
});
},

removeLoadingBar: function() {
if (!World.loaded && !World.loaded && World.resourcesLoaded && World.modelCar.isLoaded()) {
var e = document.getElementById('loadingMessage');
e.parentElement.removeChild(e);
World.loaded = true;
}
},

loadingStep: function loadingStepFn() {
if (World.resourcesLoaded && World.modelCar.isLoaded()) {
var cssDivLeft = " style='display: table-cell;vertical-align: middle; text-align: right; width: 50%; padding-right: 15px;'";
var cssDivRight = " style='display: table-cell;vertical-align: middle; text-align: left;'";
document.getElementById('loadingMessage').innerHTML =
"<div" + cssDivLeft + ">Scan CarAd ClientTracker Image:</div>" +
"<div" + cssDivRight + "><img src='assets/Bird_Target.jpg'></img></div>";
}
}
};

World.init();

I found a link for help but I have sub-folders in my WT3 file so I am not sure how to go inside the directory.

http://www.wikitude.com/external/doc/documentation/latest/android/3dmodels.html?_ga=2.260917709.1700658931.1529497708-546322608.1528728292#model_parts_animation

image

Hi Jon,


Did you check the 'Animated Model parts' sample in the sample app - this should provide details on how to work with animations in the model. Please also have a close look at the 3D model documeenatiton section.


Greetings

Nicola

I checked the documentation but the problem is that I am using sub-folders, how would i go about it?

Hi,


So you can't access / reference the animations? 


Thx and greetings

Nicola

Actually I got it to work, thank you

Login or Signup to post a comment