The size of "area" is the same after scaling
#1
HI,Tyson!

There is a problem, a box. I separate it into six faces. After I scale the z-axis direction, the area (volume) of the face is the same. Is this problem normal?


Attached Files Thumbnail(s)
   
  Reply
#2
So this could be considered a bug, yes, but it's due to the way I calculate surface areas....I use a cheat that multiplies the local-space surface area of a mesh by the square of the length of the particle's scale. This provides a scale-relative approximation of surface area that doesn't require a recalculation of the value each time the particle's scale changes...but as you see in your example it can lead to some inconsistencies and isn't a good method if you need an exact surface area reading.

The reason for the cheat is that it makes it a lot faster to get the surface area of a lot of differently-scaled particles. For example: if I have a million particles sharing the same mesh, but each with a different non-uniform scale, I would have to do a million different surface area calculations to get a reading for all of them (and that involves iterating all their faces, which is slow). But using my method, I only need to calculate surface area once, and then quickly do the scale-multiplication cheat to get a rough idea of the surface area of each one. Since usually surface area is used to simply compare sizes of particles, this is enough....but as you can see in your example, it doesn't provide an exact value and when you scale flat surfaces along the z-axis, the returned value can be quite inaccurate. So there's a trade-off of speed vs accuracy, and in tyFlow's case I've chosen speed.
  Reply
#3
Yes, I see. Thank you
I hope you have better inspiration in the future.

I was just thinking about how to solve it. Is there an option to reset these scaled particles, similar to "reset Xform" in max
  Reply
#4
No, there's no resetxform in tyFlow currently.

If you require an accurate readout, you can calculate the surface area using the Script operator manually...it's a fairly simple process.

Triangle area is half the length of the cross product of the two vectors formed by the triangle's vertices. Then you just add up the area of all the triangles and you have the surface area. If doing it with the mesh operator, make sure to multiply the vertex positions by the particle's transform...that's how you convert them from local space into world space. Here's a script that calculates the surface area of all particles in the event and puts it into an "area" custom float property.

Code:
public void simulationStep()
{    
    
    for (int i = 0; i < eventParticleCount; i++)             
    {
        int sInx = tf.GetSimIndex(i);

        var mesh = tf.GetMesh(sInx);
        var tm = tf.GetTM(sInx);
        float surfaceArea = 0;
        
        for (int q = 0; q < mesh.GetNumFaces(); q++)
        {
            var face = mesh.GetFace(q);
            var v1 = (mesh.GetVert(face.v1) * tm) - (mesh.GetVert(face.v2) * tm);
            var v2 = (mesh.GetVert(face.v3) * tm) - (mesh.GetVert(face.v2) * tm);            
            float faceArea = (Cross(v1, v2)).magnitude * 0.5f;            
            surfaceArea += faceArea;
        }
        
        tf.SetCustomFloat(sInx, "area", surfaceArea);
    }    
}
  Reply
#5
Thank you. I'll study it
  Reply


Forum Jump: