TransformGroup* GroundBasedComplexModelLoader::getGroundBasedComplexModels(const SCNXArchive &scnxArchive) const { TransformGroup *complexModels = new TransformGroup(); // Get list of all ground based complex models. vector<ComplexModel*> listOfComplexModels = scnxArchive.getListOfGroundBasedComplexModels(); // Iterate over all ground based complex models and try to build a transform group. vector<ComplexModel*>::iterator jt = listOfComplexModels.begin(); while (jt != listOfComplexModels.end()) { ComplexModel *cm = (*jt++); SharedPointer<istream> in = scnxArchive.getModelData(cm->getModelFile()); if (in.isValid()) { Node *model = NULL; // Check model. OBJXArchive *objxArchive = NULL; if (cm->getModelFile().find(".objx") != string::npos) { objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchive(*in); } else if (cm->getModelFile().find(".obj") != string::npos) { objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchiveFromPlainOBJFile(*in); } if (objxArchive != NULL) { model = objxArchive->createTransformGroup(NodeDescriptor(cm->getName())); if (model != NULL) { clog << "OBJ model successfully opened." << endl; clog << " Translation: " << cm->getPosition().toString() << endl; clog << " Rotation: " << cm->getRotation().toString() << endl; TransformGroup *complexModel = new TransformGroup(); // Translation. Point3 translation(cm->getPosition()); complexModel->setTranslation(translation); // TODO: Achsenprüfung!! Point3 rotation(cm->getRotation().getX(), cm->getRotation().getZ(), cm->getRotation().getY()); complexModel->setRotation(rotation); complexModel->addChild(model); complexModels->addChild(complexModel); } else { clog << "OBJ model could not be opened." << endl; } OPENDAVINCI_CORE_DELETE_POINTER(objxArchive); } } } return complexModels; }
Shape* SITSituationVisitor::visitShape(ASTNode *node) { Shape *s = NULL; if (node != NULL) { ASTNode *n = NULL; n = node->getFirstChild(); if (n == NULL) { OPENDAVINCI_CORE_THROW_EXCEPTION(SITSituationVisitorException, "Node to get name from SHAPE expected."); } string name = n->getValue<string>(); n = (node->getChildren().at(1))->getFirstChild(); if (n == NULL) { OPENDAVINCI_CORE_THROW_EXCEPTION(SITSituationVisitorException, "Node to get value from SHAPE expected."); } string type = n->getValue<string>(); if (type == "RECTANGLE") { Rectangle *r = visitRectangle(node->getChildren().at(1)); if (r != NULL) { r->setName(name); } s = r; } if (type == "POLYGON") { Polygon *p = visitPolygon(node->getChildren().at(1)); if (p != NULL) { p->setName(name); } s = p; } if (type == "COMPLEXMODEL") { ComplexModel *cm = visitComplexModel(node->getChildren().at(1)); if (cm != NULL) { cm->setName(name); } s = cm; } } return s; }
void ScenarioRenderer::loadGroundBasedComplexModel(ComplexModel &cm) { SharedPointer<istream> in = m_scnxArchive->getModelData(cm.getModelFile()); if (in.isValid()) { // Load model. OBJXArchive *objxArchive = NULL; if (cm.getModelFile().find(".objx") != string::npos) { objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchive(*in); } else if (cm.getModelFile().find(".obj") != string::npos) { objxArchive = OBJXArchiveFactory::getInstance().getOBJXArchiveFromPlainOBJFile(*in); } if (objxArchive != NULL) { m_listOfLoadedOBJXArchives.push_back(objxArchive); vector<TriangleSet> listOfTriangleSets = objxArchive->getListOfTriangleSets(); if (listOfTriangleSets.size() > 0) { clog << "OBJ model successfully opened (containing " << listOfTriangleSets.size() << " sets of triangles)." << endl; clog << " Translation: " << cm.getPosition().toString() << endl; clog << " Rotation: " << cm.getRotation().toString() << endl; m_mapOfGroundBasedComplexModels[cm.toString()] = listOfTriangleSets; } else { clog << "OBJ model could not be opened." << endl; } } } }
ComplexModel* SITSituationVisitor::visitComplexModel(ASTNode *node) { ComplexModel *cm = NULL; if (node != NULL) { ASTNode *n = NULL; cm = new ComplexModel(); n = node->getNodeFromFirstMatchingChildFor("MODELFILE"); if (n == NULL) { OPENDAVINCI_CORE_THROW_EXCEPTION(SITSituationVisitorException, "Node to get name from MODELFILE expected."); } cm->setModelFile(n->getValue<string>()); n = *(node->getChildren("MODELFILE").begin() + 1); // Front starts directly after MODELFILE. cm->setFront(visitVertex3(n)); n = *(node->getChildren("POSITION").begin() + 1); // Skip keyword POSITION. if (n == NULL) { OPENDAVINCI_CORE_THROW_EXCEPTION(SITSituationVisitorException, "Node to get name from POSITION expected."); } cm->setPosition(visitVertex3(n)); n = *(node->getChildren("ROTATION").begin() + 1); // Skip keyword POSITION. if (n == NULL) { OPENDAVINCI_CORE_THROW_EXCEPTION(SITSituationVisitorException, "Node to get name from ROTATION expected."); } cm->setRotation(visitVertex3(n)); BoundingBox bb; vector<ASTNode*> boundingBox = node->getChildren("BOUNDINGBOX"); if (boundingBox.size() != 5) { OPENDAVINCI_CORE_THROW_EXCEPTION(SITSituationVisitorException, "Node to get name from BOUNDINGBOX expected."); } bb.setUpperLeft(visitVertex3(boundingBox.at(1))); bb.setUpperRight(visitVertex3(boundingBox.at(2))); bb.setLowerRight(visitVertex3(boundingBox.at(3))); bb.setLowerLeft(visitVertex3(boundingBox.at(4))); cm->setBoundingBox(bb); } return cm; }