diff options
Diffstat (limited to 'indra/llmath')
-rw-r--r-- | indra/llmath/CMakeLists.txt | 4 | ||||
-rw-r--r-- | indra/llmath/llcalc.cpp | 25 | ||||
-rw-r--r-- | indra/llmath/llcalc.h | 23 | ||||
-rw-r--r-- | indra/llmath/llcalcparser.cpp | 23 | ||||
-rw-r--r-- | indra/llmath/llcalcparser.h | 23 | ||||
-rw-r--r-- | indra/llmath/llmath.h | 7 | ||||
-rw-r--r-- | indra/llmath/lloctree.h | 2 | ||||
-rw-r--r-- | indra/llmath/llv4math.h | 141 | ||||
-rw-r--r-- | indra/llmath/llv4matrix3.h | 220 | ||||
-rw-r--r-- | indra/llmath/llv4matrix4.h | 249 | ||||
-rw-r--r-- | indra/llmath/llv4vector3.h | 80 | ||||
-rw-r--r-- | indra/llmath/llvolume.cpp | 291 | ||||
-rw-r--r-- | indra/llmath/llvolume.h | 8 | ||||
-rw-r--r-- | indra/llmath/tests/v3math_test.cpp | 18 |
14 files changed, 231 insertions, 883 deletions
diff --git a/indra/llmath/CMakeLists.txt b/indra/llmath/CMakeLists.txt index cd100cdf9f..b5e59c1ca3 100644 --- a/indra/llmath/CMakeLists.txt +++ b/indra/llmath/CMakeLists.txt @@ -75,10 +75,6 @@ set(llmath_HEADER_FILES llvector4a.h llvector4a.inl llvector4logical.h - llv4math.h - llv4matrix3.h - llv4matrix4.h - llv4vector3.h llvolume.h llvolumemgr.h llvolumeoctree.h diff --git a/indra/llmath/llcalc.cpp b/indra/llmath/llcalc.cpp index 597d0815fb..1b2d609b67 100644 --- a/indra/llmath/llcalc.cpp +++ b/indra/llmath/llcalc.cpp @@ -1,9 +1,26 @@ /* * LLCalc.cpp - * SecondLife - * - * Created by Aimee Walton on 28/09/2008. - * Copyright 2008 Aimee Walton. + * Copyright 2008 Aimee Walton. + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2008, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ * */ diff --git a/indra/llmath/llcalc.h b/indra/llmath/llcalc.h index cc31950cb6..ceb9dce585 100644 --- a/indra/llmath/llcalc.h +++ b/indra/llmath/llcalc.h @@ -1,9 +1,26 @@ /* * LLCalc.h - * SecondLife - * - * Created by Aimee Walton on 28/09/2008. * Copyright 2008 Aimee Walton. + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2008, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ * */ diff --git a/indra/llmath/llcalcparser.cpp b/indra/llmath/llcalcparser.cpp index fd55376fa9..b4ca320659 100644 --- a/indra/llmath/llcalcparser.cpp +++ b/indra/llmath/llcalcparser.cpp @@ -1,9 +1,26 @@ /* * LLCalcParser.cpp - * SecondLife - * - * Created by Aimee Walton on 28/09/2008. * Copyright 2008 Aimee Walton. + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2008, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ * */ diff --git a/indra/llmath/llcalcparser.h b/indra/llmath/llcalcparser.h index 600e173661..bd9c8c2519 100644 --- a/indra/llmath/llcalcparser.h +++ b/indra/llmath/llcalcparser.h @@ -1,9 +1,26 @@ /* * LLCalcParser.h - * SecondLife - * - * Created by Aimee Walton on 28/09/2008. * Copyright 2008 Aimee Walton. + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2008, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ * */ diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index eea7c977fb..9297bcbac2 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -510,6 +510,13 @@ inline void ll_remove_outliers(std::vector<VEC_TYPE>& data, F32 k) VEC_TYPE Q1 = data[data.size()/4]; VEC_TYPE Q3 = data[data.size()-data.size()/4-1]; + if ((F32)(Q3-Q1) < 1.f) + { + // not enough variation to detect outliers + return; + } + + VEC_TYPE min = (VEC_TYPE) ((F32) Q1-k * (F32) (Q3-Q1)); VEC_TYPE max = (VEC_TYPE) ((F32) Q3+k * (F32) (Q3-Q1)); diff --git a/indra/llmath/lloctree.h b/indra/llmath/lloctree.h index e5ca47da69..3c1ae45d68 100644 --- a/indra/llmath/lloctree.h +++ b/indra/llmath/lloctree.h @@ -681,7 +681,7 @@ public: if (lt != 0x7) { - OCT_ERRS << "!!! ELEMENT EXCEEDS RANGE OF SPATIAL PARTITION !!!" << llendl; + //OCT_ERRS << "!!! ELEMENT EXCEEDS RANGE OF SPATIAL PARTITION !!!" << llendl; return false; } diff --git a/indra/llmath/llv4math.h b/indra/llmath/llv4math.h deleted file mode 100644 index 5f403ba526..0000000000 --- a/indra/llmath/llv4math.h +++ /dev/null @@ -1,141 +0,0 @@ -/** - * @file llv4math.h - * @brief LLV4* class header file - vector processor enabled math - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLV4MATH_H -#define LL_LLV4MATH_H - -// *NOTE: We do not support SSE acceleration on Windows builds. -// Our minimum specification for the viewer includes 1 GHz Athlon processors, -// which covers the Athlon Thunderbird series that does not support SSE. -// -// Our header files include statements like this -// const F32 HAVOK_TIMESTEP = 1.f / 45.f; -// This creates "globals" that are included in each .obj file. If a single -// .cpp file has SSE code generation turned on (eg, llviewerjointmesh_sse.cpp) -// these globals will be initialized using SSE instructions. This causes SL -// to crash before main() on processors without SSE. Untangling all these -// headers/variables is too much work for the small performance gains of -// vectorization. -// -// Therefore we only support vectorization on builds where the everything is -// built with SSE or Altivec. See https://jira.secondlife.com/browse/VWR-1610 -// and https://jira.lindenlab.com/browse/SL-47720 for details. -// -// Sorry the code is such a mess. JC - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4MATH - GNUC -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -#if LL_GNUC && __GNUC__ >= 4 && __SSE__ - -#define LL_VECTORIZE 1 - -#if LL_DARWIN - -#include <Accelerate/Accelerate.h> -#include <xmmintrin.h> -typedef vFloat V4F32; - -#else - -#include <xmmintrin.h> -typedef float V4F32 __attribute__((vector_size(16))); - -#endif - -#endif -#if LL_GNUC - -#define LL_LLV4MATH_ALIGN_PREFIX -#define LL_LLV4MATH_ALIGN_POSTFIX __attribute__((aligned(16))) - -#endif - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4MATH - MSVC -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -// Only vectorize if the entire Windows build uses SSE. -// _M_IX86_FP is set when SSE code generation is turned on, and I have -// confirmed this in VS2003, VS2003 SP1, and VS2005. JC -#if LL_MSVC && _M_IX86_FP - -#define LL_VECTORIZE 1 - -#include <xmmintrin.h> - -typedef __m128 V4F32; - -#endif -#if LL_MSVC - -#define LL_LLV4MATH_ALIGN_PREFIX __declspec(align(16)) -#define LL_LLV4MATH_ALIGN_POSTFIX - -#endif - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4MATH - default - no vectorization -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -#if !LL_VECTORIZE - -#define LL_VECTORIZE 0 - -struct V4F32 { F32 __pad__[4]; }; - -inline F32 llv4lerp(F32 a, F32 b, F32 w) { return ( b - a ) * w + a; } - -#endif - -#ifndef LL_LLV4MATH_ALIGN_PREFIX -# define LL_LLV4MATH_ALIGN_PREFIX -#endif -#ifndef LL_LLV4MATH_ALIGN_POSTFIX -# define LL_LLV4MATH_ALIGN_POSTFIX -#endif - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4MATH -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - - -#define LLV4_NUM_AXIS 4 - -class LLV4Vector3; -class LLV4Matrix3; -class LLV4Matrix4; - -#endif diff --git a/indra/llmath/llv4matrix3.h b/indra/llmath/llv4matrix3.h deleted file mode 100644 index 270f5d7dae..0000000000 --- a/indra/llmath/llv4matrix3.h +++ /dev/null @@ -1,220 +0,0 @@ -/** - * @file llviewerjointmesh.cpp - * @brief LLV4* class header file - vector processor enabled math - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLV4MATRIX3_H -#define LL_LLV4MATRIX3_H - -#include "llv4math.h" -#include "llv4vector3.h" -#include "m3math.h" // for operator LLMatrix3() - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4Matrix3 -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -LL_LLV4MATH_ALIGN_PREFIX - -class LLV4Matrix3 -{ -public: - union { - F32 mMatrix[LLV4_NUM_AXIS][LLV4_NUM_AXIS]; - V4F32 mV[LLV4_NUM_AXIS]; - }; - - void lerp(const LLV4Matrix3 &a, const LLV4Matrix3 &b, const F32 &w); - void multiply(const LLVector3 &a, LLVector3& out) const; - void multiply(const LLVector4 &a, LLV4Vector3& out) const; - void multiply(const LLVector3 &a, LLV4Vector3& out) const; - - const LLV4Matrix3& transpose(); - const LLV4Matrix3& operator=(const LLMatrix3& a); - - operator LLMatrix3() const { return (reinterpret_cast<const LLMatrix4*>(const_cast<const F32*>(&mMatrix[0][0])))->getMat3(); } - - friend LLVector3 operator*(const LLVector3& a, const LLV4Matrix3& b); -} - -LL_LLV4MATH_ALIGN_POSTFIX; - - - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4Matrix3 - SSE -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -#if LL_VECTORIZE - -inline void LLV4Matrix3::lerp(const LLV4Matrix3 &a, const LLV4Matrix3 &b, const F32 &w) -{ - __m128 vw = _mm_set1_ps(w); - mV[VX] = _mm_add_ps(_mm_mul_ps(_mm_sub_ps(b.mV[VX], a.mV[VX]), vw), a.mV[VX]); // ( b - a ) * w + a - mV[VY] = _mm_add_ps(_mm_mul_ps(_mm_sub_ps(b.mV[VY], a.mV[VY]), vw), a.mV[VY]); - mV[VZ] = _mm_add_ps(_mm_mul_ps(_mm_sub_ps(b.mV[VZ], a.mV[VZ]), vw), a.mV[VZ]); -} - -inline void LLV4Matrix3::multiply(const LLVector3 &a, LLVector3& o) const -{ - LLV4Vector3 j; - j.v = _mm_mul_ps(_mm_set1_ps(a.mV[VX]), mV[VX]); // ( ax * vx ) + ... - j.v = _mm_add_ps(j.v , _mm_mul_ps(_mm_set1_ps(a.mV[VY]), mV[VY])); - j.v = _mm_add_ps(j.v , _mm_mul_ps(_mm_set1_ps(a.mV[VZ]), mV[VZ])); - o.setVec(j.mV); -} - -inline void LLV4Matrix3::multiply(const LLVector4 &a, LLV4Vector3& o) const -{ - o.v = _mm_mul_ps(_mm_set1_ps(a.mV[VX]), mV[VX]); // ( ax * vx ) + ... - o.v = _mm_add_ps(o.v , _mm_mul_ps(_mm_set1_ps(a.mV[VY]), mV[VY])); - o.v = _mm_add_ps(o.v , _mm_mul_ps(_mm_set1_ps(a.mV[VZ]), mV[VZ])); -} - -inline void LLV4Matrix3::multiply(const LLVector3 &a, LLV4Vector3& o) const -{ - o.v = _mm_mul_ps(_mm_set1_ps(a.mV[VX]), mV[VX]); // ( ax * vx ) + ... - o.v = _mm_add_ps(o.v , _mm_mul_ps(_mm_set1_ps(a.mV[VY]), mV[VY])); - o.v = _mm_add_ps(o.v , _mm_mul_ps(_mm_set1_ps(a.mV[VZ]), mV[VZ])); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4Matrix3 -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -#else - -inline void LLV4Matrix3::lerp(const LLV4Matrix3 &a, const LLV4Matrix3 &b, const F32 &w) -{ - mMatrix[VX][VX] = llv4lerp(a.mMatrix[VX][VX], b.mMatrix[VX][VX], w); - mMatrix[VX][VY] = llv4lerp(a.mMatrix[VX][VY], b.mMatrix[VX][VY], w); - mMatrix[VX][VZ] = llv4lerp(a.mMatrix[VX][VZ], b.mMatrix[VX][VZ], w); - - mMatrix[VY][VX] = llv4lerp(a.mMatrix[VY][VX], b.mMatrix[VY][VX], w); - mMatrix[VY][VY] = llv4lerp(a.mMatrix[VY][VY], b.mMatrix[VY][VY], w); - mMatrix[VY][VZ] = llv4lerp(a.mMatrix[VY][VZ], b.mMatrix[VY][VZ], w); - - mMatrix[VZ][VX] = llv4lerp(a.mMatrix[VZ][VX], b.mMatrix[VZ][VX], w); - mMatrix[VZ][VY] = llv4lerp(a.mMatrix[VZ][VY], b.mMatrix[VZ][VY], w); - mMatrix[VZ][VZ] = llv4lerp(a.mMatrix[VZ][VZ], b.mMatrix[VZ][VZ], w); -} - -inline void LLV4Matrix3::multiply(const LLVector3 &a, LLVector3& o) const -{ - o.setVec( a.mV[VX] * mMatrix[VX][VX] + - a.mV[VY] * mMatrix[VY][VX] + - a.mV[VZ] * mMatrix[VZ][VX], - - a.mV[VX] * mMatrix[VX][VY] + - a.mV[VY] * mMatrix[VY][VY] + - a.mV[VZ] * mMatrix[VZ][VY], - - a.mV[VX] * mMatrix[VX][VZ] + - a.mV[VY] * mMatrix[VY][VZ] + - a.mV[VZ] * mMatrix[VZ][VZ]); -} - -inline void LLV4Matrix3::multiply(const LLVector4 &a, LLV4Vector3& o) const -{ - o.setVec( a.mV[VX] * mMatrix[VX][VX] + - a.mV[VY] * mMatrix[VY][VX] + - a.mV[VZ] * mMatrix[VZ][VX], - - a.mV[VX] * mMatrix[VX][VY] + - a.mV[VY] * mMatrix[VY][VY] + - a.mV[VZ] * mMatrix[VZ][VY], - - a.mV[VX] * mMatrix[VX][VZ] + - a.mV[VY] * mMatrix[VY][VZ] + - a.mV[VZ] * mMatrix[VZ][VZ]); -} - -inline void LLV4Matrix3::multiply(const LLVector3 &a, LLV4Vector3& o) const -{ - o.setVec( a.mV[VX] * mMatrix[VX][VX] + - a.mV[VY] * mMatrix[VY][VX] + - a.mV[VZ] * mMatrix[VZ][VX], - - a.mV[VX] * mMatrix[VX][VY] + - a.mV[VY] * mMatrix[VY][VY] + - a.mV[VZ] * mMatrix[VZ][VY], - - a.mV[VX] * mMatrix[VX][VZ] + - a.mV[VY] * mMatrix[VY][VZ] + - a.mV[VZ] * mMatrix[VZ][VZ]); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4Matrix3 -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -#endif - -inline const LLV4Matrix3& LLV4Matrix3::transpose() -{ -#if LL_VECTORIZE && defined(_MM_TRANSPOSE4_PS) - _MM_TRANSPOSE4_PS(mV[VX], mV[VY], mV[VZ], mV[VW]); - return *this; -#else - F32 temp; - temp = mMatrix[VX][VY]; mMatrix[VX][VY] = mMatrix[VY][VX]; mMatrix[VY][VX] = temp; - temp = mMatrix[VX][VZ]; mMatrix[VX][VZ] = mMatrix[VZ][VX]; mMatrix[VZ][VX] = temp; - temp = mMatrix[VY][VZ]; mMatrix[VY][VZ] = mMatrix[VZ][VY]; mMatrix[VZ][VY] = temp; -#endif - return *this; -} - -inline const LLV4Matrix3& LLV4Matrix3::operator=(const LLMatrix3& a) -{ - memcpy(mMatrix[VX], a.mMatrix[VX], sizeof(F32) * 3 ); - memcpy(mMatrix[VY], a.mMatrix[VY], sizeof(F32) * 3 ); - memcpy(mMatrix[VZ], a.mMatrix[VZ], sizeof(F32) * 3 ); - return *this; -} - -inline LLVector3 operator*(const LLVector3& a, const LLV4Matrix3& b) -{ - return LLVector3( - a.mV[VX] * b.mMatrix[VX][VX] + - a.mV[VY] * b.mMatrix[VY][VX] + - a.mV[VZ] * b.mMatrix[VZ][VX], - - a.mV[VX] * b.mMatrix[VX][VY] + - a.mV[VY] * b.mMatrix[VY][VY] + - a.mV[VZ] * b.mMatrix[VZ][VY], - - a.mV[VX] * b.mMatrix[VX][VZ] + - a.mV[VY] * b.mMatrix[VY][VZ] + - a.mV[VZ] * b.mMatrix[VZ][VZ] ); -} - -#endif diff --git a/indra/llmath/llv4matrix4.h b/indra/llmath/llv4matrix4.h deleted file mode 100644 index 2eb49d9294..0000000000 --- a/indra/llmath/llv4matrix4.h +++ /dev/null @@ -1,249 +0,0 @@ -/** - * @file llviewerjointmesh.cpp - * @brief LLV4* class header file - vector processor enabled math - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLV4MATRIX4_H -#define LL_LLV4MATRIX4_H - -#include "llv4math.h" -#include "llv4matrix3.h" // just for operator LLV4Matrix3() -#include "llv4vector3.h" - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4Matrix4 -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -LL_LLV4MATH_ALIGN_PREFIX - -class LLV4Matrix4 -{ -public: - union { - F32 mMatrix[LLV4_NUM_AXIS][LLV4_NUM_AXIS]; - V4F32 mV[LLV4_NUM_AXIS]; - }; - - void lerp(const LLV4Matrix4 &a, const LLV4Matrix4 &b, const F32 &w); - void multiply(const LLVector3 &a, LLVector3& o) const; - void multiply(const LLVector3 &a, LLV4Vector3& o) const; - - const LLV4Matrix4& transpose(); - const LLV4Matrix4& translate(const LLVector3 &vec); - const LLV4Matrix4& translate(const LLV4Vector3 &vec); - const LLV4Matrix4& operator=(const LLMatrix4& a); - - operator LLMatrix4() const { return *(reinterpret_cast<const LLMatrix4*>(const_cast<const F32*>(&mMatrix[0][0]))); } - operator LLV4Matrix3() const { return *(reinterpret_cast<const LLV4Matrix3*>(const_cast<const F32*>(&mMatrix[0][0]))); } - - friend LLVector3 operator*(const LLVector3 &a, const LLV4Matrix4 &b); -} - -LL_LLV4MATH_ALIGN_POSTFIX; - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4Matrix4 - SSE -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -#if LL_VECTORIZE - -inline void LLV4Matrix4::lerp(const LLV4Matrix4 &a, const LLV4Matrix4 &b, const F32 &w) -{ - __m128 vw = _mm_set1_ps(w); - mV[VX] = _mm_add_ps(_mm_mul_ps(_mm_sub_ps(b.mV[VX], a.mV[VX]), vw), a.mV[VX]); // ( b - a ) * w + a - mV[VY] = _mm_add_ps(_mm_mul_ps(_mm_sub_ps(b.mV[VY], a.mV[VY]), vw), a.mV[VY]); - mV[VZ] = _mm_add_ps(_mm_mul_ps(_mm_sub_ps(b.mV[VZ], a.mV[VZ]), vw), a.mV[VZ]); - mV[VW] = _mm_add_ps(_mm_mul_ps(_mm_sub_ps(b.mV[VW], a.mV[VW]), vw), a.mV[VW]); -} - -inline void LLV4Matrix4::multiply(const LLVector3 &a, LLVector3& o) const -{ - LLV4Vector3 j; - j.v = _mm_add_ps(mV[VW], _mm_mul_ps(_mm_set1_ps(a.mV[VX]), mV[VX])); // ( ax * vx ) + vw - j.v = _mm_add_ps(j.v , _mm_mul_ps(_mm_set1_ps(a.mV[VY]), mV[VY])); - j.v = _mm_add_ps(j.v , _mm_mul_ps(_mm_set1_ps(a.mV[VZ]), mV[VZ])); - o.setVec(j.mV); -} - -inline void LLV4Matrix4::multiply(const LLVector3 &a, LLV4Vector3& o) const -{ - o.v = _mm_add_ps(mV[VW], _mm_mul_ps(_mm_set1_ps(a.mV[VX]), mV[VX])); // ( ax * vx ) + vw - o.v = _mm_add_ps(o.v , _mm_mul_ps(_mm_set1_ps(a.mV[VY]), mV[VY])); - o.v = _mm_add_ps(o.v , _mm_mul_ps(_mm_set1_ps(a.mV[VZ]), mV[VZ])); -} - -inline const LLV4Matrix4& LLV4Matrix4::translate(const LLV4Vector3 &vec) -{ - mV[VW] = _mm_add_ps(mV[VW], vec.v); - return (*this); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4Matrix4 -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -#else - -inline void LLV4Matrix4::lerp(const LLV4Matrix4 &a, const LLV4Matrix4 &b, const F32 &w) -{ - mMatrix[VX][VX] = llv4lerp(a.mMatrix[VX][VX], b.mMatrix[VX][VX], w); - mMatrix[VX][VY] = llv4lerp(a.mMatrix[VX][VY], b.mMatrix[VX][VY], w); - mMatrix[VX][VZ] = llv4lerp(a.mMatrix[VX][VZ], b.mMatrix[VX][VZ], w); - - mMatrix[VY][VX] = llv4lerp(a.mMatrix[VY][VX], b.mMatrix[VY][VX], w); - mMatrix[VY][VY] = llv4lerp(a.mMatrix[VY][VY], b.mMatrix[VY][VY], w); - mMatrix[VY][VZ] = llv4lerp(a.mMatrix[VY][VZ], b.mMatrix[VY][VZ], w); - - mMatrix[VZ][VX] = llv4lerp(a.mMatrix[VZ][VX], b.mMatrix[VZ][VX], w); - mMatrix[VZ][VY] = llv4lerp(a.mMatrix[VZ][VY], b.mMatrix[VZ][VY], w); - mMatrix[VZ][VZ] = llv4lerp(a.mMatrix[VZ][VZ], b.mMatrix[VZ][VZ], w); - - mMatrix[VW][VX] = llv4lerp(a.mMatrix[VW][VX], b.mMatrix[VW][VX], w); - mMatrix[VW][VY] = llv4lerp(a.mMatrix[VW][VY], b.mMatrix[VW][VY], w); - mMatrix[VW][VZ] = llv4lerp(a.mMatrix[VW][VZ], b.mMatrix[VW][VZ], w); -} - -inline void LLV4Matrix4::multiply(const LLVector3 &a, LLVector3& o) const -{ - o.setVec( a.mV[VX] * mMatrix[VX][VX] + - a.mV[VY] * mMatrix[VY][VX] + - a.mV[VZ] * mMatrix[VZ][VX] + - mMatrix[VW][VX], - - a.mV[VX] * mMatrix[VX][VY] + - a.mV[VY] * mMatrix[VY][VY] + - a.mV[VZ] * mMatrix[VZ][VY] + - mMatrix[VW][VY], - - a.mV[VX] * mMatrix[VX][VZ] + - a.mV[VY] * mMatrix[VY][VZ] + - a.mV[VZ] * mMatrix[VZ][VZ] + - mMatrix[VW][VZ]); -} - -inline void LLV4Matrix4::multiply(const LLVector3 &a, LLV4Vector3& o) const -{ - o.setVec( a.mV[VX] * mMatrix[VX][VX] + - a.mV[VY] * mMatrix[VY][VX] + - a.mV[VZ] * mMatrix[VZ][VX] + - mMatrix[VW][VX], - - a.mV[VX] * mMatrix[VX][VY] + - a.mV[VY] * mMatrix[VY][VY] + - a.mV[VZ] * mMatrix[VZ][VY] + - mMatrix[VW][VY], - - a.mV[VX] * mMatrix[VX][VZ] + - a.mV[VY] * mMatrix[VY][VZ] + - a.mV[VZ] * mMatrix[VZ][VZ] + - mMatrix[VW][VZ]); -} - -inline const LLV4Matrix4& LLV4Matrix4::translate(const LLV4Vector3 &vec) -{ - mMatrix[3][0] += vec.mV[0]; - mMatrix[3][1] += vec.mV[1]; - mMatrix[3][2] += vec.mV[2]; - return (*this); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4Matrix4 -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -#endif - -inline const LLV4Matrix4& LLV4Matrix4::operator=(const LLMatrix4& a) -{ - memcpy(mMatrix, a.mMatrix, sizeof(F32) * 16 ); - return *this; -} - -inline const LLV4Matrix4& LLV4Matrix4::transpose() -{ -#if LL_VECTORIZE && defined(_MM_TRANSPOSE4_PS) - _MM_TRANSPOSE4_PS(mV[VX], mV[VY], mV[VZ], mV[VW]); -#else - LLV4Matrix4 mat; - mat.mMatrix[0][0] = mMatrix[0][0]; - mat.mMatrix[1][0] = mMatrix[0][1]; - mat.mMatrix[2][0] = mMatrix[0][2]; - mat.mMatrix[3][0] = mMatrix[0][3]; - - mat.mMatrix[0][1] = mMatrix[1][0]; - mat.mMatrix[1][1] = mMatrix[1][1]; - mat.mMatrix[2][1] = mMatrix[1][2]; - mat.mMatrix[3][1] = mMatrix[1][3]; - - mat.mMatrix[0][2] = mMatrix[2][0]; - mat.mMatrix[1][2] = mMatrix[2][1]; - mat.mMatrix[2][2] = mMatrix[2][2]; - mat.mMatrix[3][2] = mMatrix[2][3]; - - mat.mMatrix[0][3] = mMatrix[3][0]; - mat.mMatrix[1][3] = mMatrix[3][1]; - mat.mMatrix[2][3] = mMatrix[3][2]; - mat.mMatrix[3][3] = mMatrix[3][3]; - - *this = mat; -#endif - return *this; -} - -inline const LLV4Matrix4& LLV4Matrix4::translate(const LLVector3 &vec) -{ - mMatrix[3][0] += vec.mV[0]; - mMatrix[3][1] += vec.mV[1]; - mMatrix[3][2] += vec.mV[2]; - return (*this); -} - -inline LLVector3 operator*(const LLVector3 &a, const LLV4Matrix4 &b) -{ - return LLVector3(a.mV[VX] * b.mMatrix[VX][VX] + - a.mV[VY] * b.mMatrix[VY][VX] + - a.mV[VZ] * b.mMatrix[VZ][VX] + - b.mMatrix[VW][VX], - - a.mV[VX] * b.mMatrix[VX][VY] + - a.mV[VY] * b.mMatrix[VY][VY] + - a.mV[VZ] * b.mMatrix[VZ][VY] + - b.mMatrix[VW][VY], - - a.mV[VX] * b.mMatrix[VX][VZ] + - a.mV[VY] * b.mMatrix[VY][VZ] + - a.mV[VZ] * b.mMatrix[VZ][VZ] + - b.mMatrix[VW][VZ]); -} - - -#endif diff --git a/indra/llmath/llv4vector3.h b/indra/llmath/llv4vector3.h deleted file mode 100644 index a340d53f5a..0000000000 --- a/indra/llmath/llv4vector3.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @file llviewerjointmesh.cpp - * @brief LLV4* class header file - vector processor enabled math - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLV4VECTOR3_H -#define LL_LLV4VECTOR3_H - -#include "llv4math.h" - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4Vector3 -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -LL_LLV4MATH_ALIGN_PREFIX - -class LLV4Vector3 -{ -public: - union { - F32 mV[LLV4_NUM_AXIS]; - V4F32 v; - }; - - enum { - ALIGNMENT = 16 - }; - - void setVec(F32 x, F32 y, F32 z); - void setVec(F32 a); -} - -LL_LLV4MATH_ALIGN_POSTFIX; - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// LLV4Vector3 -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -inline void LLV4Vector3::setVec(F32 x, F32 y, F32 z) -{ - mV[VX] = x; - mV[VY] = y; - mV[VZ] = z; -} - -inline void LLV4Vector3::setVec(F32 a) -{ -#if LL_VECTORIZE - v = _mm_set1_ps(a); -#else - setVec(a, a, a); -#endif -} - -#endif diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 21cc9b22f2..da0fa32963 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -32,6 +32,7 @@ #if !LL_WINDOWS #include <stdint.h> #endif +#include <cmath> #include "llerror.h" #include "llmemtype.h" @@ -2077,7 +2078,7 @@ LLVolume::LLVolume(const LLVolumeParams ¶ms, const F32 detail, const BOOL ge mFaceMask = 0x0; mDetail = detail; mSculptLevel = -2; - mIsTetrahedron = FALSE; + mIsMeshAssetLoaded = FALSE; mLODScaleBias.setVec(1,1,1); mHullPoints = NULL; mHullIndices = NULL; @@ -2099,7 +2100,7 @@ LLVolume::LLVolume(const LLVolumeParams ¶ms, const F32 detail, const BOOL ge generate(); - if (mParams.getSculptID().isNull() && mParams.getSculptType() == LL_SCULPT_TYPE_NONE) + if (mParams.getSculptID().isNull() && mParams.getSculptType() == LL_SCULPT_TYPE_NONE || mParams.getSculptType() == LL_SCULPT_TYPE_MESH) { createVolumeFaces(); } @@ -2379,11 +2380,16 @@ bool LLVolumeFace::VertexData::operator==(const LLVolumeFace::VertexData& rhs)co bool LLVolumeFace::VertexData::compareNormal(const LLVolumeFace::VertexData& rhs, F32 angle_cutoff) const { bool retval = false; - if (rhs.mData[POSITION].equals3(mData[POSITION]) && rhs.mTexCoord == mTexCoord) + + const F32 epsilon = 0.00001f; + + if (rhs.mData[POSITION].equals3(mData[POSITION], epsilon) && + fabs(rhs.mTexCoord[0]-mTexCoord[0]) < epsilon && + fabs(rhs.mTexCoord[1]-mTexCoord[1]) < epsilon) { if (angle_cutoff > 1.f) { - retval = (mData[NORMAL].equals3(rhs.mData[NORMAL])); + retval = (mData[NORMAL].equals3(rhs.mData[NORMAL], epsilon)); } else { @@ -2402,7 +2408,7 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) LLSD mdl; if (!unzip_llsd(mdl, is, size)) { - llwarns << "not a valid mesh asset!" << llendl; + LL_DEBUGS("MeshStreaming") << "Failed to unzip LLSD blob for LoD, will probably fetch from sim again." << llendl; return false; } @@ -2499,9 +2505,9 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) } { - U16* n = (U16*) &(norm[0]); - if(n) + if (!norm.empty()) { + U16* n = (U16*) &(norm[0]); for (U32 j = 0; j < num_verts; ++j) { norm_out->set((F32) n[0], (F32) n[1], (F32) n[2]); @@ -2512,12 +2518,16 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) n += 3; } } + else + { + memset(norm_out, 0, sizeof(LLVector4a)*num_verts); + } } { - U16* t = (U16*) &(tc[0]); - if(t) + if (!tc.empty()) { + U16* t = (U16*) &(tc[0]); for (U32 j = 0; j < num_verts; j+=2) { if (j < num_verts-1) @@ -2538,6 +2548,10 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) tc_out++; } } + else + { + memset(tc_out, 0, sizeof(LLVector2)*num_verts); + } } if (mdl[i].has("Weights")) @@ -2662,6 +2676,25 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) min.setMin(min, face.mPositions[i]); max.setMax(max, face.mPositions[i]); } + + if (face.mTexCoords) + { + LLVector2& min_tc = face.mTexCoordExtents[0]; + LLVector2& max_tc = face.mTexCoordExtents[1]; + + min_tc = face.mTexCoords[0]; + max_tc = face.mTexCoords[0]; + + for (U32 j = 1; j < face.mNumVertices; ++j) + { + update_min_max(min_tc, max_tc, face.mTexCoords[j]); + } + } + else + { + face.mTexCoordExtents[0].set(0,0); + face.mTexCoordExtents[1].set(1,1); + } } } } @@ -2673,162 +2706,21 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) return true; } -void tetrahedron_set_normal(LLVolumeFace::VertexData* cv) -{ - LLVector4a v0; - v0.setSub(cv[1].getPosition(), cv[0].getNormal()); - LLVector4a v1; - v1.setSub(cv[2].getNormal(), cv[0].getPosition()); - - cv[0].getNormal().setCross3(v0,v1); - cv[0].getNormal().normalize3fast(); - cv[1].setNormal(cv[0].getNormal()); - cv[2].setNormal(cv[1].getNormal()); -} -BOOL LLVolume::isTetrahedron() +BOOL LLVolume::isMeshAssetLoaded() { - return mIsTetrahedron; + return mIsMeshAssetLoaded; } -void LLVolume::makeTetrahedron() +void LLVolume::setMeshAssetLoaded(BOOL loaded) { - mVolumeFaces.clear(); - - LLVolumeFace face; - - F32 x = 0.25f; - LLVector4a p[] = - { //unit tetrahedron corners - LLVector4a(x,x,x), - LLVector4a(-x,-x,x), - LLVector4a(-x,x,-x), - LLVector4a(x,-x,-x) - }; - - face.mExtents[0].splat(-x); - face.mExtents[1].splat(x); - - LLVolumeFace::VertexData cv[3]; - - //set texture coordinates - cv[0].mTexCoord = LLVector2(0,0); - cv[1].mTexCoord = LLVector2(1,0); - cv[2].mTexCoord = LLVector2(0.5f, 0.5f*F_SQRT3); - - - //side 1 - cv[0].setPosition(p[1]); - cv[1].setPosition(p[0]); - cv[2].setPosition(p[2]); - - tetrahedron_set_normal(cv); - - face.resizeVertices(12); - face.resizeIndices(12); - - LLVector4a* v = (LLVector4a*) face.mPositions; - LLVector4a* n = (LLVector4a*) face.mNormals; - LLVector2* tc = (LLVector2*) face.mTexCoords; - - v[0] = cv[0].getPosition(); - v[1] = cv[1].getPosition(); - v[2] = cv[2].getPosition(); - v += 3; - - n[0] = cv[0].getNormal(); - n[1] = cv[1].getNormal(); - n[2] = cv[2].getNormal(); - n += 3; - - tc[0] = cv[0].mTexCoord; - tc[1] = cv[1].mTexCoord; - tc[2] = cv[2].mTexCoord; - tc += 3; - - - //side 2 - cv[0].setPosition(p[3]); - cv[1].setPosition(p[0]); - cv[2].setPosition(p[1]); - - tetrahedron_set_normal(cv); - - v[0] = cv[0].getPosition(); - v[1] = cv[1].getPosition(); - v[2] = cv[2].getPosition(); - v += 3; - - n[0] = cv[0].getNormal(); - n[1] = cv[1].getNormal(); - n[2] = cv[2].getNormal(); - n += 3; - - tc[0] = cv[0].mTexCoord; - tc[1] = cv[1].mTexCoord; - tc[2] = cv[2].mTexCoord; - tc += 3; - - //side 3 - cv[0].setPosition(p[3]); - cv[1].setPosition(p[1]); - cv[2].setPosition(p[2]); - - tetrahedron_set_normal(cv); - - v[0] = cv[0].getPosition(); - v[1] = cv[1].getPosition(); - v[2] = cv[2].getPosition(); - v += 3; - - n[0] = cv[0].getNormal(); - n[1] = cv[1].getNormal(); - n[2] = cv[2].getNormal(); - n += 3; - - tc[0] = cv[0].mTexCoord; - tc[1] = cv[1].mTexCoord; - tc[2] = cv[2].mTexCoord; - tc += 3; - - //side 4 - cv[0].setPosition(p[2]); - cv[1].setPosition(p[0]); - cv[2].setPosition(p[3]); - - tetrahedron_set_normal(cv); - - v[0] = cv[0].getPosition(); - v[1] = cv[1].getPosition(); - v[2] = cv[2].getPosition(); - v += 3; - - n[0] = cv[0].getNormal(); - n[1] = cv[1].getNormal(); - n[2] = cv[2].getNormal(); - n += 3; - - tc[0] = cv[0].mTexCoord; - tc[1] = cv[1].mTexCoord; - tc[2] = cv[2].mTexCoord; - tc += 3; - - //set index buffer - for (U16 i = 0; i < 12; i++) - { - face.mIndices[i] = i; - } - - mVolumeFaces.push_back(face); - mSculptLevel = 0; - mIsTetrahedron = TRUE; + mIsMeshAssetLoaded = loaded; } void LLVolume::copyVolumeFaces(const LLVolume* volume) { mVolumeFaces = volume->mVolumeFaces; mSculptLevel = 0; - mIsTetrahedron = FALSE; } void LLVolume::cacheOptimize() @@ -2842,14 +2734,7 @@ void LLVolume::cacheOptimize() S32 LLVolume::getNumFaces() const { - U8 sculpt_type = (mParams.getSculptType() & LL_SCULPT_TYPE_MASK); - - if (sculpt_type == LL_SCULPT_TYPE_MESH) - { - return LL_SCULPT_MESH_MAX_FACES; - } - - return (S32)mProfilep->mFaces.size(); + return mIsMeshAssetLoaded ? getNumVolumeFaces() : (S32)mProfilep->mFaces.size(); } @@ -4420,15 +4305,25 @@ S32 LLVolume::getNumTriangleIndices() const } -S32 LLVolume::getNumTriangles() const +S32 LLVolume::getNumTriangles(S32* vcount) const { U32 triangle_count = 0; + U32 vertex_count = 0; for (S32 i = 0; i < getNumVolumeFaces(); ++i) { - triangle_count += getVolumeFace(i).mNumIndices/3; + const LLVolumeFace& face = getVolumeFace(i); + triangle_count += face.mNumIndices/3; + + vertex_count += face.mNumVertices; } + + if (vcount) + { + *vcount = vertex_count; + } + return triangle_count; } @@ -5580,7 +5475,16 @@ LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src) LLVector4a::memcpyNonAliased16((F32*) mPositions, (F32*) src.mPositions, vert_size); LLVector4a::memcpyNonAliased16((F32*) mNormals, (F32*) src.mNormals, vert_size); - LLVector4a::memcpyNonAliased16((F32*) mTexCoords, (F32*) src.mTexCoords, tc_size); + + if(src.mTexCoords) + { + LLVector4a::memcpyNonAliased16((F32*) mTexCoords, (F32*) src.mTexCoords, tc_size); + } + else + { + ll_aligned_free_16(mTexCoords) ; + mTexCoords = NULL ; + } if (src.mBinormals) @@ -5702,8 +5606,23 @@ BOOL LLVolumeFace::create(LLVolume* volume, BOOL partial_build) void LLVolumeFace::getVertexData(U16 index, LLVolumeFace::VertexData& cv) { cv.setPosition(mPositions[index]); - cv.setNormal(mNormals[index]); - cv.mTexCoord = mTexCoords[index]; + if (mNormals) + { + cv.setNormal(mNormals[index]); + } + else + { + cv.getNormal().clear(); + } + + if (mTexCoords) + { + cv.mTexCoord = mTexCoords[index]; + } + else + { + cv.mTexCoord.clear(); + } } bool LLVolumeFace::VertexMapData::operator==(const LLVolumeFace::VertexData& rhs) const @@ -5733,7 +5652,10 @@ void LLVolumeFace::optimize(F32 angle_cutoff) LLVolumeFace new_face; //map of points to vector of vertices at that point - VertexMapData::PointMap point_map; + std::map<U64, std::vector<VertexMapData> > point_map; + + LLVector4a range; + range.setSub(mExtents[1],mExtents[0]); //remove redundant vertices for (U32 i = 0; i < mNumIndices; ++i) @@ -5744,7 +5666,19 @@ void LLVolumeFace::optimize(F32 angle_cutoff) getVertexData(index, cv); BOOL found = FALSE; - VertexMapData::PointMap::iterator point_iter = point_map.find(LLVector3(cv.getPosition().getF32ptr())); + + LLVector4a pos; + pos.setSub(mPositions[index], mExtents[0]); + pos.div(range); + + U64 pos64 = 0; + + pos64 = (U16) (pos[0]*65535); + pos64 = pos64 | (((U64) (pos[1]*65535)) << 16); + pos64 = pos64 | (((U64) (pos[2]*65535)) << 32); + + std::map<U64, std::vector<VertexMapData> >::iterator point_iter = point_map.find(pos64); + if (point_iter != point_map.end()) { //duplicate point might exist for (U32 j = 0; j < point_iter->second.size(); ++j) @@ -5776,11 +5710,26 @@ void LLVolumeFace::optimize(F32 angle_cutoff) } else { - point_map[LLVector3(d.getPosition().getF32ptr())].push_back(d); + point_map[pos64].push_back(d); } } } + llassert(new_face.mNumIndices == mNumIndices); + llassert(new_face.mNumVertices <= mNumVertices); + + if (angle_cutoff > 1.f && !mNormals) + { + ll_aligned_free_16(new_face.mNormals); + new_face.mNormals = NULL; + } + + if (!mTexCoords) + { + ll_aligned_free_16(new_face.mTexCoords); + new_face.mTexCoords = NULL; + } + swapData(new_face); } @@ -7171,7 +7120,7 @@ BOOL LLVolumeFace::createSide(LLVolume* volume, BOOL partial_build) resizeVertices(num_vertices); resizeIndices(num_indices); - if ((volume->getParams().getSculptType() & LL_SCULPT_TYPE_MASK) != LL_SCULPT_TYPE_MESH) + if (!volume->isMeshAssetLoaded()) { mEdge.resize(num_indices); } diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h index f67f8f644d..afd1ec5eed 100644 --- a/indra/llmath/llvolume.h +++ b/indra/llmath/llvolume.h @@ -990,7 +990,7 @@ public: S32 getNumTriangleIndices() const; static void getLoDTriangleCounts(const LLVolumeParams& params, S32* counts); - S32 getNumTriangles() const; + S32 getNumTriangles(S32* vcount = NULL) const; void generateSilhouetteVertices(std::vector<LLVector3> &vertices, std::vector<LLVector3> &normals, @@ -1058,14 +1058,14 @@ protected: public: virtual bool unpackVolumeFaces(std::istream& is, S32 size); - virtual void makeTetrahedron(); - virtual BOOL isTetrahedron(); + virtual void setMeshAssetLoaded(BOOL loaded); + virtual BOOL isMeshAssetLoaded(); protected: BOOL mUnique; F32 mDetail; S32 mSculptLevel; - BOOL mIsTetrahedron; + BOOL mIsMeshAssetLoaded; LLVolumeParams mParams; LLPath *mPathp; diff --git a/indra/llmath/tests/v3math_test.cpp b/indra/llmath/tests/v3math_test.cpp index df7a77002f..e4ae1c10ef 100644 --- a/indra/llmath/tests/v3math_test.cpp +++ b/indra/llmath/tests/v3math_test.cpp @@ -564,4 +564,22 @@ namespace tut z1 = U8_to_F32(F32_to_U8(z, lowerz, upperz), lowerz, upperz); ensure("2:quantize8: Fail ", is_approx_equal(x1, vec3a.mV[VX]) && is_approx_equal(y1, vec3a.mV[VY]) && is_approx_equal(z1, vec3a.mV[VZ])); } + + template<> template<> + void v3math_object::test<35>() + { + LLSD sd = LLSD::emptyArray(); + sd[0] = 1.f; + + LLVector3 parsed_1(sd); + ensure("1:LLSD parse: Fail ", is_approx_equal(parsed_1.mV[VX], 1.f) && is_approx_equal(parsed_1.mV[VY], 0.f) && is_approx_equal(parsed_1.mV[VZ], 0.f)); + + sd[1] = 2.f; + LLVector3 parsed_2(sd); + ensure("2:LLSD parse: Fail ", is_approx_equal(parsed_2.mV[VX], 1.f) && is_approx_equal(parsed_2.mV[VY], 2.f) && is_approx_equal(parsed_2.mV[VZ], 0.f)); + + sd[2] = 3.f; + LLVector3 parsed_3(sd); + ensure("3:LLSD parse: Fail ", is_approx_equal(parsed_3.mV[VX], 1.f) && is_approx_equal(parsed_3.mV[VY], 2.f) && is_approx_equal(parsed_3.mV[VZ], 3.f)); + } } |