20 #include <Inventor/nodes/SoMaterial.h>
21 #include <Inventor/nodes/SoMaterialBinding.h>
22 #include <Inventor/nodes/SoCube.h>
23 #include <Inventor/nodes/SoSeparator.h>
24 #include <Inventor/nodes/SoTransform.h>
25 #include <Inventor/nodes/SoTranslation.h>
26 #include <Inventor/nodes/SoRotationXYZ.h>
27 #include <Inventor/nodes/SoScale.h>
28 #include <Inventor/SbViewportRegion.h>
29 #include <Inventor/actions/SoGetBoundingBoxAction.h>
30 #include <Inventor/VRMLnodes/SoVRMLMaterial.h>
32 #include <Inventor/actions/SoSearchAction.h>
33 #include <Inventor/actions/SoWriteAction.h>
34 #include <Inventor/nodes/SoSeparator.h>
35 #include <Inventor/nodes/SoTexture2.h>
36 #include <Inventor/SoDB.h>
37 #include <Inventor/SoInput.h>
38 #include <Inventor/SoOutput.h>
42 #include <QTemporaryDir>
48 #include "CLHEP/Units/SystemOfUnits.h"
49 #define SYSTEM_OF_UNITS CLHEP
51 #include "GaudiKernel/SystemOfUnits.h"
52 #define SYSTEM_OF_UNITS Gaudi::Units
60 SoSeparator * attachsep);
65 SoSeparator*
loadModel(
const std::string& fpath);
108 : theclass(tc), material(
mat), attachSep(as), shown(false),
109 zpos(0),vertpos(0),
sep(0), trans1(0), trans2(0), trans3(0)
122 if (!myInput.openFile(fpath.c_str()))
124 SoSeparator *
model = SoDB::readAll(&myInput);
128 unsigned int nChildren =
model->getNumChildren();
129 std::cout <<
"nChildren: " << nChildren << std::endl;
130 for (
unsigned int i=0;
i < nChildren; ++
i) {
132 std::cout <<
"node " <<
i <<
": " <<
node << std::endl;
133 if (
node->getTypeId() == SoVRMLMaterial::getClassTypeId()) {
134 std::cout <<
"Found a SoVRMLMaterial node!\n";
135 SoNode * matvrmlnode = (SoVRMLMaterial *)
node;
136 std::cout <<
"Material node: " << matvrmlnode << std::endl;
202 SbViewportRegion dummyViewport;
203 SoGetBoundingBoxAction bboxAction(dummyViewport);
204 bboxAction.apply(
node);
205 SbXfBox3f xfbox = bboxAction.getXfBoundingBox();
206 SbBox3f box = xfbox.project();
207 float minx, miny, minz, maxx, maxy, maxz;
208 box.getBounds(minx, miny, minz, maxx, maxy, maxz);
210 box.getCenter().getValue(
cx,
cy,cz);
213 float heightModel = (maxy - miny);
215 float heightDesired = desiredHeight;
217 double scaleFactor = heightDesired / heightModel;
236 theclass->messageVerbose(
"Building 3D objects");
237 sep =
new SoSeparator;
sep->ref();
238 sep->addChild(material);
245 QTemporaryDir tempDir;
246 QFile w1 = QFile(
":/vp1/data/models/worker1.wrl");
247 QFile w2 = QFile(
":/vp1/data/models/worker2.wrl");
248 SoSeparator* worker1 =
nullptr;
249 SoSeparator* worker2 =
nullptr;
250 if (tempDir.isValid()) {
251 const QString tempFile1 = tempDir.path() +
"/worker1.wrl";
252 if ( w1.copy(tempFile1) ) {
253 worker1 = loadModel( tempFile1.toStdString() );
255 std::cout <<
"ERROR!! QFile copy of Worker1 was NOT successful!\n";
257 const QString tempFile2 = tempDir.path() +
"/worker2.wrl";
258 if ( w2.copy(tempFile2) ) {
259 worker2 = loadModel( tempFile2.toStdString() );
261 std::cout <<
"ERROR!! QFile copy of Worker2 was NOT successful!\n";
264 std::cout <<
"ERROR!! TempDir is NOT valid!\n";
266 if (worker1 ==
nullptr) {
267 std::cout <<
"\n\nERROR! The 3D model Worker1 could not be loaded!\n\n";
270 if (worker2 ==
nullptr) {
271 std::cout <<
"\n\nERROR! The 3D model Worker2 could not be loaded!\n\n";
285 SoScale* myScale1 =
new SoScale();
286 myScale1->scaleFactor.setValue(scaleFactor1, scaleFactor1, scaleFactor1);
287 SoScale* myScale2 =
new SoScale();
288 myScale2->scaleFactor.setValue(scaleFactor2, scaleFactor2, scaleFactor2);
291 trans1 =
new SoTranslation;
293 trans2 =
new SoTranslation;
295 trans3 =
new SoTranslation;
299 SoRotationXYZ * rotY =
new SoRotationXYZ();
303 SoVRMLMaterial* matVRML =
new SoVRMLMaterial();
304 matVRML->diffuseColor.setValue(0., 1., 1.);
309 SoSeparator* sepScaledWorker1 =
new SoSeparator();
310 sepScaledWorker1->addChild(matVRML);
311 sepScaledWorker1->addChild(myScale1);
312 sepScaledWorker1->addChild(rotY);
313 sepScaledWorker1->addChild(worker1);
315 SoSeparator* sepWorker1 =
new SoSeparator();
316 sepWorker1->addChild(trans1);
317 sepWorker1->addChild(sepScaledWorker1);
319 SoSeparator* sepScaledWorker2 =
new SoSeparator();
320 sepScaledWorker2->addChild(myScale2);
321 sepScaledWorker2->addChild(rotY);
322 sepScaledWorker2->addChild(worker2);
323 SoSeparator* sepWorker2 =
new SoSeparator();
324 sepWorker2->addChild(trans2);
325 sepWorker2->addChild(sepScaledWorker2);
327 SoTranslation*
xt =
new SoTranslation();
329 SoSeparator* sepWorker3 =
new SoSeparator();
330 sepWorker3->addChild(trans3);
331 sepWorker3->addChild(sepScaledWorker1);
332 sepWorker3->addChild(
xt);
333 sepWorker3->addChild(sepScaledWorker2);
336 sep->addChild(sepWorker1);
337 sep->addChild(sepWorker2);
338 sep->addChild(sepWorker3);
344 ensureInit3DObjects();
345 theclass->messageVerbose(
"Updating fields");
346 trans1->translation.setValue(0, vertpos, zpos);
354 theclass->messageVerbose(
"Updating packed colour");
355 if (!
sep||
sep->getNumChildren()<1)
357 SoNode *
n =
sep->getChild(0);
358 if (!
n||
n->getTypeId()!=SoVRMLMaterial::getClassTypeId())
361 SoVRMLMaterial* matVRML =
static_cast<SoVRMLMaterial*
>(
n);
362 matVRML->diffuseColor.setValue( colourAndTransp.getValue() );