6
6
7
7
VGEOMETRY *NODER::gs = nullptr ;
8
8
VDX9RENDER *NODER::rs = nullptr ;
9
- static long nlab = 0 ;
10
9
long NODER::depth = -1 ;
11
10
long NODER::node;
12
11
extern long clip_nps;
@@ -15,7 +14,6 @@ extern const CVECTOR *clip_c;
15
14
extern float clip_r;
16
15
extern GEOS::ADD_POLYGON_FUNC clip_geosap;
17
16
extern ADD_POLYGON_FUNC clip_ap;
18
- char nm[256 ];
19
17
GEOS::PLANE clip_gp[256 ];
20
18
NODE *bestTraceNode = nullptr ;
21
19
GEOS *clipGeo;
@@ -43,7 +41,7 @@ bool AddPolygon(const GEOS::VERTEX *vr, long nv)
43
41
// -------------------------------------------------------------------
44
42
bool NODER::Clip ()
45
43
{
46
- if (isReleaed )
44
+ if (isReleased )
47
45
return false ;
48
46
49
47
// check for bounding spheres intersection
@@ -122,7 +120,7 @@ float NODER::Update(CMatrix &mtx, CVECTOR &cnt)
122
120
// ----------------------------------------------------------
123
121
float NODER::Trace (const CVECTOR &src, const CVECTOR &dst)
124
122
{
125
- if (isReleaed )
123
+ if (isReleased )
126
124
return 2 .0f ;
127
125
// check for bounding spheres intersection
128
126
const auto lmn = dst - src;
@@ -174,17 +172,14 @@ NODER::NODER()
174
172
nnext = 0 ;
175
173
next = nullptr ;
176
174
parent = nullptr ;
177
- sys_modelName = nullptr ;
178
- sys_TexPath = nullptr ;
179
- sys_LightPath = nullptr ;
180
- sys_lmPath = nullptr ;
181
175
182
176
max_view_dist = 0 .f ;
183
177
}
184
178
185
179
bool NODER::Init (const char *lightPath, const char *pname, const char *oname, const CMatrix &m, const CMatrix &globm,
186
180
NODER *par, const char *lmPath)
187
181
{
182
+ isReleased = false ;
188
183
name[0 ] = 0 ;
189
184
technique[0 ] = 0 ;
190
185
geoMaterialFunc = nullptr ;
@@ -193,44 +188,28 @@ bool NODER::Init(const char *lightPath, const char *pname, const char *oname, co
193
188
loc_mtx = m;
194
189
glob_mtx.EqMultiply (loc_mtx, globm);
195
190
196
- nlab++;
197
- if (oname[0 ] == 0 )
198
- sprintf_s (nm, " %s" , pname);
199
- else
200
- sprintf_s (nm, " %s_%s" , pname, oname);
201
-
202
- char lp[256 ];
203
- // sprintf_s(lp, "%s\\%s", lightPath, nm);
204
- sprintf_s (lp, " %s" , lightPath);
205
-
206
- auto len = strlen (nm) + 1 ;
207
- sys_modelName = new char [len];
208
- memcpy (sys_modelName, nm, len);
209
-
210
- len = strlen (lp) + 1 ;
211
- sys_LightPath = new char [len];
212
- memcpy (sys_LightPath, lp, len);
191
+ if (pname == nullptr )
192
+ {
193
+ throw std::runtime_error (fmt::format (" NODER::Init: got nullptr model name" ));
194
+ }
195
+ sys_modelName_base = pname;
213
196
214
- len = strlen (lmPath) + 1 ;
215
- sys_lmPath = new char [len];
216
- memcpy (sys_lmPath, lmPath, len);
197
+ if (oname && oname[0 ])
198
+ sys_modelName_full = fmt::format (" {}_{}" , sys_modelName_base, oname);
199
+ else
200
+ sys_modelName_full = sys_modelName_base;
201
+
202
+ if (lightPath)
203
+ sys_LightPath = lightPath;
217
204
218
- const auto *const tPath = gs->GetTexturePath ();
219
- len = strlen (tPath) + 1 ;
220
- sys_TexPath = new char [len];
221
- memcpy (sys_TexPath, tPath, len);
205
+ if (lmPath)
206
+ sys_lmPath = lmPath;
222
207
223
- isReleaed = false ;
208
+ sys_TexPath = gs-> GetTexturePath () ;
224
209
225
- geo = gs->CreateGeometry (nm, lp , 0 , lmPath);
210
+ geo = gs->CreateGeometry (sys_modelName_full. c_str (), sys_LightPath. c_str () , 0 , lmPath);
226
211
if (!geo)
227
212
{
228
- delete sys_modelName;
229
- sys_modelName = nullptr ;
230
- delete sys_LightPath;
231
- sys_LightPath = nullptr ;
232
- delete sys_lmPath;
233
- sys_lmPath = nullptr ;
234
213
return false ;
235
214
}
236
215
@@ -305,19 +284,15 @@ NODER::~NODER()
305
284
delete next[l];
306
285
if (nnext > 0 )
307
286
free (next);
308
- delete sys_modelName;
309
- delete sys_LightPath;
310
- delete sys_lmPath;
311
- delete sys_TexPath;
312
287
}
313
288
314
289
void NODER::ReleaseGeometry ()
315
290
{
316
- if (isReleaed )
291
+ if (isReleased )
317
292
return ;
318
293
delete geo;
319
294
geo = nullptr ;
320
- isReleaed = true ;
295
+ isReleased = true ;
321
296
for (long i = 0 ; i < nnext; i++)
322
297
{
323
298
if (!next[i])
@@ -328,21 +303,21 @@ void NODER::ReleaseGeometry()
328
303
329
304
void NODER::RestoreGeometry ()
330
305
{
331
- if (!isReleaed )
306
+ if (!isReleased )
332
307
return ;
333
308
334
309
const auto *const tPath = gs->GetTexturePath ();
335
310
const auto len = strlen (tPath) + 1 ;
336
311
auto *const ttPath = new char [len];
337
312
memcpy (ttPath, tPath, len);
338
- gs->SetTexturePath (sys_TexPath);
339
- geo = gs->CreateGeometry (sys_modelName , sys_LightPath, 0 , sys_lmPath);
313
+ gs->SetTexturePath (sys_TexPath. c_str () );
314
+ geo = gs->CreateGeometry (sys_modelName_full. c_str () , sys_LightPath. c_str () , 0 , sys_lmPath. c_str () );
340
315
gs->SetTexturePath (ttPath);
341
316
delete[] ttPath;
342
317
if (!geo)
343
- throw std::runtime_error (" No geometry" );
318
+ throw std::runtime_error (fmt::format ( " Cannot restore geometry {} " , sys_modelName_full) );
344
319
345
- isReleaed = false ;
320
+ isReleased = false ;
346
321
for (long i = 0 ; i < nnext; i++)
347
322
{
348
323
if (!next[i])
@@ -359,7 +334,7 @@ GEOS::PLANE TViewPlane[4];
359
334
360
335
void NODER::Draw ()
361
336
{
362
- if (isReleaed )
337
+ if (isReleased )
363
338
return ;
364
339
365
340
const auto cnt = glob_mtx * center;
@@ -617,3 +592,10 @@ void NODER::SetMaxViewDist(float fDist)
617
592
if (next[n])
618
593
static_cast <NODER *>(next[n])->SetMaxViewDist (fDist );
619
594
}
595
+
596
+ void NODER::SubstituteGeometry (const std::string &new_model)
597
+ {
598
+ sys_modelName_full = fmt::format (" {}_{}" , sys_modelName_base, new_model);
599
+ ReleaseGeometry ();
600
+ RestoreGeometry ();
601
+ }
0 commit comments