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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Distance between camera and model

Lucas
7-Bedrock

Distance between camera and model

Hello for a customer project I need the distance between camera and a model (that does not have x,y,z 0,0,0). I want the model to start fading out at a distance of 1 meter. Then the closer I get to it the more I want it to fade out.

i have already read these articles
https://community.ptc.com/t5/Vuforia-Studio/Get-surface-coordinates-of-a-model/m-p/646408#M7459
https://community.ptc.com/t5/Vuforia-Studio/Finding-distance-from-the-model/m-p/647022
https://community.ptc.com/t5/Vuforia-Studio/Re-Finding-distance-from-the-model/m-p/648253

But unfortunately I have not been able to derive a working way on it.
Please help me I do not know what to do.

1 ACCEPTED SOLUTION

Accepted Solutions

Hello Roland, I was able to solve the problem with the rectangle using a radius. This works well enough. I had a similar idea with the dummys, but that didn't work so well.

For the distance calculation I came to the following solution:

  distance = Math.abs((+magnitute($scope.view.wdg["model-2"]["x"]-fargs.position[0].toFixed(2),$scope.view.wdg["model-2"]["y"]-fargs.position[1].toFixed(2),$scope.view.wdg["model-2"]["z"]-fargs.position[2].toFixed(2))));

Of course I took parts from the mentioned posts.

It works well and I thank you for your fast and friendly help.

View solution in original post

5 REPLIES 5

Hi @Lucas ,

as mentioned in the post  the distance to an object is | modelPosVec - eyePosVec |

The question is what is the modelPosVec ... it could be 0,0,0 or any other x,y,z but this is the coordinate of the widget. The model itself could be translated in delta x,y,z. In this case you can define a fix model centrum coordinates which should be used a modelPosVec.  Currently we can consider the model/or modelItem widget for the distance calculation only as point or ball with radius R. I think if this is working in your case it will be easy to set the transparency of the model depending to the distance   // something    /pseudo code:

 

opacity = 1.0;
if( distanceToMidPOintofModel< Radius)
opacity = distanceToMidPOintofModel/Radius - floor(distanceToMidPOintofModel/Radius);

 

So it means that when our distance is < Radius  or with other words smaller than the min distance  then it will be decrease the opacity - make the model transparent

Thank you very much for your answer @RolandRaytchev. Yes it would be ok to take x,y,z of a point and from that take the radius. But also here I have problems with the code. An example experience would help me a lot.

Furthermore, I have a machine on this topic, this machine has a danger area (rectangular). So it is not possible to take the radius here. How could this be implemented?

Hello @Lucas , thanks for the feedback!

Yes , when you have a geometry which is not possible to simplify with balls  e.g. U or very long   rectangle. In this case we need to setup many controls points (as fix points (x,y,z) list as part of the javascript code) In this case we can check the minimum of the distance to all points of the lists and when the distance of the nearest point is < as critical distance then we can have some warning.

Other approach will be to use some "dummy" 3d Widgets which are located additionally on the 3d model outline. For each point of the list, we have such holder widget with specific name (contains some string in the name to be able to collect them later with the query). So, in a query we can find all this accessory object and build the lists. This should be alternative option to a fix option of the border points.

Ok this above are some ideas because there is no direct functionality for this.

I will try in the next days to create a simple example project where we can check a distance to rectangular object which could be used as example.

Hello Roland, I was able to solve the problem with the rectangle using a radius. This works well enough. I had a similar idea with the dummys, but that didn't work so well.

For the distance calculation I came to the following solution:

  distance = Math.abs((+magnitute($scope.view.wdg["model-2"]["x"]-fargs.position[0].toFixed(2),$scope.view.wdg["model-2"]["y"]-fargs.position[1].toFixed(2),$scope.view.wdg["model-2"]["z"]-fargs.position[2].toFixed(2))));

Of course I took parts from the mentioned posts.

It works well and I thank you for your fast and friendly help.

Hi @Lucas ,

in the post (https://community.ptc.com/t5/Vuforia-Studio/Arrow-Navigator/td-p/748245 ) I provided example to the post but it is also relevant to  the distnace issue. There I have 3D Widgets (testTXT-1 ... testTXT-3) which  represent the objects and depending on the location of device it will find the distance to the neares widget I hope this could be helpful.

Top Tags