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 " Max.h"
21+ #include " stdmat.h"
22+ #include " decomp.h"
23+ #include " shape.h"
24+ #include " splshape.h"
25+ #include " dummy.h"
26+ #include " istdplug.h"
27+
28+ #include " ../ifcmax/IfcMax.h"
29+ #include " ../ifcmax/MaxMaterials.h"
30+ #include " ../ifcparse/IfcGeomObjects.h"
31+
32+ int controlsInit = false ;
33+
34+ BOOL WINAPI DllMain (HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved) {
35+ if (!controlsInit) {
36+ controlsInit = true ;
37+ InitCommonControls ();
38+ }
39+ return true ;
40+ }
41+
42+ __declspec ( dllexport ) const TCHAR* LibDescription() {
43+ return _T (" IfcOpenShell IFC Importer" );
44+ }
45+
46+ __declspec ( dllexport ) int LibNumberClasses() { return 1 ; }
47+
48+ static class IFCImpClassDesc :public ClassDesc {
49+ 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" );}
56+ } IFCImpDesc;
57+
58+ __declspec ( dllexport ) ClassDesc* LibClassDesc(int i) {
59+ return i == 0 ? &IFCImpDesc : 0 ;
60+ }
61+
62+ __declspec ( dllexport ) ULONG LibVersion() {
63+ return VERSION_3DSMAX;
64+ }
65+
66+ int IFCImp::ExtCount () { return 1 ; }
67+
68+ const TCHAR * IFCImp::Ext (int n) {
69+ return n == 0 ? _T (" IFC" ) : _T (" " );
70+ }
71+
72+ const TCHAR * IFCImp::LongDesc () {
73+ return _T (" IfcOpenShell IFC Importer for 3ds Max" );
74+ }
75+
76+ const TCHAR * IFCImp::ShortDesc () {
77+ return _T (" Industry Foundation Classes" );
78+ }
79+
80+ const TCHAR * IFCImp::AuthorName () {
81+ return _T (" Thomas Krijnen" );
82+ }
83+
84+ const TCHAR * IFCImp::CopyrightMessage () {
85+ return _T (" Copyight (c) 2011 IfcOpenShell" );
86+ }
87+
88+ const TCHAR * IFCImp::OtherMessage1 () {
89+ return _T (" " );
90+ }
91+
92+ const TCHAR * IFCImp::OtherMessage2 () {
93+ return _T (" " );
94+ }
95+
96+ unsigned int IFCImp::Version () {
97+ return 12 ;
98+ }
99+
100+ static BOOL CALLBACK AboutBoxDlgProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
101+ return TRUE ;
102+ }
103+
104+ void IFCImp::ShowAbout (HWND hWnd) {}
105+
106+ DWORD WINAPI fn (LPVOID arg) { return 0 ; }
107+
108+ int IFCImp::DoImport (const TCHAR *name, ImpInterface *impitfc, Interface *itfc, BOOL suppressPrompts) {
109+
110+ itfc->ProgressStart (" Importing file..." , TRUE , fn, NULL );
111+
112+ if ( ! IfcGeomObjects::Init ((char *)name) ) return false ;
113+
114+ std::map<int , TriObject*> dict;
115+ MtlBaseLib* mats = itfc->GetSceneMtls ();
116+ int slot = mats->Count ();
117+
118+ do {
119+
120+ const IfcGeomObjects::IfcGeomObject* o = IfcGeomObjects::Get ();
121+
122+ Mtl *m;
123+ const int matIndex = mats->FindMtlByName (MSTR (o->type .c_str ()));
124+ if ( matIndex == -1 ) {
125+ StdMat2* stdm = GetMaterial (o->type );
126+ m = stdm;
127+ m->SetName (o->type .c_str ());
128+ mats->Add (m);
129+ itfc->PutMtlToMtlEditor (m,slot++);
130+ } else {
131+ m = static_cast <Mtl*>((*mats)[matIndex]);
132+ }
133+
134+ std::map<int , TriObject*>::const_iterator it = dict.find (o->mesh ->id );
135+
136+ TriObject* tri;
137+ if ( it == dict.end () ) {
138+ tri = CreateNewTriObject ();
139+ const int numVerts = o->mesh ->verts .size ()/3 ;
140+ tri->mesh .setNumVerts (numVerts);
141+ for ( int i = 0 ; i < numVerts; i ++ ) {
142+ tri->mesh .setVert (i,o->mesh ->verts [3 *i+0 ],o->mesh ->verts [3 *i+1 ],o->mesh ->verts [3 *i+2 ]);
143+ }
144+ const int numFaces = o->mesh ->faces .size ()/3 ;
145+ tri->mesh .setNumFaces (numFaces);
146+ for ( int i = 0 ; i < numFaces; i ++ ) {
147+ tri->mesh .faces [i].setVerts (o->mesh ->faces [3 *i+0 ],o->mesh ->faces [3 *i+1 ],o->mesh ->faces [3 *i+2 ]);
148+ tri->mesh .faces [i].setEdgeVisFlags (o->mesh ->edges [3 *i+0 ],o->mesh ->edges [3 *i+1 ],o->mesh ->edges [3 *i+2 ]);
149+ }
150+ tri->mesh .InvalidateTopologyCache ();
151+ tri->mesh .InvalidateGeomCache ();
152+ tri->mesh .buildNormals ();
153+ tri->mesh .BuildStripsAndEdges ();
154+ dict[o->mesh ->id ] = tri;
155+ } else {
156+ tri = (*it).second ;
157+ }
158+
159+ ImpNode* node = impitfc->CreateNode ();
160+ node->Reference (tri);
161+ node->SetName (o->name .c_str ());
162+ node->GetINode ()->SetMtl (m);
163+ node->SetTransform (0 ,Matrix3 ( Point3 (o->matrix [0 ],o->matrix [1 ],o->matrix [2 ]),Point3 (o->matrix [3 ],o->matrix [4 ],o->matrix [5 ]),
164+ Point3 (o->matrix [6 ],o->matrix [7 ],o->matrix [8 ]),Point3 (o->matrix [9 ],o->matrix [10 ],o->matrix [11 ]) ));
165+ impitfc->AddNodeToScene (node);
166+
167+ itfc->ProgressUpdate (IfcGeomObjects::Progress (),true ," " );
168+
169+ } while ( IfcGeomObjects::Next () );
170+
171+ itfc->ProgressEnd ();
172+
173+ return true ;
174+ }
0 commit comments