Img3D: fix deformation of meshes that are using dynamic scale factor
Context
The current 3D particle system relies on three primary parameters to define mesh position, scale, and rotation: turn, scale, and offset. These are initialized in mesh constructors, such as BarGauss, which calculates specific values to align the geometry (e.g., applying a 45-degree rotation and compensating with a sqrt2 scaling factor):
BarGauss::BarGauss(float L, float W, float H)
: PlotParticle(Key(BaseShape::Column, 1.0f, 4))
{
isNull = (L < 0 || W < 0 || H < 0) || (L <= 0 && W <= 0 && H <= 0);
turn = F3(0, 0, 45 * pi / 180.0f);
scale = F3(L * sqrt2f, W * sqrt2f, H);
offset = F3(0, 0, 0);
set();
}
Currently, dynamic scaling logic is handled externally in Particle.cpp, which modifies these parameters during runtime.
While important define these parameters to make sure your mesh is in correct position, scale and rotation. Using dynamic scaling can introduce issue of Stretching.
Examples of Problematic Behavior
Expected Behavior:
When rendering a Pyramid2 mesh with dimensions Length: 100, Width: 16, Height: 16, and Alpha: 80, the mesh should maintain its correct aspect ratio and geometric integrity. For example, when using the fixed, pre-calculated scale from the constructor (e.g., scale = (sqrt2, sqrt2, sqrt2)), the mesh renders with correct proportions.
Problematic/Observed Behavior:
When the same Pyramid2 mesh uses dynamic scaling (currently located in Particle.cpp), the mesh becomes distorted. Instead of maintaining the correct proportions defined in the constructor, the dynamic scaling introduces unwanted stretching artifacts, deforming the visual output of the particle.
Cause of the Bug:
The issue arises because this kind of scaling in Particle.cpp
BarGauss::BarGauss(float L, float W, float H)
: PlotParticle(Key(BaseShape::Column, 1.0f, 4))
{
isNull = (L < 0 || W < 0 || H < 0) || (L <= 0 && W <= 0 && H <= 0);
turn = F3(0, 0, 45 * pi / 180.0f);
scale = F3(L * sqrt2f, W * sqrt2f, H); <==== This line here
offset = F3(0, 0, 0);
set();
}
when it is generically applied to all particles. It does not account for the specific geometric composition defined in the specific mesh constructors like BarGauss. Therefore this introduces stretching.
Possible Solutions
Refactor and modify the Particle.cpp and Geometry.cpp to move dynamic scaling logic out of the generic Particle.cpp and into mesh-specific functions. This will allow each shape to define exactly how the scaling would affect its shape.
Important: I already tested this solution and it works. Please see Merge request !3433 to identify how this was achieved.

