From ba9ea065e4701c823b05928e0c3269b284847388 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 8 Jan 2018 21:26:43 +0100 Subject: [PATCH] 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 #222 --- panda/src/gobj/geomVertexData.cxx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/panda/src/gobj/geomVertexData.cxx b/panda/src/gobj/geomVertexData.cxx index b692c36bf5..7d8e0e63f3 100644 --- a/panda/src/gobj/geomVertexData.cxx +++ b/panda/src/gobj/geomVertexData.cxx @@ -1836,17 +1836,21 @@ do_transform_vector_column(const GeomVertexFormat *format, GeomVertexRewriter &d bool normalize = false; if (data_column->get_contents() == C_normal) { // This is to preserve perpendicularity to the surface. - LVecBase3 scale, shear, hpr; - if (decompose_matrix(mat.get_upper_3(), scale, shear, hpr) && - IS_NEARLY_EQUAL(scale[0], scale[1]) && - IS_NEARLY_EQUAL(scale[0], scale[2])) { - if (scale[0] == 1) { + LVecBase3 scale_sq(mat.get_row3(0).length_squared(), + mat.get_row3(1).length_squared(), + mat.get_row3(2).length_squared()); + if (IS_THRESHOLD_EQUAL(scale_sq[0], scale_sq[1], 2.0e-3f) && + IS_THRESHOLD_EQUAL(scale_sq[0], scale_sq[2], 2.0e-3f)) { + // There is a uniform scale. + LVecBase3 scale, shear, hpr; + if (IS_THRESHOLD_EQUAL(scale_sq[0], 1, 2.0e-3f)) { // No scale to worry about. xform = mat; - } else { - // Simply take the uniform scale out of the transformation. Not sure - // if it might be better to just normalize? + } else if (decompose_matrix(mat.get_upper_3(), scale, shear, hpr)) { + // Make a new matrix with scale/translate taken out of the equation. compose_matrix(xform, LVecBase3(1, 1, 1), shear, hpr, LVecBase3::zero()); + } else { + normalize = true; } } else { // There is a non-uniform scale, so we need to do all this to preserve