From 97c954dd84d50ec7b739d2dd3adb7365589f3034 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Tue, 6 Jul 2021 21:26:15 +0300
Subject: [PATCH] SL-15522 Initial addition of meshoptimizer

---
 autobuild.xml                             | 56 +++++++++++++++++++++++
 indra/CMakeLists.txt                      |  1 +
 indra/cmake/CMakeLists.txt                |  1 +
 indra/cmake/LLMeshOptimizer.cmake         |  7 +++
 indra/cmake/MESHOPTIMIZER.cmake           | 16 +++++++
 indra/llmeshoptimizer/CMakeLists.txt      | 41 +++++++++++++++++
 indra/llmeshoptimizer/llmeshoptimizer.cpp | 43 +++++++++++++++++
 indra/llmeshoptimizer/llmeshoptimizer.h   | 37 +++++++++++++++
 indra/newview/CMakeLists.txt              |  3 ++
 9 files changed, 205 insertions(+)
 create mode 100644 indra/cmake/LLMeshOptimizer.cmake
 create mode 100644 indra/cmake/MESHOPTIMIZER.cmake
 create mode 100644 indra/llmeshoptimizer/CMakeLists.txt
 create mode 100644 indra/llmeshoptimizer/llmeshoptimizer.cpp
 create mode 100644 indra/llmeshoptimizer/llmeshoptimizer.h

diff --git a/autobuild.xml b/autobuild.xml
index 2470b2e5aa6..cf18d3f32fb 100644
--- a/autobuild.xml
+++ b/autobuild.xml
@@ -2394,6 +2394,62 @@
         <key>version</key>
         <string>7.11.1.297294</string>
       </map>
+      <key>meshoptimizer</key>
+      <map>
+        <key>canonical_repo</key>
+        <string>https://bitbucket.org/lindenlab/3p-meshoptimizer</string>
+        <key>copyright</key>
+        <string>Copyright (c) 2016-2021 Arseny Kapoulkine</string>
+        <key>description</key>
+        <string>Meshoptimizer. Mesh optimization library.</string>
+        <key>license</key>
+        <string>meshoptimizer</string>
+        <key>license_file</key>
+        <string>LICENSES/meshoptimizer.txt</string>
+        <key>name</key>
+        <string>meshoptimizer</string>
+        <key>platforms</key>
+        <map>
+          <key>darwin64</key>
+          <map>
+            <key>archive</key>
+            <map>
+              <key>hash</key>
+              <string>1d979dc9e0392aa8298f17a7104c8e8c</string>
+              <key>url</key>
+              <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/83991/783527/meshoptimizer-0.16.561213-darwin64-561213.tar.bz2</string>
+            </map>
+            <key>name</key>
+            <string>darwin64</string>
+          </map>
+          <key>windows</key>
+          <map>
+            <key>archive</key>
+            <map>
+              <key>hash</key>
+              <string>273dd2587b55a1efd108996d9b451b7e</string>
+              <key>url</key>
+              <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/83995/783559/meshoptimizer-0.16.561213-windows-561213.tar.bz2</string>
+            </map>
+            <key>name</key>
+            <string>windows</string>
+          </map>
+          <key>windows64</key>
+          <map>
+            <key>archive</key>
+            <map>
+              <key>hash</key>
+              <string>4cfe23766c1d71dd80cd61874d1032fe</string>
+              <key>url</key>
+              <string>https://automated-builds-secondlife-com.s3.amazonaws.com/ct2/83996/783560/meshoptimizer-0.16.561213-windows64-561213.tar.bz2</string>
+            </map>
+            <key>name</key>
+            <string>windows64</string>
+          </map>
+        </map>
+        <key>version</key>
+        <string>0.16.561213</string>
+      </map>
       <key>nghttp2</key>
       <map>
         <key>copyright</key>
diff --git a/indra/CMakeLists.txt b/indra/CMakeLists.txt
index 53e5d7b6a54..c504ca3b028 100644
--- a/indra/CMakeLists.txt
+++ b/indra/CMakeLists.txt
@@ -37,6 +37,7 @@ add_subdirectory(${LIBS_OPEN_PREFIX}llkdu)
 add_subdirectory(${LIBS_OPEN_PREFIX}llimagej2coj)
 add_subdirectory(${LIBS_OPEN_PREFIX}llinventory)
 add_subdirectory(${LIBS_OPEN_PREFIX}llmath)
+add_subdirectory(${LIBS_OPEN_PREFIX}llmeshoptimizer)
 add_subdirectory(${LIBS_OPEN_PREFIX}llmessage)
 add_subdirectory(${LIBS_OPEN_PREFIX}llprimitive)
 add_subdirectory(${LIBS_OPEN_PREFIX}llrender)
diff --git a/indra/cmake/CMakeLists.txt b/indra/cmake/CMakeLists.txt
index a17e37cd320..7795aa7db12 100644
--- a/indra/cmake/CMakeLists.txt
+++ b/indra/cmake/CMakeLists.txt
@@ -61,6 +61,7 @@ set(cmake_SOURCE_FILES
     LLKDU.cmake
     LLLogin.cmake
     LLMath.cmake
+    LLMeshOptimizer.cmake
     LLMessage.cmake
     LLPhysicsExtensions.cmake
     LLPlugin.cmake
diff --git a/indra/cmake/LLMeshOptimizer.cmake b/indra/cmake/LLMeshOptimizer.cmake
new file mode 100644
index 00000000000..b79944f6187
--- /dev/null
+++ b/indra/cmake/LLMeshOptimizer.cmake
@@ -0,0 +1,7 @@
+# -*- cmake -*-
+
+set(LLMESHOPTIMIZER_INCLUDE_DIRS
+    ${LIBS_OPEN_DIR}/llmeshoptimizer
+    )
+
+set(LLMESHOPTIMIZER_LIBRARIES llmeshoptimizer)
diff --git a/indra/cmake/MESHOPTIMIZER.cmake b/indra/cmake/MESHOPTIMIZER.cmake
new file mode 100644
index 00000000000..7600a56999b
--- /dev/null
+++ b/indra/cmake/MESHOPTIMIZER.cmake
@@ -0,0 +1,16 @@
+# -*- cmake -*-
+
+include(Prebuilt)
+
+use_prebuilt_binary(meshoptimizer)
+
+if (WINDOWS)
+  set(MESHOPTIMIZER_LIBRARIES
+    debug meshoptimizer
+    optimized meshoptimizer)
+elseif (LINUX)
+  set(MESHOPTIMIZER_LIBRARIES meshoptimizer)
+elseif (DARWIN)
+  set(MESHOPTIMIZER_LIBRARIES libmeshoptimizer.o)
+endif (WINDOWS)
+set(MESHOPTIMIZER_INCLUDE_DIRS ${LIBS_PREBUILT_DIR}/include/meshoptimizer)
diff --git a/indra/llmeshoptimizer/CMakeLists.txt b/indra/llmeshoptimizer/CMakeLists.txt
new file mode 100644
index 00000000000..1eea19de66c
--- /dev/null
+++ b/indra/llmeshoptimizer/CMakeLists.txt
@@ -0,0 +1,41 @@
+# -*- cmake -*-
+
+project(llmeshoptimizer)
+
+include(MESHOPTIMIZER)
+
+include(00-Common)
+include(LLCommon)
+
+include_directories(
+    ${LLCOMMON_INCLUDE_DIRS}
+    ${LLMESHOPTIMIZER_INCLUDE_DIR}
+    ${MESHOPTIMIZER_INCLUDE_DIRS}
+    ${LIBS_PREBUILT_DIR}/include  #access to boost headers, needed for LLError
+    )
+
+set(llmeshoptimizer_SOURCE_FILES
+    llmeshoptimizer.cpp
+    )
+
+set(llmeshoptimizer_HEADER_FILES
+    CMakeLists.txt
+
+    llmeshoptimizer.h
+    )
+
+set_source_files_properties(${llmeshoptimizer_HEADER_FILES}
+                            PROPERTIES HEADER_FILE_ONLY TRUE)
+
+list(APPEND llmeshoptimizer_SOURCE_FILES ${llmeshoptimizer_HEADER_FILES})
+
+#if (USE_MESHOPT)
+  add_library (llmeshoptimizer ${llmeshoptimizer_SOURCE_FILES})
+
+  target_link_libraries(llmeshoptimizer
+    ${LLCOMMON_LIBRARIES}
+    ${MESHOPTIMIZER_LIBRARY})
+  
+  # Add tests
+
+#endif (USE_MESHOPT)
diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp
new file mode 100644
index 00000000000..770cd5aa3c5
--- /dev/null
+++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp
@@ -0,0 +1,43 @@
+ /** 
+* @file llmeshoptimizer.cpp
+* @brief Wrapper around meshoptimizer
+*
+* $LicenseInfo:firstyear=2021&license=viewerlgpl$
+* Second Life Viewer Source Code
+* Copyright (C) 2021, 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 "llmeshoptimizer.h"
+
+#include "linden_common.h"
+
+#include "meshoptimizer.h"
+#include "llmath.h"
+
+
+LLMeshOptimizer::LLMeshOptimizer()
+{
+
+}
+
+LLMeshOptimizer::~LLMeshOptimizer()
+{
+
+}
diff --git a/indra/llmeshoptimizer/llmeshoptimizer.h b/indra/llmeshoptimizer/llmeshoptimizer.h
new file mode 100644
index 00000000000..edce4edf056
--- /dev/null
+++ b/indra/llmeshoptimizer/llmeshoptimizer.h
@@ -0,0 +1,37 @@
+/** 
+* @file llmeshoptimizer.h
+* @brief Wrapper around meshoptimizer
+*
+* $LicenseInfo:firstyear=2021&license=viewerlgpl$
+* Second Life Viewer Source Code
+* Copyright (C) 2021, 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 LLMESHOPTIMIZER_H
+#define LLMESHOPTIMIZER_H
+
+class LLMeshOptimizer
+{
+public:
+    LLMeshOptimizer();
+    ~LLMeshOptimizer();
+private:
+};
+
+#endif //LLMESHOPTIMIZER_H
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index 424fd17707b..72d01b264cf 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -33,6 +33,7 @@ include(LLInventory)
 include(LLKDU)
 include(LLLogin)
 include(LLMath)
+include(LLMeshOptimizer)
 include(LLMessage)
 include(LLPhysicsExtensions)
 include(LLPlugin)
@@ -79,6 +80,7 @@ include_directories(
     ${LLKDU_INCLUDE_DIRS}
     ${LLINVENTORY_INCLUDE_DIRS}
     ${LLMATH_INCLUDE_DIRS}
+    ${LLMESHOPTIMIZER_INCLUDE_DIRS}
     ${LLMESSAGE_INCLUDE_DIRS}
     ${LLPLUGIN_INCLUDE_DIRS}
     ${LLPRIMITIVE_INCLUDE_DIRS}
@@ -2027,6 +2029,7 @@ target_link_libraries(${VIEWER_BINARY_NAME}
     ${LLCHARACTER_LIBRARIES}
     ${LLIMAGE_LIBRARIES}
     ${LLINVENTORY_LIBRARIES}
+    ${LLMESHOPTIMIZER_LIBRARIES}
     ${LLMESSAGE_LIBRARIES}
     ${LLPLUGIN_LIBRARIES}
     ${LLPRIMITIVE_LIBRARIES}
-- 
GitLab