# 3D Vision

This is an open group. Sign in and click the "Join Group" button to become a group member and start posting.
Highlighted
Solved! Go to solution

## Select objects in 3D picture control - select primitive in mesh

Once I have selected an object in the 3D picture control using "pick point", how can I identify the selected the primitive of the object.

All I have is the position on the 3D picture, and the object (returned from 3Dpicture Control / pick model as selected by 3Dpicture control/ pick point)

Lets say I have a cube on a 3D picture, when I click on the cube, I can identify the object (the cube), but I would like to identify the triangle / quad primitive, and change/highlight its color.

Message 1 of 9
(4,429 Views)
8 REPLIES 8

## Re: Select objects in 3D picture control - select primitive in mesh

I am not aware of any special function in LabVIEW that would do that for you (but I would be happy to hear from anyone who would know one) but it can be done.

I can see two methods:

1. tracking yourself within the mesh to find which surface the clicked point belongs
2. converts a mesh into multiple meshes.

Method 1 is probably what would be done by non-LabVIEW programmers. You need to take the point, removes all rotations and translations of the mesh in the 3D Pict space, and then loop through the surfaces of your mesh to find to what surface the point belongs. It is the hard way. Fortunately, the LabVIEW helps us a little bit. Below is the code to extract point, and then transform it back in the referential of your mesh (I did not try to loop through the surfaces).

Method 2 is probably your best bet. This is how I produced the image at the top of this post. You simply need to convert each surface into its own mesh, add all those meshes into a single object, and then handle that object. When you click on a surface, you just need to change the color using the reference provided to you. Below is an example of the code to build a multiple-mesh cube (I put the vertices, normals, and indices as constants for simplicity.

Hope it helps.

Marc Dubois
HaroTek LLC
www.harotek.com

Message 2 of 9
(4,408 Views)

## Re: Select objects in 3D picture control - select primitive in mesh

Hi Mark

Thanks for the assistance.

Will try option 1 for the complex geometries.

For the pre-set geometries (cones, sphere, box etc), is there a way to obtain the mesh vertices (they appear to be internal to LabView) ?

Would you mind sharing your example in LabView 15 for me please.

Message 3 of 9
(4,400 Views)

## Re: Select objects in 3D picture control - select primitive in mesh

Thank you Mark, I have implemented your suggestion (attached) for picking a primitive..... linear operation.... quite fast.

But I had to have the mesh before I can use it.... how do I get the mesh class out of a named Object?

I have a complex scene, so obtaining the mesh programmatically would be much neater.

See below .... the incorrectly wired "get more specific class"

Example also traverses the model to get the correct point on the model (thanks to Mark for his example on which this is based).

Example doesn't use the in-range on the cluster, but splits it up into X,Y,Z, as LabView 15 appears to have a bug with the in-Range instruction.

Anyone know how to get a mesh from a built in primitive (box, cone etc)?

Message 4 of 9
(4,387 Views)
Solution
Accepted by topic author Philippe_RSA
06-21-2017 11:30 PM

## Re: Select objects in 3D picture control - select primitive in mesh

Hi Philippe,

I don't think it is possible to extract the mesh arrays from an object after it has been added. I would love to be able to do it so if you find a way, please let me know.

I think that you will have to manage your meshes yourself. First, you can generate the simple shapes yourself. I did that in C++ a while ago and I have just created a dll (SimpleMesh.dll) that can be called from LabVIEW (code is from "Introduction to 3D Game Programming with DirectX 12"
from Frank D. Luna). This way, you have access to the full data from the mesh. Also, for your detection algorithm, I am not sure what you are trying to do. If you try to see if a point is within a triangle, there are techniques to do that. I have just copied the Barycentric algorithm code from the  blackpawn.com/texts/pointinpoly/ into a Formula node and it seems to work (you have to test for co-planarity first).

I modified your VI with those 2 modifications and below is an image I obtained.

I have attached the 3 VIs and the dll with this post, along with the two previous VIs in LabVIEW 2015 format. The dll requires Visual Studio 2015 redistributable x86.

Good luck and let us know how it goes.

Marc Dubois
HaroTek LLC
www.harotek.com

Message 5 of 9
(4,361 Views)

## Re: Select objects in 3D picture control - select primitive in mesh

Hi Mark

Thanks for the mesh generators. I will try and put some textures on them, to see if it handles differently to the LabView standard geometries.

I suspect my version of the primitive selection is 10* faster (only has to do comparisons, and no dot products or multiplications)....

Please let me know if you get a solution for mesh reference from object.

Message 6 of 9
(4,256 Views)

## Re: Select objects in 3D picture control - select primitive in mesh

H

ere is a new version of the SimpleMesh DLL. This version (1.1) is not going to crash with zero or negative values.

The SimpleMesh DLL can be used to generate 3D objects of simple shapes and to have access to the vertices, indices, normals, and texture coefficients of the meshes (only triangles). The different shape types are:

• Box
• Cylinder
• Sphere
• Geosphere.

For all shapes, the absolute value of the parameter is used, except for the cylinder. If you put negative values for parameters 2 or 3 (bottom and top radii) of the cylinder, the corresponding cap is not drawn.

Quality is a factor between 0 and 1 (it is actually not capped at 1). You can use the quality factor with values close to 0 with the Cylinder, Sphere, and Geosphere, to generate more complex shapes (try it!).

The difference between the sphere and geosphere is that the geosphere is made of triangles that have all the same size.

The DLL is demonstrated by two VIs,  Generate Simple Mesh.vi and Generate Simple Mesh - Vertices.vi. The first VI calls the DLL and generates the requested shape as a 3D object and Mesh object. The second DLL also calls the DLL to generate a requested shape but provides the vertices, indices, normals and texture coefficients.

The two VIs are demonstrated in a test VI: test create mesh.vi. Below is an image of the front panel of the test vi. Use the random colors option to be able to see all the different triangles.

The VIs are LabVIEW 2015 and the SimpleMesh DLL requires the Visual Studio 2015 redistributable x86.

Marc Dubois
HaroTek LLC
www.harotek.com

Message 7 of 9
(4,167 Views)

## Re: Select objects in 3D picture control - select primitive in mesh

Hi, i already use your first example to get a point from my 3d picture from a STL file.

Now i need to get the vertex or the normal from that point.

I already use the property "NormalArray" to get the array from all the STL file but i can´t determine exactly wich normal correspond to the pick point.

Message 8 of 9
(716 Views)

## Re: Select objects in 3D picture control - select primitive in mesh

Based on the example "Pick and color primitive (mod).vi", you can simply extract the normal array from the model (just pull down the SceneMesh property node and select "NormalArray". Bring the array to the For Loop and output the correct array using a select function connected to the ouput of the function "Point in triangle.vi", as shown in the diagram below. Notice that there is one normal for each point defining a triangle but those 3 normals should be have the same values.

Marc Dubois
HaroTek LLC
www.harotek.com

Message 9 of 9
(708 Views)
This is an open group. Sign in and click the "Join Group" button to become a group member and start posting.