コード例 #1
0
            OBJXArchive* OBJXArchiveFactory::getOBJXArchiveFromPlainOBJFile(istream &in) throw (InvalidArgumentException) {
                if (!(in.good())) {
                    // Try to rewind the stream.
                    clog << "Trying to rewind the stream." << endl;
                    in.clear();
                    in.seekg(ios::beg);

                    if (!(in.good())) {
                        HESPERIA_CORE_THROW_EXCEPTION(InvalidArgumentException, "Given inputstream is invalid.");
                    }
                }

                OBJXArchive *objxArchive = new OBJXArchive();

                char c;
                stringstream s;
                while (in.good()) {
                    in.get(c);
                    s << c;
                }
                objxArchive->setContentsOfObjFile(s.str());

                return objxArchive;
            }
コード例 #2
0
            OBJXArchive* OBJXArchiveFactory::getOBJXArchive(istream &in) throw (InvalidArgumentException) {
                if (!(in.good())) {
                    // Try to rewind the stream.
                    clog << "Trying to rewind the stream." << endl;
                    in.clear();
                    in.seekg(ios::beg);

                    if (!(in.good())) {
                        HESPERIA_CORE_THROW_EXCEPTION(InvalidArgumentException, "Given inputstream is invalid.");
                    }
                }

                OBJXArchive *objxArchive = NULL;

                // Use CompressionFactory to read the contents of the OBJXArchive.
                core::wrapper::DecompressedData *data = core::wrapper::CompressionFactory::getInstance().getContents(in);

                if (data != NULL) {
                    // Create OBJXArchive.
                    objxArchive = new OBJXArchive();

                    vector<string> listOfEntries = data->getListOfEntries();
                    vector<string>::iterator it = listOfEntries.begin();

                    while (it != listOfEntries.end()) {
                        string entry = (*it++);

                        if (entry.find(".obj") != string::npos) {
                            // Set object file.
                            istream *stream = data->getInputStreamFor(entry);

                            char c;
                            stringstream s;
                            while (stream->good()) {
                                stream->get(c);
                                s << c;
                            }
                            objxArchive->setContentsOfObjFile(s.str());
                        } else if (entry.find(".mtl") != string::npos) {
                            // Set material file.
                            istream *stream = data->getInputStreamFor(entry);

                            char c;
                            stringstream s;
                            while (stream->good()) {
                                stream->get(c);
                                s << c;
                            }
                            objxArchive->setContentsOfMtlFile(s.str());
                        } else {
                            // Try to load an image.
                            istream *stream = data->getInputStreamFor(entry);

                            if (stream != NULL) {
                                core::wrapper::Image *image = core::wrapper::ImageFactory::getInstance().getImage(*stream);

                                if (image != NULL) {
                                    // TODO: Check where origin lies.
                                    image->rotate(static_cast<float>(data::Constants::PI));

                                    // Remove any directory prefixes from the entry.
                                    string name = entry;
                                    if (name.rfind('/') != string::npos) {
                                        name = name.substr(name.rfind('/') + 1);
                                    }

                                    objxArchive->addImage(name, image);
                                }
                            }
                        }

                    }
                }

                return objxArchive;
            }