Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Turning cloth object into a perfect static rectangle
#1
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?
Reply
#2
(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.
Reply
#3
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
Reply
#4
(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
Reply