commit 5a0b1a209e8b677480c74deed9aa5dd189a6f452 Author: indigo Date: Sun Sep 24 20:49:29 2023 +0800 Init git diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..701e84f --- /dev/null +++ b/.hgignore @@ -0,0 +1,3 @@ +syntax: glob +build/ +install/ diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..e32901c --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,26 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**", + "C:/aw/Maya2020/include", + "D:/library/build/vc15.0/pybind11/include", + "C:/Miniconda2/include", + "D:/library/build/vc15.0/zlib/include" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.19041.0", + "compilerPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\Hostx64\\x64\\cl.exe", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "windows-msvc-x64", + "configurationProvider": "ms-vscode.cmake-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a32b2c4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.14) + +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) + +set(Python2_USE_STATIC_LIBS TRUE) +set(PYTHON_INCLUDE_DIRS "C:/Miniconda2/include") +set(PYTHON_LIBRARIES "C:/Miniconda2/libs/python27.lib") +set(ZLIB_ROOT "D:/library/build/vc15.0/zlib") +set(ZLIB_LIBRARY "D:/library/build/vc15.0/zlib/lib/zlibstatic.lib") +set(MAYA_LOCATION "C:/aw/Maya2020") +set(PYBIND11_HOME "D:/library/build/vc15.0/pybind11") + +add_subdirectory(src) diff --git a/README.md b/README.md new file mode 100644 index 0000000..39c90f7 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# VRayHexer +This is a tool for convert data structure into HEX string, now support + +* TraceTransform + +### VRayHexerMaya +The plugin is convert object transformation ( `MMatrix` ) to HEX string. +#### Example +```python +import maya.cmds as cmds +cmds.VraySceneHexer('pCube1', q=True, transformHex=True) +# result :[u'0000803F0000000000000000000000000000803F0000000000000000000000000000803F00000000000000000000000000000000000000000000000000000000'] +``` + +### VRayHexerPython +This is a python module for generate HEX string from matrix class. + +#### Example +```python +from VRayHexer import TraceTransform +tm = TraceTransform() +tm.getHex() +# result : u'0000803F0000000000000000000000000000803F0000000000000000000000000000803F00000000000000000000000000000000000000000000000000000000' +``` + + + diff --git a/cmake/modules/FindMaya.cmake b/cmake/modules/FindMaya.cmake new file mode 100644 index 0000000..d9c40a5 --- /dev/null +++ b/cmake/modules/FindMaya.cmake @@ -0,0 +1,97 @@ +if(NOT DEFINED MAYA_VERSION) + set(MAYA_VERSION 2013.5 CACHE STRING "Maya version") +endif() + +set(MAYA_COMPILE_DEFINITIONS "REQUIRE_IOSTREAM;_BOOL;_CRT_SECURE_NO_WARNINGS;NOMINMAX") +set(MAYA_INSTALL_BASE_SUFFIX "") +set(MAYA_LIB_SUFFIX "lib") +set(MAYA_INC_SUFFIX "include") +set(MAYA_TARGET_TYPE LIBRARY) + +if(WIN32) + # Windows + set(MAYA_INSTALL_BASE "C:/Program Files/Autodesk") + set(OPENMAYA OpenMaya.lib) + set(MAYA_COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS};NT_PLUGIN") + set(MAYA_PLUGIN_EXTENSION ".mll") + set(MAYA_TARGET_TYPE RUNTIME) +elseif(APPLE) + # Mac + set(MAYA_INSTALL_BASE "/Applications/Autodesk") + set(OPENMAYA libOpenMaya.dylib) + set(MAYA_LIB_SUFFIX "Maya.app/Contents/MacOS") + set(MAYA_INC_SUFFIX "devkit/include") + set(MAYA_COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS};OSMac") + set(MAYA_PLUGIN_EXTENSION ".dylib") +else() + # Linux + set(MAYA_INSTALL_BASE "/usr/autodesk") + set(MAYA_INSTALL_BASE_SUFFIX -x64) + set(OPENMAYA libOpenMaya.so) + set(MAYA_COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS};LINUX") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + set(MAYA_PLUGIN_EXTENSION ".so") +endif() + +set(MAYA_INSTALL_BASE_PATH ${MAYA_INSTALL_BASE} CACHE STRING "Maya Root Installation Path") + +if(NOT DEFINED MAYA_LOCATION) + set(MAYA_LOCATION ${MAYA_INSTALL_BASE_PATH}/maya${MAYA_VERSION}${MAYA_INSTALL_BASE_SUFFIX}) +endif() + +message(STATUS "MAYA_INSTALL_BASE_PATH : ${MAYA_INSTALL_BASE_PATH}") +find_path(MAYA_LIBRARY_DIR ${OPENMAYA} + PATHS + ${MAYA_LOCATION} + $ENV{MAYA_LOCATION} + PATH_SUFFIXES + "${MAYA_LIB_SUFFIX}/" + DOC "Maya library path" +) + +find_path(MAYA_INCLUDE_DIR maya/MTypes.h + PATHS + ${MAYA_LOCATION} + $ENV{MAYA_LOCATION} + PATH_SUFFIXES + "${MAYA_INC_SUFFIX}/" + DOC "Maya include path" +) +message(STATUS "${MAYA_INCLUDE_DIR}/maya/MTypes.h") +if(MAYA_INCLUDE_DIR AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MTypes.h") + file(STRINGS + ${MAYA_INCLUDE_DIR}/maya/MTypes.h + _maya_tmp + REGEX "#define MAYA_APP_VERSION .*$") + string(REGEX MATCHALL "[0-9]+$" MAYA_VERSION ${_maya_tmp}) + message(STATUS "MAYA_VERSION : ${MAYA_VERSION}") +endif() + +set(_MAYA_LIBRARIES OpenMaya OpenMayaAnim OpenMayaFx OpenMayaRender OpenMayaUI Foundation) + +foreach(MAYA_LIB ${_MAYA_LIBRARIES}) + find_library(MAYA_${MAYA_LIB}_LIBRARY NAMES ${MAYA_LIB} PATHS ${MAYA_LIBRARY_DIR} NO_DEFAULT_PATH) + set(MAYA_LIBRARIES ${MAYA_LIBRARIES} ${MAYA_${MAYA_LIB}_LIBRARY}) +endforeach() + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(Maya + REQUIRED_VARS + MAYA_INCLUDE_DIR + MAYA_LIBRARIES + VERSION_VAR + MAYA_VERSION) + +function(MAYA_PLUGIN _target) + + if(WIN32) + set_target_properties(${_target} PROPERTIES + LINK_FLAGS "/export:initializePlugin /export:uninitializePlugin") + endif() + set_target_properties(${_target} PROPERTIES + COMPILE_DEFINITIONS "${MAYA_COMPILE_DEFINITIONS}" + PREFIX "" + SUFFIX ${MAYA_PLUGIN_EXTENSION} + ) +endfunction() \ No newline at end of file diff --git a/cmake/modules/FindPybind11.cmake b/cmake/modules/FindPybind11.cmake new file mode 100644 index 0000000..3baf0fb --- /dev/null +++ b/cmake/modules/FindPybind11.cmake @@ -0,0 +1,45 @@ +#-*-cmake-*- +# +# This auxiliary CMake file helps in find the pybind headers +# +# PYBIND11_FOUND Set if Pybind11 is found. +# PYBIND11_INCLUDE_DIR Pybind11's include directory. +# PYBIND11_VERSION Pybind11 version +# PYBIND11_VERSION_MAJOR +# PYBIND11_VERSION_MINOR +# PYBIND11_VERSION_PATCH + +find_package(PackageHandleStandardArgs) + +if (EXISTS "$ENV{PYBIND11_HOME}") + set(PYBIND11_HOME $ENV{PYBIND11_HOME}) +endif () + +# include/pybind11/detail/common.h +find_path(PYBIND11_INCLUDE_DIR pybind11/pybind11.h + PATHS ${PYBIND11_HOME}/include + DOC "Pybind11 Include Path") + + + +if(PYBIND11_INCLUDE_DIR AND EXISTS "${PYBIND11_INCLUDE_DIR}/pybind11/detail/common.h") + foreach(_pybind11_comp MAJOR MINOR PATCH) + file(STRINGS + ${PYBIND11_INCLUDE_DIR}/pybind11/detail/common.h + _pybind11_tmp + REGEX "#define PYBIND11_VERSION_${_pybind11_comp} .*$") + string(REGEX MATCHALL "[0-9]+$" PYBIND11_VERSION_${_pybind11_comp} ${_pybind11_tmp}) + endforeach() + set(PYBIND11_VERSION ${PYBIND11_VERSION_MAJOR}.${PYBIND11_VERSION_MINOR}.${PYBIND11_VERSION_PATCH}) +endif() + +message(STATUS "PYBIND11_VERSION : ${PYBIND11_VERSION}") +message(STATUS "PYBIND11_HOME : ${PYBIND11_HOME}") +message(STATUS "PYBIND11_INCLUDE_DIR : ${PYBIND11_INCLUDE_DIR}") + +find_package_handle_standard_args(Pybind11 + REQUIRED_VARS + PYBIND11_INCLUDE_DIR + VERSION_VAR + PYBIND11_VERSION +) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..d4f0b64 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(VRayHexer) +add_subdirectory(VRayHexerMaya) +add_subdirectory(VRayHexerPython) \ No newline at end of file diff --git a/src/VRayHexer/CMakeLists.txt b/src/VRayHexer/CMakeLists.txt new file mode 100644 index 0000000..26762b5 --- /dev/null +++ b/src/VRayHexer/CMakeLists.txt @@ -0,0 +1,23 @@ +project(VRayHexer) + +find_package(ZLIB) + +set(SRC_FILES + "VRayHexer.h" + "VRayHexer.cpp" + "math.hpp") + +include_directories( + ${ZLIB_INCLUDE_DIRS} +) + +link_directories( + ${ZLIB_LIBRARY} +) + +add_library(${PROJECT_NAME} STATIC ${SRC_FILES}) + +set(${PROJECT_NAME}_INCLUDE_DIRS ${PROJECT_SOURCE_DIR} + CACHE INTERNAL "${PROJECT_NAME}: Include Directories" FORCE) + +# install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION "${CMAKE_SOURCE_DIR}/install/lib") \ No newline at end of file diff --git a/src/VRayHexer/VRayHexer.cpp b/src/VRayHexer/VRayHexer.cpp new file mode 100644 index 0000000..c1d9baa --- /dev/null +++ b/src/VRayHexer/VRayHexer.cpp @@ -0,0 +1,204 @@ +#include +#include +#include + +#include "math.hpp" +#include "VRayHexer.h" + +struct TraceTransform { + float m[3][3]; + double v[3]; +}; + +inline char letr2char(int d) +{ + if (d>=0 && d<26) return 'A'+d; + d-=26; + if (d>=0 && d<=9) return '0'+d; + d-=10; + if (d>=0 && d<26) return 'a'+d; + return '?'; +} + + +inline void word2str(u_int16_t w, char *str) +{ + int d0=w%41; + w/=41; + int d1=w%41; + w/=41; + int d2=w%41; + *str=letr2char(d0); + str++; + *str=letr2char(d1); + str++; + *str=letr2char(d2); +} + + +static char int2hexValue(char d) +{ + return d<=9 ? '0'+d : (d-10+'A'); +} + +static void int2hex(u_int32_t i, char *hex) +{ + u_int8_t f[4]; + *((u_int32_t*)&f)=i; + for (int i=0; i<4; i++) { + char val0=int2hexValue((f[i]>>4)&0xF); + char val1=int2hexValue((f[i])&0xF); + hex[i*2+0]=val0; + hex[i*2+1]=val1; + } +} + +static int hex2str(const u_int8_t *bytes, unsigned numBytes, char *str, unsigned strMaxLen) +{ + if (strMaxLen>4)&0xF); + char val1 = int2hexValue(buf[i]&0xF); + pstr[i*2+0] = val0; + pstr[i*2+1] = val1; + } + pstr[nBytes*2] = 0; +} + +char* GetHex(const u_int8_t* data, unsigned dataLen) +{ + char* buf = new char[dataLen * 2 + 1]; + + getStringHex(data, dataLen, buf); + + return buf; +} + +char* GetStringZip(const u_int8_t *buf, unsigned bufLen) +{ + // First compress the data into a temporary buffer + // + uLongf tempLen = bufLen+bufLen/10+12; + char *temp = new char[tempLen]; + + int err = compress2((Bytef*)temp, &tempLen, (Bytef*)buf, bufLen, 1); + if(err == Z_MEM_ERROR) { + delete [] temp; + return NULL; + } + if(err == Z_BUF_ERROR) { + delete [] temp; + return NULL; + } + + // Convert the zipped buffer into an ASCII string + // + char *pstr = NULL; + unsigned offset = 4+8+8; + unsigned strLen = (tempLen/2+1)*3+offset+1; + + pstr = new char[strLen]; + + hex2str((u_int8_t*)temp, tempLen, &pstr[offset], strLen-offset); + delete [] temp; + + // Add the Zip header + pstr[0]='Z'; pstr[1]='I'; pstr[2]='P'; pstr[3]='B'; + pstr[strLen-1] = '\0'; + + int2hex(bufLen, &pstr[4]); + int2hex(tempLen, &pstr[8+4]); + + return pstr; +} + +char* GetFloatArrayZip(float *data, size_t size) +{ + float *ptr = new float[size]; + size_t nBytes = size * sizeof(float); + + if(!data) + memset(ptr, 0, nBytes); + else + memcpy(ptr, data, nBytes); + + char *charBuf = GetStringZip((u_int8_t*)ptr, (unsigned)nBytes); + + delete [] ptr; + + return charBuf; +} + + +void GetDoubleHex(float f, char *buf) +{ + double d = double(f); + const u_int8_t *d8 = (const u_int8_t*)&d; + getStringHex(d8, sizeof(d), buf); +} + + +void GetFloatHex(float f, char *buf) +{ + float d = f; + const u_int8_t *d8 = (const u_int8_t*)&d; + getStringHex(d8, sizeof(d), buf); +} + + +void GetVectorHex(float f[3], char *buf) +{ + float d[3]; + copy_v3_v3(d, f); + const u_int8_t *d8 = (const u_int8_t*)&d; + getStringHex(d8, sizeof(d), buf); +} + + +void GetTransformHex(float m[4][4], char *buf) +{ + TraceTransform tm; + copy_m3_m4(tm.m, m); + copy_v3db_v3fl(tm.v, m[3]); + + const u_int8_t *tm8 = (const u_int8_t*)&tm; + getStringHex(tm8, sizeof(tm), buf); +} + +/*std::string GetTransformHex(const BLTransform &bl_tm) +{ + float m[4][4]; + ::memcpy(m, bl_tm.data, 16 * sizeof(float)); + + char buf[CGR_TRANSFORM_HEX_SIZE]; + GetTransformHex(m, buf); + + return buf; +}*/ + +/*std::string GetTransformHex(const MMatrix& tm) +{ + float m[4][4]; + tm.get(m); + char buf[CGR_TRANSFORM_HEX_SIZE]; + GetTransformHex(m, buf); + return buf; +}*/ \ No newline at end of file diff --git a/src/VRayHexer/VRayHexer.h b/src/VRayHexer/VRayHexer.h new file mode 100644 index 0000000..eeeae2a --- /dev/null +++ b/src/VRayHexer/VRayHexer.h @@ -0,0 +1,26 @@ +#ifndef VRSCENE_H +#define VRSCENE_H + +#ifdef _WIN32 +typedef unsigned __int8 u_int8_t; +typedef unsigned __int16 u_int16_t; +typedef unsigned __int32 u_int32_t; +typedef unsigned __int64 u_int64_t; +#endif + +#define CGR_TRANSFORM_HEX_SIZE 129 + +#include + +void getStringHex(const u_int8_t *buf, unsigned nBytes, char *pstr); + +void GetDoubleHex(float f, char *buf); +void GetFloatHex(float f, char *buf); +void GetVectorHex(float f[3], char *buf); +void GetTransformHex(float m[4][4], char *buf); + +char* GetHex(const u_int8_t *buf, unsigned bufLen); +char* GetStringZip(const u_int8_t *buf, unsigned bufLen); +char* GetFloatArrayZip(float *data, size_t size); + +#endif // VRSCENE_H \ No newline at end of file diff --git a/src/VRayHexer/math.hpp b/src/VRayHexer/math.hpp new file mode 100644 index 0000000..8e5129e --- /dev/null +++ b/src/VRayHexer/math.hpp @@ -0,0 +1,28 @@ +void copy_m3_m4(float m1[3][3], float m2[4][4]) +{ + m1[0][0] = m2[0][0]; + m1[0][1] = m2[0][1]; + m1[0][2] = m2[0][2]; + + m1[1][0] = m2[1][0]; + m1[1][1] = m2[1][1]; + m1[1][2] = m2[1][2]; + + m1[2][0] = m2[2][0]; + m1[2][1] = m2[2][1]; + m1[2][2] = m2[2][2]; +} + +void copy_v3_v3(float r[3], const float a[3]) +{ + r[0] = a[0]; + r[1] = a[1]; + r[2] = a[2]; +} + +void copy_v3db_v3fl(double r[3], const float a[3]) +{ + r[0] = (double)a[0]; + r[1] = (double)a[1]; + r[2] = (double)a[2]; +} \ No newline at end of file diff --git a/src/VRayHexerMaya/CMakeLists.txt b/src/VRayHexerMaya/CMakeLists.txt new file mode 100644 index 0000000..c1e77a3 --- /dev/null +++ b/src/VRayHexerMaya/CMakeLists.txt @@ -0,0 +1,35 @@ +project(VRayHexerMaya) + +find_package(Maya) +find_package(ZLIB) + +set(SRC_FILES + PluginMain.cpp + VRaySceneUtils.h + VRaySceneUtils.cpp +) +set(RESOURCE_FILES + "resources/VRayHexerMaya.mod") + +include_directories( + ${VRayHexer_INCLUDE_DIRS} + ${MAYA_INCLUDE_DIR} + ${ZLIB_INCLUDE_DIRS} + "${CMAKE_SOURCE_DIR}/src/VrayHexer" +) + +link_directories( + ${MAYA_LIBRARY_DIR} +) +link_libraries( + VRayHexer + ${MAYA_LIBRARIES} + ${ZLIB_LIBRARIES} +) + +add_library(${PROJECT_NAME} SHARED ${SRC_FILES}) + +MAYA_PLUGIN(${PROJECT_NAME}) + +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "${CMAKE_SOURCE_DIR}/install/plug-ins/${MAYA_VERSION}") +install(FILES ${RESOURCE_FILES} DESTINATION "${CMAKE_SOURCE_DIR}/install") \ No newline at end of file diff --git a/src/VRayHexerMaya/PluginMain.cpp b/src/VRayHexerMaya/PluginMain.cpp new file mode 100644 index 0000000..b5d3c9a --- /dev/null +++ b/src/VRayHexerMaya/PluginMain.cpp @@ -0,0 +1,26 @@ +#include + +#include "VRaySceneUtils.h" + +PLUGIN_EXPORT MStatus initializePlugin(MObject obj) +{ + MStatus status = MStatus::kSuccess; + MFnPlugin plugin(obj, "CGCG Inc.2021", "1.0"); + + plugin.registerCommand(kCommandName, VraySceneHexCmd::creator, VraySceneHexCmd::newSyntex); + if (!status) { + printf("Failed to register plugin (%s)", kCommandName); + } + return status; +} + +PLUGIN_EXPORT MStatus uninitializePlugin(MObject obj) +{ + MStatus status = MStatus::kSuccess; + MFnPlugin plugin(obj); + plugin.deregisterCommand(kCommandName); + if (!status) { + printf("Failed to deregister plugin (%s)", kCommandName); + } + return status; +} diff --git a/src/VRayHexerMaya/VRaySceneUtils.cpp b/src/VRayHexerMaya/VRaySceneUtils.cpp new file mode 100644 index 0000000..53aaa28 --- /dev/null +++ b/src/VRayHexerMaya/VRaySceneUtils.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +#include + +#include "VRayHexer.h" + +#include "VRaySceneUtils.h" + +VraySceneHexCmd::VraySceneHexCmd() +{ +} + +VraySceneHexCmd::~VraySceneHexCmd() +{ +} + +void* VraySceneHexCmd::creator() +{ + return new VraySceneHexCmd(); +} + +std::string VraySceneHexCmd::getTransformHex(const MMatrix& tm) +{ + float m[4][4]; + tm.get(m); + char buf[CGR_TRANSFORM_HEX_SIZE]; + GetTransformHex(m, buf); + return buf; +} + +MSyntax VraySceneHexCmd::newSyntex() +{ + MSyntax syntax; + syntax.useSelectionAsDefault(true); + syntax.setObjectType(MSyntax::kSelectionList); + syntax.setMinObjects(1); + syntax.addFlag(kTransfromHex, kTransfromHexLong); + + syntax.enableQuery(true); + return syntax; +} + +MStatus VraySceneHexCmd::doIt(const MArgList& args) +{ + MStatus status; + MArgDatabase argData(syntax(), args); + bool isQuery = argData.isQuery(); + bool isTransformHex = argData.isFlagSet(kTransfromHex); + if (isTransformHex){ + + if (isQuery){ + + MSelectionList list; + status = argData.getObjects(list); + + if (MS::kSuccess != status) { + MGlobal::displayError("Error to get objects"); + return status; + } + + if (list.isEmpty()) { + + MGlobal::displayError("Error to get object in selection list"); + return MS::kNotFound; + } + + MStringArray result; + for (unsigned int i = 0; i < list.length(); i++) + { + MDagPath currentPath; + list.getDagPath(i, currentPath); + std::string tmHex = getTransformHex(currentPath.inclusiveMatrix()); + result.append(tmHex.c_str()); + } + setResult(result); + return MS::kSuccess; + } + else { + unsigned int i, nth = 0; + unsigned int numArgs = args.length(); + while (status == MS::kSuccess && nth < numArgs - 1) { + MString argName = args.asString(nth, &status); + MGlobal::displayInfo(argName); + nth++; + } + + return MS::kSuccess; + MArgList values; + if (argData.getFlagArgumentList(kTransfromHex, 0, values) == MStatus::kSuccess) + { + for (unsigned int v=0; v < values.length(); v++) + { + double x; + if (values.get(v, x)) + { + + } + } + } + + + unsigned int idx; + //MDoubleArray dArray = values.asDoubleArray(idx); + //unsigned int l = dArray.length(); + + if (values.length() < 12) { + MGlobal::displayError("Not enough argument of -tranformHex(tmh)"); + return MS::kInvalidParameter; + } + + MStringArray result; + MMatrix tm; + + values.get(0, tm[0][0]); values.get(1, tm[0][1]); values.get(2, tm[0][2]); + values.get(3, tm[1][0]); values.get(4, tm[1][1]); values.get(5, tm[1][2]); + values.get(6, tm[2][0]); values.get(7, tm[2][1]); values.get(8, tm[2][2]); + values.get(9, tm[3][0]); values.get(10, tm[3][1]); values.get(11, tm[3][2]); + + std::string tmHex = getTransformHex(tm); + result.append(tmHex.c_str()); + setResult(result); + return MS::kSuccess; + } + } + return MS::kSuccess; +} + + diff --git a/src/VRayHexerMaya/VRaySceneUtils.h b/src/VRayHexerMaya/VRaySceneUtils.h new file mode 100644 index 0000000..73c34ea --- /dev/null +++ b/src/VRayHexerMaya/VRaySceneUtils.h @@ -0,0 +1,28 @@ +#ifndef VRAYSCENE_UTILS_H +#define VRAYSCENE_UTILS_H + +#include +#include +#include + +#define kCommandName "VraySceneHexer" + +#define kTransfromHex "-tmh" +#define kTransfromHexLong "-tranformHex" +#define kHelp "-h" +#define kHelpLong "-help" + +class VraySceneHexCmd : public MPxCommand +{ +public: + VraySceneHexCmd(); + ~VraySceneHexCmd(); + + virtual MStatus doIt(const MArgList&); + static MSyntax newSyntex(); + static void* creator(); + + std::string getTransformHex(const MMatrix& tm); +}; + +#endif //VRAYSCENE_UTIL_H \ No newline at end of file diff --git a/src/VRayHexerMaya/resources/VRayHexerMaya.mod b/src/VRayHexerMaya/resources/VRayHexerMaya.mod new file mode 100644 index 0000000..d6226d7 --- /dev/null +++ b/src/VRayHexerMaya/resources/VRayHexerMaya.mod @@ -0,0 +1,7 @@ ++ MAYAVERSION:2020 VRayHexerMaya 1.0 . +PYTHONPATH +:= python +plug-ins : plug-ins/2020 + ++ MAYAVERSION:2022 VRayHexerMaya 1.0 . +PYTHONPATH +:= python +plug-ins : plug-ins/2022 \ No newline at end of file diff --git a/src/VRayHexerPython/CMakeLists.txt b/src/VRayHexerPython/CMakeLists.txt new file mode 100644 index 0000000..88ca6db --- /dev/null +++ b/src/VRayHexerPython/CMakeLists.txt @@ -0,0 +1,37 @@ +project(VrayHexerPython) + +set(SRC_FILES + "vrayHexer.cpp" +) + +find_package(ZLIB) +find_package(Pybind11) +find_package(Python2 COMPONENTS Interpreter Development) + + +message(STATUS "${PROJECT_NAME} : PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}") + +include_directories( + ${PYBIND11_INCLUDE_DIR} + ${PYTHON_INCLUDE_DIRS} + ${ZLIB_INCLUDE_DIRS} + "${CMAKE_SOURCE_DIR}/src/VrayHexer" +) +link_libraries( + VRayHexer + ${PYTHON_LIBRARIES} + ${ZLIB_LIBRARIES} +) + +message(STATUS "PYBIND11_INCLUDE_DIR : ${PYBIND11_INCLUDE_DIR}") +message(STATUS "PYTHON_INCLUDE_DIRS : ${PYTHON_INCLUDE_DIRS}") +message(STATUS "PYTHON_LIBRARIES : ${PYTHON_LIBRARIES}") + +add_library(${PROJECT_NAME} SHARED ${SRC_FILES}) + +set_target_properties(${PROJECT_NAME} + PROPERTIES POSITION_INDEPENDENT_CODE ON + OUTPUT_NAME "VrayHexer" + SUFFIX ".pyd") + +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "${CMAKE_SOURCE_DIR}/install/python") \ No newline at end of file diff --git a/src/VRayHexerPython/vrayHexer.cpp b/src/VRayHexerPython/vrayHexer.cpp new file mode 100644 index 0000000..475b4be --- /dev/null +++ b/src/VRayHexerPython/vrayHexer.cpp @@ -0,0 +1,108 @@ +#include "VrayHexer.h" +#include +#include +#include +#include +#include + +namespace py = pybind11; + +struct TraceTransform { + TraceTransform(){ + m_data[0] = 1.0f; m_data[1] = 0.0f; m_data[2] = 0.0f; + m_data[3] = 0.0f; m_data[4] = 1.0f; m_data[5] = 0.0f; + m_data[6] = 0.0f; m_data[7] = 0.0f; m_data[8] = 1.0f; + + m_data[9] = 0.0f; m_data[10] = 0.0f; m_data[11] = 0.0f; + + m_size = 12; + }; + ~TraceTransform() { + }; + + void setMatrix( float m0, float m1, float m2, + float m3, float m4, float m5, + float m6, float m7, float m8) { + m_data[0] = m0; m_data[1] = m1; m_data[2] = m2; + m_data[3] = m3; m_data[4] = m4; m_data[5] = m5; + m_data[6] = m6; m_data[7] = m7; m_data[8] = m8; + }; + + std::vector getMatrix() + { + std::vector m; + for (unsigned i = 0; i < 9; i++) + { + m.push_back((float)m_data[i]); + } + return m; + } + + std::vector getOffset() + { + std::vector offset; + offset.push_back(m_data[9]); + offset.push_back(m_data[10]); + offset.push_back(m_data[11]); + return offset; + } + + void setOffset(double v1, double v2, double v3) { + m_data[9] = v1; m_data[10] = v2; m_data[11] = v3; + } + + void copy(float sm[4][4]) { + sm[0][0] = (float)m_data[0]; sm[0][1] = (float)m_data[1]; sm[0][2] = (float)m_data[2]; sm[0][3] = 0; + sm[1][0] = (float)m_data[3]; sm[1][1] = (float)m_data[4]; sm[1][2] = (float)m_data[5]; sm[1][3] = 0; + sm[2][0] = (float)m_data[6]; sm[2][1] = (float)m_data[7]; sm[2][2] = (float)m_data[8]; sm[2][3] = 0; + + sm[3][0] = (float)m_data[9]; sm[3][1] = (float)m_data[10]; sm[3][2] = (float)m_data[11]; sm[3][3] = 1.0f; + } + + double operator[](size_t index) const { + return m_data[index]; + } + + double& operator[](size_t index) { + return m_data[index]; + } + + size_t size() const { return m_size; } + + std::string getHex(){ + float m[4][4]; + copy(m); + char buf[CGR_TRANSFORM_HEX_SIZE]; + GetTransformHex(m, buf); + return buf; + } + double m_data[12]; + size_t m_size; +}; + +PYBIND11_MODULE(VrayHexer, m) { + m.doc() = "VrayHexer for Python"; + py::class_(m, "TraceTransform") + .def(py::init()) + .def("__getitem__", + [](const TraceTransform& tm, size_t i) { + if(i > tm.size() || i < 0) + throw py::index_error(); + return tm[i]; + }) + .def("__setitem__", + [](TraceTransform &tm, size_t i, float v) { + if (i >= tm.size()) + throw py::index_error(); + tm[i] = v; + }) + .def("set_matrix", &TraceTransform::setMatrix, + py::arg("m0"), py::arg("m1"), py::arg("m2"), + py::arg("m3"), py::arg("m4"), py::arg("m5"), + py::arg("m6"), py::arg("m7"), py::arg("m8")) + .def("get_matrix", &TraceTransform::getMatrix, "Get Matrix") + .def("set_offset", &TraceTransform::setOffset, + py::arg("v0"), py::arg("v1"), py::arg("v2")) + .def("get_offset", &TraceTransform::getOffset, "Get Offset") + .def("get_hex", &TraceTransform::getHex, "Get Transform Hex"); +} \ No newline at end of file