-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathApp_SceneObjects.cpp
701 lines (598 loc) · 18.8 KB
/
App_SceneObjects.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
#include "pch.h"
#include "RenderConst.h"
#include "Def_Str.h"
#include "paths.h"
#include "settings.h"
#include "App.h"
#ifdef SR_EDITOR
#include "CGui.h"
#include "Road.h"
#else
#include "game.h"
#endif
#include "SceneXml.h"
#include "CScene.h"
#include "CData.h"
#include "PresetsXml.h"
#include "Axes.h"
#include "BtOgreGP.h"
#include "ShapeData.h"
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
#include <LinearMath/btDefaultMotionState.h>
#include <BulletDynamics/Dynamics/btRigidBody.h>
#include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
#include <LinearMath/btSerializer.h>
#include <BulletFileLoader/btBulletFile.h>
#include <BulletWorldImporter/btBulletWorldImporter.h>
#include <OgreCommon.h>
#include <OgreMeshManager.h>
#include <OgreMaterialManager.h>
#include <OgreItem.h>
#include <OgreSceneManager.h>
#include <OgreSceneNode.h>
#include <OgreCamera.h>
#include <OgreWindow.h>
using namespace Ogre;
using namespace std;
/// 🎳📦 Objects ... .. . . .
//----------------------------------------------------------------------------------------------------------------------
class BulletWorldOffset : public btBulletWorldImporter
{
public:
btTransform mTrOfs; // in offset
btDefaultMotionState* ms; // out
btRigidBody* rb; // out
BulletWorldOffset(btDynamicsWorld* world=0)
: btBulletWorldImporter(world), ms(0), rb(0)
{
mTrOfs.setIdentity();
}
//todo: shape->setUserPointer((void*)SU_ObjectDynamic); // mark shapes..
btCollisionObject* createCollisionObject(const btTransform& startTransform, btCollisionShape* shape, const char* bodyName)
{
return createRigidBody(false,0,startTransform,shape,bodyName);
}
btRigidBody* createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform,
btCollisionShape* shape, const char* bodyName)
{
btVector3 localInertia;
localInertia.setZero();
if (mass)
shape->calculateLocalInertia(mass,localInertia);
ms = new btDefaultMotionState();
ms->setWorldTransform(mTrOfs);
btRigidBody* body = new btRigidBody(mass,ms,shape,localInertia);
body->setDamping(0.1, 0.3);
//body->setFriction(0.5);
rb = body;
#ifdef SR_EDITOR
//body->setActivationState(DISABLE_DEACTIVATION);
#else
body->setActivationState(WANTS_DEACTIVATION); // game creates deactivated (sleeping)
#endif
if (m_dynamicsWorld)
m_dynamicsWorld->addRigidBody(body);
/*if (bodyName)
{
char* newname = duplicateName(bodyName);
m_objectNameMap.insert(body,newname);
m_nameBodyMap.insert(newname,body);
}*/
m_allocatedRigidBodies.push_back(body);
return body;
}
};
// 🆕 Create
//-------------------------------------------------------------------------------------------------------
void App::CreateObjects()
{
// maps for file exist (optimized)
using std::map; using std::string;
map<string,bool> objExists, objHasBlt;
for (int i=0; i < scn->sc->objects.size(); ++i)
{
const string& s = scn->sc->objects[i].name;
objExists[s] = false; objHasBlt[s] = false;
}
const static int dirCnt = 7;
const static char* dirs[dirCnt] = { // add also in all resources3.cfg
"objects", "rocks", "objects2", "obstacles", "objects0", "objectsC", "rockshex"};
for (auto& o : objExists)
{
o.second = false;
for (int d=0; d < dirCnt; ++d)
if (PATHS::FileExists(PATHS::Models() +"/"+ dirs[d] +"/"+ o.first + ".mesh"))
{ o.second = true; break; }
if (!o.second)
LogO("Warning: CreateObjects mesh doesn't exist: " + o.first + ".mesh");
}
for (auto& ob : objHasBlt)
ob.second = PATHS::FileExists(PATHS::Models() +"/"+ dirs[0] +"/"+ ob.first + ".bullet");
// loader
#ifndef SR_EDITOR
btDiscreteDynamicsWorld* world = pGame->collision.world;
#endif
BulletWorldOffset* fileLoader = new BulletWorldOffset(world);
/// create . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
for (int i=0; i < scn->sc->objects.size(); ++i)
{
Object& o = scn->sc->objects[i];
String s = toStr(i); // counter for names
o.dyn = o.stat ? false : objHasBlt[o.name];
#ifndef SR_EDITOR
if (o.dyn && !pSet->game.dyn_objects) continue;
#endif
// add to ogre
bool no = !objExists[o.name];
if (no) continue; //- no spheres
try
{ o.it = mSceneMgr->createItem((no ? "sphere" : o.name) + ".mesh");
if (!o.material.empty())
o.it->setDatablockOrMaterialName(o.material);
o.it->setName("oE"+s);
SetTexWrap(o.it);
o.it->setCastShadows(o.shadow);
}
catch (Exception& e)
{
LogO(String("Create object fail: ") + e.what());
continue;
}
o.nd = mSceneMgr->getRootSceneNode(SCENE_DYNAMIC)->createChildSceneNode();
o.SetFromBlt();
o.nd->attachObject(o.it); o.it->setVisibilityFlags(RV_Objects);
o.nd->setScale(o.scale);
// alpha from presets.xml
auto* veg = scn->data->pre->GetVeget(o.name);
if (veg)
o.it->setRenderQueueGroup( veg->alpha ? RQG_AlphaVegObj : RQG_Road );
if (no) continue;
// add to bullet world (in game)
if (!o.dyn)
{
/// 🏢 static . . . . . . . . . . . .
Vector3 posO = Axes::toOgre(o.pos);
Quaternion rotO = Axes::toOgreW(o.rot);
Matrix4 tre; tre.makeTransform(posO, o.scale, rotO);
BtOgre::StaticMeshToShapeConverter converter(o.it, tre);
btCollisionShape* shape = converter.createTrimesh(); //=new x2 todo:del?...
shape->setUserPointer((void*)SU_ObjectStatic); // mark
btCollisionObject* bco = new btCollisionObject();
btTransform tr; tr.setIdentity(); //tr.setOrigin(btVector3(pos.x,-pos.z,pos.y));
bco->setActivationState(DISABLE_SIMULATION); // WANTS_DEACTIVATION
bco->setCollisionShape(shape); bco->setWorldTransform(tr);
bco->setFriction(0.7f); //+
bco->setRestitution(0.f);
bco->setCollisionFlags(bco->getCollisionFlags() |
btCollisionObject::CF_STATIC_OBJECT | btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT/**/);
world->addCollisionObject(bco);
#ifndef SR_EDITOR
o.co = bco; o.ms = 0; o.rb = 0;
pGame->collision.shapes.push_back(shape);
#endif
}
else /// 📦 dynamic . . . . . . . . . . . .
{
// .bullet load
fileLoader->mTrOfs.setOrigin(btVector3(o.pos[0],o.pos[1],o.pos[2]));
fileLoader->mTrOfs.setRotation(btQuaternion(o.rot[0],o.rot[1],o.rot[2],o.rot[3]));
//fileLoader->setVerboseMode(true);//
std::string file = PATHS::Objects() + o.name + ".bullet";
if (fileLoader->loadFile(file.c_str()))
{
o.ms = fileLoader->ms; // 1 only
o.rb = fileLoader->rb; // 1 only
o.rb->setUserPointer(new ShapeData(ST_Object, 0, 0, 0, 0, 0, 0.f, &o)); ///~~
/*int nshp = fileLoader->getNumCollisionShapes();
for (int i=0; i < nshp; ++i)
pGame->collision.shapes.push_back(
fileLoader->getCollisionShapeByIndex(i));/**/
#ifndef SR_EDITOR
btTransform t1; // save 1st pos for reset
o.ms->getWorldTransform(t1);
o.tr1 = new btTransform(t1);
#endif
#if 0
LogO(".bullet: "+o.name+
" shapes:"+toStr(fileLoader->getNumCollisionShapes())+
" bodies:"+toStr(fileLoader->getNumRigidBodies())+
" constr:"+toStr(fileLoader->getNumConstraints())); /**/
#endif
// sound from presets
auto* obj = scn->data->pre->GetObject(o.name);
if (obj)
o.sound = obj->sound;
else
LogO("Object: "+o.name+" has no sound in presets!");
}else
LogO(".bullet: Load Error: "+o.name);
}
}
delete fileLoader;
}
/// 💥 destroy
void App::DestroyObjects(bool clear)
{
for (int i=0; i < scn->sc->objects.size(); ++i)
{
Object& o = scn->sc->objects[i];
delete o.tr1; o.tr1 = 0;
// ogre
if (o.nd) mSceneMgr->destroySceneNode(o.nd); o.nd = 0;
if (o.it) mSceneMgr->destroyItem(o.it); o.it = 0;
#ifdef SR_EDITOR
// bullet
if (o.co)
{ delete o.co->getCollisionShape();
#ifdef SR_EDITOR
world->removeCollisionObject(o.co);
#else
pGame->collision.world->removeCollisionObject(o.co);
#endif
delete o.co; o.co = 0;
}
if (o.rb)
{ delete o.rb->getCollisionShape();
delete o.ms; o.ms = 0;
#ifdef SR_EDITOR
world->removeRigidBody(o.rb);
#else
pGame->collision.world->removeCollisionObject(o.rb);
#endif
delete o.rb; o.rb = 0;
}
#endif
}
if (clear)
scn->sc->objects.clear();
}
void App::ResetObjects()
{
for (Object& o : scn->sc->objects)
if (o.dyn && o.ms && o.tr1)
{
o.rb->clearForces();
o.rb->setHitFraction(0.f);
o.rb->setLinearVelocity(btVector3(0,0,0));
o.rb->setAngularVelocity(btVector3(0,0,0));
o.rb->setActivationState(WANTS_DEACTIVATION);
o.rb->setWorldTransform(*o.tr1);
o.ms->setWorldTransform(*o.tr1);
o.SetFromBlt();
}
}
// 👆 Pick
//-------------------------------------------------------------------------------------------------------
#ifdef SR_EDITOR
void App::UpdObjPick()
{
bool st = edMode == ED_Start && !bMoveCam;
if (boxStart[0].nd) boxStart[0].nd->setVisible(st);
if (boxStart[1].nd) boxStart[1].nd->setVisible(st && !scn->road->isLooped); // end separate
int objs = scn->sc->objects.size();
bool bObjects = edMode == ED_Objects && !bMoveCam && objs > 0 && iObjCur >= 0;
if (objs > 0)
iObjCur = std::min(iObjCur, objs-1);
if (!boxObj.nd) return;
boxObj.nd->setVisible(bObjects);
if (!bObjects) return;
const Object& o = scn->sc->objects[iObjCur];
const Aabb& ab = o.nd->getAttachedObject(0)->getLocalAabb();
Vector3 s = o.scale * ab.getSize(); // * sel obj's node aabb
Vector3 posO = Axes::toOgre(o.pos);
Quaternion rotO = Axes::toOgreW(o.rot);
// Vector3 scaledCenter = ab.getCenter() * o.scale;
// posO += (rotO * scaledCenter);
boxObj.nd->setPosition(posO);
boxObj.nd->setOrientation(rotO);
boxObj.nd->setScale(s);
boxObj.nd->_getFullTransformUpdated();
}
void App::PickObject()
{
const auto& objs = scn->sc->objects;
if (objs.empty()) return;
iObjCur = -1;
const MyGUI::IntPoint& mp = MyGUI::InputManager::getInstance().getMousePosition();
Real mx = Real(mp.left)/mWindow->getWidth(), my = Real(mp.top)/mWindow->getHeight();
Ray ray = mCamera->getCameraToViewportRay(mx,my); // 0..1
const Vector3& pos = mCamera->getDerivedPosition(), dir = ray.getDirection();
// query scene (aabbs are enough)
RaySceneQuery* rq = mSceneMgr->createRayQuery(ray);
rq->setSortByDistance(true);
RaySceneQueryResult& res = rq->execute();
Real distC = 100000.f;
int io = -1;
for (auto it = res.begin(); it != res.end(); ++it)
{
const String& s = (*it).movable->getName();
if (StringUtil::startsWith(s,"oE",false))
{
// LogO("RAY "+s+" "+fToStr((*it).distance,2,4));
int i = -1;
// find obj with same name
for (int o=0; o < objs.size(); ++o)
if (objs[o].it && s == objs[o].it->getName())
{ i = o; break; }
// pick
if (i != -1)
{
//Aabb ab = objs[i].it->getLocalAabb();
//ab.getCenter(); ab.getSize();
// closest to obj center // fixme fails..
const Vector3 posSph = objs[i].nd->getPosition();
const Vector3 ps = pos - posSph;
Vector3 crs = ps.crossProduct(dir);
Real dC = crs.length() / dir.length();
//if ((*it).distance < dist) // closest aabb
if (dC < distC) // closest center
{
io = i;
//dist = (*it).distance;
distC = dC;
} }
} }
if (io != -1) // if none picked
if (iObjCur == -1)
iObjCur = io;
//rq->clearResults();
mSceneMgr->destroyQuery(rq);
}
// upd obj selected glow
void App::UpdObjSel()
{
int objs = scn->sc->objects.size();
for (int i=0; i < objs; ++i)
{
bool bSel = vObjSel.find(i) != vObjSel.end();
auto* rend = scn->sc->objects[i].it->getSubItem(0);
UpdSelectGlow(rend, bSel);
}
}
// selection center pos, or picked pos for multi rotate and scale
Vector3 App::GetObjPos0()
{
Vector3 pos0{0,0,0};
if (iObjCur>=0)
{
MATHVECTOR<float,3> p = scn->sc->objects[iObjCur].pos;
pos0 = Vector3(p[0],p[2],-p[1]);
}
else if (!vObjSel.empty())
{
for (std::set<int>::iterator it = vObjSel.begin(); it != vObjSel.end(); ++it)
{
MATHVECTOR<float,3> p = scn->sc->objects[(*it)].pos;
pos0 += Vector3(p[0],p[2],-p[1]);
}
pos0 /= Real(vObjSel.size());
}
return pos0;
}
/// 🎳 toggle objects simulation (bullet world)
//-------------------------------------------------------------------------------------------------------
void App::ToggleObjSim()
{
if (gui->objPan) gui->objPan->setVisible(objSim);
DestroyObjects(false);
if (!objSim) // off sim
{
// Destroy blt world
for (int i = world->getNumCollisionObjects() - 1; i >= 0; i--)
{
btCollisionObject* obj = world->getCollisionObjectArray()[i];
delete obj->getCollisionShape();
btRigidBody* body = btRigidBody::upcast(obj);
if (body)
delete body->getMotionState();
if (obj->getUserPointer() != (void*)111)
{
ShapeData* sd = static_cast<ShapeData*>(obj->getUserPointer());
delete sd;
}
world->removeCollisionObject(obj);
delete obj;
}
}
else // on sim
{
// Create blt world
scn->CreateBltTerrains();
scn->road->RebuildRoadInt(false,true);
}
CreateObjects();
UpdObjPick();
}
/// 🆕 add new object
void App::AddNewObj(bool getName) //App..
{
::Object o = objNew;
if (getName)
o.name = vObjNames[iObjTNew];
///TODO: ?dyn objs size, !?get center,size, rmb height..
// pos, rot
if (getName)
{ // one new
const Vector3& v = scn->road->posHit;
o.pos[0] = v.x; o.pos[1] =-v.z; o.pos[2] = v.y + objNew.pos[2];
}else // many
{ // offset for cursor pos..
//o.pos[0] = v.x; o.pos[1] =-v.z; o.pos[2] = v.y + objNew.pos[2];
}
// create object
try
{ o.it = mSceneMgr->createItem(o.name + ".mesh");
// alpha from presets.xml
auto* veg = scn->data->pre->GetVeget(o.name);
if (veg)
o.it->setRenderQueueGroup( veg->alpha ? RQG_AlphaVegObj : RQG_Road );
o.nd = mSceneMgr->getRootSceneNode()->createChildSceneNode();
o.SetFromBlt();
o.nd->setScale(o.scale);
o.nd->attachObject(o.it); o.it->setVisibilityFlags(RV_Vegetation);
o.dyn = PATHS::FileExists(PATHS::Objects() + o.name + ".bullet");
auto* obj = scn->data->pre->GetObject(o.name);
LogO("OBJ+ "+o.name+" "+(!obj?" !!":obj->sound));
if (obj)
o.sound = obj->sound;
scn->sc->objects.push_back(o);
}
catch (Exception ex)
{
LogO("no object! " + ex.getFullDescription());
}
}
// change obj to insert
#define ITEM_NONE -1 //?
void CGui::listObjsChng(MyGUI::List* l, size_t t)
{
// unselect other
if (l != objListDyn) objListDyn->setIndexSelected(ITEM_NONE);
if (l != objListSt) objListSt->setIndexSelected(ITEM_NONE);
if (l != objListBld) objListBld->setIndexSelected(ITEM_NONE);
if (t == ITEM_NONE) // sel default
{ /*l = objListDyn;*/ t = 0; l->setIndexSelected(t); }
std::string s = l->getItemNameAt(t).substr(7);
for (int i=0; i < app->vObjNames.size(); ++i)
if (s == app->vObjNames[i])
{
app->SetObjNewType(i);
Upd3DView(s+".mesh"); //,mtr);
return;
}
}
void CGui::listObjsNext(int rel)
{
Li li = 0;
if (objListDyn->getIndexSelected()!= ITEM_NONE) li = objListDyn; //else
if (objListSt->getIndexSelected() != ITEM_NONE) li = objListSt;
if (objListBld->getIndexSelected()!= ITEM_NONE) li = objListBld;
if (li)
{
size_t cnt = li->getItemCount();
if (cnt == 0) return;
int i = std::max(0, std::min((int)cnt-1, (int)li->getIndexSelected()+rel ));
li->setIndexSelected(i);
li->beginToItemAt(std::max(0, i-11)); // center
listObjsChng(li, li->getIndexSelected());
}
}
// change category, fill 🏢 buildings list
void CGui::listObjsCatChng(Li li, size_t id)
{
if (id == ITEM_NONE || id >= li->getItemCount()) id = 0;
if (li->getItemCount()==0) return;
string cat = li->getItemNameAt(id).substr(7);
objListBld->removeAllItems();
for (size_t i=0; i < app->vBuildings.size(); ++i)
{
const string& s = app->vBuildings[i];
if (//id == 0 ||/*all*/
s.length() > 4 && s.substr(0,4) == cat)
objListBld->addItem("#E0E080"+s);
}
}
// 🔮 cycle object materials
void App::NextObjMat(int add)
{
if (!vObjSel.empty())
{ for (int i : vObjSel)
NextObjMat(add, scn->sc->objects[i]);
return;
}
bool bNew = iObjCur == -1;
Object& o = bNew || scn->sc->objects.empty() ? objNew : scn->sc->objects[iObjCur];
NextObjMat(add, o);
}
void App::NextObjMat(int add, Object& o)
{
const PObject* obj = scn->data->pre->GetObject(o.name);
if (!obj || !obj->pMatSet) return;
auto& m = obj->pMatSet->mats;
int j = -1, si = m.size();
if (si < 2) return;
for (int i=0; i < si; ++i) // find cur
if (m[i] == o.material)
{ j = i; break; }
if (j == -1)
j = 0;
else
j = (j + add + si) % si; // inc
o.material = m[j]; // set
if (!o.material.empty())
o.it->setDatablockOrMaterialName(o.material);
}
void App::TogObjStatic() // toggle static
{
if (!vObjSel.empty())
{ for (int i : vObjSel)
scn->sc->objects[i].stat = !scn->sc->objects[i].stat;
return;
}
bool bNew = iObjCur == -1;
Object& o = bNew || scn->sc->objects.empty() ? objNew : scn->sc->objects[iObjCur];
o.stat = !o.stat;
}
// preview model for insert
void App::SetObjNewType(int tnew)
{
iObjTNew = tnew;
if (objNew.nd) { mSceneMgr->destroySceneNode(objNew.nd); objNew.nd = 0; }
if (objNew.it) { mSceneMgr->destroyItem(objNew.it); objNew.it = 0; }
String name = vObjNames[iObjTNew];
objNew.dyn = PATHS::FileExists(PATHS::Objects() + name + ".bullet");
if (objNew.dyn) objNew.scale = Vector3::UNIT_SCALE; // dyn no scale
try
{ objNew.it = mSceneMgr->createItem(name + ".mesh");
objNew.nd = mSceneMgr->getRootSceneNode()->createChildSceneNode();
objNew.nd->attachObject(objNew.it); objNew.it->setVisibilityFlags(RV_Vegetation);
UpdObjNewNode();
}
catch (Exception ex)
{
LogO("no object! " + ex.getFullDescription());
}
}
void App::UpdObjNewNode()
{
if (!scn->road || !objNew.nd) return;
bool vis = scn->road->bHitTer && bEdit() && iObjCur == -1 && edMode == ED_Objects;
objNew.nd->setVisible(vis);
if (!vis) return;
Vector3 p = scn->road->posHit; p.y += objNew.pos[2];
objNew.SetFromBlt();
objNew.nd->setPosition(p);
objNew.nd->setScale(objNew.scale);
objNew.nd->_getFullTransformUpdated();
}
// 💧🌊 Fluids set type
void CGui::listFluidsChng(Li li, size_t id)
{
if (id == ITEM_NONE || id >= li->getItemCount()) id = 0;
if (li->getItemCount()==0) return;
string mat = li->getItemNameAt(id);
if (mat[0]=='#') mat = mat.substr(7);
// const auto& dfl = scn->data->fluids->fls;
int fls = scn->sc->fluids.size();
if (!fls || app->iFlCur < 0)
{ app->newFluidName = mat; return; }
FluidBox& fb = scn->sc->fluids[app->iFlCur]; // set
fb.id = id; fb.name = mat; //dfl[fb.id].name;
app->bRecreateFluids = true;
}
// ✨ Particles set type
void CGui::listParticlesChng(Li li, size_t id)
{
if (id == ITEM_NONE || id >= li->getItemCount()) id = 0;
if (li->getItemCount()==0) return;
string mat = li->getItemNameAt(id);
if (mat[0]=='#') mat = mat.substr(7);
int emts = scn->sc->emitters.size();
if (!emts || app->iEmtCur < 0) // none or no sel, set default new
{ app->newEmtName = mat; return; }
SEmitter& em = scn->sc->emitters[app->iEmtCur]; // set
em.name = mat; //app->vEmtNames[id];
app->bRecreateEmitters = true;
}
#endif // ed