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) {
131 const SoNode*
node = model->getChild(i);
132 std::cout <<
"node " << i <<
": " <<
node << std::endl;
133 if (
node->getTypeId() == SoVRMLMaterial::getClassTypeId()) {
134 std::cout <<
"Found a SoVRMLMaterial node!\n";
135 const SoNode * matvrmlnode =
static_cast<const 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();
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";
281 double scaleFactor1 =
getScaleFactor(worker1, 1.80*SYSTEM_OF_UNITS::m);
282 double scaleFactor2 =
getScaleFactor(worker2, 1.80*SYSTEM_OF_UNITS::m);
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();
300 rotY->axis=SoRotationXYZ::Y;
301 rotY->angle = 45*SYSTEM_OF_UNITS::deg;
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();
328 xt->translation.setValue(2*SYSTEM_OF_UNITS::m, 0., 1*SYSTEM_OF_UNITS::m);
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);