Obi Official Forum
Help Turning cloth object into a perfect static rectangle - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Cloth (https://obi.virtualmethodstudio.com/forum/forum-2.html)
+--- Thread: Help Turning cloth object into a perfect static rectangle (/thread-3490.html)



Turning cloth object into a perfect static rectangle - KaanOzcelik - 17-06-2022

I need to turn my cloth object into a regular rectangle shape, much like a plane. I don't want to destroy the cloth and instantiate a new object in its place to do this. How can I do it?


RE: Turning cloth object into a perfect static rectangle - josemendez - 17-06-2022

(17-06-2022, 10:36 AM)KaanOzcelik Wrote: I need to turn my cloth object into a regular rectangle shape, much like a plane.

Hi,

What do you mean exactly by a "regular" rectangle shape? A simple static mesh?

You can access the current shape of the cloth mesh from the cloth renderer:

Code:
var mesh = cloth.GetComponent<ObiClothRenderer>().clothMesh;
Then you can do anything you want with it, as an example: instantiate it and assign it to another object's MeshFilter component.

(17-06-2022, 10:36 AM)KaanOzcelik Wrote: I don't want to destroy the cloth and instantiate a new object in its place to do this. How can I do it?

You can't convert an object into some other type magically (this applies to programming in general). Best you can do if both types have the same size in memory, is reinterpret that memory.

More specifically, components in Unity cannot be "converted" into one another. A cloth component is a cloth component, very much like a rigidbody is a rigidbody. You can't turn a rigidbody into cloth, or a cloth into a static mesh, except by destroying one and creating the other. So you can't "turn" an object into a different object: you destroy the old one and instantiate the new one.


RE: Turning cloth object into a perfect static rectangle - KaanOzcelik - 17-06-2022

Quote:josemendez
What do you mean exactly by a "regular" rectangle shape? A simple static mesh? 

Not exactly. I want to disable the simulation entirely and return the mesh back to its original shape, the shape it had before the simulation have started.


Quote:josemendez
You can't convert an object into some other type magically (this applies to programming in general). Best you can do if both types have the same size in memory, is reinterpret that memory.


More specifically, components in Unity cannot be "converted" into one another. A cloth component is a cloth component, very much like a rigidbody is a rigidbody. You can't turn a rigidbody into cloth, or a cloth into a static mesh, except by destroying one and creating the other. So you can't "turn" an object into a different object: you destroy the old one and instantiate the new one.




Yes, I am aware of this. I wondered if I could make the actor so stiff using the obi cloth parameters that it almost resembled a static, straight, primitive rectangle. Seems like I will have to move predefined groups into desired positions and then instantiate a primitive rectangle in the position, and then destroy the actor.

Thanks for the quick reply tho!  Corazón


RE: Turning cloth object into a perfect static rectangle - josemendez - 17-06-2022

(17-06-2022, 11:42 AM)KaanOzcelik Wrote: Yes, I am aware of this. I wondered if I could make the actor so stiff using the obi cloth parameters that it almost resembled a static, straight, primitive rectangle. Seems like I will have to move predefined groups into desired positions and then instantiate a primitive rectangle in the position, and then destroy the actor.


You can make cloth arbitrarily stiff by setting its max bending setting to 0 and then using a very small timestep (like you can with any physical simulation of any kind), however this increases the cost of the simulation a lot. I don't recommend doing that. Replacing the cloth by a primitive rectangle or any other static mesh has no cost at all and will look better.

(17-06-2022, 11:42 AM)KaanOzcelik Wrote: Thanks for the quick reply tho!  Corazón


You're welcome! Sonrisa