solving x*V1 + y*V2 = V3

Started by
13 comments, last by Max Power 5 years, 6 months ago
4 hours ago, Max Power said:

VertMorphInfo[v].Height = (Pos - p1).ProjectOnTo(Normal).Size();

Is Size() really the length, or the size of a vector (so always 3 elements)? 'Size' is really a confusing term for magnitude.

Other than that you code looks right to me. Maybe a indexing bug. But first i would debug my code snippets if thy return the same point after both conversions. I'm not really sure they work - can't rmemeber for what purpose i've used it.

 

9 hours ago, Max Power said:

One thing though: does "p" have to be on the triangle plane or can it be anywhere?

Can be anywhere.

Advertisement

Yes, it's called size in UE4 for whatever reason. I forgot to mention that, apparently, locations differ even when the body hasn't been morphed at all and is identical to the initial reference body. Well, if there's nothing wrong with the code I posted, I'm gonna have some debugging to do ...

If I have the same 3 triangle vertex positions and a vector I want to save the barymetric coordinates for, shouldn't I get the original vector back like this:

BC = ToBarycentricCoords3D(p1, p2, p3, Vec);

Vec = FromBarycentricCoords(p1, p2, p3, BC);

???

Because I'm getting different values every time. Am I missing something here? I checked the vertex positions and it's not an index problem - they match.

I'll check my functions myself...

... seems i have a bug. Go to fix it...

Ok - sorry, but my snippets did not agree upon conventions. Here is one way to fix it:


inline vec ToBarycentricCoords3D (vec a, vec b, vec c, vec p)
	{
		vec v0 = b - a, 
			v1 = c - a, 
			v2 = p - a;
		float d00 = v0.Dot(v0);
		float d01 = v0.Dot(v1);
		float d11 = v1.Dot(v1);
		float d20 = v2.Dot(v0);
		float d21 = v2.Dot(v1);
		float denom = d00 * d11 - d01 * d01;
		vec bc;
		//bc[0] = (d11 * d20 - d01 * d21) / denom;
		//bc[1] = (d00 * d21 - d01 * d20) / denom;
		//bc[2] = (1.0f - bc[0] - bc[1]);				
		bc[1] = (d11 * d20 - d01 * d21) / denom;
		bc[2] = (d00 * d21 - d01 * d20) / denom;
		bc[0] = 1.0f - bc[1] - bc[2];
		return bc;
	}

	inline vec FromBarycentricCoords (vec a, vec b, vec c, vec bc)
	{
		return bc[0] * (a - c) + bc[1] * (b - c) + c;
	}

I'll need to check why my stuff worked anyways... :)

Sorry again!

So, your idea is to constrain cloth particels with a max distance constraint to the closest position on triangle in rest pose, and also to the outside of the triangle plane if i get you right.

I think i've tried something similar too, and it did not work well. I ended up with using capsules at each skin vertex aligned to the vertex normal.

The capsules are scaled along the normal, so the round part gets more flat to approximate skin curvature better. And the capsules go deep into the skin, so penetrations can be resolved more robustly. This works very well, even for very tight cloth, but i also allowed to slide over neighboring vertices. Performance was good.

However, maybe you could use a sphere instead the plane constraint. Should be much better already, faster than my approach and maybe good enough.

Np, I appreciate it! Looks almost good now :)

25 minutes ago, JoeJ said:

So, your idea is to constrain cloth particels with a max distance constraint to the closest position on triangle in rest pose, and also to the outside of the triangle plane if i get you right.

I think i've tried something similar too, and it did not work well. I ended up with using capsules at each skin vertex aligned to the vertex normal.

The capsules are scaled along the normal, so the round part gets more flat to approximate skin curvature better. And the capsules go deep into the skin, so penetrations can be resolved more robustly. This works very well, even for very tight cloth, but i also allowed to slide over neighboring vertices. Performance was good.

However, maybe you could use a sphere instead the plane constraint. Should be much better already, faster than my approach and maybe good enough.

Well, thanks for the advice. First I'm gonna see how it looks, then I may look into that.

This topic is closed to new replies.

Advertisement