cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

How to dynamically load different model TARGETS with javascript code in Vuforia Studio

HectorAtLmco
7-Bedrock

How to dynamically load different model TARGETS with javascript code in Vuforia Studio

Hello!

 

We need to be able to dynamically load a model target using Java Script. This will reduce the number of experiences we have to create significantly. I was given a sample by PTC that shows how to do this, but I keep getting a message that reads 'Error loading tracker data' and it never actually loads. Just FYI, I am trying to load this from a THINGWORX REPOSITORY located in the same server as Vuforia. This is the sample:

1. I added a TML Text widget to the Experience, and I added this text, as suggested by PTC:

 

<twx-dt-target id="variabletarget"
guide-src="{{app.params.targetGuideSrc}}"
src="{{app.params.targetSrc}}"
x="{{app.params.targetXOrigin}}"
y="{{app.params.targetYOrigin}}"
z="{{app.params.targetZOrigin}}"
rx="{{app.params.targetRXOrigin}}"
ry="{{app.params.targetRYOrigin}}"
rz="{{app.params.targetRZOrigin}}"
enablescalegesture="{{app.params.gestures}}"
enablerotategesture="{{app.params.gestures}}"
enabletranslategesture="{{app.params.gestures}}"
istracked="false">
</twx-dt-target>

 

You can clearly see that several of these properties are set by Application Parameters. Suffice to say that I properly added those parameters previously.

 

I then assign variables and set the parameter values before calling the view with the TML:

 

var areaName = 'LWR_3';
var targetFilePath = "/Thingworx/FileRepositories/FwBracketInspectionFileRepo_hhenry/Targets/CTOL/"
var targetPvzFileName = targetFilePath + areaName + '/' + areaName + '.pvz';
var targetUUIDname = 'd6e488db-56f0-4e2e-8c32-29f8cbe1a19a';

//Target
$scope.app.params.targetsrc='vuforia-model:///' + targetPvzFileName;
$scope.app.params.targetGuidesrc=targetFilePath + areaName + '/' + targetUUIDname + '.png';
$scope.app.params.gestures = 'false';
$scope.app.fn.navigate('Main');

 

So... if anyone has a clear example of how to load and use a model target programmatically, that would be great!

 

Thank you so much!

1 REPLY 1

Hi @HectorAtLmco ,

here is a sample project  on the github which is related to your quesiton and possibly could be helpful:

https://github.com/steveghee/partAI-experience

but ...

  1. a model target data is  saved in subfolder of the upload project folder
  2. The model target data consist of different models / xml files and .dat files. This is requires the usage of the MTG according to  

    https://library.vuforia.com/articles/Solution/trained-model-target-datasets.html

    https://library.vuforia.com/articles/Solution/model-target-guide-view.html

  3. The data is first prepared and loaded to a project subfolder. So that it is not possible additional to add models without changing and republishing of the project.
  4. The project used also a TMLText widget to load the multi model Target data – but the syntax of the widget seem to be different to that what you try to use.
Top Tags