Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  ObiRope Points
#1
Hello everyone, I want to know if my ropes are crossing, for that I want to check the position of the leftmost and rightmost points of my rope, how can I access all the points of my rope? I tried to get them through ObiRopeBlueprints points array, but nothing came of it, it displays the length of 0. Thanks Sonrojado


Attached Files
.png   unknown-1.png (Size: 43.16 KB / Downloads: 60)
Reply
#2
(19-10-2021, 10:26 AM)Matbee Wrote: Hello everyone, I want to know if my ropes are crossing, for that I want to check the position of the leftmost and rightmost points of my rope, how can I access all the points of my rope? I tried to get them through ObiRopeBlueprints points array, but nothing came of it, it displays the length of 0. Thanks Sonrojado

Hi there,

Blueprints are similar to prefabs: they're just "instructions" to build (instantiate) a rope. At runtime, particle data is contained in the solver.

Check out the manual's page for particle scripting, let me know if you have further questions:
http://obi.virtualmethodstudio.com/manua...icles.html
Reply
#3
(19-10-2021, 10:26 AM)Matbee Wrote: Hello everyone, I want to know if my ropes are crossing, for that I want to check the position of the leftmost and rightmost points of my rope, how can I access all the points of my rope? I tried to get them through ObiRopeBlueprints points array, but nothing came of it, it displays the length of 0. Thanks Sonrojado
Can't I get the global position of a particle in space? And in general, if, for example, I have a very small value for the number of particles, how can I get, for example, a point from the middle of the rope?

(19-10-2021, 10:26 AM)Matbee Wrote: Hello everyone, I want to know if my ropes are crossing, for that I want to check the position of the leftmost and rightmost points of my rope, how can I access all the points of my rope? I tried to get them through ObiRopeBlueprints points array, but nothing came of it, it displays the length of 0. Thanks Sonrojado

_rope.solver.actors[0].particleCount.  I got the number of particles of the actor, but the list of all particles how can i get?
Reply
#4
(19-10-2021, 11:00 AM)Matbee Wrote: Can't I get the global position of a particle in space?

Yes of course! you can express particle data in any space you'd like, including world space. Just use Unity's TransformPoint/Vector/Direction methods:
https://docs.unity3d.com/ScriptReference...Point.html

(19-10-2021, 11:00 AM)Matbee Wrote: And in general, if, for example, I have a very small value for the number of particles, how can I get, for example, a point from the middle of the rope?

You can just take the element at the middle of the rope, and get either particle at its ends. The following code would return the position of the particle in the middle, expressed in world space:

Code:
int particleIndex = rope.elements[rope.elements.Count/2].particle1;
var position = rope.solver.transform.TransformPoint(rope.solver.positions[particleIndex]);
Reply
#5
(19-10-2021, 10:50 AM)josemendez Wrote: Hi there,

Blueprints are similar to prefabs: they're just "instructions" to build (instantiate) a rope. At runtime, particle data is contained in the solver.

Check out the manual's page for particle scripting, let me know if you have further questions:
http://obi.virtualmethodstudio.com/manua...icles.html
Oops, I accidentally replied to my own message) .

_rope.solver.actors[0].particleCount.  I got the number of particles of the actor, but the list of all particles how can i get?
Reply
#6
(19-10-2021, 11:24 AM)Matbee Wrote: Oops, I accidentally replied to my own message) .

_rope.solver.actors[0].particleCount.  I got the number of particles of the actor, but the list of all particles how can i get?

From the example in the manual:

Code:
// Iterate over all particles in an actor:
for (int i = 0; i < actor.solverIndices.Length; ++i)
{
// do something with each particle
}

For instance, to print the solver-space position of all particles (including inactive ones):

Code:
for (int i = 0; i < actor.solverIndices.Length; ++i)
{
Debug.Log(solver.positions[actor.solverIndices[i]]);
}
Reply
#7
(19-10-2021, 11:24 AM)josemendez Wrote: Yes of course! you can express particle data in any space you'd like, including world space. Just use Unity's TransformPoint/Vector/Direction methods:
https://docs.unity3d.com/ScriptReference...Point.html


You can just take the element at the middle of the rope, and get either particle at its ends. The following code would return the position of the particle in the middle, expressed in world space:

Code:
int particleIndex = rope.elements[rope.elements.Count/2].particle1;
var position = rope.solver.transform.TransformPoint(rope.solver.positions[particleIndex]);
Do I understand correctly that each rope element contains 2 particles? Particle1 and particle2?
Reply
#8
(19-10-2021, 11:28 AM)Matbee Wrote: Do I understand correctly that each rope element contains 2 particles? Particle1 and particle2?

Correct. Each element is an "edge" joining 2 particles together, like this:

O-----O-----O-----O-----O

"O" being particles, and "-----" being elements.
Reply
#9
(19-10-2021, 11:29 AM)josemendez Wrote: Correct. Each element is an "edge" joining 2 particles together, like this:

O-----O-----O-----O-----O

"O" being particles, and "-----" being elements.
I got it to display several different positions for all particles, but most of the particles have the same position as in the screenshot below
   



I also created a small sphere at each position, as you can see, some spheres were created at the correct position, but most of them were created at the point (0,0,1.8)

(19-10-2021, 11:29 AM)josemendez Wrote: Correct. Each element is an "edge" joining 2 particles together, like this:

O-----O-----O-----O-----O

"O" being particles, and "-----" being elements.


Attached Files Thumbnail(s)
   

.png   Image333333333.PNG (Size: 23.2 KB / Downloads: 56)
Reply
#10
(19-10-2021, 11:47 AM)Matbee Wrote: I got it to display several different positions for all particles, but most of the particles have the same position as in the screenshot below

Yes, those are the pooled (inactive) particles. Quoting myself:

Quote:For instance, to print the solver-space position of all particles (including inactive ones):
Code:
for (int i = 0; i < actor.solverIndices.Length; ++i)
{
Debug.Log(solver.positions[actor.solverIndices[i]]);
}

A certain amount of extra particles are preallocated when you create a rope blueprint. These are collectively referred to as the particle "pool", and start out inactive (invisible, and not used in the simulation). If you do not plan on resizing or cutting the rope at runtime, you can set the blueprint's pool size to zero. No inactive particles will be added to the rope.

The reason for preallocating particles and activating/deactivating them instead of just creating/destroying particles at runtime is -as with most pooling strategies in Unity- to avoid runtime allocation and minimize garbage collection. See:
http://obi.virtualmethodstudio.com/manua...setup.html

Quote:Pooled particles:
(Ropes only). Extra particles allocated to be used when tearing or resizing the rope. You can set this value to zero if you do not plan on tearing or resizing the rope at runtime, as no extra particles besides the initial ones will be needed.

Assuming you do have a non-empty pool, if you want to only get the active particles you should do:
Code:
for (int i = 0; i < actor.activeParticleCount; ++i)
{
Debug.Log(solver.positions[actor.solverIndices[i]]);
}
Reply