Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
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.
Solved! Go to Solution.
Thank you. I guess I'll have to create a dedicated metadata. I'll do my best to create a metadata with coordinates.
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
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
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.
Yes, in the default metadata is not information, therefore was the suggestion to use the CreoViewRWExtension. to create your own metadata as suggested in post what I referred to in previous post. Or you have to create your own data -e.g. json where you add the component id - position mapping.
Otherwise you can use some technique of the eye vector to calculate the position of component related to the camera position. Related post: https://community.ptc.com/t5/Vuforia-Studio/How-to-get-camera-position/m-p/557897#M3539
So e.g. you could have some arrow object , as pointer which is moved with the eye vector e.g. one 1.5 meter in front of the device plane and to touch with this pointer the object and in the same time you know based on the calculation of model coordinates, eye position and eye vector which is the position what you selected.
Thank you. I guess I'll have to create a dedicated metadata. I'll do my best to create a metadata with coordinates.