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;
        }
Esempio n. 2
0
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;
            }
        }
    }
}
Esempio n. 3
0
void ScenarioRenderer::visitSurroundings(Surroundings &s) {
    Lock l(m_scenarioRendererMutex);
    if ( (m_scnxArchive != NULL) && (m_renderer != NULL) ) {
        const vector<Shape*> &listOfShapes = s.getListOfShapes();

        vector<Shape*>::const_iterator it = listOfShapes.begin();
        while (it != listOfShapes.end()) {
            Shape *shape = (*it++);
            if (shape != NULL) {
                ComplexModel *cm = dynamic_cast<data::scenario::ComplexModel*>(shape);
                if (cm != NULL) {
                    vector<TriangleSet> listOfTriangleSets = m_mapOfGroundBasedComplexModels[cm->toString()];

                    // Check if the complex model must be loaded first.
                    if (listOfTriangleSets.size() == 0) {
                        loadGroundBasedComplexModel(*cm);
                    }

                    // Draw list of triangle sets.
                    m_renderer->beginPainting();
                    m_renderer->drawListOfTriangleSets(listOfTriangleSets, cm->getPosition(), cm->getRotation());
                    m_renderer->endPainting();
                }
            }
        }
    }
}