X3DConverter::X3DConverter(const string& filename, bool binary) : RVMReader(), m_binary(binary), m_id(0) { X3DWriter* writer = binary ? (X3DWriter*)new X3DWriterFI() : (X3DWriter*)new X3DWriterXML(); writer->setProperty(Property::IntEncodingAlgorithm, (void*)Encoder::DeltazlibIntArrayEncoder); writer->setProperty(Property::FloatEncodingAlgorithm, (void*)Encoder::QuantizedzlibFloatArrayEncoder); writer->openFile(filename.data()); m_writers.push_back(writer); }
void X3DConverter::startGroup(const std::string& name, const Vector3F& translation, const int& materialId) { // Ensuring the name is compatible with the DEF attribute string x3dName = name; size_t p; while ((p = x3dName.find_first_of(' ')) != string::npos) x3dName[p] = '_'; while (x3dName[0] == '-') x3dName[0] = '_'; while ((p = x3dName.find_first_of('/')) != string::npos) { x3dName[p] = '_'; } m_materials.push_back(materialId); m_groups.push_back(name); if (m_split) { startNode(ID::Inline); MFString name; name.push_back(x3dName + ".x3d"); m_writers.back()->setMFString(ID::url, name); X3DWriter* writer = m_binary ? (X3DWriter*)new X3DWriterFI() : (X3DWriter*)new X3DWriterXML(); writer->setProperty(Property::IntEncodingAlgorithm, (void*)Encoder::DeltazlibIntArrayEncoder); writer->setProperty(Property::FloatEncodingAlgorithm, (void*)Encoder::QuantizedzlibFloatArrayEncoder); writer->openFile((x3dName + ".x3d").data()); m_writers.push_back(writer); multimap<std::string, std::string> meta; meta.insert(pair<string, string>("generator", "Plant Mock-Up Converter 0.1")); m_writers.back()->startX3DDocument(Immersive, VERSION_3_0, &meta, false); startNode(ID::Background); m_writers.back()->setSFColor(ID::skyColor, .9f, .9f, .9f); endNode(ID::Background); } startNode(ID::Transform); // Problems with encoding and unicity so changed name from DEF storage to metadata. See after translation. //m_writers.back()->setSFString(ID::DEF, x3dName); /*m_writers.back()->setSFVec3f(ID::translation, (translation[0] - m_translations.back()[0]), (translation[1] - m_translations.back()[1]), (translation[2] - m_translations.back()[2]));*/ m_translations.push_back(translation); // PDMS name as metadata. // writeMetaDataString("pdms", name); }
int start() { X3DWriter* writer[2]; writer[0] = new X3DWriterXML(); writer[1] = new X3DWriterFI(); for(int i = 0; i< 2; i++) { X3DWriter* w = writer[i]; if (i == 0) w->openFile("iotest.x3d"); else w->openFile("iotest.x3db"); w->startX3DDocument(); w->startNode(ID::Shape); w->startNode(ID::Appearance); w->startNode(ID::Material); w->setSFVec3f(ID::diffuseColor, 1.0f, 0.0f, 0.0f); w->setSFFloat(ID::transparency, 0.1f); w->endNode(); w->endNode(); // Appearance w->startNode(ID::Box); w->setSFVec3f(ID::size, 0.5f, 0.5f, 0.5f); w->endNode(); // Box w->endNode();//Shape w->endX3DDocument(); w->closeFile(); delete w; } for(int i = 0; i< 2; i++) { X3DLoader loader; MyNodeHandler handler; loader.setNodeHandler(&handler); try { if (i == 0) loader.load("iotest.x3d"); else loader.load("iotest.x3db"); } catch (X3DParseException& e) { cerr << "Error while parsing file:" << endl; cerr << e.getMessage() << " (Line: " << e.getLineNumber() << ", Column: " << e.getColumnNumber() << ")" << endl; return 1; } } return 0; }