66
77VGEOMETRY *NODER::gs = nullptr ;
88VDX9RENDER *NODER::rs = nullptr ;
9- static long nlab = 0 ;
109long NODER::depth = -1 ;
1110long NODER::node;
1211extern long clip_nps;
@@ -15,7 +14,6 @@ extern const CVECTOR *clip_c;
1514extern float clip_r;
1615extern GEOS::ADD_POLYGON_FUNC clip_geosap;
1716extern ADD_POLYGON_FUNC clip_ap;
18- char nm[256 ];
1917GEOS::PLANE clip_gp[256 ];
2018NODE *bestTraceNode = nullptr ;
2119GEOS *clipGeo;
@@ -43,7 +41,7 @@ bool AddPolygon(const GEOS::VERTEX *vr, long nv)
4341// -------------------------------------------------------------------
4442bool NODER::Clip ()
4543{
46- if (isReleaed )
44+ if (isReleased )
4745 return false ;
4846
4947 // check for bounding spheres intersection
@@ -122,7 +120,7 @@ float NODER::Update(CMatrix &mtx, CVECTOR &cnt)
122120// ----------------------------------------------------------
123121float NODER::Trace (const CVECTOR &src, const CVECTOR &dst)
124122{
125- if (isReleaed )
123+ if (isReleased )
126124 return 2 .0f ;
127125 // check for bounding spheres intersection
128126 const auto lmn = dst - src;
@@ -174,17 +172,14 @@ NODER::NODER()
174172 nnext = 0 ;
175173 next = nullptr ;
176174 parent = nullptr ;
177- sys_modelName = nullptr ;
178- sys_TexPath = nullptr ;
179- sys_LightPath = nullptr ;
180- sys_lmPath = nullptr ;
181175
182176 max_view_dist = 0 .f ;
183177}
184178
185179bool NODER::Init (const char *lightPath, const char *pname, const char *oname, const CMatrix &m, const CMatrix &globm,
186180 NODER *par, const char *lmPath)
187181{
182+ isReleased = false ;
188183 name[0 ] = 0 ;
189184 technique[0 ] = 0 ;
190185 geoMaterialFunc = nullptr ;
@@ -193,44 +188,28 @@ bool NODER::Init(const char *lightPath, const char *pname, const char *oname, co
193188 loc_mtx = m;
194189 glob_mtx.EqMultiply (loc_mtx, globm);
195190
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;
213196
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;
217204
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;
222207
223- isReleaed = false ;
208+ sys_TexPath = gs-> GetTexturePath () ;
224209
225- geo = gs->CreateGeometry (nm, lp , 0 , lmPath);
210+ geo = gs->CreateGeometry (sys_modelName_full. c_str (), sys_LightPath. c_str () , 0 , lmPath);
226211 if (!geo)
227212 {
228- delete sys_modelName;
229- sys_modelName = nullptr ;
230- delete sys_LightPath;
231- sys_LightPath = nullptr ;
232- delete sys_lmPath;
233- sys_lmPath = nullptr ;
234213 return false ;
235214 }
236215
@@ -305,19 +284,15 @@ NODER::~NODER()
305284 delete next[l];
306285 if (nnext > 0 )
307286 free (next);
308- delete sys_modelName;
309- delete sys_LightPath;
310- delete sys_lmPath;
311- delete sys_TexPath;
312287}
313288
314289void NODER::ReleaseGeometry ()
315290{
316- if (isReleaed )
291+ if (isReleased )
317292 return ;
318293 delete geo;
319294 geo = nullptr ;
320- isReleaed = true ;
295+ isReleased = true ;
321296 for (long i = 0 ; i < nnext; i++)
322297 {
323298 if (!next[i])
@@ -328,21 +303,21 @@ void NODER::ReleaseGeometry()
328303
329304void NODER::RestoreGeometry ()
330305{
331- if (!isReleaed )
306+ if (!isReleased )
332307 return ;
333308
334309 const auto *const tPath = gs->GetTexturePath ();
335310 const auto len = strlen (tPath) + 1 ;
336311 auto *const ttPath = new char [len];
337312 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 () );
340315 gs->SetTexturePath (ttPath);
341316 delete[] ttPath;
342317 if (!geo)
343- throw std::runtime_error (" No geometry" );
318+ throw std::runtime_error (fmt::format ( " Cannot restore geometry {} " , sys_modelName_full) );
344319
345- isReleaed = false ;
320+ isReleased = false ;
346321 for (long i = 0 ; i < nnext; i++)
347322 {
348323 if (!next[i])
@@ -359,7 +334,7 @@ GEOS::PLANE TViewPlane[4];
359334
360335void NODER::Draw ()
361336{
362- if (isReleaed )
337+ if (isReleased )
363338 return ;
364339
365340 const auto cnt = glob_mtx * center;
@@ -617,3 +592,10 @@ void NODER::SetMaxViewDist(float fDist)
617592 if (next[n])
618593 static_cast <NODER *>(next[n])->SetMaxViewDist (fDist );
619594}
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