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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

How to reset whole experience while in AR World

Qwtll
9-Granite

How to reset whole experience while in AR World

Hello everyone !

 

This time i'm looking for a way to optimise my application code.

 

I currently have a RESET function, but it takes all my widgets, one by one, to set them as default (position, visibility etc...)

This is an extra fat function (~100 lines with comments) and i'm sure there is a way to get back to the default application in one line !

But i have no clue about how to make it...

 

I basically need to know how to set an application back to it's default settings without using a fat function, or closing the app, re-open vuforia view and lauch the app.

 

I hope this time my request is about something existing 😅

6 REPLIES 6

Hi @Qwtll ,

you can  reduce the code  for reseting of widgets but it depends what you means as reset. Example you want to move all 3d widgets to a specific location and make them invisible. The following sample code:

 

 

//================
$scope.widgetBlank=function(partOfWdgNameStr){
twx.app.fn.addSnackbarMessage("fn: blanks all widgets where the name contains:"+partOfWdgNameStr,"twLogo");
 
  var wdgs=$scope.app.view.Home.wdg; 
  for(wdg in wdgs)
  {  
    if(hasWdgProp(wdgs[wdg],'idpath')) {
      console.log("this widget ::"+wdgs[wdg]['widgetName']+" is a modelitem");}
    if(hasWdgProp(wdgs[wdg],'placeholder_img')) {
      console.log("this widget ::"+wdgs[wdg]['widgetName']+" is a 3DImages");
      if(wdgs[wdg]['widgetName'].indexOf(partOfWdgNameStr) !=-1) 
         // check if the widget name conntains the partOfWdgNameStr 
             {$scope.setWidgetProp(wdgs[wdg]['widgetName'],  'visible',true);}
      else   {$scope.setWidgetProp(wdgs[wdg]['widgetName'],  'visible',false);}
    $scope.$applyAsync()
    }
    if(hasWdgProp(wdgs[wdg],'imgsrc')) {
      console.log("this widget ::"+wdgs[wdg]['widgetName']+" is a 2D Image");}

  // else console.log("this widget ::"+wdgs[wdg]['widgetName']+" is NOT a modelitem");
  }
};
//////////////////////////////////////////////////////
//========================================================
function hasWdgProp(widget,property)
{
 	for (wp in widget)	{
            //console.log("property="+property+" | wp="+wp);
           if(wp==property) return true;
           else continue;
						}
 return false;
}
//

 

 

This example will select all widgets and will check them - the main filter will check if the name contains some string.  The more interesting details is to check for particular  property which is specific for some type of widgets e.g. modelItems  etc. So when we could identify some type of widget based on availability of specific property we can set /reset all common properties. If we want to set some generic properties like visibility then we possibly we do not to make a type check.

Another way to reset / or to set of properties to use a multivalve set user defined function which will read a e.g. json list which contains a definition of all properties which should be set. / reset

Example of such defintion:

 

 

//Global Variable defines the name of the json file which contains info about
// properties and values which should be set		
var pjson ="properties.json"; //JSON File Name without extension
$scope.jsonData={}; //global $scope variable

gotJSON=function(data){
 try{
$scope.jsonData=JSON.parse(data);
 console.warn(  JSON.stringify($scope.jsonData))
   $scope.setMutipleProps($scope.jsonData)
 } 
catch(wrong){    console.warn(wrong);}

}
doRead=function (jsonFile){
fetch(jsonFile)
  .then(response=>response.text())
  .then(data=>gotJSON(data))
}

$scope.Init=function() {// will read the json file from upload project folder
doRead('app/resources/Uploaded/'+pjson);
}
///// when View is loaded we will start the setting
$scope.$on('$ionicView.afterEnter',function(){
  console.log("$ionicView.afterEnter was called");
$scope.Init();}) //event: when 2d View loaded
//the code will read the complette JSON File and
//assignee it to a jsonData global variable
//func will set mutliple widget properties according JSON
$scope.setMutipleProps  = function(obj){

 Object.keys(obj).forEach(function (item)  {
                for(var prop in obj[item])    {
                           $scope.view.wdg[item][prop]=obj[item][prop];  
                           //print the setting for debugging                 
							console.log("==>$scope.view.wdg["+item+"]["+prop+"]="+obj[item][prop] )
                                              } 
                							})
                                       };
                  
 

 

 

and here is an example for properties.json which is saved in Studio Upload folder. 

 

 

{"button-1":{"class":"button1"},"button-2":{"class":"button1"},"button-3":{"class":"button1"},"3DLabel-1":{"visible":false,"text":"This is PTC Remote Control Model"}} 

 

 

In this case the javascript case will remain constants - only you can change the name of the json file which should be red - possible are also different configuration (each configuration in extra json file) which could be called to set of specific state or reset of widget properties

Hey @RolandRaytchev 

 

I admit that i've been not precise in my original post...

I didn't expected something that heavy but it depends on how you understood my request i believe.

Also, i don't have access to the Vuforia Upload folder, which is on a server where i don't have access to. When i use it, it's only to download my new version to the holo.

 

My definition of reset in this case is just about a button which could reset the application as it is just after it has being lauched.

As i move a lot of Model Items, and play with visibilty/opacty of Model Items & buttons/3D Labels, i have to reset my app before i trigger a new function.

So to be more specific i don't want to recall x,y,z coordinates of my model items, i more or less want it to be automatically...
But i saw that your function call every widgets isn't it ?

 

Here is a very short sample of my mess that i want to shorten the most as possible : 

$scope.reset = function()
{
  clipMid = 0;
  $scope.view.wdg['BtnGRA']['visible'] = true;
  $scope.view.wdg['BtnCONN']['visible'] = true;
  $scope.view.wdg['BtnCAP']['visible'] = true;
  $scope.view.wdg['Securite']['visible'] = true;
  $scope.view.wdg['CAP1']['visible'] = false; // this one is a part of a hidden group of button until the user trigger them (it's also unchecked for visible in Studio)
  //here all my buttons and images
//-------------------------
  stopGras = 0;
  $scope.view.wdg['gra1']['x'] = -0.025;
  $scope.view.wdg['gra1']['y'] = -0.042;
  $scope.view.wdg['gra1']['z'] = -0.039;
  $scope.view.wdg['gra2']['x'] = 0 ;
  // here all my items moved by 1 function (x.y.z coord)
//---------------------
  $scope.view.wdg['pin1-2']['opacity'] = 1;
  $scope.view.wdg['pin2-2']['opacity'] = 1;
  $scope.view.wdg['pin1-1']['color'] = "";
  $scope.view.wdg['pin2-1']['color'] = "";
  // all opacity and color things triggered by some functions, i've groupped'em cuz' they are triggered everywhere
}

It's extremly basic code but it's to messy

I force the user to execute this function after he triggered each function, so it contains absolutelly all of the widgets and model items

 

I hope you understand a bit more my issue, and i'm sure you'll have ideas to update your first code 🙂

Hi @Qwtll ,

thanks for the feedback! when I look that code your posted I think that this was the kind of question where my post was traying to answer. Let  me , please, explain.  The upload folder in your project is the folder where you could upload any files e.g. also JSON File with properties. This folder is ALLWAYS  loaded with your project to the mobile device (mobile or eyewear) and you can the use the javaScript code construct from  the example of my last post to read data and to set the property. In this case you have to manage all properties in a json file. In case that you want to change the initialization you do not need to change the Studio javaScript  code but only the property list in the Json file. Of course you can use any other file formats instead of Json format  but Json file is very easy to edit , to check for errors and to read it in JavaScript

 

Hi @RolandRaytchev !

 

Theses last days i tried to apply your code and i did'nt managed to do it well.

My code is meant to be used by other persons after my internshp, so it must be kind from me if it is easier to understand for everyone 😅... 

I'm also looking for lower quality models, it might solve a part of my problem, and finally, in terms of readabiliy the current Reset is the best solution.

I noticed I had to much useless model items so it should gain some FPS if I delete theses items...

 

Sorry for leaving this idea but i hope someone will need your solution.

Thank's for your time, have a good day !

Here is another approach, without any code, few taps to reload the experience.

 

1, Tap the option menu optionMenu dots.jpg  (top right corner)

2, Tap on either Experiences or Scan

 

Now you start from the beginning without close, re-open and launch View.

 

Hello @dsgnrClarK !

 

I am working on Hololens and I understand what you mean, I discovered this yesterday and now i'm using that to navigate between 'Downloads' and 'Librairy'

This is actually a good solution but it forces the user to replace the application... it gives me an idea ! 😮 

You didn't helped me as expected but thank you anymway ! 

Announcements

Top Tags