summaryrefslogtreecommitdiff
path: root/indra/llmath
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmath')
-rw-r--r--indra/llmath/CMakeLists.txt4
-rw-r--r--indra/llmath/llcalc.cpp162
-rw-r--r--indra/llmath/llcalc.h100
-rw-r--r--indra/llmath/llcalcparser.cpp63
-rw-r--r--indra/llmath/llcalcparser.h191
-rwxr-xr-x[-rw-r--r--]indra/llmath/llvolume.cpp202
-rw-r--r--indra/llmath/llvolumemgr.cpp4
-rw-r--r--indra/llmath/tests/v3math_test.cpp18
8 files changed, 693 insertions, 51 deletions
diff --git a/indra/llmath/CMakeLists.txt b/indra/llmath/CMakeLists.txt
index 9dadad7dd3..cd100cdf9f 100644
--- a/indra/llmath/CMakeLists.txt
+++ b/indra/llmath/CMakeLists.txt
@@ -12,6 +12,8 @@ include_directories(
set(llmath_SOURCE_FILES
llbbox.cpp
llbboxlocal.cpp
+ llcalc.cpp
+ llcalcparser.cpp
llcamera.cpp
llcoordframe.cpp
llline.cpp
@@ -46,6 +48,8 @@ set(llmath_HEADER_FILES
coordframe.h
llbbox.h
llbboxlocal.h
+ llcalc.h
+ llcalcparser.h
llcamera.h
llcoord.h
llcoordframe.h
diff --git a/indra/llmath/llcalc.cpp b/indra/llmath/llcalc.cpp
new file mode 100644
index 0000000000..1b2d609b67
--- /dev/null
+++ b/indra/llmath/llcalc.cpp
@@ -0,0 +1,162 @@
+/*
+ * LLCalc.cpp
+ * 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$
+ *
+ */
+
+#include "linden_common.h"
+
+#include "llcalc.h"
+
+#include "llcalcparser.h"
+#include "llmath.h"
+
+
+// Variable names for use in the build floater
+const char* LLCalc::X_POS = "PX";
+const char* LLCalc::Y_POS = "PY";
+const char* LLCalc::Z_POS = "PZ";
+const char* LLCalc::X_SCALE = "SX";
+const char* LLCalc::Y_SCALE = "SY";
+const char* LLCalc::Z_SCALE = "SZ";
+const char* LLCalc::X_ROT = "RX";
+const char* LLCalc::Y_ROT = "RY";
+const char* LLCalc::Z_ROT = "RZ";
+const char* LLCalc::HOLLOW = "HLW";
+const char* LLCalc::CUT_BEGIN = "CB";
+const char* LLCalc::CUT_END = "CE";
+const char* LLCalc::PATH_BEGIN = "PB";
+const char* LLCalc::PATH_END = "PE";
+const char* LLCalc::TWIST_BEGIN = "TB";
+const char* LLCalc::TWIST_END = "TE";
+const char* LLCalc::X_SHEAR = "SHX";
+const char* LLCalc::Y_SHEAR = "SHY";
+const char* LLCalc::X_TAPER = "TPX";
+const char* LLCalc::Y_TAPER = "TPY";
+const char* LLCalc::RADIUS_OFFSET = "ROF";
+const char* LLCalc::REVOLUTIONS = "REV";
+const char* LLCalc::SKEW = "SKW";
+const char* LLCalc::X_HOLE = "HLX";
+const char* LLCalc::Y_HOLE = "HLY";
+const char* LLCalc::TEX_U_SCALE = "TSU";
+const char* LLCalc::TEX_V_SCALE = "TSV";
+const char* LLCalc::TEX_U_OFFSET = "TOU";
+const char* LLCalc::TEX_V_OFFSET = "TOV";
+const char* LLCalc::TEX_ROTATION = "TROT";
+const char* LLCalc::TEX_TRANSPARENCY = "TRNS";
+const char* LLCalc::TEX_GLOW = "GLOW";
+
+
+LLCalc* LLCalc::sInstance = NULL;
+
+LLCalc::LLCalc() : mLastErrorPos(0)
+{
+ // Init table of constants
+ mConstants["PI"] = F_PI;
+ mConstants["TWO_PI"] = F_TWO_PI;
+ mConstants["PI_BY_TWO"] = F_PI_BY_TWO;
+ mConstants["SQRT_TWO_PI"] = F_SQRT_TWO_PI;
+ mConstants["SQRT2"] = F_SQRT2;
+ mConstants["SQRT3"] = F_SQRT3;
+ mConstants["DEG_TO_RAD"] = DEG_TO_RAD;
+ mConstants["RAD_TO_DEG"] = RAD_TO_DEG;
+ mConstants["GRAVITY"] = GRAVITY;
+}
+
+LLCalc::~LLCalc()
+{
+}
+
+//static
+void LLCalc::cleanUp()
+{
+ delete sInstance;
+ sInstance = NULL;
+}
+
+//static
+LLCalc* LLCalc::getInstance()
+{
+ if (!sInstance) sInstance = new LLCalc();
+ return sInstance;
+}
+
+void LLCalc::setVar(const std::string& name, const F32& value)
+{
+ mVariables[name] = value;
+}
+
+void LLCalc::clearVar(const std::string& name)
+{
+ mVariables.erase(name);
+}
+
+void LLCalc::clearAllVariables()
+{
+ mVariables.clear();
+}
+
+/*
+void LLCalc::updateVariables(LLSD& vars)
+{
+ LLSD::map_iterator cIt = vars.beginMap();
+ for(; cIt != vars.endMap(); cIt++)
+ {
+ setVar(cIt->first, (F32)(LLSD::Real)cIt->second);
+ }
+}
+*/
+
+bool LLCalc::evalString(const std::string& expression, F32& result)
+{
+ std::string expr_upper = expression;
+ LLStringUtil::toUpper(expr_upper);
+
+ LLCalcParser calc(result, &mConstants, &mVariables);
+
+ mLastErrorPos = 0;
+ std::string::iterator start = expr_upper.begin();
+ parse_info<std::string::iterator> info;
+
+ try
+ {
+ info = parse(start, expr_upper.end(), calc, space_p);
+ lldebugs << "Math expression: " << expression << " = " << result << llendl;
+ }
+ catch(parser_error<std::string, std::string::iterator> &e)
+ {
+ mLastErrorPos = e.where - expr_upper.begin();
+
+ llinfos << "Calc parser exception: " << e.descriptor << " at " << mLastErrorPos << " in expression: " << expression << llendl;
+ return false;
+ }
+
+ if (!info.full)
+ {
+ mLastErrorPos = info.stop - expr_upper.begin();
+ llinfos << "Unhandled syntax error at " << mLastErrorPos << " in expression: " << expression << llendl;
+ return false;
+ }
+
+ return true;
+}
diff --git a/indra/llmath/llcalc.h b/indra/llmath/llcalc.h
new file mode 100644
index 0000000000..ceb9dce585
--- /dev/null
+++ b/indra/llmath/llcalc.h
@@ -0,0 +1,100 @@
+/*
+ * LLCalc.h
+ * 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$
+ *
+ */
+
+#ifndef LL_CALC_H
+#define LL_CALC_H
+
+#include <map>
+#include <string>
+
+class LLCalc
+{
+public:
+ LLCalc();
+ ~LLCalc();
+
+ // Variable name constants
+ static const char* X_POS;
+ static const char* Y_POS;
+ static const char* Z_POS;
+ static const char* X_SCALE;
+ static const char* Y_SCALE;
+ static const char* Z_SCALE;
+ static const char* X_ROT;
+ static const char* Y_ROT;
+ static const char* Z_ROT;
+ static const char* HOLLOW;
+ static const char* CUT_BEGIN;
+ static const char* CUT_END;
+ static const char* PATH_BEGIN;
+ static const char* PATH_END;
+ static const char* TWIST_BEGIN;
+ static const char* TWIST_END;
+ static const char* X_SHEAR;
+ static const char* Y_SHEAR;
+ static const char* X_TAPER;
+ static const char* Y_TAPER;
+ static const char* RADIUS_OFFSET;
+ static const char* REVOLUTIONS;
+ static const char* SKEW;
+ static const char* X_HOLE;
+ static const char* Y_HOLE;
+ static const char* TEX_U_SCALE;
+ static const char* TEX_V_SCALE;
+ static const char* TEX_U_OFFSET;
+ static const char* TEX_V_OFFSET;
+ static const char* TEX_ROTATION;
+ static const char* TEX_TRANSPARENCY;
+ static const char* TEX_GLOW;
+
+ void setVar(const std::string& name, const F32& value);
+ void clearVar(const std::string& name);
+ void clearAllVariables();
+// void updateVariables(LLSD& vars);
+
+ bool evalString(const std::string& expression, F32& result);
+ std::string::size_type getLastErrorPos() { return mLastErrorPos; }
+
+ static LLCalc* getInstance();
+ static void cleanUp();
+
+ typedef std::map<std::string, F32> calc_map_t;
+
+private:
+ std::string::size_type mLastErrorPos;
+
+ calc_map_t mConstants;
+ calc_map_t mVariables;
+
+ // *TODO: Add support for storing user defined variables, and stored functions.
+ // Will need UI work, and a means to save them between sessions.
+// calc_map_t mUserVariables;
+
+ // "There shall be only one"
+ static LLCalc* sInstance;
+};
+
+#endif // LL_CALC_H
diff --git a/indra/llmath/llcalcparser.cpp b/indra/llmath/llcalcparser.cpp
new file mode 100644
index 0000000000..b4ca320659
--- /dev/null
+++ b/indra/llmath/llcalcparser.cpp
@@ -0,0 +1,63 @@
+/*
+ * LLCalcParser.cpp
+ * 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$
+ *
+ */
+
+#include "linden_common.h"
+
+#include "llcalcparser.h"
+using namespace boost::spirit::classic;
+
+F32 LLCalcParser::lookup(const std::string::iterator& start, const std::string::iterator& end) const
+{
+ LLCalc::calc_map_t::iterator iter;
+
+ std::string name(start, end);
+
+ if (mConstants)
+ {
+ iter = mConstants->find(name);
+ if (iter != mConstants->end())
+ {
+ return (*iter).second;
+ }
+ }
+ else
+ {
+ // This should never happen!
+ throw_(end, std::string("Missing constants table"));
+ }
+
+ if (mVariables)
+ {
+ iter = mVariables->find(name);
+ if (iter != mVariables->end())
+ {
+ return (*iter).second;
+ }
+ }
+
+ throw_(end, std::string("Unknown symbol " + name));
+ return 0.f;
+}
diff --git a/indra/llmath/llcalcparser.h b/indra/llmath/llcalcparser.h
new file mode 100644
index 0000000000..bd9c8c2519
--- /dev/null
+++ b/indra/llmath/llcalcparser.h
@@ -0,0 +1,191 @@
+/*
+ * LLCalcParser.h
+ * 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$
+ *
+ */
+
+#ifndef LL_CALCPARSER_H
+#define LL_CALCPARSER_H
+
+#include <boost/spirit/include/classic_attribute.hpp>
+#include <boost/spirit/include/classic_core.hpp>
+#include <boost/spirit/include/classic_error_handling.hpp>
+#include <boost/spirit/include/classic_position_iterator.hpp>
+#include <boost/spirit/include/phoenix1_binders.hpp>
+#include <boost/spirit/include/classic_symbols.hpp>
+using namespace boost::spirit::classic;
+
+#include "llcalc.h"
+#include "llmath.h"
+
+struct LLCalcParser : grammar<LLCalcParser>
+{
+ LLCalcParser(F32& result, LLCalc::calc_map_t* constants, LLCalc::calc_map_t* vars) :
+ mResult(result), mConstants(constants), mVariables(vars) {};
+
+ struct value_closure : closure<value_closure, F32>
+ {
+ member1 value;
+ };
+
+ template <typename ScannerT>
+ struct definition
+ {
+ // Rule declarations
+ rule<ScannerT> statement, identifier;
+ rule<ScannerT, value_closure::context_t> expression, term,
+ power,
+ unary_expr,
+ factor,
+ unary_func,
+ binary_func,
+ group;
+
+ // start() should return the starting symbol
+ rule<ScannerT> const& start() const { return statement; }
+
+ definition(LLCalcParser const& self)
+ {
+ using namespace phoenix;
+
+ assertion<std::string> assert_domain("Domain error");
+// assertion<std::string> assert_symbol("Unknown symbol");
+ assertion<std::string> assert_syntax("Syntax error");
+
+ identifier =
+ lexeme_d[(alpha_p | '_') >> *(alnum_p | '_')]
+ ;
+
+ group =
+ '(' >> expression[group.value = arg1] >> assert_syntax(ch_p(')'))
+ ;
+
+ unary_func =
+ ((str_p("SIN") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_sin)(self,arg1)]) |
+ (str_p("COS") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_cos)(self,arg1)]) |
+ (str_p("TAN") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_tan)(self,arg1)]) |
+ (str_p("ASIN") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_asin)(self,arg1)]) |
+ (str_p("ACOS") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_acos)(self,arg1)]) |
+ (str_p("ATAN") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_atan)(self,arg1)]) |
+ (str_p("SQRT") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_sqrt)(self,arg1)]) |
+ (str_p("LOG") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_log)(self,arg1)]) |
+ (str_p("EXP") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_exp)(self,arg1)]) |
+ (str_p("ABS") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_fabs)(self,arg1)]) |
+ (str_p("FLR") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_floor)(self,arg1)]) |
+ (str_p("CEIL") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_ceil)(self,arg1)])
+ ) >> assert_syntax(ch_p(')'))
+ ;
+
+ binary_func =
+ ((str_p("ATAN2") >> '(' >> expression[binary_func.value = arg1] >> ',' >>
+ expression[binary_func.value = bind(&LLCalcParser::_atan2)(self, binary_func.value, arg1)]) |
+ (str_p("MIN") >> '(' >> expression[binary_func.value = arg1] >> ',' >>
+ expression[binary_func.value = bind(&LLCalcParser::_min)(self, binary_func.value, arg1)]) |
+ (str_p("MAX") >> '(' >> expression[binary_func.value = arg1] >> ',' >>
+ expression[binary_func.value = bind(&LLCalcParser::_max)(self, binary_func.value, arg1)])
+ ) >> assert_syntax(ch_p(')'))
+ ;
+
+ // *TODO: Localisation of the decimal point?
+ // Problem, LLLineEditor::postvalidateFloat accepts a comma when appropriate
+ // for the current locale. However to do that here could clash with using
+ // the comma as a separator when passing arguments to functions.
+ factor =
+ (ureal_p[factor.value = arg1] |
+ group[factor.value = arg1] |
+ unary_func[factor.value = arg1] |
+ binary_func[factor.value = arg1] |
+ // Lookup throws an Unknown Symbol error if it is unknown, while this works fine,
+ // would be "neater" to handle symbol lookup from here with an assertive parser.
+// constants_p[factor.value = arg1]|
+ identifier[factor.value = bind(&LLCalcParser::lookup)(self, arg1, arg2)]
+ ) >>
+ // Detect and throw math errors.
+ assert_domain(eps_p(bind(&LLCalcParser::checkNaN)(self, factor.value)))
+ ;
+
+ unary_expr =
+ !ch_p('+') >> factor[unary_expr.value = arg1] |
+ '-' >> factor[unary_expr.value = -arg1]
+ ;
+
+ power =
+ unary_expr[power.value = arg1] >>
+ *('^' >> assert_syntax(unary_expr[power.value = bind(&powf)(power.value, arg1)]))
+ ;
+
+ term =
+ power[term.value = arg1] >>
+ *(('*' >> assert_syntax(power[term.value *= arg1])) |
+ ('/' >> assert_syntax(power[term.value /= arg1])) |
+ ('%' >> assert_syntax(power[term.value = bind(&fmodf)(term.value, arg1)]))
+ )
+ ;
+
+ expression =
+ assert_syntax(term[expression.value = arg1]) >>
+ *(('+' >> assert_syntax(term[expression.value += arg1])) |
+ ('-' >> assert_syntax(term[expression.value -= arg1]))
+ )
+ ;
+
+ statement =
+ !ch_p('=') >> ( expression )[var(self.mResult) = arg1] >> (end_p)
+ ;
+ }
+ };
+
+private:
+ // Member functions for semantic actions
+ F32 lookup(const std::string::iterator&, const std::string::iterator&) const;
+ F32 _min(const F32& a, const F32& b) const { return llmin(a, b); }
+ F32 _max(const F32& a, const F32& b) const { return llmax(a, b); }
+
+ bool checkNaN(const F32& a) const { return !llisnan(a); }
+
+ //FIX* non ambigious function fix making SIN() work for calc -Cryogenic Blitz
+ F32 _sin(const F32& a) const { return sin(DEG_TO_RAD * a); }
+ F32 _cos(const F32& a) const { return cos(DEG_TO_RAD * a); }
+ F32 _tan(const F32& a) const { return tan(DEG_TO_RAD * a); }
+ F32 _asin(const F32& a) const { return asin(a * RAD_TO_DEG); }
+ F32 _acos(const F32& a) const { return acos(a * RAD_TO_DEG); }
+ F32 _atan(const F32& a) const { return atan(a * RAD_TO_DEG); }
+ F32 _sqrt(const F32& a) const { return sqrt(a); }
+ F32 _log(const F32& a) const { return log(a); }
+ F32 _exp(const F32& a) const { return exp(a); }
+ F32 _fabs(const F32& a) const { return fabs(a); }
+ F32 _floor(const F32& a) const { return llfloor(a); }
+ F32 _ceil(const F32& a) const { return llceil(a); }
+
+ F32 _atan2(const F32& a,const F32& b) const { return atan2(a,b); }
+
+
+
+ LLCalc::calc_map_t* mConstants;
+ LLCalc::calc_map_t* mVariables;
+// LLCalc::calc_map_t* mUserVariables;
+
+ F32& mResult;
+};
+
+#endif // LL_CALCPARSER_H
diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index 8c81f27784..2893e746e9 100644..100755
--- 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"
@@ -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
{
@@ -2499,38 +2505,52 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size)
}
{
- U16* n = (U16*) &(norm[0]);
- for (U32 j = 0; j < num_verts; ++j)
+ if (!norm.empty())
{
- norm_out->set((F32) n[0], (F32) n[1], (F32) n[2]);
- norm_out->div(65535.f);
- norm_out->mul(2.f);
- norm_out->sub(1.f);
- norm_out++;
- n += 3;
+ 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]);
+ norm_out->div(65535.f);
+ norm_out->mul(2.f);
+ norm_out->sub(1.f);
+ norm_out++;
+ n += 3;
+ }
+ }
+ else
+ {
+ memset(norm_out, 0, sizeof(LLVector4a)*num_verts);
}
}
{
- U16* t = (U16*) &(tc[0]);
- for (U32 j = 0; j < num_verts; j+=2)
+ if (!tc.empty())
{
- if (j < num_verts-1)
- {
- tc_out->set((F32) t[0], (F32) t[1], (F32) t[2], (F32) t[3]);
- }
- else
+ U16* t = (U16*) &(tc[0]);
+ for (U32 j = 0; j < num_verts; j+=2)
{
- tc_out->set((F32) t[0], (F32) t[1], 0.f, 0.f);
- }
+ if (j < num_verts-1)
+ {
+ tc_out->set((F32) t[0], (F32) t[1], (F32) t[2], (F32) t[3]);
+ }
+ else
+ {
+ tc_out->set((F32) t[0], (F32) t[1], 0.f, 0.f);
+ }
- t += 4;
+ t += 4;
- tc_out->div(65535.f);
- tc_out->mul(tc_range);
- tc_out->add(min_tc4);
+ tc_out->div(65535.f);
+ tc_out->mul(tc_range);
+ tc_out->add(min_tc4);
- tc_out++;
+ tc_out++;
+ }
+ }
+ else
+ {
+ memset(tc_out, 0, sizeof(LLVector2)*num_verts);
}
}
@@ -2656,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);
+ }
}
}
}
@@ -2735,11 +2774,13 @@ void LLVolume::makeTetrahedron()
n[2] = cv[2].getNormal();
n += 3;
- tc[0] = cv[0].mTexCoord;
- tc[1] = cv[1].mTexCoord;
- tc[2] = cv[2].mTexCoord;
- tc += 3;
-
+ if(tc)
+ {
+ tc[0] = cv[0].mTexCoord;
+ tc[1] = cv[1].mTexCoord;
+ tc[2] = cv[2].mTexCoord;
+ tc += 3;
+ }
//side 2
cv[0].setPosition(p[3]);
@@ -2758,11 +2799,14 @@ void LLVolume::makeTetrahedron()
n[2] = cv[2].getNormal();
n += 3;
- tc[0] = cv[0].mTexCoord;
- tc[1] = cv[1].mTexCoord;
- tc[2] = cv[2].mTexCoord;
- tc += 3;
-
+ if(tc)
+ {
+ 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]);
@@ -2780,10 +2824,13 @@ void LLVolume::makeTetrahedron()
n[2] = cv[2].getNormal();
n += 3;
- tc[0] = cv[0].mTexCoord;
- tc[1] = cv[1].mTexCoord;
- tc[2] = cv[2].mTexCoord;
- tc += 3;
+ if(tc)
+ {
+ tc[0] = cv[0].mTexCoord;
+ tc[1] = cv[1].mTexCoord;
+ tc[2] = cv[2].mTexCoord;
+ tc += 3;
+ }
//side 4
cv[0].setPosition(p[2]);
@@ -2802,10 +2849,13 @@ void LLVolume::makeTetrahedron()
n[2] = cv[2].getNormal();
n += 3;
- tc[0] = cv[0].mTexCoord;
- tc[1] = cv[1].mTexCoord;
- tc[2] = cv[2].mTexCoord;
- tc += 3;
+ if(tc)
+ {
+ 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++)
@@ -3253,7 +3303,7 @@ void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components,
{
F32 area = sculptGetSurfaceArea();
- const F32 SCULPT_MAX_AREA = 32.f;
+ const F32 SCULPT_MAX_AREA = 384.f;
if (area < SCULPT_MIN_AREA || area > SCULPT_MAX_AREA)
{
@@ -5574,7 +5624,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)
@@ -5696,8 +5755,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
@@ -5727,7 +5801,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)
@@ -5738,7 +5815,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)
@@ -5770,11 +5859,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);
}
diff --git a/indra/llmath/llvolumemgr.cpp b/indra/llmath/llvolumemgr.cpp
index c60b750088..42180197fe 100644
--- a/indra/llmath/llvolumemgr.cpp
+++ b/indra/llmath/llvolumemgr.cpp
@@ -49,7 +49,7 @@ LLVolumeMgr::LLVolumeMgr()
{
// the LLMutex magic interferes with easy unit testing,
// so you now must manually call useMutex() to use it
- //mDataMutex = new LLMutex(gAPRPoolp);
+ //mDataMutex = new LLMutex;
}
LLVolumeMgr::~LLVolumeMgr()
@@ -216,7 +216,7 @@ void LLVolumeMgr::useMutex()
{
if (!mDataMutex)
{
- mDataMutex = new LLMutex(gAPRPoolp);
+ mDataMutex = new LLMutex;
}
}
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));
+ }
}