├── INSTALL.txt ├── img ├── demo.gif ├── edge.gif ├── menu.png └── compare.gif ├── UDIMTextureImporterData ├── ZFileUtils │ ├── ZFileUtils.lib │ └── ZFileUtils64.dll ├── src │ ├── logger.hpp │ ├── timer.hpp │ ├── util.hpp │ ├── udimTextureImporter.hpp │ ├── logger.cpp │ ├── image.hpp │ ├── timer.cpp │ ├── util.cpp │ ├── goz.hpp │ ├── udimTextureImporter.cpp │ ├── image.cpp │ └── goz.cpp └── UDIMTextureImporter_2022.txt ├── version.txt ├── .gitmodules ├── CMakeLists.txt ├── README.md └── LICENSE /INSTALL.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /img/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minoue/UDIMTextureImporter/HEAD/img/demo.gif -------------------------------------------------------------------------------- /img/edge.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minoue/UDIMTextureImporter/HEAD/img/edge.gif -------------------------------------------------------------------------------- /img/menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minoue/UDIMTextureImporter/HEAD/img/menu.png -------------------------------------------------------------------------------- /img/compare.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minoue/UDIMTextureImporter/HEAD/img/compare.gif -------------------------------------------------------------------------------- /UDIMTextureImporterData/ZFileUtils/ZFileUtils.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minoue/UDIMTextureImporter/HEAD/UDIMTextureImporterData/ZFileUtils/ZFileUtils.lib -------------------------------------------------------------------------------- /UDIMTextureImporterData/ZFileUtils/ZFileUtils64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minoue/UDIMTextureImporter/HEAD/UDIMTextureImporterData/ZFileUtils/ZFileUtils64.dll -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | // UDIMTextureImporter 2.3.0 2 | 3 | // GUI ver : 2.3.0 4 | // DLL ver : 2.2.1 5 | // libtiff ver : 4.6.0 6 | // zlib ver : 1.3 7 | // libdeflate ver : 1.19 -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "DisplacementImporterData/src/FromZ"] 2 | path = UDIMTextureImporterData/src/FromZ 3 | url = https://github.com/n-taka/FromZ 4 | [submodule "DisplacementImporterData/src/eigen"] 5 | path = UDIMTextureImporterData/src/eigen 6 | url = https://gitlab.com/libeigen/eigen 7 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/logger.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include 5 | 6 | class Logger { 7 | public: 8 | static void init(const std::string& filePath); 9 | static void write(const std::string& log); 10 | static void close(); 11 | 12 | private: 13 | static std::string filePath; 14 | static FILE* file; 15 | }; 16 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/timer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class Timer { 7 | public: 8 | Timer(); 9 | ~Timer(); 10 | void start(); 11 | void showDuration(std::string message); 12 | static std::string getCurrentTime(); 13 | 14 | private: 15 | std::chrono::system_clock::time_point start_point; 16 | }; 17 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/util.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __UTIL_HPP__ 2 | #define __UTIL_HPP__ 3 | 4 | #include 5 | #include 6 | 7 | class Utils { 8 | public: 9 | Utils(); 10 | ~Utils(); 11 | static size_t split(const std::string& txt, std::vector& strs, char ch); 12 | static std::string pathGetUdim(const std::string path); 13 | 14 | private: 15 | }; 16 | 17 | #endif // __UTIL_HPP__ 18 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/udimTextureImporter.hpp: -------------------------------------------------------------------------------- 1 | #ifndef displacementImporter_hpp 2 | #define displacementImporter_hpp 3 | 4 | #ifdef _WIN32 5 | #include 6 | #define EXPORT __declspec(dllexport) 7 | #endif 8 | 9 | #ifdef __APPLE__ 10 | #define EXPORT __attribute__((visibility("default"))) 11 | #endif 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | float EXPORT ImportUDIM(char* textFromZBrush, 18 | double gamma, 19 | char* pOptBuffer1, 20 | int optBuffer1Size, 21 | char* pOptBuffer2, 22 | int optBuffer2Size, 23 | char** zData); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif /* displacementImporter_hpp */ 30 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/logger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "logger.hpp" 4 | #include "timer.hpp" 5 | 6 | 7 | std::string Logger::filePath = ""; 8 | FILE* Logger::file = NULL; 9 | 10 | 11 | void Logger::init(const std::string& path) { 12 | std::filesystem::path gozPath(path); 13 | gozPath.replace_filename("UDIMImporter.log"); 14 | 15 | file = fopen(gozPath.string().c_str(), "w"); 16 | if (file == NULL) { 17 | // err 18 | } 19 | 20 | char line[128]; 21 | snprintf(line, sizeof(line), "[%s] : UDIMImporter started.\n", Timer::getCurrentTime().c_str()); 22 | fputs(line, file); 23 | } 24 | 25 | void Logger::write(const std::string& message) { 26 | char line[128]; 27 | snprintf(line, sizeof(line), "[%s] : %s\n", Timer::getCurrentTime().c_str(), message.c_str()); 28 | fputs(line, file); 29 | } 30 | 31 | void Logger::close() { 32 | fclose(file); 33 | } 34 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/image.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "eigen/Eigen/Core" 4 | #include "eigen/Eigen/Dense" 5 | #include "eigen/Eigen/LU" 6 | #include "tiffio.hxx" 7 | #include 8 | 9 | using namespace Eigen; 10 | 11 | class Image { 12 | public: 13 | Image(); 14 | Image(std::string path); 15 | ~Image(); 16 | int width; 17 | int height; 18 | int nchannels; 19 | std::vector pixels; 20 | void read(const std::string path); 21 | bool isEmpty = true; 22 | 23 | private: 24 | void loadExr(const std::string& path); 25 | void loadTif(const std::string& path); 26 | void loadImg(const std::string& path); 27 | }; 28 | 29 | namespace ImageUtils { 30 | size_t get_udim(const float u, const float v); 31 | Vector2f localize_uv(const float& u, const float& v); 32 | Vector3f get_pixel_values(const float u, const float v, const std::vector& texture, const int width, const int height, const int nchannel); 33 | } 34 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/timer.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "timer.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | Timer::Timer() {}; 9 | 10 | Timer::~Timer() {}; 11 | 12 | void Timer::start() 13 | { 14 | this->start_point = std::chrono::system_clock::now(); 15 | } 16 | 17 | void Timer::showDuration(std::string message) 18 | { 19 | auto end = std::chrono::system_clock::now(); 20 | std::chrono::duration fdur = end - start_point; 21 | std::cout << message << fdur.count() << " seconds" << std::endl; 22 | } 23 | 24 | std::string Timer::getCurrentTime() 25 | { 26 | // 27 | const auto now = std::chrono::system_clock::now(); 28 | const std::time_t time = std::chrono::system_clock::to_time_t(now); 29 | 30 | // std::tm tm = *std::gmtime(&time); //GMT (UTC) 31 | std::tm tm = *std::localtime(&time); //Locale time-zone, usually UTC by default. 32 | std::stringstream ss; 33 | std::string format = "UTC: %Y-%m-%d %H:%M:%S"; 34 | ss << std::put_time( &tm, format.c_str()); 35 | return ss.str(); 36 | } 37 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/util.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "util.hpp" 5 | 6 | Utils::Utils() {}; 7 | 8 | Utils::~Utils() {}; 9 | 10 | size_t Utils::split(const std::string& txt, std::vector& strs, char ch) 11 | { 12 | size_t pos = txt.find(ch); 13 | size_t initialPos = 0; 14 | strs.clear(); 15 | 16 | // Decompose statement 17 | while (pos != std::string::npos) { 18 | strs.push_back(txt.substr(initialPos, pos - initialPos)); 19 | initialPos = pos + 1; 20 | 21 | pos = txt.find(ch, initialPos); 22 | } 23 | 24 | // Add the last one 25 | strs.push_back(txt.substr(initialPos, std::min(pos, txt.size()) - initialPos + 1)); 26 | 27 | return strs.size(); 28 | } 29 | 30 | std::string Utils::pathGetUdim(const std::string path) 31 | { 32 | std::vector pathSplit; 33 | split(path, pathSplit, '.'); 34 | size_t n = pathSplit.size(); 35 | std::string& word = pathSplit[n - 2]; 36 | size_t strLen = word.length(); 37 | 38 | std::string udim = word.substr(strLen - 4); 39 | 40 | return udim; 41 | } 42 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/goz.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "image.hpp" 6 | 7 | using namespace Eigen; 8 | 9 | class GoZ { 10 | public: 11 | GoZ(); 12 | ~GoZ(); 13 | 14 | void read(std::string inputPath); 15 | void write(std::string outPath); 16 | void writeObj(std::string outPath, bool exportColor); 17 | void writePly(std::string outPath); 18 | void importVectorDisplacement(std::vector& texture_paths); 19 | void importNormalDisplacement(std::vector& texture_paths, double midValue); 20 | void importVertexColor(std::vector& texture_paths, double gamma); 21 | 22 | private: 23 | std::string name; 24 | std::vector> vertices; 25 | std::vector> vertexColor; 26 | std::vector mask; 27 | std::vector groups; 28 | std::vector> faces; 29 | std::vector>> UVs; 30 | std::vector normals; 31 | 32 | std::vector initTextures(std::vector& texture_paths); 33 | void computeVertexNormals(); 34 | void computeTangentBasis(const Vector3f& A, 35 | const Vector3f& B, 36 | const Vector3f& C, 37 | const Vector3f& H, 38 | const Vector3f& K, 39 | const Vector3f& L, 40 | Vector3f& T, 41 | Vector3f& U, 42 | Vector3f& N); 43 | }; 44 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | project(UDIMTextureImporter) 3 | 4 | set(DLL_VERSION 2.5.0) 5 | 6 | set(SOURCE_FILES 7 | ${CMAKE_SOURCE_DIR}/UDIMTextureImporterData/src/udimTextureImporter.cpp 8 | ${CMAKE_SOURCE_DIR}/UDIMTextureImporterData/src/goz.cpp 9 | ${CMAKE_SOURCE_DIR}/UDIMTextureImporterData/src/util.cpp 10 | ${CMAKE_SOURCE_DIR}/UDIMTextureImporterData/src/image.cpp 11 | ${CMAKE_SOURCE_DIR}/UDIMTextureImporterData/src/timer.cpp 12 | ${CMAKE_SOURCE_DIR}/UDIMTextureImporterData/src/logger.cpp 13 | ) 14 | 15 | set(CMAKE_CXX_STANDARD 17) 16 | 17 | if (WIN32) 18 | if (MSVC_VERSION GREATER_EQUAL "1900") 19 | include(CheckCXXCompilerFlag) 20 | CHECK_CXX_COMPILER_FLAG("/std:c++latest" _cpp_latest_flag_supported) 21 | if (_cpp_latest_flag_supported) 22 | add_compile_options("/std:c++latest") 23 | endif() 24 | endif() 25 | set(PLUGIN_SUFFIX ".dll") 26 | else() 27 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra) 28 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fvisibility=hidden") 29 | set(CMAKE_CXX_FLAGS_DEBUG "-g") 30 | set(CMAKE_CXX_FLAGS_RELEASE "-O3") 31 | set(PLUGIN_SUFFIX ".lib") 32 | set(CMAKE_SHARED_LINKER_FLAGS "-dynamiclib, -current_version ${DLL_VERSION}") 33 | set(CMAKE_MACOSX_RPATH 1) 34 | endif() 35 | 36 | if (TIFF_INSTALL_DIR) 37 | set(TIFF_INCLUDE_DIR "${TIFF_INSTALL_DIR}/include") 38 | set(TIFF_LIB_DIR "${TIFF_INSTALL_DIR}/lib") 39 | message(STATUS "Tiff include dir : ${TIFF_INCLUDE_DIR}") 40 | message(STATUS "Tiff lib dir : ${TIFF_LIB_DIR}") 41 | 42 | include_directories(${TIFF_INCLUDE_DIR}) 43 | link_directories(${TIFF_LIB_DIR}) 44 | else () 45 | find_package(TIFF) 46 | if (TIFF_FOUND) 47 | message("Tiff include dir : ${TIFF_INCLUDE_DIR}") 48 | message("Tiff libraries : ${TIFF_LIBRARIES}") 49 | include_directories(${TIFF_INCLUDE_DIR}) 50 | else () 51 | message(NOTICE "Tiff package not found. Using custom libtiff dir") 52 | if (NOT TIFF_INSTALL_DIR) 53 | message(FATAL_ERROR "Tiff install dir must be set") 54 | endif() 55 | endif () 56 | endif() 57 | 58 | set(INSTALL_DIR "../UDIMTextureImporterData") 59 | 60 | add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES}) 61 | set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ${PLUGIN_SUFFIX}) 62 | if (TIFF_FOUND) 63 | target_link_libraries(${PROJECT_NAME} PRIVATE TIFF::TIFF) 64 | else () 65 | target_link_libraries(${PROJECT_NAME} PRIVATE tiff) 66 | endif() 67 | 68 | install(TARGETS ${PROJECT_NAME} 69 | RUNTIME DESTINATION ../UDIMTextureImporterData 70 | LIBRARY DESTINATION ../UDIMTextureImporterData) 71 | 72 | set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}) 73 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/udimTextureImporter.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #define LOG( message ) { Logger::write( message ); } 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "logger.hpp" 14 | #include "goz.hpp" 15 | #include "udimTextureImporter.hpp" 16 | 17 | float EXPORT ImportUDIM(char* GoZFilePath, 18 | double midValue, 19 | char* pOptBuffer1, 20 | int optBuffer1Size, 21 | char* pOptBuffer2, 22 | int optBuffer2Size, 23 | char** zData) 24 | { 25 | std::string GoZPathStr(GoZFilePath); 26 | 27 | // If a path from zscript starts with '!:', delete them. 28 | if (GoZPathStr.c_str()[0] == '!') { 29 | GoZPathStr.erase(0, 2); 30 | } 31 | 32 | std::filesystem::path gozPath(GoZPathStr); 33 | Logger::init(gozPath.string()); 34 | 35 | // Check if GoZ file exists 36 | bool gozFileExist = std::filesystem::exists(gozPath); 37 | if (!gozFileExist) { 38 | std::string message; 39 | message = "Cannot find GoZ file : "; 40 | message.append(gozPath.string()); 41 | strncpy(pOptBuffer2, message.c_str(), static_cast(optBuffer2Size)); 42 | Logger::close(); 43 | return 1; 44 | } 45 | 46 | // Split/Convert the long texture path string to vector 47 | // pOptBuffer1 comes in this format: 48 | // "1#C:/path/image.1001.tif#C:/path/image.1002.tif#C:/path.image.1003.tif .... 49 | // The first element is the mode(1-4), and the second to the last is the texture paths. 50 | std::vector texture_paths; 51 | std::string pathString(pOptBuffer1); 52 | int pathStringLength = static_cast(pathString.length()); 53 | 54 | std::string path; 55 | for (int i = 0; i < pathStringLength; i++) { 56 | const char c = pOptBuffer1[i]; 57 | if (c == '#') { 58 | texture_paths.push_back(path); 59 | path.clear(); 60 | } else { 61 | path.push_back(c); 62 | } 63 | } 64 | 65 | // Extract the mode value, which is the first element of the texture_paths vector 66 | std::string modeStr = texture_paths[0]; 67 | int mode = std::stoi(modeStr); 68 | texture_paths.erase(texture_paths.begin()); 69 | 70 | GoZ obj; 71 | obj.read(gozPath.string()); 72 | 73 | double gamma = 1.0; 74 | 75 | if (mode == 1) { 76 | obj.importVectorDisplacement(texture_paths); 77 | } else if (mode == 2) { 78 | obj.importNormalDisplacement(texture_paths, midValue); 79 | } else if (mode == 3) { 80 | obj.importVertexColor(texture_paths, gamma); 81 | } else { 82 | strncpy(pOptBuffer2, "Invalid mode number", static_cast(optBuffer2Size)); 83 | Logger::close(); 84 | return 1; 85 | } 86 | LOG("Finished applying UDIM textures.") 87 | 88 | // Export modified GoZ file 89 | gozPath.replace_filename("UDIMImporter_from_DLL.obj"); 90 | 91 | // Disabled GoZ import until offset issue is resolved. 92 | // Using obj file format instead 93 | 94 | if (mode == 3) { 95 | // obj.writeObj(gozPath.string(), true); 96 | gozPath.replace_extension("ply"); 97 | obj.writePly(gozPath.string()); 98 | } else { 99 | obj.writeObj(gozPath.string(), false); 100 | } 101 | 102 | LOG("Done.") 103 | Logger::close(); 104 | 105 | return 0; 106 | } 107 | 108 | #ifdef _WIN32 109 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 110 | { 111 | switch (fdwReason) { 112 | case DLL_PROCESS_ATTACH: 113 | // attach to process 114 | // return FALSE to fail DLL load 115 | break; 116 | 117 | case DLL_PROCESS_DETACH: 118 | // detach from process 119 | break; 120 | 121 | case DLL_THREAD_ATTACH: 122 | // attach to thread 123 | break; 124 | 125 | case DLL_THREAD_DETACH: 126 | // detach from thread 127 | break; 128 | } 129 | return TRUE; // succesful 130 | } 131 | #endif 132 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DEPRECATED 2 | **This repository/plugin is no longer maintained. 3 | For an alternative plugin, see the new UDIMTextureImporter3 that is based on GoZ SDK.** 4 | 5 | # UDIM Texture Importer for ZBrush 6 | 7 | Import UDIM Vector/Normal displacement.
8 | This plugin may still have bugs. Be sure to sve your tool first. 9 | 10 | ![img](./img/demo.gif) 11 | 12 | Comparison between the original high res sculpt and the one re-sculpted base mesh using exported vector displacement maps. 13 | If mesh, UVs, texture maps are all correct and consistent, then the result should be almost the same as the original sculpt. 14 | ![img_compare](./img/compare.gif) 15 | 16 | There may be a few small artefacts depending on the texture border edges. 17 | ![img_compare](./img/edge.gif) 18 | 19 | ## Getting Started 20 | 21 | ### Prerequisties 22 | 23 | In addition to being a UDIM naming convention (eg. **filename.1001.tif**), **textures must meet the following requrements**. 24 | 25 | For MacOS, you must install libtiff first. `brew install libtiff` 26 | 27 | #### Vector Displacement 28 | 29 | * Tangent Vector 30 | * 32bit tiff/exr or 16bit float-point exr 31 | * Mid point 0.0 32 | * **Flip and switch: 25 (ZBrush)** 33 | * **Tangent Flip and switch: 25 (ZBrush)** 34 | * **Absolute tangent (Mudbox)** 35 | 36 | #### Normal Displacement 37 | * 32bit or 16bit float-point EXR 38 | * 8/16/32 bit tiff 39 | * Mid point can be changed between 0-1 40 | 41 | #### Color 42 | * 8bit tiff/jpg/png or 16bit tiff 43 | * **Supported but extra steps are required** 44 | * Tool loses UVs after importing color textures, so you need to restore it manually. Check the [usage](#usage) section. 45 | 46 | #### Supported tiff compression 47 | * Deflate 48 | * None 49 | * LZW 50 | 51 | ### Installation 52 | 53 | #### Windows10 & ZBrush2022 54 | 1. Go to [release page](https://github.com/minoue/UDIMTextureImporter/releases), download the latest and extract it. 55 | 2. Move `tiff.dll`, `zlib.dll`, and `libdeflate.dll` to the same directory as ZBrush.exe. (eg. `C:\Program Files\Pixologic\ZBrush 2022\tiff.dll`) 56 | 3. Move `UDIMTextureImporter_2022.zsc` to `ZPlugs64` folder. 57 | 4. Move `UDIMTextureImporterData` to `ZPlugs64` folder. 58 | 59 | ``` 60 | ZStartup/ 61 | ├─ ZPlugs64/ 62 | │ ├─ UDIMTextureImporterData/ 63 | │ │ ├─ ZFileUtils/ 64 | │ │ │ ├─ ZFileUtils.dll 65 | │ │ ├─ UDIMTextureImporter.dll 66 | │ ├─ UDIMTextureImporter_2022.zsc 67 | ``` 68 | 69 | #### MacOS & ZBrush2022 70 | -- 71 | 72 | ## Usage 73 | Go to `ZPlugin` -> `UDIM Texture Importer`, and select the texture type you want to import. 74 | 75 | “” 76 | 77 | ### Displacement 78 | 79 | ### Color 80 | Tool loses UVs after importing color textures because of technical limitation, so you need to restore it manually. 81 | 82 | 1. Switch to the lowest subdiv. 83 | 2. Export obj as UV backup. 84 | 3. Switch to the highest subdiv. 85 | 4. Import color textures. 86 | 5. Switch to the lowest subdiv. 87 | 6. Import the obj file to restore UVs. 88 | 89 | ## Build Instruction 90 | 91 | ### Requirements 92 | 93 | * C++17 94 | * [libtiff](http://www.libtiff.org) 95 | * [zlib](https://www.zlib.net/) (optional for libtiff) 96 | * [libdeflate](https://github.com/ebiggers/libdeflate) (optional for libtiff) 97 | 98 | For MacOS, you can use homebrew: `brew install libtiff` 99 | 100 | For Windows, you may use a package manager such as Chocolatey or build from source code. 101 | 102 | ### How to build 103 | 104 | ```sh 105 | git clone https://github.com/minoue/UDIMTextureImporter 106 | cd UDIMTextureImporter 107 | git submodule update --init --recursive 108 | mkdir build 109 | cd build 110 | cmake -DCMAKE_BUILD_TYPE=Release ../ 111 | cmake --build . --config Release --target install 112 | ``` 113 | 114 | ## License 115 | [GPLv3](./LICENSE) 116 | 117 | ## Contact 118 | 119 | `michitaka.inoue at icloud.com` 120 | 121 | 122 | ## Credits 123 | This software uses the following libraries. 124 | 125 | [tinyexr](https://github.com/syoyo/tinyexr) / The 3-Clause BSD License / Shoyo Fujita
126 | [libtiff](http://www.libtiff.org) / LibTIFF license / Copyright © 1988-1997 Sam Leffler / Copyright © 1991-1997 Silicon Graphics, Inc.
127 | [zlib](https://www.zlib.net) / zlib License / © Jean-loup Gailly, Mark Adler
128 | [libdeflate](https://github.com/ebiggers/libdeflate) / MIT License / ©ebiggers
129 | [FromZ](https://github.com/n-taka/FromZ) / GPLv3 / © Kazutaka Nakashima
130 | [Eigen](https://eigen.tuxfamily.org/) / MPL2
131 | [stb_image](https://github.com/nothings/stb) / [MIT License](https://github.com/nothings/stb/blob/master/LICENSE) / © 2017 Sean Barrett
132 | 133 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/image.cpp: -------------------------------------------------------------------------------- 1 | #define TINYEXR_IMPLEMENTATION 2 | #define STB_IMAGE_IMPLEMENTATION 3 | #define LOG( message ) { Logger::write( message ); } 4 | 5 | #include 6 | #include 7 | 8 | #include "stb_image.h" 9 | #include "image.hpp" 10 | #include "util.hpp" 11 | #include "logger.hpp" 12 | 13 | #pragma warning(push, 0) 14 | #include "tinyexr.h" 15 | #pragma warning(pop) 16 | 17 | Image::Image() {}; 18 | 19 | Image::Image(std::string path) 20 | { 21 | read(path); 22 | this->isEmpty = false; 23 | } 24 | 25 | Image::~Image() {}; 26 | 27 | void Image::read(const std::string path) 28 | { 29 | 30 | std::filesystem::path p = path; 31 | auto ext = p.extension(); 32 | 33 | if (ext == ".exr") { 34 | loadExr(path); 35 | } else if (ext == ".tif" || ext == ".tiff") { 36 | loadTif(path); 37 | } else if (ext == ".png" || ext == ".jpg" || ext == ".jpeg") { 38 | loadImg(path); 39 | } else { 40 | std::cout << "Not supported images" << std::endl; 41 | exit(EXIT_FAILURE); 42 | } 43 | } 44 | 45 | void Image::loadImg(const std::string& path) 46 | { 47 | int& width = this->width; 48 | int& height = this->height; 49 | int& nchannels = this->nchannels; 50 | 51 | unsigned char *data = stbi_load(path.c_str(), &width, &height, &nchannels, 3); 52 | 53 | LOG("Loading img : " + path); 54 | 55 | size_t img_size = static_cast(width * height * nchannels); 56 | 57 | this->pixels.resize(img_size); 58 | 59 | if (data != NULL) { 60 | for (size_t i=0; ipixels[i] = float_value; 64 | } 65 | } else { 66 | stbi_image_free(data); 67 | std::cout << "err image loading img" << std::endl; 68 | exit(EXIT_FAILURE); 69 | } 70 | stbi_image_free(data); 71 | } 72 | 73 | void Image::loadExr(const std::string& path) 74 | { 75 | int& width = this->width; 76 | int& height = this->height; 77 | int& nchannels = this->nchannels; 78 | nchannels = 4; 79 | 80 | LOG("Loading exr : " + path); 81 | float* out; 82 | const char* err = nullptr; 83 | 84 | int ret = LoadEXR(&out, &width, &height, path.c_str(), &err); 85 | if (ret != TINYEXR_SUCCESS) { 86 | if (err) { 87 | fprintf(stderr, "ERR : %s\n", err); 88 | FreeEXRErrorMessage(err); // release memory of error message. 89 | exit(EXIT_FAILURE); 90 | } 91 | } else { 92 | int size = width * height * nchannels; 93 | this->pixels.resize(static_cast(size)); 94 | for (int i = 0; i < size; i++) { 95 | float x = out[i]; 96 | this->pixels[static_cast(i)] = x; 97 | } 98 | 99 | free(out); // release memory of image data 100 | } 101 | } 102 | 103 | void Image::loadTif(const std::string& path) 104 | { 105 | uint32_t width, height; 106 | uint16_t nc, bitDepth, row; 107 | 108 | LOG("Loading tif : " + path); 109 | 110 | TIFF* tif = TIFFOpen(path.c_str(), "r"); 111 | 112 | if (tif) { 113 | TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height); 114 | TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width); 115 | TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &nc); 116 | TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitDepth); 117 | TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &row); 118 | 119 | this->nchannels = static_cast(nc); 120 | this->width = static_cast(width); 121 | this->height = static_cast(height); 122 | 123 | uint32_t npixels = width * height; 124 | uint32_t img_size = npixels * nc; 125 | 126 | // Initialize iamge pixel array 127 | this->pixels.resize(img_size); 128 | std::fill(this->pixels.begin(), this->pixels.end(), 0.0f); 129 | 130 | if (row == 1 && bitDepth == 8) { 131 | // Use TIFFReadRGBAImage function instead of scanline 132 | // Tif images from certain softwares such as 3dcoat need to be processed 133 | // in this way. This is maybe because Rows/Strip is 1, but not sure. 134 | // 135 | uint32_t* raster = (uint32_t*)_TIFFmalloc(npixels * sizeof(uint32_t)); 136 | if (raster == NULL) { 137 | std::cout << "err1" << std::endl; 138 | } else { 139 | if (TIFFReadRGBAImage(tif, width, height, raster, 0)) { 140 | for (uint32_t y=0; ypixels[targetNum * nc + 0] = r; 159 | this->pixels[targetNum * nc + 1] = g; 160 | this->pixels[targetNum * nc + 2] = b; 161 | this->pixels[targetNum * nc + 3] = a; 162 | } 163 | } 164 | } else { 165 | std::cout << "err2" << std::endl; 166 | } 167 | _TIFFfree(raster); 168 | } 169 | } else { 170 | // For most standart tiff images 171 | // 172 | tdata_t buf = _TIFFmalloc(TIFFScanlineSize(tif)); 173 | 174 | for (uint32_t row = 0; row < height; row++) { 175 | TIFFReadScanline(tif, buf, row); 176 | for (uint32_t col = 0; col < width; col++) { 177 | float r, g, b; 178 | if (bitDepth == 32) { 179 | r = static_cast(buf)[col * nc + 0]; 180 | g = static_cast(buf)[col * nc + 1]; 181 | b = static_cast(buf)[col * nc + 2]; 182 | } else if (bitDepth == 16) { 183 | uint16_t R = static_cast(buf)[col * nc + 0]; 184 | uint16_t G = static_cast(buf)[col * nc + 1]; 185 | uint16_t B = static_cast(buf)[col * nc + 2]; 186 | r = static_cast(R) / static_cast(65535.0); 187 | g = static_cast(G) / static_cast(65535.0); 188 | b = static_cast(B) / static_cast(65535.0); 189 | } else { 190 | uint16_t R = static_cast(buf)[col * nc + 0]; 191 | uint16_t G = static_cast(buf)[col * nc + 1]; 192 | uint16_t B = static_cast(buf)[col * nc + 2]; 193 | r = static_cast(R) / static_cast(255.0); 194 | g = static_cast(G) / static_cast(255.0); 195 | b = static_cast(B) / static_cast(255.0); 196 | } 197 | size_t targetNum = (col + (width * row)) * nc; 198 | this->pixels[targetNum + 0] = r; 199 | this->pixels[targetNum + 1] = g; 200 | this->pixels[targetNum + 2] = b; 201 | } 202 | } 203 | _TIFFfree(buf); 204 | } 205 | TIFFClose(tif); 206 | } else { 207 | std::cout << "err" << std::endl; 208 | exit(EXIT_FAILURE); 209 | } 210 | } 211 | 212 | size_t ImageUtils::get_udim(const float u, const float v) 213 | { 214 | size_t U = static_cast(ceil(u)); 215 | size_t V = static_cast(floor(v)) * 10; 216 | return U + V; 217 | } 218 | 219 | Vector2f ImageUtils::localize_uv(const float& u, const float& v) 220 | { 221 | float u_local = u - floor(u); 222 | float v_local = v - floor(v); 223 | Vector2f uv(u_local, v_local); 224 | return uv; 225 | } 226 | 227 | Vector3f ImageUtils::get_pixel_values(const float u, const float v, const std::vector& texture, const int width, const int height, const int nchannel) 228 | { 229 | // Get pixel values by bilinear filtering 230 | 231 | float float_width = static_cast(width); 232 | float float_height = static_cast(height); 233 | 234 | int x1 = static_cast(std::round(float_width * u)); 235 | int x2 = x1 + 1; 236 | int y1 = static_cast(std::round(float_height * (1 - v))); 237 | int y2 = y1 + 1; 238 | 239 | size_t target_pixel1 = static_cast(((width * (y1 - 1) + x1) - 1) * nchannel); 240 | size_t target_pixel2 = static_cast(((width * (y1 - 1) + x2) - 1) * nchannel); 241 | size_t target_pixel3 = static_cast(((width * (y2 - 1) + x1) - 1) * nchannel); 242 | size_t target_pixel4 = static_cast(((width * (y2 - 1) + x2) - 1) * nchannel); 243 | 244 | Vector3f A; 245 | A << texture[target_pixel1], texture[target_pixel1 + 1], texture[target_pixel1 + 2]; 246 | Vector3f B; 247 | B << texture[target_pixel2], texture[target_pixel2 + 1], texture[target_pixel2 + 2]; 248 | Vector3f C; 249 | C << texture[target_pixel3], texture[target_pixel3 + 1], texture[target_pixel3 + 2]; 250 | Vector3f D; 251 | D << texture[target_pixel4], texture[target_pixel4 + 1], texture[target_pixel4 + 2]; 252 | 253 | float u1 = (static_cast(x1) - 0.5f) / float_width; 254 | float u2 = (static_cast(x2) - 0.5f) / float_width; 255 | float v1 = (static_cast(y1) - 0.5f) / float_height; 256 | float v2 = (static_cast(y2) - 0.5f) / float_height; 257 | 258 | Vector3f E = ((u2 - u) / (u2 - u1)) * A + ((u - u1) / (u2 - u1)) * B; 259 | Vector3f F = ((u2 - u) / (u2 - u1)) * C + ((u - u1) / (u2 - u1)) * D; 260 | Vector3f G = ((v2 - (1 - v)) / (v2 - v1)) * E + (((1 - v) - v1) / (v2 - v1)) * F; 261 | 262 | return G; 263 | } 264 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/UDIMTextureImporter_2022.txt: -------------------------------------------------------------------------------- 1 | // GUI version 2.3.7 2 | 3 | [VarDef, dllPath,""] //path to dll 4 | [VarDef, err, 0] //standard error 5 | [VarDef, fileName, ""] 6 | [VarDef, udimPluginPath, ""] 7 | [VarDef, dllLog, ""] 8 | [VarDef, layerPath, ""] 9 | [VarDef, subtoolNameOrig, ""] 10 | [VarDef, currentSubdiv, 0] 11 | 12 | [VarDef, GoZPathToDLL, ""] 13 | [VarDef, objPathFromDLL, ""] 14 | [VarDef, plyPathFromDLL, ""] 15 | [VarDef, objPathUV, ""] 16 | [VarDef, Gamma, 1.0] 17 | [VarDef, midValue, 0.0] 18 | 19 | // Import model 20 | // 0 : Disabled 21 | // 1 : Vector Displacement 22 | // 2 : Normal 23 | // 3 : Color 24 | [VarDef, mode, 1] 25 | 26 | 27 | [RoutineDef, CheckSystem, 28 | // Get zbrush version 29 | 30 | [VarSet, isMac, [ZBrushInfo, 6]] // check Mac or PC 31 | // Make sure we have the dll and set its path 32 | 33 | [VarSet, GoZPathToDLL, [FileNameResolvePath, "ZPUBLIC_Temp/UDIMImporter_to_DLL.GoZ"]] 34 | [VarSet, objPathFromDLL, [FileNameResolvePath, "ZPUBLIC_Temp/UDIMImporter_from_DLL.obj"]] 35 | [VarSet, plyPathFromDLL, [FileNameResolvePath, "ZPUBLIC_Temp/UDIMImporter_from_DLL.ply"]] 36 | 37 | [If, isMac, 38 | // For release 39 | [VarSet, dllPath, "ZBRUSH_ZSTARTUP/ZPlugs64/UDIMTextureImporterData/ZFileUtils/ZFileUtils.lib"] 40 | [VarSet, udimPluginPath, "ZBRUSH_ZSTARTUP/ZPlugs64/UDIMTextureImporterData/UDIMTextureImporter.lib"] 41 | 42 | , // else, Windows 43 | [VarSet, dllPath, "ZBRUSH_ZSTARTUP\ZPlugs64\UDIMTextureImporterData\ZFileUtils\ZFileUtils64.dll"] 44 | [VarSet, udimPluginPath, "ZBRUSH_ZSTARTUP\ZPlugs64\UDIMTextureImporterData\UDIMTextureImporter.dll"] 45 | ] 46 | 47 | // Check ZFileUtils 48 | [If, [FileExists, [Var,dllPath]], 49 | //check that correct version 50 | [VarSet, dllVersion, [FileExecute, [Var,dllPath], Version]] 51 | [If, [Val,dllVersion] >= 1.0, //dll version 52 | //OK 53 | ,//else earlier version 54 | [Note,"\Cff9923Note :\Cc0c0c0 The \Cff9923 ZFileUtils plugin DLL is an earlier version which does not support this plugin. Please install correct version."] 55 | [Exit] 56 | ] 57 | , // else no DLL. 58 | [Note,"\Cff9923Note :\Cc0c0c0 The \Cff9923 ZFileUtils plugin \CffffffDLL\Cc0c0c0 could not be found at the correct location. Please re-install the plugin, making sure the relevant files and folders are in the \CffffffZStartup/ZPlugs\Cc0c0c0 folder."] 59 | [Exit] 60 | ] 61 | 62 | // Check displacementImporter plugin 63 | [If, [FileExists, [Var, udimPluginPath]], 64 | 65 | // If exists, good. do nothing 66 | 67 | , // else no DLL. 68 | [Note,"\Cff9923Note :\Cc0c0c0 The \Cff9923 DisplacementImporter plugin \CffffffDLL\Cc0c0c0 could not be found at the correct location. Please re-install the plugin, making sure the relevant files and folders are in the \CffffffZStartup/ZPlugs\Cc0c0c0 folder."] 69 | [Exit] 70 | ] 71 | ]//end routine 72 | 73 | 74 | //call routine here to ensure it's called every time plugin loaded 75 | [RoutineCall, CheckSystem] 76 | 77 | 78 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 79 | // ~~~ INTERFACE 80 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 81 | 82 | 83 | [ISubPalette,"ZPlugin:UDIM Texture Importer"] 84 | 85 | 86 | [ISwitch, 87 | "ZPlugin:UDIM Texture Importer:Vector Displacement", 88 | 1, 89 | "Switch 1", 90 | // on command 91 | [IUnPress, "ZPlugin:UDIM Texture Importer:Normal Displacement"] 92 | [IUnPress, "ZPlugin:UDIM Texture Importer:Vertex Color"] 93 | [VarSet, mode, 1] 94 | , 95 | // off command 96 | [VarSet, mode, 0] 97 | , 98 | 0, // Initially disabled? 99 | 150, // Width 100 | 25, // Height 101 | ] 102 | [IEnable, "ZPlugin:UDIM Texture Importer:Vector Displacement"] 103 | 104 | [ISwitch, 105 | "ZPlugin:UDIM Texture Importer:Normal Displacement", 106 | 0, 107 | "Switch 1", 108 | // on command 109 | [IUnPress, "ZPlugin:UDIM Texture Importer:Vector Displacement"] 110 | [IUnPress, "ZPlugin:UDIM Texture Importer:Vertex Color"] 111 | [VarSet, mode, 2] 112 | , 113 | // off command 114 | [VarSet, mode, 0] 115 | , 116 | 0, // Initially disabled? 117 | 150, // Width 118 | 25, // Height 119 | ] 120 | [IEnable, "ZPlugin:UDIM Texture Importer:Normal Displacement"] 121 | 122 | [ISwitch, 123 | "ZPlugin:UDIM Texture Importer:Vertex Color", 124 | 0, 125 | "Switch 1", 126 | // on command 127 | [IUnPress, "ZPlugin:UDIM Texture Importer:Vector Displacement"] 128 | [IUnPress, "ZPlugin:UDIM Texture Importer:Normal Displacement"] 129 | [VarSet, mode, 3] 130 | , 131 | // off command 132 | [VarSet, mode, 0] 133 | , 134 | 1, // Initially disabled? 135 | 150, // Width 136 | 25, // Height 137 | ] 138 | [IEnable, "ZPlugin:UDIM Texture Importer:Vertex Color"] 139 | 140 | 141 | [ISlider, 142 | "ZPlugin:UDIM Texture Importer:Mid Value", 143 | 0, // initial value 144 | 0.1, // Resolution 145 | 0, // Min value 146 | 1.0, // Max value 147 | , // Info text 148 | [VarSet, midValue, [IGet, "ZPlugin:UDIM Texture Importer:Mid Value"]], // Command group 149 | 0, 150 | 150, 151 | 0 152 | ] 153 | [IEnable, "ZPlugin:UDIM Texture Importer:Mid Value"] 154 | 155 | [IButton, 156 | "ZPlugin:UDIM Texture Importer:Import UDIM Textures", // Button name 157 | "Import UDIM Textures", // Popup info text 158 | 159 | [If, mode == 0, 160 | [Note, "Select Import mode. Aborted"] 161 | [Exit] 162 | , 163 | ] 164 | 165 | // Import textures 166 | [VarDef, dialogTitle, "Please select image files"] 167 | [VarSet, fileExt, "tif,tiff,exr,png,jpg,jpeg"] 168 | [MemCreate, ZFileUTils_FileExt, 256, 0] 169 | [MemWriteString, ZFileUTils_FileExt, fileExt, 0] 170 | [VarSet, fileCount, [FileExecute, [Var,dllPath], "GetFilesDialog", #dialogTitle, , ZFileUTils_FileExt]] 171 | 172 | [if, fileCount == 0, 173 | [Note, "No textures are selected. Aborted."] 174 | [MemDelete, ZFileUTils_FileExt] 175 | [Exit] 176 | , 177 | ] 178 | 179 | // Cleanup 180 | [MemDelete, ZFileUTils_FileExt] 181 | 182 | // Store orig tool name 183 | [VarSet, subtoolNameOrig, [IGetTitle,Tool:ItemInfo]] 184 | 185 | // Save original UV data 186 | // Return obj file has no UVs so needs to export/import UV mesh to 187 | // update UVs at the end of the process 188 | [VarSet, objPathUV, [FileNameResolvePath, [StrMerge, "ZPUBLIC_Temp/", subtoolNameOrig, "obj"]]] 189 | [VarSet, currentSubdiv, [IGet, Tool:Geometry:SDiv]] 190 | [ISet,Tool:Geometry:SDiv,1] 191 | [FileNameSetNext, objPathUV] 192 | [IPress, Tool:Export] 193 | [ISet,Tool:Geometry:SDiv, [Var, currentSubdiv]] 194 | 195 | // Create new layer for displacement 196 | // no layer needed for color 197 | [If, mode != 3, 198 | [IPress, Tool:Layers:New] 199 | [IPress, Tool:Layers:Rename] 200 | [VarSet, layerPath, [StrMerge,"Tool:Layers:", [IGetTitle, "Tool:Layers:Layer Intensity"]]] 201 | , // else, do nothing 202 | ] 203 | 204 | // Export GoZ file 205 | [FileNameSetNext, GoZPathToDLL] 206 | [IPress, Tool:Export] 207 | 208 | [if, fileCount > 0, 209 | [MemCreate, memTexturePaths, 256, 0] // to store single texture path 210 | [MemCreate, memOutputPaths, 32768, 0] 211 | [MemCreate, memDllLog, 256, 0] 212 | 213 | [VarSet, index, 1] 214 | [VarSet, offset, 0] 215 | 216 | [MemWriteString, memOutputPaths, [StrMerge, mode, "#"], offset] 217 | [VarInc, offset] 218 | [VarInc, offset] 219 | 220 | [Loop, fileCount, 221 | [VarSet, err, [FileExecute, [Var, dllPath], GetFilePath, , index, memTexturePaths]] 222 | [VarInc, index] 223 | [if, err == 0, 224 | [MemReadString, memTexturePaths, fileName] 225 | 226 | // Append texture path with "#" at the end of memOutputPaths 227 | [MemWriteString, memOutputPaths, [StrMerge, fileName, "#"], offset] 228 | [VarSet, offset, offset + [StrLength, fileName] + 1] 229 | , 230 | [LoopContinue] 231 | ] 232 | ] // End loop 233 | 234 | [VarSet, err, [FileExecute, 235 | [Var, udimPluginPath], 236 | "ImportUDIM", 237 | GoZPathToDLL, 238 | midValue, 239 | memOutputPaths, 240 | memDllLog]] 241 | [If, err, 242 | [Note, "Failed to run the command in DLL."] 243 | [MemReadString, memDllLog, dllLog] 244 | [Note, [Var, dllLog]] 245 | [MemDelete, memTexturePaths] 246 | [MemDelete, memOutputPaths] 247 | [MemDelete, memDllLog] 248 | [Exit] 249 | , 250 | ] 251 | 252 | [MemDelete, memTexturePaths] 253 | [MemDelete, memOutputPaths] 254 | [MemDelete, memDllLog] 255 | 256 | ] // End if fileCount 257 | 258 | [If, mode == 3, 259 | // Import color 260 | [If, [FileExists, plyPathFromDLL], 261 | [FileNameSetNext, plyPathFromDLL] 262 | [IPress,Tool:Import] 263 | , // else 264 | [Note, "ply file not found." , , 2] 265 | [Exit] 266 | ] 267 | , // else, import displacement 268 | [If, [FileExists, objPathFromDLL], 269 | [FileNameSetNext, objPathFromDLL] 270 | [IPress,Tool:Import] 271 | , // else 272 | [Note, "obj file not found." , , 2] 273 | [Exit] 274 | ] 275 | ] 276 | 277 | // Restore UVs 278 | [If, mode != 3, 279 | [ISet, [Var, layerPath] ,1] 280 | [ISet, [Var, layerPath] ,0] 281 | , 282 | ] 283 | 284 | [ISet,Tool:Geometry:SDiv,1] 285 | [FileNameSetNext, objPathUV] 286 | [IPress,Tool:Import] 287 | [ISet,Tool:Geometry:SDiv, [Var, currentSubdiv]] 288 | 289 | [If, mode != 3, 290 | [ISet, [Var, layerPath] ,0] 291 | [ISet, [Var, layerPath] ,1] 292 | , 293 | ] 294 | 295 | [MessageOK, "Done"], 296 | 297 | 0, // Initially Disabled? (0: enabled) 298 | 1, // Button width in pixels, 299 | , // optional button icon 300 | , 301 | 36 // height 302 | ]//end button 303 | -------------------------------------------------------------------------------- /UDIMTextureImporterData/src/goz.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #define LOG( message ) { Logger::write( message ); } 3 | 4 | #include 5 | 6 | #pragma warning(push, 0) 7 | #include "FromZ/src/readGoZFile.h" 8 | #include "FromZ/src/writeGoZFile.h" 9 | #pragma warning(pop) 10 | 11 | #include "goz.hpp" 12 | #include "timer.hpp" 13 | #include "util.hpp" 14 | #include "logger.hpp" 15 | 16 | GoZ::GoZ() {}; 17 | 18 | GoZ::~GoZ() {}; 19 | 20 | void GoZ::read(std::string inputPath) 21 | { 22 | std::cout << "Reading GoZ File..." << std::endl; 23 | FromZ::readGoZFile(inputPath, name, vertices, faces, UVs, vertexColor, mask, groups); 24 | 25 | std::cout << "Initializing Vertex Normals..." << std::endl; 26 | computeVertexNormals(); 27 | } 28 | 29 | void GoZ::write(std::string outPath) 30 | { 31 | FromZ::writeGoZFile(outPath, name, vertices, faces, UVs, vertexColor, mask, groups); 32 | } 33 | 34 | void GoZ::computeVertexNormals() 35 | { 36 | LOG("calculating vertex normal.") 37 | 38 | Timer timer; 39 | timer.start(); 40 | 41 | this->normals.resize(this->vertices.size()); 42 | Vector3f zeroVec(0, 0, 0); 43 | std::fill(normals.begin(), normals.end(), zeroVec); 44 | 45 | // Set vertex normals 46 | size_t numFaces = this->faces.size(); 47 | for (size_t i = 0; i < numFaces; i++) { 48 | std::vector& faceVertices = this->faces[i]; 49 | 50 | size_t numFaceVertices = faceVertices.size(); 51 | 52 | for (size_t j = 0; j < numFaceVertices; j++) { 53 | 54 | int currentVertexID, nextVertexID, nextNextVertexID; 55 | 56 | if (numFaceVertices - j == 2) { 57 | // One before the last 58 | currentVertexID = faceVertices[j]; 59 | nextVertexID = faceVertices[j + 1]; 60 | nextNextVertexID = faceVertices[0]; 61 | } else if (numFaceVertices - j == 1) { 62 | // last 63 | currentVertexID = faceVertices[j]; 64 | nextVertexID = faceVertices[0]; 65 | nextNextVertexID = faceVertices[1]; 66 | } else { 67 | currentVertexID = faceVertices[j]; 68 | nextVertexID = faceVertices[j + 1]; 69 | nextNextVertexID = faceVertices[j + 2]; 70 | } 71 | 72 | std::vector& p0 = this->vertices[static_cast(currentVertexID)]; 73 | std::vector& p1 = this->vertices[static_cast(nextVertexID)]; 74 | std::vector& p2 = this->vertices[static_cast(nextNextVertexID)]; 75 | 76 | Vector3f P0(p0.data()); 77 | Vector3f P1(p1.data()); 78 | Vector3f P2(p2.data()); 79 | 80 | // Re-calculate Normals 81 | Vector3f E1 = P1 - P0; 82 | Vector3f E2 = P2 - P0; 83 | Vector3f faceNormal = E1.cross(E2); 84 | 85 | this->normals[static_cast(currentVertexID)] += faceNormal; 86 | } 87 | } 88 | for (auto& n : this->normals) { 89 | n.normalize(); 90 | } 91 | 92 | LOG("calculated vertex normal sucessfully.") 93 | timer.showDuration("Vertex normal calculated in "); 94 | } 95 | 96 | // https://stackoverflow.com/questions/5255806/how-to-calculate-tangent-and-binorma 97 | void GoZ::computeTangentBasis(const Vector3f& A, 98 | const Vector3f& B, 99 | const Vector3f& C, 100 | const Vector3f& H, 101 | const Vector3f& K, 102 | const Vector3f& L, 103 | Vector3f& T, 104 | Vector3f& U, 105 | Vector3f& N) 106 | { 107 | 108 | Vector3f D = B - A; 109 | Vector3f E = C - A; 110 | Vector3f F = K - H; 111 | Vector3f G = L - H; 112 | 113 | MatrixXf DE(2, 3); 114 | DE << D.x(), D.y(), D.z(), 115 | E.x(), E.y(), E.z(); 116 | 117 | Matrix2f FG; 118 | FG << F.x(), F.y(), 119 | G.x(), G.y(); 120 | 121 | MatrixXf result(2, 3); 122 | result = FG.inverse() * DE; 123 | 124 | Vector3f new_T = result.row(0); 125 | new_T -= N * new_T.dot(N); 126 | new_T.normalize(); 127 | Vector3f bitangent = N.cross(new_T); 128 | 129 | T = new_T; 130 | U = bitangent.normalized(); 131 | } 132 | 133 | std::vector GoZ::initTextures(std::vector& texture_paths) 134 | { 135 | 136 | Timer timer; 137 | timer.start(); 138 | 139 | // Find out the last number of the UDIM images 140 | int max_udim = 0; 141 | for (auto& path : texture_paths) { 142 | std::string texture_udim = Utils::pathGetUdim(path); 143 | int udim = std::stoi(texture_udim) - 1000; 144 | if (udim > max_udim) { 145 | max_udim = udim; 146 | } 147 | } 148 | 149 | // Init texture data by the number of udim textures 150 | std::vector textures; 151 | textures.resize(static_cast(max_udim)); 152 | for (auto& path : texture_paths) { 153 | Image img(path); 154 | std::string texture_udim = Utils::pathGetUdim(path); 155 | int udim = stoi(texture_udim) - 1000; 156 | textures[static_cast(udim - 1)] = img; 157 | } 158 | 159 | timer.showDuration("Finished loading textures in "); 160 | 161 | return textures; 162 | } 163 | 164 | void GoZ::importVectorDisplacement(std::vector& texture_paths) 165 | { 166 | LOG("Applying Vector Displacement.") 167 | 168 | Timer timer; 169 | timer.start(); 170 | 171 | std::vector textures = initTextures(texture_paths); 172 | 173 | // Vector Displacement 174 | std::vector> outVertices = this->vertices; 175 | 176 | size_t numFaces = this->faces.size(); 177 | for (size_t i = 0; i < numFaces; i++) { 178 | std::vector& faceVertices = this->faces[i]; 179 | std::vector>& faceUVs = this->UVs[i]; 180 | 181 | size_t numFaceVertices = faceVertices.size(); 182 | 183 | for (size_t j = 0; j < numFaceVertices; j++) { 184 | 185 | int currentVertexID, nextVertexID, nextNextVertexID; 186 | Vector3f uv0; 187 | Vector3f uv1; 188 | Vector3f uv2; 189 | 190 | if (numFaceVertices - j == 2) { 191 | // One before the last 192 | currentVertexID = faceVertices[j]; 193 | nextVertexID = faceVertices[j + 1]; 194 | nextNextVertexID = faceVertices[0]; 195 | uv0 << faceUVs[j].first, faceUVs[j].second, 0.0; 196 | uv1 << faceUVs[j + 1].first, faceUVs[j + 1].second, 0.0; 197 | uv2 << faceUVs[0].first, faceUVs[0].second, 0.0; 198 | } else if (numFaceVertices - j == 1) { 199 | // last 200 | currentVertexID = faceVertices[j]; 201 | nextVertexID = faceVertices[0]; 202 | nextNextVertexID = faceVertices[1]; 203 | uv0 << faceUVs[j].first, faceUVs[j].second, 0.0; 204 | uv1 << faceUVs[0].first, faceUVs[0].second, 0.0; 205 | uv2 << faceUVs[1].first, faceUVs[1].second, 0.0; 206 | } else { 207 | currentVertexID = faceVertices[j]; 208 | nextVertexID = faceVertices[j + 1]; 209 | nextNextVertexID = faceVertices[j + 2]; 210 | uv0 << faceUVs[j].first, faceUVs[j].second, 0.0; 211 | uv1 << faceUVs[j + 1].first, faceUVs[j + 1].second, 0.0; 212 | uv2 << faceUVs[j + 2].first, faceUVs[j + 2].second, 0.0; 213 | } 214 | 215 | std::vector& p0 = this->vertices[static_cast(currentVertexID)]; 216 | std::vector& p1 = this->vertices[static_cast(nextVertexID)]; 217 | std::vector& p2 = this->vertices[static_cast(nextNextVertexID)]; 218 | 219 | Vector3f P0(p0.data()); 220 | Vector3f P1(p1.data()); 221 | Vector3f P2(p2.data()); 222 | 223 | Vector3f T, B, N; 224 | N = this->normals[static_cast(currentVertexID)]; 225 | N.normalize(); 226 | 227 | computeTangentBasis(P0, P1, P2, uv0, uv1, uv2, T, B, N); 228 | 229 | Matrix3f mat; 230 | mat << T.x(), T.y(), T.z(), 231 | N.x(), N.y(), N.z(), 232 | B.x(), B.y(), B.z(); 233 | 234 | float u = uv0.x(); 235 | float v = uv0.y(); 236 | 237 | size_t udim = ImageUtils::get_udim(u, v); 238 | 239 | if (udim > textures.size()) { 240 | // If UVs are outside of the given UDIM range, use same point 241 | continue; 242 | } 243 | 244 | Image& img = textures[udim - 1]; 245 | 246 | if (!img.isEmpty) { 247 | Vector2f local_uv = ImageUtils::localize_uv(u, v); 248 | Vector3f rgb = ImageUtils::get_pixel_values( 249 | local_uv.x(), 250 | local_uv.y(), 251 | img.pixels, 252 | img.width, 253 | img.height, 254 | img.nchannels); 255 | Vector3f displace = rgb.transpose() * mat; 256 | Vector3f new_pp = P0 + displace; 257 | std::vector xyz = { new_pp.x(), new_pp.y(), new_pp.z() }; 258 | outVertices[static_cast(currentVertexID)] = xyz; 259 | } 260 | } 261 | } 262 | this->vertices = outVertices; 263 | 264 | timer.showDuration("Finished Vector Displacement in "); 265 | LOG("Finished Apllying Vector Displacement.") 266 | } 267 | 268 | void GoZ::importNormalDisplacement(std::vector& texture_paths, double midValue) 269 | { 270 | LOG("Applying Normal Displacement.") 271 | 272 | Timer timer; 273 | timer.start(); 274 | 275 | std::cout << "Mid value : " << midValue << std::endl; 276 | 277 | std::vector textures = initTextures(texture_paths); 278 | 279 | std::vector> outVertices = this->vertices; 280 | 281 | size_t numFaces = this->faces.size(); 282 | for (size_t i = 0; i < numFaces; i++) { 283 | std::vector& faceVertices = this->faces[i]; 284 | std::vector>& faceUVs = this->UVs[i]; 285 | 286 | size_t numFaceVertices = faceVertices.size(); 287 | 288 | for (size_t j = 0; j < numFaceVertices; j++) { 289 | 290 | int vertexID = faceVertices[j]; 291 | std::vector& P = this->vertices[static_cast(vertexID)]; 292 | 293 | Vector3f uv; 294 | uv << faceUVs[j].first, faceUVs[j].second, 0.0; 295 | 296 | Vector3f P0(P.data()); 297 | 298 | Vector3f N; 299 | N = this->normals[static_cast(vertexID)]; 300 | N.normalize(); 301 | 302 | float u = uv.x(); 303 | float v = uv.y(); 304 | 305 | size_t udim = ImageUtils::get_udim(u, v); 306 | 307 | if (udim > textures.size()) { 308 | // If UVs are outside of the given UDIM range, use same point 309 | continue; 310 | } 311 | 312 | Image& img = textures[udim - 1]; 313 | 314 | if (!img.isEmpty) { 315 | Vector2f local_uv = ImageUtils::localize_uv(u, v); 316 | Vector3f rgb = ImageUtils::get_pixel_values( 317 | local_uv.x(), 318 | local_uv.y(), 319 | img.pixels, 320 | img.width, 321 | img.height, 322 | img.nchannels); 323 | Vector3f new_pp = P0 + (N * (rgb.x() - midValue)); 324 | std::vector xyz = { new_pp.x(), new_pp.y(), new_pp.z() }; 325 | outVertices[static_cast(vertexID)] = xyz; 326 | } 327 | } 328 | } 329 | this->vertices = outVertices; 330 | 331 | timer.showDuration("Finished Normal Displacement in "); 332 | LOG("Finished Apllying Normal Displacement.") 333 | } 334 | 335 | void GoZ::importVertexColor(std::vector& texture_paths, double gamma) 336 | { 337 | 338 | Timer timer; 339 | timer.start(); 340 | 341 | std::vector textures = initTextures(texture_paths); 342 | 343 | size_t numFaces = this->faces.size(); 344 | for (size_t i = 0; i < numFaces; i++) { 345 | std::vector& faceVertices = this->faces[i]; 346 | std::vector>& faceUVs = this->UVs[i]; 347 | 348 | size_t numFaceVertices = faceVertices.size(); 349 | 350 | for (size_t j = 0; j < numFaceVertices; j++) { 351 | 352 | int vertexID = faceVertices[j]; 353 | std::vector& P = this->vertices[static_cast(vertexID)]; 354 | 355 | Vector3f uv; 356 | uv << faceUVs[j].first, faceUVs[j].second, 0.0; 357 | 358 | Vector3f P0(P.data()); 359 | 360 | float u = uv.x(); 361 | float v = uv.y(); 362 | 363 | size_t udim = ImageUtils::get_udim(u, v); 364 | 365 | if (udim > textures.size()) { 366 | // If UVs are outside of the given UDIM range, no color changes 367 | continue; 368 | } 369 | 370 | Image& img = textures[udim - 1]; 371 | 372 | if (!img.isEmpty) { 373 | Vector3f rgb; 374 | Vector2f local_uv = ImageUtils::localize_uv(u, v); 375 | rgb = ImageUtils::get_pixel_values( 376 | local_uv.x(), 377 | local_uv.y(), 378 | img.pixels, 379 | img.width, 380 | img.height, 381 | img.nchannels); 382 | float gammaCorrection = static_cast(1.0 / gamma); 383 | 384 | std::vector col = { pow(rgb.x(), gammaCorrection), 385 | pow(rgb.y(), gammaCorrection), 386 | pow(rgb.z(), gammaCorrection), 387 | 1.0 }; 388 | 389 | this->vertexColor[static_cast(vertexID)] = col; 390 | } 391 | } 392 | } 393 | 394 | timer.showDuration("Finished color to polypaint in "); 395 | } 396 | 397 | void GoZ::writeObj(std::string out_path, bool exportColor) { 398 | 399 | LOG("Exporting obj file for ZBruush..."); 400 | 401 | FILE* fp; 402 | fp = fopen(out_path.c_str(), "w"); 403 | 404 | if (fp == NULL) { 405 | printf("%s file cannot be opened\n", out_path.c_str()); 406 | exit(EXIT_FAILURE); 407 | } 408 | 409 | char line[128]; 410 | 411 | // Export Vertex positions 412 | size_t numVerts = this->vertices.size(); 413 | 414 | for (size_t i=0; i& v = this->vertices[i]; 416 | std::vector& Cd = this->vertexColor[i]; 417 | line[0] = '\0'; // clear 418 | // 419 | if (exportColor) { 420 | snprintf( 421 | line, 422 | sizeof(line), 423 | "v %f %f %f %f %f %f\n", v[0], -v[1], -v[2], Cd[0], Cd[1], Cd[2]); // ZBrush is flipped in y and z by default so negate them 424 | } else { 425 | snprintf(line, sizeof(line), "v %f %f %f\n", v[0], -v[1], -v[2]); 426 | } 427 | 428 | fputs(line, fp); 429 | } 430 | 431 | char indices[32]; 432 | 433 | for (std::vector& face : this->faces) { 434 | line[0] = '\0'; // clear 435 | snprintf(line, sizeof(line), "f"); 436 | for (int& fv : face) { 437 | indices[0] = '\0'; // clear 438 | snprintf(indices, sizeof(indices), " %i", fv+1); // Add +1 for goz -> obj conversion 439 | strcat(line, indices); 440 | } 441 | strcat(line, "\n"); 442 | fputs(line, fp); 443 | } 444 | 445 | fclose(fp); 446 | 447 | LOG("Finished exporting obj file."); 448 | } 449 | 450 | void GoZ::writePly(std::string out_path) { 451 | 452 | LOG("Exporting ply file for ZBruush..."); 453 | 454 | FILE* fp; 455 | fp = fopen(out_path.c_str(), "w"); 456 | 457 | if (fp == NULL) { 458 | printf("%s file cannot be opened\n", out_path.c_str()); 459 | exit(EXIT_FAILURE); 460 | } 461 | 462 | // Export Vertex positions 463 | size_t numVerts = this->vertices.size(); 464 | size_t numFaces = this->faces.size(); 465 | 466 | char header[512]; 467 | snprintf(header, sizeof(header), "ply\n" 468 | "format ascii 1.0\n" 469 | "element vertex %i\n" 470 | "property float x\n" 471 | "property float y\n" 472 | "property float z\n" 473 | "property uchar red\n" 474 | "property uchar green\n" 475 | "property uchar blue\n" 476 | "property uchar alpha\n" 477 | "element face %i\n" 478 | "property list uchar uint vertex_indices\n" 479 | "end_header\n", (int)numVerts, (int)numFaces); 480 | 481 | fputs(header, fp); 482 | 483 | char line[128]; 484 | 485 | // Vertices 486 | for (size_t i=0; i& v = this->vertices[i]; 488 | std::vector& Cd = this->vertexColor[i]; 489 | int r = (int)(255 * Cd[0]); 490 | int g = (int)(255 * Cd[1]); 491 | int b = (int)(255 * Cd[2]); 492 | line[0] = '\0'; // clear 493 | snprintf(line, sizeof(line), "%f %f %f %i %i %i 255\n", v[0], -v[1], -v[2], r, g, b); // ZBrush is flipped in y and z by default so negate them 494 | fputs(line, fp); 495 | } 496 | 497 | // Faces 498 | char indices[32]; 499 | 500 | for (std::vector& face : this->faces) { 501 | line[0] = '\0'; // clear 502 | size_t numFaceVerts = face.size(); 503 | 504 | snprintf(line, sizeof(line), "%i", (int)numFaceVerts); 505 | 506 | for (int& fv : face) { 507 | indices[0] = '\0'; // clear 508 | snprintf(indices, sizeof(indices), " %i", fv); 509 | strcat(line, indices); 510 | } 511 | strcat(line, "\n"); 512 | fputs(line, fp); 513 | } 514 | 515 | fclose(fp); 516 | 517 | LOG("Finished exporting ply file."); 518 | } 519 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------