Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
22-09-2018, 02:17 PM
(This post was last modified: 22-09-2018, 02:19 PM by josemendez.)
(19-09-2018, 10:29 PM)arrnav96 Wrote: All that information is very useful, thanks. Again, my coding skills are very basic, apologies if I mixed the thread up with programming questions.
So I've been playing around with various parameters for the slime cloth and as mentioned before, I tried using height, normal and occlusion maps on materials to get the "depth" and "folds" effects.
Nothing I did could reproduce this effect.
As you can see, ignoring the colour and lighting changes, the slime shown here reforms very slowly and creates actual folds in the object. How do I create these "folds"? No amount of material modification seems to help, as what's shown here seems to be true mesh manipulation.
Next, instead of using a flat square plane mesh, I tried out using something like this -
This is a low poly "rough surface" mesh. I fixed all of it's edge particles, then initialized it as a new cloth. But instead of deforming properly on touch, it creates huge graphical glitches (Infinite stretching on mouse touch, etc).
Is there no way I can reproduce the aforementioned style of slime correctly on cloth objects? I've tried alternating everything, from damping, slack, stretch, etc. but in vain.
Use a mesh that's not a flat plane, but has some folds. The one you show here should work fine. However, make sure that your export it with unit scale. (scale = <1,1,1>). 99% of the issues I see regarding exploding cloth are because the mesh has a random scale value, and the topology has a completely different one. The easiest way to get consistent scaling from your 3D package->Unity->Obi is to just use unit scale.
Posts: 38
Threads: 8
Joined: Sep 2018
Reputation:
0
(22-09-2018, 02:17 PM)josemendez Wrote: Use a mesh that's not a flat plane, but has some folds. The one you show here should work fine. However, make sure that your export it with unit scale. (scale = <1,1,1>). 99% of the issues I see regarding exploding cloth are because the mesh has a random scale value, and the topology has a completely different one. The easiest way to get consistent scaling from your 3D package->Unity->Obi is to just use unit scale.
This seems to have solved the glitch issue! Thanks for your useful advice. I'm pretty close to finishing this.
Also, you mentioned in your previous post about using a radial function to represent a finger press. Could you shed some light on that?
Specifically, where is the part in the ObiClothPicker script which attenuates the mesh, starting from the center point of touch towards the outside? I just want to use a radial equation according to the particle's distance from the center.
If I'm majorly missing something about this code, it'd be great if there's a document explaining some method's such as what "cloth.topology.visualMap.Length" does.
Code: if (Input.GetMouseButton(0))
{
meshCollider.enabled = true;
GameObject.Destroy(currentCollisionMesh);
currentCollisionMesh = GameObject.Instantiate(cloth.clothMesh);
meshCollider.sharedMesh = currentCollisionMesh;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (meshCollider.Raycast(ray,out hitInfo,100)){
int[] tris = currentCollisionMesh.triangles;
Vector3[] vertices = currentCollisionMesh.vertices;
// find closest vertex in the triangle we just hit:
int closestVertex = -1;
float minDistance = float.MaxValue;
for (int i = 0; i < 3; ++i)
{
int vertex = tris[hitInfo.triangleIndex*3+i];
float distance = (vertices[vertex] - hitInfo.point).sqrMagnitude;
if (distance < minDistance){
minDistance = distance;
closestVertex = vertex;
}
}
// get particle index:
if (closestVertex >= 0 && closestVertex < cloth.topology.visualMap.Length){
pickedParticleIndex = cloth.topology.visualMap[closestVertex];
pickedParticleDepth = Mathf.Abs((cloth.transform.TransformPoint(vertices[closestVertex]) - Camera.main.transform.position).z);
if (OnParticlePicked != null){
Vector3 worldPosition = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, pickedParticleDepth));
OnParticlePicked(this,new ParticlePickEventArgs(pickedParticleIndex, worldPosition));
}
}
}
meshCollider.enabled = false;
}
Posts: 38
Threads: 8
Joined: Sep 2018
Reputation:
0
Posts: 7
Threads: 0
Joined: Feb 2021
Reputation:
0
(11-09-2018, 10:32 AM)josemendez Wrote: A finger is basically a circular (or ellipsoidal) shape. Using a radial support function you can displace particles to the border of the circle/ellipsoid, to make it look like the user is "pressing down" on the slime.
Keep in mind that while the user is dragging, it is very unlikely he will see what's happening under his finger. Something I'd think about would be splatting a fingerprint normalmap on top of the slime, and vanish it over time (a few seconds). This would allow the user to see his "fingerprints" for a while after raising the finger off the screen.
Using more substeps basically means re-doing the entire simulation more times per frame, including collision detection. So yes, if all you're looking for is relatively simple user interaction, substepping is complete overkill (specially for mobile)
Looking slimy, or behaving slimy?
If the first, use a shader with high smoothness/glossiness and a normal map.
If the second, increase distance constraints slack and decrease stiffness a bit. Also consider increasing the solver's "damping" for a thicker/viscous behavior. Please help me! "Using a radial support function you can displace particles to the border of the circle/ellipsoid, to make it look like the user is "pressing down" on the slime.", Could you shed some light on that?
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(26-03-2021, 10:00 AM)akayashi1212 Wrote: Please help me! "Using a radial support function you can displace particles to the border of the circle/ellipsoid, to make it look like the user is "pressing down" on the slime.", Could you shed some light on that?
It just means to use some function of the distance between the particle and the point the user is pressing. You could use a constant function (all particles within some radius of the finger), or some kind of falloff function (smooth step, gaussian, etc).
Posts: 7
Threads: 0
Joined: Feb 2021
Reputation:
0
(26-03-2021, 11:03 AM)josemendez Wrote: It just means to use some function of the distance between the particle and the point the user is pressing. You could use a constant function (all particles within some radius of the finger), or some kind of falloff function (smooth step, gaussian, etc). thanks you for reply! have any function or parameter in solver/actor to do that? can you suggest me one?
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
29-03-2021, 09:59 AM
(This post was last modified: 29-03-2021, 10:00 AM by josemendez.)
(27-03-2021, 04:24 AM)akayashi1212 Wrote: thanks you for reply! have any function or parameter in solver/actor to do that? can you suggest me one?
You have Vector3.Distance ( https://docs.unity3d.com/ScriptReference...tance.html), which will return the distance between two points.
One of the points should be your user's finger position (Input.mousePosition, or other depending on which input system you're using), and the other point should be a particle position. You can get these from Obi's particle API: http://obi.virtualmethodstudio.com/tutor...icles.html
You can then just get the distance from the user's finger to all particles, and use that as input to your support function.
Posts: 7
Threads: 0
Joined: Feb 2021
Reputation:
0
29-03-2021, 11:35 AM
(This post was last modified: 29-03-2021, 02:01 PM by akayashi1212.)
(29-03-2021, 09:59 AM)josemendez Wrote: You have Vector3.Distance (https://docs.unity3d.com/ScriptReference...tance.html), which will return the distance between two points.
One of the points should be your user's finger position (Input.mousePosition, or other depending on which input system you're using), and the other point should be a particle position. You can get these from Obi's particle API: http://obi.virtualmethodstudio.com/tutor...icles.html
You can then just get the distance from the user's finger to all particles, and use that as input to your support function. thank you! but that was not what i mean. i can get all particles i want in finger shape, but i don't know how to make it look like finger shape. when i change Y position of it, it look like video. When i use Velocity/externalForce, all of particle down. I don't want change the position of another particles i'm not select like video. And the cloth is more elastic, how to decrease it ?
video: https://www.youtube.com/watch?v=CAEbkiKxaZs
I want make it look like the video, and i know obi cloth can do it. But i don't understand Obi Cloth's API.
video: https://www.youtube.com/watch?v=c5tGB6k6240
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
31-03-2021, 10:09 AM
(This post was last modified: 31-03-2021, 10:15 AM by josemendez.)
(29-03-2021, 11:35 AM)akayashi1212 Wrote: thank you! but that was not what i mean. i can get all particles i want in finger shape, but i don't know how to make it look like finger shape. when i change Y position of it, it look like video. When i use Velocity/externalForce, all of particle down. I don't want change the position of another particles i'm not select like video.
video: https://www.youtube.com/watch?v=CAEbkiKxaZs
This isn't really related to Obi, it's basic math. If you want to have an ellipsoidal shape for the user's finger, you can use an anisotropic support function (as opposed to an isotropic one). This is just math lingo for a shape that's not radially symmetric, like a circle. So what you do is calculate the distance from the user's finger to all particles, pass the distance to your support function, and it will tell you which particles to move and how much. I can't really be more specific without writing the code for you.
(29-03-2021, 11:35 AM)akayashi1212 Wrote: And the cloth is more elastic, how to decrease it ? You can increase the cloth's compliance (expressed in meters/newton). That will make it more elastic. See:
http://obi.virtualmethodstudio.com/tutor...aints.html
(29-03-2021, 11:35 AM)akayashi1212 Wrote: I want make it look like the video, and i know obi cloth can do it. But i don't understand Obi Cloth's API.
video: https://www.youtube.com/watch?v=c5tGB6k6240
The video shows a circular shape when the user presses. This can be accomplished simply by calculating the distance from every particle to the user's finger, then moving these particles closer than a distance. All you need to do is iterate trough the solver.positions array and use Vector3.Distance with each one, should be very simple:
Code: for (int i = 0; i < cloth.solverIndices.Length; ++i)
{
int solverIndex = cloth.solverIndices[i];
float distance = Vector3.Distance(cloth.solver.positions[solverIndex], <user finger>);
//use your support function here, for instance a step function with radius 0.7:
if (distance < 0.7f)
{
// move particle
}
}
kind regards,
Posts: 7
Threads: 0
Joined: Feb 2021
Reputation:
0
31-03-2021, 02:47 PM
(This post was last modified: 31-03-2021, 03:51 PM by akayashi1212.)
(31-03-2021, 10:09 AM)josemendez Wrote: This isn't really related to Obi, it's basic math. If you want to have an ellipsoidal shape for the user's finger, you can use an anisotropic support function (as opposed to an isotropic one). This is just math lingo for a shape that's not radially symmetric, like a circle. So what you do is calculate the distance from the user's finger to all particles, pass the distance to your support function, and it will tell you which particles to move and how much. I can't really be more specific without writing the code for you.
You can increase the cloth's compliance (expressed in meters/newton). That will make it more elastic. See:
http://obi.virtualmethodstudio.com/tutor...aints.html
The video shows a circular shape when the user presses. This can be accomplished simply by calculating the distance from every particle to the user's finger, then moving these particles closer than a distance. All you need to do is iterate trough the solver.positions array and use Vector3.Distance with each one, should be very simple:
Code: for (int i = 0; i < cloth.solverIndices.Length; ++i)
{
int solverIndex = cloth.solverIndices[i];
float distance = Vector3.Distance(cloth.solver.positions[solverIndex], <user finger>);
//use your support function here, for instance a step function with radius 0.7:
if (distance < 0.7f)
{
// move particle
}
}
kind regards,
Thank you very much for detailed reponse! But again, i mean i stuck at "move particle", not at select particle. i've tried move down the particle by change Y position like this code: " solver.positions[solverIndex] = new vector4(solver.positions[solverIndex][0], -2f,solver.positions[solverIndex][2],solver.positions[solverIndex][3])" and it very glitchy like the video. when i change particle velocity or externalForce, all particle in cloth move down too @@. Now i'm thinking about move particle to around finger shape ( by X and Z position) instead of move below finger shape ( Y position). Then, all i want to ask is: have any functions/parameters in Obi's API support me do it? thank you again for the best support ^^.
|