Skip to main content
10-Marble
June 23, 2023
Solved

How can I get the coordinates of a selected part in "Vuforia Studio"?

  • June 23, 2023
  • 1 reply
  • 2038 views

How can I get the coordinates of a selected part in "Vuforia Studio"?
I tried the following, but could not get the correct coordinates.

 

 

 

tml3dRenderer.GetObject('model-1-/3').GetWidget().GetLocation().position.x

 

 

 

 Specifically, no matter which part was selected, all X, Y, and Z coordinates were always zero.

 

 

Best answer by nishihira

Thank you. I guess I'll have to create a dedicated metadata. I'll do my best to create a metadata with coordinates.

1 reply

21-Topaz I
June 23, 2023

Hi @nishihira ,

so far I know the GetWidget() method will not work on some/or all mobile platforms - so seem that is  only reported in chrome - and possibly  this indented for UI usage. Therefore I thing this work in chrome browser only. Here I could find a old test code where I tested this feature in js.

$scope.testButton=()=>{console.warn($scope);console.warn(tml3dRenderer);
 $scope.setWidgetProp('modelItem-1','rx',45.0); 
 $scope.setWidgetProp('modelItem-2','rx',45.0); 
if( isPreview()) {
 //modelItem-1
 console.warn( tml3dRenderer.GetObject('model-1-/0/0/10/2').GetWidget().GetLocation() ); 
 console.info("X="+ tml3dRenderer.GetObject('model-1-/0/0/10/2').GetWidget().GetLocation().position.x ); 
 
 //modelItem-2
 console.warn( tml3dRenderer.GetObject('model-1-/0/0/10/1').GetWidget().GetLocation() ); 
 console.info("X="+ tml3dRenderer.GetObject('model-1-/0/0/10/1').GetWidget().GetLocation().position.x );
}
 $scope.$applyAsync();
 }
 

//----------------------------
//where the preview check is defined as
//----------------------------
isPreview = function() { 
 if(window.twx.app.isPreview()) // is in Preview
 return true;
 return false; }
//======================================================

So what possibly you can use instead is some techniques as described in the boding box - so getting information via metadata which is extracted as in the following link is mentioned.

https://community.ptc.com/t5/Vuforia-Studio/Obtaining-Bounding-Boxes-for-3D-Models/m-p/779434#M10634

https://community.ptc.com/t5/Vuforia-Studio/metadata-vuforia-experience-service/m-p/778822#M10621

https://community.ptc.com/t5/Vuforia-Studio/metadata-vuforia-experience-service/m-p/779433#M10633

 

 

21-Topaz I
June 23, 2023

So when extracted and imported the metadata in Studio via the CreoViewRWExtension

 

//==========================================
$scope.app.getAttrArr= function(modelName,pathId,attribute) { 
 let retVal= [0.,0.,0.,0.,0.,0.];
try {
let arr= metaDataArray[modelName].data[pathId]['__PV_SystemProperties'][attribute].split(' ');
 for (let i=0;i<6;i++) retVal[i]= parseFloat(arr[i]);
 return retVal;
}
catch(e) {return retVal;}
}
//======================================
//===========================================
$scope.app.getModTransformMat= function(modelName,pathId) { 
return $scope.app.getAttrMat(modelName,pathId,'Model Transformation'); }

//==========================================
$scope.app.getInstTransformMat= function(modelName,pathId) { 
return $scope.app.getAttrMat(modelName,pathId,'Instance Transformation'); } 
//==========================================
$scope.app.getModLocationMat= function(modelName,pathId) { 
return $scope.eulerVec2trfMatR ($scope.app.getAttrArr(modelName,pathId,'Model Location'));
}
//==========================================

$scope.app.getInstLocationMat= function(modelName,pathId) { 
return $scope.eulerVec2trfMatR ($scope.app.getAttrArr(modelName,pathId,'Instance Location'));
}
//=======================================================================================

 

 

 I used some functions as mentioned in  this sample studio project where tried to apply more complex operations like space rotation via any csys point - where all calculation are based on  the meta data which was extracted via the  CreoViewRWExtension.

So possibly could be helpful as additional information

nishihira10-MarbleAuthor
10-Marble
June 23, 2023

Thank you @RolandRaytchev for your speedy and thorough replies! However, as you said, it didn't work on mobile platforms.Thanks also for the suggestion to get it from the metadata. Unfortunately, however, there is no coordinate information in the metadata of the CAD data we are dealing with.