osgDB.Input
osgDB.Input是一个输入流类,用于从文件读取二进制数据并将其转换为OpenSceneGraph图形数据格式。它可以从任何std :: istream读取二进制数据。此类通常用于读取OSG二进制文件,该文件包含OpenGL绘图命令和其他相关数据。
用法示例
以下是使用osgDB.Input的示例:
std::ifstream fin("model.osg", std::ios::binary);
if (fin.is_open()) {
osgDB::Input input(&fin);
osg::ref_ptr<osg::Node> model = osgDB::readNode(input);
if (model.valid()) {
}
else {
}
}
else {
}
在以上示例中,osgDB.Input从打开的文件流中读取二进制数据,然后将其传递给osgDB.readNode()方法,该方法将解析数据并返回一个osg :: Node对象。
方法概述
以下是osgDB.Input的主要方法:
osgDB.Input(std::istream* istream)
创建osgDB.Input对象,并从指定的输入流中读取数据。
bool readBool();
从输入流中读取布尔值。
void readBoolArray(bool* boolArray, unsigned int numBools);
从输入流中读取指定数量的布尔值。
char readChar();
从输入流中读取字符。
void readCharArray(char* charArray, unsigned int numChars);
从输入流中读取指定数量的字符。
unsigned char readUChar();
从输入流中读取无符号字符。
void readUCharArray(unsigned char* ucharArray, unsigned int numUChars);
从输入流中读取指定数量的无符号字符。
short readShort();
从输入流中读取短整数。
void readShortArray(short* shortArray, unsigned int numShorts);
从输入流中读取指定数量的短整数。
unsigned short readUShort();
从输入流中读取无符号短整数。
void readUShortArray(unsigned short* ushortArray, unsigned int numUShorts);
从输入流中读取指定数量的无符号短整数。
int readInt();
从输入流中读取整数。
void readIntArray(int* intArray, unsigned int numInts);
从输入流中读取指定数量的整数。
unsigned int readUInt();
从输入流中读取无符号整数。
void readUIntArray(unsigned int* uintArray, unsigned int numUInts);
从输入流中读取指定数量的无符号整数。
float readFloat();
从输入流中读取单精度浮点数。
void readFloatArray(float* floatArray, unsigned int numFloats);
从输入流中读取指定数量的单精度浮点数。
double readDouble();
从输入流中读取双精度浮点数。
void readDoubleArray(double* doubleArray, unsigned int numDoubles);
从输入流中读取指定数量的双精度浮点数。
osg::Vec2 readVec2();
从输入流中读取2D向量。
void readVec2Array(osg::Vec2* vecArray, unsigned int numVecs);
从输入流中读取指定数量的2D向量。
osg::Vec3 readVec3();
从输入流中读取3D向量。
void readVec3Array(osg::Vec3* vecArray, unsigned int numVecs);
从输入流中读取指定数量的3D向量。
osg::Vec4 readVec4();
从输入流中读取4D向量。
void readVec4Array(osg::Vec4* vecArray, unsigned int numVecs);
从输入流中读取指定数量的4D向量。
osg::Quat readQuat();
从输入流中读取四元数。
void readQuatArray(osg::Quat* quatArray, unsigned int numQuats);
从输入流中读取指定数量的四元数。
osg::Matrix readMatrix();
从输入流中读取矩阵。
void readMatrixArray(osg::Matrix* matrixArray, unsigned int numMatrices);
从输入流中读取指定数量的矩阵。
osg::BoundingSphere readBoundingSphere();
从输入流中读取边界球。
void readBoundingSphereArray(osg::BoundingSphere* bsArray, unsigned int numBoundingSpheres);
从输入流中读取指定数量的边界球。
osg::BoundingBox readBoundingBox();
从输入流中读取边界框。
void readBoundingBoxArray(osg::BoundingBox* bbArray, unsigned int numBoundingBoxes);
从输入流中读取指定数量的边界框。
osg::Object* readObject();
从输入流中读取osg :: Object对象。
osg::Object* readObjectOfType(const std::string& className);
从输入流中读取指定类型的osg :: Object对象。
void beginObjectProperty();
指示将开始读取对象属性。
std::string readObjectPropertyString();
从输入流中读取对象属性字符串。
void endObjectProperty();
指示对象属性已读取完毕。
osg::Object* readObjectPointer();
从输入流中读取osg :: Object指针。
osg::Referenced* readRefObject();
从输入流中读取osg :: Referenced对象。
osg::Referenced* readRefObjectOfType(const std::string& className);
从输入流中读取指定类型的osg :: Referenced对象。
void enterElement();
指示将进入新元素。
void leaveElement();
指示将离开元素。
std::string readString();
从输入流中读取字符串。
std::string readWrappedString();
从输入流中读取包含在引号中的字符串。
osgDB::BaseSerializer::Type readType();
从输入流中读取BaseSerializer :: Type枚举。
bool eof();
指示输入流是否已到达文件结尾。
unsigned int tell();
返回当前输入流的位置。
void seek(unsigned int pos);
将当前输入流的位置设置为指定的位置。
unsigned int getNextBlockSize();
返回下一个块的大小。
osg::UIntArray* readUIntValues();
从输入流中读取一组无符号整数值,并返回osg :: UIntArray对象。
void readRegisteredObject(osg::Object& object);
从输入流中读取已注册的对象。如果读取错误,则抛出异常。
osg::Object* readRegisteredObject();
从输入流中读取已注册的对象,并返回osg :: Object指针。如果读取错误,则返回NULL。
参考文献
https://github.com/openscenegraph/OpenSceneGraph/blob/master/include/osgDB/Input.h
https://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a00103.html