Posts: 16
Threads: 4
Joined: Oct 2020
Reputation:
0
Hi !
I've tried to find it in the API, but I couldn't, so here I am : I'd like to add some sound to a chain (obi rope) object : the easiest way would be to trigger a sound whenever a particle collides with another object. Is there an easy way to get such an information ?
Thank you !
Vincent
Posts: 6,346
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
05-08-2021, 08:33 AM
(This post was last modified: 05-08-2021, 08:33 AM by josemendez.)
Hi!
There's an entire page in the scripting section of the manual focused on collision callbacks:
http://obi.virtualmethodstudio.com/manua...sions.html
Using this, you can get a list of all contacts generated each frame (either particle-collider, or particle-particle).
kind regards,
Posts: 16
Threads: 4
Joined: Oct 2020
Reputation:
0
(05-08-2021, 08:33 AM)josemendez Wrote: Hi!
There's an entire page in the scripting section of the manual focused on collision callbacks:
http://obi.virtualmethodstudio.com/manua...sions.html
Using this, you can get a list of all contacts generated each frame (either particle-collider, or particle-particle).
kind regards, I knew it existed, thank you !!
I do have two follow-up questions after trying it out:
First I am a bit confused by the fact that collision point are Vector4 and not Vector3, are just the x, y, z components of the Vector4 the world position ?
Secondly, contacts keep existing after the original impact : I'm guessing I should check the relative speed of the two bodies, but I'm not sure what the best way to do that is, whether I should use one of the 'impulse' floats (normal impulse, tangent, bitangent, stick..?)... I'm also a bit concerned it might be quite expensive to check every contact as well as their relative velocity every frame ?
Thanks a lot for your help !
[url=http://obi.virtualmethodstudio.com/docs/struct_oni_1_1_contact.html#aa758d2c4172da3f24bfe74acd2a290f7][/url]
Posts: 6,346
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
05-08-2021, 11:06 AM
(This post was last modified: 05-08-2021, 11:14 AM by josemendez.)
(05-08-2021, 10:46 AM)VincentAbert Wrote: I do have two follow-up questions after trying it out:
First I am a bit confused by the fact that collision point are Vector4 and not Vector3, are just the x, y, z components of the Vector4 the world position ?
From scripting particles:
http://obi.virtualmethodstudio.com/manua...icles.html
Quote:Dimensional data in Obi (such as positions and velocities) has 4 components (x,y,z,w) instead of the usual 3 (x,y,z). This is for efficiency reasons (memory alignment). You can safely ignore the fourth component in these, casting Vector4 to Vector3 whenever necessary.
Longer answer: vectorized or SIMD instructions (single instruction, multiple data) typically process 4 pairs of operands in parallel. This allows the CPU to for instance, add together two Vector4s in the same time it would take to add two floats. However these instructions only work on 2, 4, or 8 pairs of operands, and they have to be aligned in memory in a very specific way. For this reason Obi exposes multidimensional data as Vector4s, with the last component (w) being 0. This allows it to perform arithmetic operations up to 75% faster than it would otherwise.
Another, less important reason is that matrix algebra usually involves multiplying 4x4 matrices against points/vectors. Using Vector4s directly avoids having to internally convert Vector3 to Vector4 and back, which results in even better performance and more streamlined code.
(05-08-2021, 10:46 AM)VincentAbert Wrote: Secondly, contacts keep existing after the original impact : I'm guessing I should check the relative speed of the two bodies, but I'm not sure what the best way to do that is, whether I should use one of the 'impulse' floats (normal impulse, tangent, bitangent, stick..?)...
If you want to for instance modulate sound volume depending on impact "force", use the normal impulse magnitude. Tangent and bitangent impulses are used for friction, and stick impulses are used for well...sticky contacts
(05-08-2021, 10:46 AM)VincentAbert Wrote: I'm also a bit concerned it might be quite expensive to check every contact as well as their relative velocity every frame.
Depends on how you do it and what your budget is. Obi generates and deals with tens of thousands of contacts every frame, but it does it in a extremely optimized way. This data is made available to you, then it's your turn to process it in any way you like: simplest is a for loop over all of them, will do fine if you're not on a tight budget or want something simple. This is of course not very efficient: runs in the main thread and no vectorization is taken advantage of.
You could also process all this data in parallel using jobs, and exploit vectorization, which is the way Obi does it. Will result in orders of magnitude better performance at the cost of slightly more complex code.
Posts: 16
Threads: 4
Joined: Oct 2020
Reputation:
0
(05-08-2021, 11:06 AM)josemendez Wrote: From scripting particles:
http://obi.virtualmethodstudio.com/manua...icles.html
Longer answer: vectorized or SIMD instructions (single instruction, multiple data) typically process 4 pairs of operands in parallel. This allows the CPU to for instance, add together two Vector4s in the same time it would take to add two floats. However these instructions only work on 2, 4, or 8 pairs of operands, and they have to be aligned in memory in a very specific way. For this reason Obi exposes multidimensional data as Vector4s, with the last component (w) being 0. This allows it to perform arithmetic operations up to 75% faster than it would otherwise.
Another, less important reason is that matrix algebra usually involves multiplying 4x4 matrices against points/vectors. Using Vector4s directly avoids having to internally convert Vector3 to Vector4 and back, which results in even better performance and more streamlined code.
If you want to for instance modulate sound volume depending on impact "force", use the normal impulse magnitude. Tangent and bitangent impulses are used for friction, and stick impulses are used for well...sticky contacts
Depends on how you do it and what your budget is. Obi generates and deals with tens of thousands of contacts every frame, but it does it in a extremely optimized way. This data is made available to you, then it's your turn to process it in any way you like: simplest is a for loop over all of them, will do fine if you're not on a tight budget or want something simple. This is of course not very efficient: runs in the main thread and no vectorization is taken advantage of.
You could also process all this data in parallel using jobs, and exploit vectorization, which is the way Obi does it. Will result in orders of magnitude better performance at the cost of slightly more complex code.
Thank you so much for that detailed answer ! I managed to make it work just as I wanted For now it's using a basic foreach loop, and it seems to be good enough performance wise.
Have a nice day !
|