Grabbing objects in a scene with Open VR Controller

Grabbing objects in a scene with Open VR Controller

Anonymous
Not applicable
2,132 Views
11 Replies
Message 1 of 12

Grabbing objects in a scene with Open VR Controller

Anonymous
Not applicable

I'm trying to create an application that would allow a user to "grab" and "hold" a single part from a large CAD assembly. Basically snap the part to the Vive controller location on a button click, then duplicate the controller's translations and rotations while the button is held so the user can manipulate and inspect the part in an intuitive manner.

 

The problem I am having is that in the imported CAD assemblies, the "center" of the individual parts rarely in coincident with the geometry. When something is "grabbed," it will offset from controller location, sometimes by a significant amount, and rotations do not match the direction. I had the same problems when I made a similar application with OSG and VR Juggler many years ago, but every solution I used back then is not working VRED. I'm not sure if VRED handles matrices differently or if its just been too long since I've done this sort of thing.

 

It seems like this should be relatively standard, simple functionality - what is best practice for accomplishing it? My one caveat is that it must be done programmatically as these assemblies are many thousands of parts and it's just feasible to go through and make manual adjustments on every part.

 

Thanks in advance!

0 Likes
2,133 Views
11 Replies
Replies (11)
Message 2 of 12

Florian_Hilmer
Contributor
Contributor

Hi,

 

did you look at the following commands already:

 

  • getWorldTransform()
  • getBBCenter()
  • setPivot(index, point, x, y, z)

 

I think with a combination of those you should be able to achieve what you are trying to do.

 

Of yourse you could also unshare all part instances in your assembly and flush all transforms (via the optimize module). Then all parts should be centered when you grab them.

0 Likes
Message 3 of 12

Anonymous
Not applicable

Thank you for the reply.

 

I've tried setting the rotation pivot of the node to the node's bounding box center but have had no luck. I've used other commands, though, not setPivot(). I'm not clear on what the index input to that function is supposed to be.

 

I just tried to run the optimizer as suggested, it does not seem to have effected the location of the geometry relative to the Vive controller when the part is set to the controller coordinates.

 

Do you have any other ideas?  Assuming you had properly centered objects, how would you go about "grabbing" them and tying them to the controller location? It's possible its my method for doing that that's faulty.

0 Likes
Message 4 of 12

j.kaestle
Enthusiast
Enthusiast

Hi,

I think you can solve the Problem with getBoundingBoxCenter() and getWorldTransform(). With these two informations you can calculate the Transformation matrix between the coordinate system of the part and the position of the bounding box. Then you can transform the part position to the boundingbox position.

 

I have implemented something similar, but the part is not snapping to the controlers Position. It is keeping its relative Position to the controler when the controler is moved.

 

regards

Jochen

Message 5 of 12

Anonymous
Not applicable
Thanks for the reply.
I've moved to a relative movement method like you described rather than the snap method I described in my original post. It works great for translation, but I'm having some really bizarre issues with rotation. I get the frame-to-frame rotation of the wand and apply it to the part I've grabbed, but axes of rotation don't always match between the part and the controller. I'm setting the part's rotation pivot the origin of the controller and the part's rotation orientation equal to the rotation orientation of the controller. Some parts work just fine, some work just fine if you grab them with the wand oriented the right way, and others will have misaligned axes no matter what. I'm having a really hard time finding a pattern or identifying what I'm overlooking. How are you tying the part rotation to controller rotation?
0 Likes
Message 6 of 12

j.kaestle
Enthusiast
Enthusiast

Hi,

I am not surprised that you have some trouble with the rotation. To implement this functionality is not so easy. The best way is not to set translation and rotatipn seperately, but to calcalute it with Matrix operations.

I do it like this:

1. I read the controlers world transformation

2. I read the parts world transformation

3. I calculate the transformation Matrix  controler->part (relative Position controler-part)

4. I read the world transformation of the parts parent node

5. When the controler is moved, i read the controlers new world transformation

6. I calculate the new world Position of the part with the transformation Matrix from step 3

7. unfortunately I cannot apply this Position directly to the part. So I calculate with the transformation Matrix of the parent node and the new Position of the part the new (lokal) transformation Matrix parent node->part and apply it to the part

 

To do all these steps you must be familiar with Matrix calculations and transformation of coordinates.

To make the calculations in Python easier, I use Numpy. Ist a module with numerical functions. It's not included in VRED by default:

https://forums.autodesk.com/t5/vred-forum/python-of-vred-with-library-numpy/td-p/6677176

 

I check, if I can create a simple Scene for you, so you can reproduce it.

If somebody knows an easier/better way to do it, please let me know.

 

Regards

Jochen

 

Message 7 of 12

Anonymous
Not applicable

Thank you Jochen! Unfortunately my VR rig got carted off to a conference for demos so I won't be able to test until mid-late next week, but that makes a lot of sense and I think it should work. If you're able to provide that sample scene without wasting too much of your time that would be fantastic.

0 Likes
Message 8 of 12

j.kaestle
Enthusiast
Enthusiast

Hi,

here is my Scene. Maybe it's not programmed the best way (I am not a trained programmer), but it's working fine for me.

As written above, you must add numpy to Python (described in the link above).

One more remark: It's only working with Transform Nodes, not with geometry nodes. Means you Need a transform-parent-node for the geometry you want to grab.

 

Regards

Jochen

Message 9 of 12

Anonymous
Not applicable

it seems like it grabbing everything is there away to tell it not to grab things u dont want it to? 

0 Likes
Message 10 of 12

j.kaestle
Enthusiast
Enthusiast

You can check the name of the grabbed node. That's the way we do it. When importing geometry in our template, we add an extention to the node names to have unique names. Only nodes with this Extension will be moved.

A second possibility is to add a tag to the nodes and check the tag (see the Autodesk Teleport example for walkable geometry). May be there are some more possibilities.

0 Likes
Message 11 of 12

Anonymous
Not applicable

Hi,

 

Thanks for your response. I have the same problem but very little python script knowledge. Is there anyway you could show me an example of how to add extension tag and checking script to the previous script?

 

A

0 Likes
Message 12 of 12

sergio.carena
Participant
Participant

Hi All,

it's been a while since the beginning of this forum, but I'm using the script and i customized it according to my needs. But now I have the following questions:
- is there any way to activate / deactivate the ability to move objects generally (in few words, activate/deactivate the script)?
- Is it possible to have feedback when two objects collide with each other?
thanks!

0 Likes