Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  create Obi handle on script at runtime
#1
Can I create obi handle by script at runtime ?
I want to pick up particles by script, not by editor. I saw script of ObiClothParticleHandles, and I thought I can do that.
If yes, I want you to teach me how to do that.
#2
(23-05-2019, 10:42 AM)Richard Wrote: Can I create obi handle by script at runtime ?
I want to pick up particles by script, not by editor. I saw script of ObiClothParticleHandles, and I thought I can do that.
If yes, I want you to teach me how to do that.

Hi Richard,

Handles have a very simple API: you can add particle indices to them, or remove particle indices from them. That's pretty much it:
http://obi.virtualmethodstudio.com/api.html

For instance, to create a handle that fixes the position of the first two particles in a cloth:

Code:
// Create a new game object and add the handle component:
GameObject obj = new GameObject("Obi Handle");
ObiParticleHandle handle = obj.AddComponent<ObiParticleHandle>();

// Add the first two particles to it:
handle.AddParticle(i, actor.GetParticlePosition(0),Quaternion.identity,actor.invMasses[0],0);
handle.AddParticle(i, actor.GetParticlePosition(1),Quaternion.identity,actor.invMasses[1],0);
#3
(23-05-2019, 02:59 PM)josemendez Wrote: Hi Richard,

Handles have a very simple API: you can add particle indices to them, or remove particle indices from them. That's pretty much it:
http://obi.virtualmethodstudio.com/api.html

For instance, to create a handle that fixes the position of the first two particles in a cloth:

Code:
// Create a new game object and add the handle component:
GameObject obj = new GameObject("Obi Handle");
ObiParticleHandle handle = obj.AddComponent<ObiParticleHandle>();

// Add the first two particles to it:
handle.AddParticle(i, actor.GetParticlePosition(0),Quaternion.identity,actor.invMasses[0],0);
handle.AddParticle(i, actor.GetParticlePosition(1),Quaternion.identity,actor.invMasses[1],0);

I checked API, but how can I choose particle like
float left = Mathf.Min(startPos.x,currentPos.x);
float right = Mathf.Max(startPos.x,currentPos.x);
float bottom = Mathf.Min(startPos.y,currentPos.y);
float top = Mathf.Max(startPos.y,currentPos.y);
of "ObiClothParticleEditor" on script by assigning number?
#4
(24-05-2019, 07:32 AM)Richard Wrote: I checked API, but how can I choose particle like
float left = Mathf.Min(startPos.x,currentPos.x);
float right = Mathf.Max(startPos.x,currentPos.x);
float bottom = Mathf.Min(startPos.y,currentPos.y);
float top = Mathf.Max(startPos.y,currentPos.y);
of "ObiClothParticleEditor" on script by assigning number?

Hi,

Sorry, I don't understand your question. What does Mathf.Min/Max have to do with handles?
#5
(24-05-2019, 07:34 AM)josemendez Wrote: Hi,

Sorry, I don't understand your question. What does Mathf.Min/Max have to do with handles?

Sorry for my English, I mean I want to choose particle like when we choose particle on "Edit particle" of obi cloth or obi tearable cloth. and create obi handles. When I choose the particle, I want to choose particle like by those(Mathf.Min/Max) on script "ObiClothParticleHandles".
#6
(24-05-2019, 09:03 AM)Richard Wrote: Sorry for my English, I mean I want to choose particle like when we choose particle on "Edit particle" of obi cloth or obi tearable cloth. and create obi handles. When I choose the particle, I want to choose particle like by those(Mathf.Min/Max) on script "ObiClothParticleHandles".

Sorry but I still cannot figure out what you want.

"Edit particle" allows you to choose particles using a editor tool. You cannot use this at runtime.

Code:
float left = Mathf.Min(startPos.x,currentPos.x);
float right = Mathf.Max(startPos.x,currentPos.x);
float bottom = Mathf.Min(startPos.y,currentPos.y);
float top = Mathf.Max(startPos.y,currentPos.y);

This code is used in a editor handle script, not to be confused with runtime particle handles. They're not the same. This is part of a UI tool, used to determine which particles will be selected/unselected when the user is dragging a selection box. It does not have anything to do with the particle simulation.

I think you want to create a runtime selection marquee tool, is that it?
#7
(24-05-2019, 09:40 AM)josemendez Wrote: Sorry but I still cannot figure out what you want.

"Edit particle" allows you to choose particles using a editor tool. You cannot use this at runtime.

Code:
float left = Mathf.Min(startPos.x,currentPos.x);
float right = Mathf.Max(startPos.x,currentPos.x);
float bottom = Mathf.Min(startPos.y,currentPos.y);
float top = Mathf.Max(startPos.y,currentPos.y);

This code is used in a editor handle script, not to be confused with runtime particle handles. They're not the same. This is part of a UI tool, used to determine which particles will be selected/unselected when the user is dragging a selection box. It does not have anything to do with the particle simulation.

I think you want to create a runtime selection marquee tool, is that it?

Sorry...  That's it. I want to create that. Can I choose particle on script by marquee tool?
#8
(24-05-2019, 10:46 AM)Richard Wrote: Sorry...  That's it. I want to create that. Can I choose particle on script by marquee tool?

Implementing a marquee selection tool has very little to do with Obi. It mainly involves Unity GUI/events, so it's unfortunately out of the scope of Obi support.

Once you have a screen-space marquee rectangle working (all the clicking/dragging logic in place, as well as UI drawing) you can simply iterate trough all particles getting their world space position and projecting it to screen space to see it they're within the marquee.

Code:
for (int i = 0; i < actor.particleIndices.Length; ++i){
Vector3 wsPos = actor.GetParticlePosition(i);

//TODO: convert wsPos to screen space, and check if the coordinates are within the marquee.
}

I'd suggest taking a look at some Unity GUI tutorials, or browse the Unity forums for ready-made stuff:
https://forum.unity.com/threads/rts-styl...ox.265739/
https://www.habrador.com/tutorials/selec...rectangle/
#9
(24-05-2019, 02:27 PM)josemendez Wrote: Implementing a marquee selection tool has very little to do with Obi. It mainly involves Unity GUI/events, so it's unfortunately out of the scope of Obi support.

Once you have a screen-space marquee rectangle working (all the clicking/dragging logic in place, as well as UI drawing) you can simply iterate trough all particles getting their world space position and projecting it to screen space to see it they're within the marquee.

Code:
for (int i = 0; i < actor.particleIndices.Length; ++i){
Vector3 wsPos = actor.GetParticlePosition(i);

//TODO: convert wsPos to screen space, and check if the coordinates are within the marquee.
}

I'd suggest taking a look at some Unity GUI tutorials, or browse the Unity forums for ready-made stuff:
https://forum.unity.com/threads/rts-styl...ox.265739/
https://www.habrador.com/tutorials/selec...rectangle/

Can I implement such marquee tool without combining with Edit Particle of Obi cloth or Obi tearable cloth? If I should, how can I connect marquee tool made by myself to obi cloth editor?
#10
(24-05-2019, 03:03 PM)Richard Wrote: Can I implement such marquee tool without combining with Edit Particle of Obi cloth or Obi tearable cloth? If I should, how can I connect marquee tool made by myself to obi cloth editor?

Hi,

In Unity, implementing things for the editor and for runtime (play mode) is often radically different. The editor uses immediate mode GUI, while at runtime you generally use Unity's UI system. Both work in completely different ways, so yes you can implement marquee selection for either purpose. You don't have to use the one implemented in edit particle mode. I already gave you two links with examples, both implement marquee selection tools in different ways and none of them needs Obi.

So you need to think about whether you want to implement this for an editor tool, or for a game/application. It is not entirely clear to me what you're after.