Skip to content

Commit 5ee9bed

Browse files
committed
CMakeLists.txt for IfcMax. Tested with VS 2015 and 3ds Max + SDK 2016
1 parent 481515f commit 5ee9bed

File tree

9 files changed

+107
-62
lines changed

9 files changed

+107
-62
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Dependencies
2424
* [SWIG](http://www.swig.org/), [Python](https://www.python.org/) libraries - *optional*
2525
For building the IfcOpenShell Python interface and the Blender add-on
2626
* 3ds Max SDK - *optional*
27-
For building the 3ds Max plug-in
27+
For building the 3ds Max plug-in.
28+
All recent versions of 3ds Max (2014 and newer) are 64-bit only, so a 64-bit installation is assumed.
2829

2930

3031
Compiling on Windows

cmake/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ OPTION(USE_IFC4 "Use IFC 4 instead of IFC 2x3 (full rebuild recommended when swi
2929
OPTION(BUILD_IFCPYTHON "Build IfcPython." ON)
3030
OPTION(BUILD_EXAMPLES "Build example applications." ON)
3131
OPTION(USE_VLD "Use Visual Leak Detector for debugging memory leaks, MSVC-only." OFF)
32+
OPTION(BUILD_IFCMAX "Build IfcMax, a 3ds Max plug-in, Windows-only." OFF)
3233
# TODO QtViewer is deprecated ATM as it uses the 0.4 API
3334
# OPTION(BUILD_QTVIEWER "Build IfcOpenShell Qt GUI Viewer (requires Qt 4 framework)." OFF)
3435

@@ -48,6 +49,9 @@ UNIFY_ENVVARS_AND_CACHE(OPENCOLLADA_INCLUDE_DIR)
4849
UNIFY_ENVVARS_AND_CACHE(OPENCOLLADA_LIBRARY_DIR)
4950
UNIFY_ENVVARS_AND_CACHE(PCRE_LIBRARY_DIR)
5051
UNIFY_ENVVARS_AND_CACHE(PYTHON_EXECUTABLE)
52+
IF(WIN32)
53+
UNIFY_ENVVARS_AND_CACHE(THREEDS_MAX_SDK_HOME)
54+
ENDIF()
5155

5256
# Find Boost
5357
IF(MSVC)
@@ -419,6 +423,10 @@ IF(BUILD_EXAMPLES)
419423
ADD_SUBDIRECTORY(../src/examples examples)
420424
ENDIF()
421425

426+
IF(BUILD_IFCMAX)
427+
ADD_SUBDIRECTORY(../src/ifcmax ifcmax)
428+
ENDIF()
429+
422430
# CMake installation targets
423431
INSTALL(FILES ${IFCPARSE_H_FILES} DESTINATION include/ifcparse)
424432
INSTALL(FILES ${IFCGEOM_H_FILES} DESTINATION include/ifcgeom)

src/ifcmax/CMakeLists.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
################################################################################
2+
# #
3+
# This file is part of IfcOpenShell. #
4+
# #
5+
# IfcOpenShell is free software: you can redistribute it and/or modify #
6+
# it under the terms of the Lesser GNU General Public License as published by #
7+
# the Free Software Foundation, either version 3.0 of the License, or #
8+
# (at your option) any later version. #
9+
# #
10+
# IfcOpenShell is distributed in the hope that it will be useful, #
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
13+
# Lesser GNU General Public License for more details. #
14+
# #
15+
# You should have received a copy of the Lesser GNU General Public License #
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
17+
# #
18+
################################################################################
19+
20+
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${OCC_INCLUDE_DIR} ${OPENCOLLADA_INCLUDE_DIRS} ${ICU_INCLUDE_DIR}
21+
${Boost_INCLUDE_DIRS} ${THREEDS_MAX_SDK_HOME}/include
22+
)
23+
24+
# All recent versions of 3ds Max (2014 and newer) are 64-bit only so assume lib/x64 directory
25+
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${IfcOpenShell_BINARY_DIR} ${OCC_LIBRARY_DIR} ${OPENCOLLADA_LIBRARY_DIR}
26+
${ICU_LIBRARY_DIR} ${Boost_LIBRARY_DIRS} ${THREEDS_MAX_SDK_HOME}/lib/x64/Release
27+
)
28+
29+
ADD_LIBRARY(IfcMax SHARED IfcMax.h IfcMax.cpp)
30+
31+
TARGET_LINK_LIBRARIES(IfcMax IfcParse IfcGeom Comctl32.lib zlibdll.lib bmm.lib core.lib CustDlg.lib edmodel.lib expr.lib
32+
flt.lib geom.lib gfx.lib gup.lib imageViewers.lib ManipSys.lib maxnet.lib Maxscrpt.lib
33+
maxutil.lib MenuMan.lib menus.lib mesh.lib MNMath.lib Paramblk2.lib particle.lib Poly.lib RenderUtil.lib
34+
tessint.lib viewfile.lib ${OPENCASCADE_LIBRARIES}
35+
)
36+
37+
SET_TARGET_PROPERTIES(IfcMax PROPERTIES SUFFIX ".dli")
38+
39+
INSTALL(TARGETS IfcMax RUNTIME DESTINATION bin)

src/ifcmax/IfcMax.cpp

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,54 @@
2020
#include <map>
2121
#include <set>
2222

23-
#include <Max.h>
2423
#include <stdmat.h>
2524
#include <istdplug.h>
2625

27-
#include "../ifcmax/IfcMax.h"
26+
#include "IfcMax.h"
2827
#include "../ifcgeom/IfcGeomIterator.h"
2928

3029
static const int NUM_MATERIAL_SLOTS = 24;
3130

32-
int controlsInit = false;
33-
34-
BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved) {
31+
BOOL WINAPI DllMain(HINSTANCE /*hinstDLL*/, ULONG /*fdwReason*/, LPVOID /*lpvReserved*/) {
32+
static int controlsInit = false;
3533
if (!controlsInit) {
3634
controlsInit = true;
3735
InitCommonControls();
38-
}
39-
return true;
40-
}
41-
42-
__declspec( dllexport ) const TCHAR* LibDescription() {
43-
return _T("IfcOpenShell IFC Importer");
36+
}
37+
return TRUE;
4438
}
4539

46-
__declspec( dllexport ) int LibNumberClasses() { return 1; }
47-
48-
static class IFCImpClassDesc:public ClassDesc {
40+
static class IFCImpClassDesc :public ClassDesc {
4941
public:
50-
int IsPublic() {return 1;}
51-
void * Create(BOOL loading = FALSE) {return new IFCImp;}
52-
const TCHAR * ClassName() {return _T("IFCImp");}
53-
SClass_ID SuperClassID() {return SCENE_IMPORT_CLASS_ID;}
54-
Class_ID ClassID() {return Class_ID(0x3f230dbf, 0x5b3015c2);}
55-
const TCHAR* Category() {return _T("Chrutilities");}
42+
int IsPublic() { return 1; }
43+
void * Create(BOOL /*loading = FALSE*/) { return new IFCImp; }
44+
// TODO Delete() function?
45+
const TCHAR * ClassName() { return _T("IFCImp"); }
46+
SClass_ID SuperClassID() { return SCENE_IMPORT_CLASS_ID; }
47+
Class_ID ClassID() { return Class_ID(0x3f230dbf, 0x5b3015c2); }
48+
const TCHAR* Category() { return _T("Chrutilities"); }
5649
} IFCImpDesc;
5750

58-
__declspec( dllexport ) ClassDesc* LibClassDesc(int i) {
59-
return i == 0 ? &IFCImpDesc : 0;
51+
#define DLLEXPORT __declspec(dllexport)
52+
53+
extern "C" {
54+
55+
DLLEXPORT const TCHAR* LibDescription() {
56+
return _T("IfcOpenShell IFC Importer");
57+
}
58+
59+
DLLEXPORT int LibNumberClasses() { return 1; }
60+
61+
DLLEXPORT ClassDesc* LibClassDesc(int i) {
62+
return i == 0 ? &IFCImpDesc : 0;
6063
}
6164

62-
__declspec( dllexport ) ULONG LibVersion() {
63-
return VERSION_3DSMAX;
65+
DLLEXPORT ULONG LibVersion() {
66+
return VERSION_3DSMAX;
6467
}
6568

69+
} // extern "C"
70+
6671
int IFCImp::ExtCount() { return 1; }
6772

6873
const TCHAR * IFCImp::Ext(int n) {
@@ -82,7 +87,7 @@ const TCHAR * IFCImp::AuthorName() {
8287
}
8388

8489
const TCHAR * IFCImp::CopyrightMessage() {
85-
return _T("Copyight (c) 2011 IfcOpenShell");
90+
return _T("Copyright (c) 2011-2016 IfcOpenShell");
8691
}
8792

8893
const TCHAR * IFCImp::OtherMessage1() {
@@ -97,13 +102,14 @@ unsigned int IFCImp::Version() {
97102
return 12;
98103
}
99104

100-
static BOOL CALLBACK AboutBoxDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
101-
return TRUE;
102-
}
105+
// TODO Use this in IFCImp::ShowAbout() if/when wanted
106+
//static BOOL CALLBACK AboutBoxDlgProc(HWND /*hWnd*/, UINT /*msg*/, WPARAM /*wParam*/, LPARAM /*lParam*/) {
107+
// return TRUE;
108+
//}
103109

104-
void IFCImp::ShowAbout(HWND hWnd) {}
110+
void IFCImp::ShowAbout(HWND /*hWnd*/) {}
105111

106-
DWORD WINAPI fn(LPVOID arg) { return 0; }
112+
DWORD WINAPI fn(LPVOID /*arg*/) { return 0; }
107113

108114
#if MAX_RELEASE > 14000
109115
# define S(x) (TSTR::FromCStr(x.c_str()))
@@ -113,16 +119,17 @@ DWORD WINAPI fn(LPVOID arg) { return 0; }
113119
# define S(x) (CStr(x.c_str()))
114120
#endif
115121

116-
Mtl* FindMaterialByName(MtlBaseLib* library, const std::string& material_name) {
117-
const int mat_index = library->FindMtlByName(S(material_name));
122+
static Mtl* FindMaterialByName(MtlBaseLib* library, const std::string& material_name) {
123+
TSTR mat_name = S(material_name);
124+
const int mat_index = library->FindMtlByName(mat_name);
118125
Mtl* m = 0;
119126
if (mat_index != -1) {
120127
m = static_cast<Mtl*>((*library)[mat_index]);
121128
}
122129
return m;
123130
}
124131

125-
Mtl* FindOrCreateMaterial(MtlBaseLib* library, Interface* max_interface, int& slot, const IfcGeom::Material& material) {
132+
static Mtl* FindOrCreateMaterial(MtlBaseLib* library, Interface* max_interface, int& slot, const IfcGeom::Material& material) {
126133
Mtl* m = FindMaterialByName(library, material.name());
127134
if (m == 0) {
128135
StdMat2* stdm = NewDefaultStdMat();
@@ -136,10 +143,10 @@ Mtl* FindOrCreateMaterial(MtlBaseLib* library, Interface* max_interface, int& sl
136143
stdm->SetSpecular(Color(specular[0], specular[1], specular[2]),t);
137144
}
138145
if (material.hasSpecularity()) {
139-
stdm->SetShininess(material.specularity(), t);
146+
stdm->SetShininess((float)material.specularity(), t);
140147
}
141148
if (material.hasTransparency()) {
142-
stdm->SetOpacity(1.0 - material.transparency(), t);
149+
stdm->SetOpacity(1.0f - (float)material.transparency(), t);
143150
}
144151
m = stdm;
145152
m->SetName(S(material.name()));
@@ -151,7 +158,10 @@ Mtl* FindOrCreateMaterial(MtlBaseLib* library, Interface* max_interface, int& sl
151158
return m;
152159
}
153160

154-
Mtl* ComposeMultiMaterial(std::map<std::vector<std::string>, Mtl*>& multi_mats, MtlBaseLib* library, Interface* max_interface, int& slot, const std::vector<IfcGeom::Material>& materials, const std::string& object_type, const std::vector<int>& material_ids) {
161+
static Mtl* ComposeMultiMaterial(std::map<std::vector<std::string>, Mtl*>& multi_mats, MtlBaseLib* library,
162+
Interface* max_interface, int& slot, const std::vector<IfcGeom::Material>& materials,
163+
const std::string& object_type, const std::vector<int>& material_ids)
164+
{
155165
std::vector<std::string> material_names;
156166
bool needs_default = std::find(material_ids.begin(), material_ids.end(), -1) != material_ids.end();
157167
if (needs_default) {
@@ -184,7 +194,7 @@ Mtl* ComposeMultiMaterial(std::map<std::vector<std::string>, Mtl*>& multi_mats,
184194
return i->second;
185195
}
186196
MultiMtl* multi_mat = NewDefaultMultiMtl();
187-
multi_mat->SetNumSubMtls(material_names.size());
197+
multi_mat->SetNumSubMtls((int)material_names.size());
188198
int mtl_id = 0;
189199
if (needs_default) {
190200
multi_mat->SetSubMtlAndName(mtl_id ++, default_material, default_material->GetName());
@@ -201,7 +211,7 @@ Mtl* ComposeMultiMaterial(std::map<std::vector<std::string>, Mtl*>& multi_mats,
201211
return multi_mat;
202212
}
203213

204-
int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, BOOL suppressPrompts) {
214+
int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, BOOL /*suppressPrompts*/) {
205215

206216
IfcGeom::IteratorSettings settings;
207217
settings.use_world_coords() = false;
@@ -217,7 +227,7 @@ int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc,
217227
#endif
218228

219229
IfcGeom::Iterator<float> iterator(settings, fn_mb);
220-
230+
delete fn_mb;
221231
if (!iterator.initialize()) return false;
222232

223233
itfc->ProgressStart(_T("Importing file..."), TRUE, fn, NULL);
@@ -237,12 +247,12 @@ int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc,
237247

238248
TriObject* tri = CreateNewTriObject();
239249

240-
const int numVerts = o->geometry().verts().size()/3;
250+
const int numVerts = (int)o->geometry().verts().size()/3;
241251
tri->mesh.setNumVerts(numVerts);
242252
for( int i = 0; i < numVerts; i ++ ) {
243253
tri->mesh.setVert(i,o->geometry().verts()[3*i+0],o->geometry().verts()[3*i+1],o->geometry().verts()[3*i+2]);
244254
}
245-
const int numFaces = o->geometry().faces().size()/3;
255+
const int numFaces = (int)o->geometry().faces().size()/3;
246256
tri->mesh.setNumFaces(numFaces);
247257

248258
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,
274284
tri->mesh.faces[i].setVerts(v1, v2, v3);
275285
tri->mesh.faces[i].setEdgeVisFlags(b1, b2, b3);
276286

277-
MtlID mtlid = o->geometry().material_ids()[i];
287+
MtlID mtlid = (MtlID)o->geometry().material_ids()[i];
278288
if (needs_default) {
279289
mtlid ++;
280290
}
@@ -310,4 +320,4 @@ int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc,
310320
itfc->ProgressEnd();
311321

312322
return true;
313-
}
323+
}

src/ifcmax/IfcMax.def

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/ifcmax/IfcMax.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
#define IFCMAX_H
2222

2323
#include "Max.h"
24-
#include "istdplug.h"
25-
#include "stdmat.h"
26-
#include "decomp.h"
27-
#include "shape.h"
28-
#include "splshape.h"
29-
#include "dummy.h"
3024

3125
extern ClassDesc* GetIFCImpDesc();
3226

@@ -38,7 +32,7 @@ class IFCImp : public SceneImport
3832
const TCHAR * LongDesc(); // = "IfcOpenShell IFC Importer for 3ds Max"
3933
const TCHAR * ShortDesc(); // = "Industry Foundation Classes"
4034
const TCHAR * AuthorName(); // = "Thomas Krijnen"
41-
const TCHAR * CopyrightMessage(); // = "Copyight (c) 2011 IfcOpenShell"
35+
const TCHAR * CopyrightMessage(); // = "Copyright (c) 2011-2016 IfcOpenShell"
4236
const TCHAR * OtherMessage1(); // = ""
4337
const TCHAR * OtherMessage2(); // = ""
4438
unsigned int Version(); // = 12

win/build-deps.cmd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,3 @@ echo - https://www.visualstudio.com/
434434
echo 5. Run this batch script with Visual Studio environment variables set.
435435
echo - https://msdn.microsoft.com/en-us/library/ms229859(v=vs.110).aspx
436436
echo.
437-
REM TODO 3ds Max SDK instructions?

win/readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ After this, one can build the project using the `IfcOpenShell.sln` file in the b
4040
if wanted. Convenience batch files `build-ifcopenshell.cmd` and `install-ifcopenshell.cmd` can also be used. The batch files
4141
expect `%1` and `%2` in same fashion as above and possible extra parameters are passed for the `MSBuild` call. The project will
4242
be installed to `installed-vs<VERSION>-<ARCHITECTURE>\` folder in the project's root folder and the required IfcOpenShell-Python
43-
parts are deployed to the `<PYTHONHOME>\Lib\site-packages\` folder.
43+
parts are deployed to the `<PYTHONHOME>\Lib\site-packages\` folder. The 3ds Max plug-in, IfcMax.dli, needs to be copied manually
44+
to the 3ds Max's `plugins` folder.
4445

4546
**Note:** All of the dependencies are build as static libraries against the static run-time allowing the developer
4647
to effortlessly deploy standalone IFCOS binaries.

win/run-cmake.bat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ set PYTHON_LIBRARY=%PYTHONHOME%\libs\python%PY_VER_MAJOR_MINOR%.lib
5959
set PYTHON_EXECUTABLE=%PYTHONHOME%\python.exe
6060
set SWIG_DIR=%INSTALL_DIR%\swigwin
6161
set PATH=%PATH%;%SWIG_DIR%;%PYTHONHOME%
62-
:: TODO 3ds Max SDK?
62+
set THREEDS_MAX_SDK_HOME=C:\Program Files\Autodesk\3ds Max 2016 SDK\maxsdk
6363

6464
echo.
6565
call cecho.cmd 0 10 "Script configuration:"
@@ -80,6 +80,7 @@ echo PYTHON_INCLUDE_DIR = %PYTHON_INCLUDE_DIR%
8080
echo PYTHON_LIBRARY = %PYTHON_LIBRARY%
8181
echo PYTHON_EXECUTABLE = %PYTHON_EXECUTABLE%
8282
echo SWIG_DIR = %SWIG_DIR%
83+
echo THREEDS_MAX_SDK_HOME = %THREEDS_MAX_SDK_HOME%
8384
echo.
8485
echo CMAKE_INSTALL_PREFIX = %CMAKE_INSTALL_PREFIX%
8586
echo.

0 commit comments

Comments
 (0)