Skip to content

Commit ba9ea06

Browse files
committed
gobj: performance improvement for CPU animation
In particular it seems that decomposition is slow, so the code to handle the transformation of the normal column now tries harder to avoid it, especially in the case of a scale of 1. Also see panda3d#222
1 parent 5831a31 commit ba9ea06

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

panda/src/gobj/geomVertexData.cxx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,17 +1836,21 @@ do_transform_vector_column(const GeomVertexFormat *format, GeomVertexRewriter &d
18361836
bool normalize = false;
18371837
if (data_column->get_contents() == C_normal) {
18381838
// This is to preserve perpendicularity to the surface.
1839-
LVecBase3 scale, shear, hpr;
1840-
if (decompose_matrix(mat.get_upper_3(), scale, shear, hpr) &&
1841-
IS_NEARLY_EQUAL(scale[0], scale[1]) &&
1842-
IS_NEARLY_EQUAL(scale[0], scale[2])) {
1843-
if (scale[0] == 1) {
1839+
LVecBase3 scale_sq(mat.get_row3(0).length_squared(),
1840+
mat.get_row3(1).length_squared(),
1841+
mat.get_row3(2).length_squared());
1842+
if (IS_THRESHOLD_EQUAL(scale_sq[0], scale_sq[1], 2.0e-3f) &&
1843+
IS_THRESHOLD_EQUAL(scale_sq[0], scale_sq[2], 2.0e-3f)) {
1844+
// There is a uniform scale.
1845+
LVecBase3 scale, shear, hpr;
1846+
if (IS_THRESHOLD_EQUAL(scale_sq[0], 1, 2.0e-3f)) {
18441847
// No scale to worry about.
18451848
xform = mat;
1846-
} else {
1847-
// Simply take the uniform scale out of the transformation. Not sure
1848-
// if it might be better to just normalize?
1849+
} else if (decompose_matrix(mat.get_upper_3(), scale, shear, hpr)) {
1850+
// Make a new matrix with scale/translate taken out of the equation.
18491851
compose_matrix(xform, LVecBase3(1, 1, 1), shear, hpr, LVecBase3::zero());
1852+
} else {
1853+
normalize = true;
18501854
}
18511855
} else {
18521856
// There is a non-uniform scale, so we need to do all this to preserve

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy