diff --git a/README.md b/README.md index 10d03630a1..069ab3f3ec 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ Dependencies * [SWIG](http://www.swig.org/), [Python](https://www.python.org/) libraries - *optional* For building the IfcOpenShell Python interface and the Blender add-on * 3ds Max SDK - *optional* - For building the 3ds Max plug-in + For building the 3ds Max plug-in. + All recent versions of 3ds Max (2014 and newer) are 64-bit only, so a 64-bit installation is assumed. Compiling on Windows diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 71963665ca..27e71cb278 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -29,6 +29,7 @@ OPTION(USE_IFC4 "Use IFC 4 instead of IFC 2x3 (full rebuild recommended when swi OPTION(BUILD_IFCPYTHON "Build IfcPython." ON) OPTION(BUILD_EXAMPLES "Build example applications." ON) OPTION(USE_VLD "Use Visual Leak Detector for debugging memory leaks, MSVC-only." OFF) +OPTION(BUILD_IFCMAX "Build IfcMax, a 3ds Max plug-in, Windows-only." OFF) # TODO QtViewer is deprecated ATM as it uses the 0.4 API # OPTION(BUILD_QTVIEWER "Build IfcOpenShell Qt GUI Viewer (requires Qt 4 framework)." OFF) @@ -48,6 +49,9 @@ UNIFY_ENVVARS_AND_CACHE(OPENCOLLADA_INCLUDE_DIR) UNIFY_ENVVARS_AND_CACHE(OPENCOLLADA_LIBRARY_DIR) UNIFY_ENVVARS_AND_CACHE(PCRE_LIBRARY_DIR) UNIFY_ENVVARS_AND_CACHE(PYTHON_EXECUTABLE) +IF(WIN32) + UNIFY_ENVVARS_AND_CACHE(THREEDS_MAX_SDK_HOME) +ENDIF() # Find Boost IF(MSVC) @@ -419,6 +423,10 @@ IF(BUILD_EXAMPLES) ADD_SUBDIRECTORY(../src/examples examples) ENDIF() +IF(BUILD_IFCMAX) + ADD_SUBDIRECTORY(../src/ifcmax ifcmax) +ENDIF() + # CMake installation targets INSTALL(FILES ${IFCPARSE_H_FILES} DESTINATION include/ifcparse) INSTALL(FILES ${IFCGEOM_H_FILES} DESTINATION include/ifcgeom) diff --git a/src/ifcmax/CMakeLists.txt b/src/ifcmax/CMakeLists.txt new file mode 100644 index 0000000000..923532b073 --- /dev/null +++ b/src/ifcmax/CMakeLists.txt @@ -0,0 +1,39 @@ +################################################################################ +# # +# This file is part of IfcOpenShell. # +# # +# IfcOpenShell is free software: you can redistribute it and/or modify # +# it under the terms of the Lesser GNU General Public License as published by # +# the Free Software Foundation, either version 3.0 of the License, or # +# (at your option) any later version. # +# # +# IfcOpenShell is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# Lesser GNU General Public License for more details. # +# # +# You should have received a copy of the Lesser GNU General Public License # +# along with this program. If not, see . # +# # +################################################################################ + +INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${OCC_INCLUDE_DIR} ${OPENCOLLADA_INCLUDE_DIRS} ${ICU_INCLUDE_DIR} + ${Boost_INCLUDE_DIRS} ${THREEDS_MAX_SDK_HOME}/include +) + +# All recent versions of 3ds Max (2014 and newer) are 64-bit only so assume lib/x64 directory +LINK_DIRECTORIES(${LINK_DIRECTORIES} ${IfcOpenShell_BINARY_DIR} ${OCC_LIBRARY_DIR} ${OPENCOLLADA_LIBRARY_DIR} + ${ICU_LIBRARY_DIR} ${Boost_LIBRARY_DIRS} ${THREEDS_MAX_SDK_HOME}/lib/x64/Release +) + +ADD_LIBRARY(IfcMax SHARED IfcMax.h IfcMax.cpp) + +TARGET_LINK_LIBRARIES(IfcMax IfcParse IfcGeom Comctl32.lib zlibdll.lib bmm.lib core.lib CustDlg.lib edmodel.lib expr.lib + flt.lib geom.lib gfx.lib gup.lib imageViewers.lib ManipSys.lib maxnet.lib Maxscrpt.lib + maxutil.lib MenuMan.lib menus.lib mesh.lib MNMath.lib Paramblk2.lib particle.lib Poly.lib RenderUtil.lib + tessint.lib viewfile.lib ${OPENCASCADE_LIBRARIES} +) + +SET_TARGET_PROPERTIES(IfcMax PROPERTIES SUFFIX ".dli") + +INSTALL(TARGETS IfcMax RUNTIME DESTINATION bin) diff --git a/src/ifcmax/IfcMax.cpp b/src/ifcmax/IfcMax.cpp index dde5cc8547..46bf0f39f8 100644 --- a/src/ifcmax/IfcMax.cpp +++ b/src/ifcmax/IfcMax.cpp @@ -20,49 +20,54 @@ #include #include -#include #include #include -#include "../ifcmax/IfcMax.h" +#include "IfcMax.h" #include "../ifcgeom/IfcGeomIterator.h" static const int NUM_MATERIAL_SLOTS = 24; -int controlsInit = false; - -BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved) { +BOOL WINAPI DllMain(HINSTANCE /*hinstDLL*/, ULONG /*fdwReason*/, LPVOID /*lpvReserved*/) { + static int controlsInit = false; if (!controlsInit) { controlsInit = true; InitCommonControls(); - } - return true; + } + return TRUE; } -__declspec( dllexport ) const TCHAR* LibDescription() { - return _T("IfcOpenShell IFC Importer"); -} - -__declspec( dllexport ) int LibNumberClasses() { return 1; } - -static class IFCImpClassDesc:public ClassDesc { +static class IFCImpClassDesc :public ClassDesc { public: - int IsPublic() {return 1;} - void * Create(BOOL loading = FALSE) {return new IFCImp;} - const TCHAR * ClassName() {return _T("IFCImp");} - SClass_ID SuperClassID() {return SCENE_IMPORT_CLASS_ID;} - Class_ID ClassID() {return Class_ID(0x3f230dbf, 0x5b3015c2);} - const TCHAR* Category() {return _T("Chrutilities");} + int IsPublic() { return 1; } + void * Create(BOOL /*loading = FALSE*/) { return new IFCImp; } + // TODO Delete() function? + const TCHAR * ClassName() { return _T("IFCImp"); } + SClass_ID SuperClassID() { return SCENE_IMPORT_CLASS_ID; } + Class_ID ClassID() { return Class_ID(0x3f230dbf, 0x5b3015c2); } + const TCHAR* Category() { return _T("Chrutilities"); } } IFCImpDesc; -__declspec( dllexport ) ClassDesc* LibClassDesc(int i) { - return i == 0 ? &IFCImpDesc : 0; +#define DLLEXPORT __declspec(dllexport) + +extern "C" { + +DLLEXPORT const TCHAR* LibDescription() { + return _T("IfcOpenShell IFC Importer"); } -__declspec( dllexport ) ULONG LibVersion() { - return VERSION_3DSMAX; +DLLEXPORT int LibNumberClasses() { return 1; } + +DLLEXPORT ClassDesc* LibClassDesc(int i) { + return i == 0 ? &IFCImpDesc : 0; } +DLLEXPORT ULONG LibVersion() { + return VERSION_3DSMAX; +} + +} // extern "C" + int IFCImp::ExtCount() { return 1; } const TCHAR * IFCImp::Ext(int n) { @@ -82,7 +87,7 @@ const TCHAR * IFCImp::AuthorName() { } const TCHAR * IFCImp::CopyrightMessage() { - return _T("Copyight (c) 2011 IfcOpenShell"); + return _T("Copyright (c) 2011-2016 IfcOpenShell"); } const TCHAR * IFCImp::OtherMessage1() { @@ -97,13 +102,14 @@ unsigned int IFCImp::Version() { return 12; } -static BOOL CALLBACK AboutBoxDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - return TRUE; -} +// TODO Use this in IFCImp::ShowAbout() if/when wanted +//static BOOL CALLBACK AboutBoxDlgProc(HWND /*hWnd*/, UINT /*msg*/, WPARAM /*wParam*/, LPARAM /*lParam*/) { +// return TRUE; +//} -void IFCImp::ShowAbout(HWND hWnd) {} +void IFCImp::ShowAbout(HWND /*hWnd*/) {} -DWORD WINAPI fn(LPVOID arg) { return 0; } +DWORD WINAPI fn(LPVOID /*arg*/) { return 0; } #if MAX_RELEASE > 14000 # define S(x) (TSTR::FromCStr(x.c_str())) @@ -113,8 +119,9 @@ DWORD WINAPI fn(LPVOID arg) { return 0; } # define S(x) (CStr(x.c_str())) #endif -Mtl* FindMaterialByName(MtlBaseLib* library, const std::string& material_name) { - const int mat_index = library->FindMtlByName(S(material_name)); +static Mtl* FindMaterialByName(MtlBaseLib* library, const std::string& material_name) { + TSTR mat_name = S(material_name); + const int mat_index = library->FindMtlByName(mat_name); Mtl* m = 0; if (mat_index != -1) { m = static_cast((*library)[mat_index]); @@ -122,7 +129,7 @@ Mtl* FindMaterialByName(MtlBaseLib* library, const std::string& material_name) { return m; } -Mtl* FindOrCreateMaterial(MtlBaseLib* library, Interface* max_interface, int& slot, const IfcGeom::Material& material) { +static Mtl* FindOrCreateMaterial(MtlBaseLib* library, Interface* max_interface, int& slot, const IfcGeom::Material& material) { Mtl* m = FindMaterialByName(library, material.name()); if (m == 0) { StdMat2* stdm = NewDefaultStdMat(); @@ -136,10 +143,10 @@ Mtl* FindOrCreateMaterial(MtlBaseLib* library, Interface* max_interface, int& sl stdm->SetSpecular(Color(specular[0], specular[1], specular[2]),t); } if (material.hasSpecularity()) { - stdm->SetShininess(material.specularity(), t); + stdm->SetShininess((float)material.specularity(), t); } if (material.hasTransparency()) { - stdm->SetOpacity(1.0 - material.transparency(), t); + stdm->SetOpacity(1.0f - (float)material.transparency(), t); } m = stdm; m->SetName(S(material.name())); @@ -151,7 +158,10 @@ Mtl* FindOrCreateMaterial(MtlBaseLib* library, Interface* max_interface, int& sl return m; } -Mtl* ComposeMultiMaterial(std::map, Mtl*>& multi_mats, MtlBaseLib* library, Interface* max_interface, int& slot, const std::vector& materials, const std::string& object_type, const std::vector& material_ids) { +static Mtl* ComposeMultiMaterial(std::map, Mtl*>& multi_mats, MtlBaseLib* library, + Interface* max_interface, int& slot, const std::vector& materials, + const std::string& object_type, const std::vector& material_ids) +{ std::vector material_names; bool needs_default = std::find(material_ids.begin(), material_ids.end(), -1) != material_ids.end(); if (needs_default) { @@ -184,7 +194,7 @@ Mtl* ComposeMultiMaterial(std::map, Mtl*>& multi_mats, return i->second; } MultiMtl* multi_mat = NewDefaultMultiMtl(); - multi_mat->SetNumSubMtls(material_names.size()); + multi_mat->SetNumSubMtls((int)material_names.size()); int mtl_id = 0; if (needs_default) { multi_mat->SetSubMtlAndName(mtl_id ++, default_material, default_material->GetName()); @@ -201,7 +211,7 @@ Mtl* ComposeMultiMaterial(std::map, Mtl*>& multi_mats, return multi_mat; } -int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, BOOL suppressPrompts) { +int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, BOOL /*suppressPrompts*/) { IfcGeom::IteratorSettings settings; settings.use_world_coords() = false; @@ -217,7 +227,7 @@ int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, #endif IfcGeom::Iterator iterator(settings, fn_mb); - + delete fn_mb; if (!iterator.initialize()) return false; itfc->ProgressStart(_T("Importing file..."), TRUE, fn, NULL); @@ -237,12 +247,12 @@ int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, TriObject* tri = CreateNewTriObject(); - const int numVerts = o->geometry().verts().size()/3; + const int numVerts = (int)o->geometry().verts().size()/3; tri->mesh.setNumVerts(numVerts); for( int i = 0; i < numVerts; i ++ ) { tri->mesh.setVert(i,o->geometry().verts()[3*i+0],o->geometry().verts()[3*i+1],o->geometry().verts()[3*i+2]); } - const int numFaces = o->geometry().faces().size()/3; + const int numFaces = (int)o->geometry().faces().size()/3; tri->mesh.setNumFaces(numFaces); bool needs_default = std::find(o->geometry().material_ids().begin(), o->geometry().material_ids().end(), -1) != o->geometry().material_ids().end(); @@ -274,7 +284,7 @@ int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, tri->mesh.faces[i].setVerts(v1, v2, v3); tri->mesh.faces[i].setEdgeVisFlags(b1, b2, b3); - MtlID mtlid = o->geometry().material_ids()[i]; + MtlID mtlid = (MtlID)o->geometry().material_ids()[i]; if (needs_default) { mtlid ++; } @@ -310,4 +320,4 @@ int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, itfc->ProgressEnd(); return true; -} \ No newline at end of file +} diff --git a/src/ifcmax/IfcMax.def b/src/ifcmax/IfcMax.def deleted file mode 100644 index 03d30e4b97..0000000000 --- a/src/ifcmax/IfcMax.def +++ /dev/null @@ -1,8 +0,0 @@ -LIBRARY ifcmax.dli -EXPORTS - LibDescription @1 - LibNumberClasses @2 - LibClassDesc @3 - LibVersion @4 -SECTIONS - .data READ WRITE \ No newline at end of file diff --git a/src/ifcmax/IfcMax.h b/src/ifcmax/IfcMax.h index d144f9c777..19a89d9da0 100644 --- a/src/ifcmax/IfcMax.h +++ b/src/ifcmax/IfcMax.h @@ -21,12 +21,6 @@ #define IFCMAX_H #include "Max.h" -#include "istdplug.h" -#include "stdmat.h" -#include "decomp.h" -#include "shape.h" -#include "splshape.h" -#include "dummy.h" extern ClassDesc* GetIFCImpDesc(); @@ -38,7 +32,7 @@ public: const TCHAR * LongDesc(); // = "IfcOpenShell IFC Importer for 3ds Max" const TCHAR * ShortDesc(); // = "Industry Foundation Classes" const TCHAR * AuthorName(); // = "Thomas Krijnen" - const TCHAR * CopyrightMessage(); // = "Copyight (c) 2011 IfcOpenShell" + const TCHAR * CopyrightMessage(); // = "Copyright (c) 2011-2016 IfcOpenShell" const TCHAR * OtherMessage1(); // = "" const TCHAR * OtherMessage2(); // = "" unsigned int Version(); // = 12 diff --git a/win/build-deps.cmd b/win/build-deps.cmd index d7d8b44b35..974b578134 100644 --- a/win/build-deps.cmd +++ b/win/build-deps.cmd @@ -434,4 +434,3 @@ echo - https://www.visualstudio.com/ echo 5. Run this batch script with Visual Studio environment variables set. echo - https://msdn.microsoft.com/en-us/library/ms229859(v=vs.110).aspx echo. -REM TODO 3ds Max SDK instructions? diff --git a/win/readme.md b/win/readme.md index dd85e652e0..6497d0ba4c 100644 --- a/win/readme.md +++ b/win/readme.md @@ -40,7 +40,8 @@ After this, one can build the project using the `IfcOpenShell.sln` file in the b if wanted. Convenience batch files `build-ifcopenshell.cmd` and `install-ifcopenshell.cmd` can also be used. The batch files expect `%1` and `%2` in same fashion as above and possible extra parameters are passed for the `MSBuild` call. The project will be installed to `installed-vs-\` folder in the project's root folder and the required IfcOpenShell-Python -parts are deployed to the `\Lib\site-packages\` folder. +parts are deployed to the `\Lib\site-packages\` folder. The 3ds Max plug-in, IfcMax.dli, needs to be copied manually +to the 3ds Max's `plugins` folder. **Note:** All of the dependencies are build as static libraries against the static run-time allowing the developer to effortlessly deploy standalone IFCOS binaries. diff --git a/win/run-cmake.bat b/win/run-cmake.bat index 1c2865d723..e29fd6dd65 100644 --- a/win/run-cmake.bat +++ b/win/run-cmake.bat @@ -59,7 +59,7 @@ set PYTHON_LIBRARY=%PYTHONHOME%\libs\python%PY_VER_MAJOR_MINOR%.lib set PYTHON_EXECUTABLE=%PYTHONHOME%\python.exe set SWIG_DIR=%INSTALL_DIR%\swigwin set PATH=%PATH%;%SWIG_DIR%;%PYTHONHOME% -:: TODO 3ds Max SDK? +set THREEDS_MAX_SDK_HOME=C:\Program Files\Autodesk\3ds Max 2016 SDK\maxsdk echo. call cecho.cmd 0 10 "Script configuration:" @@ -80,6 +80,7 @@ echo PYTHON_INCLUDE_DIR = %PYTHON_INCLUDE_DIR% echo PYTHON_LIBRARY = %PYTHON_LIBRARY% echo PYTHON_EXECUTABLE = %PYTHON_EXECUTABLE% echo SWIG_DIR = %SWIG_DIR% +echo THREEDS_MAX_SDK_HOME = %THREEDS_MAX_SDK_HOME% echo. echo CMAKE_INSTALL_PREFIX = %CMAKE_INSTALL_PREFIX% echo.