⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lwo2parser.h

📁 最新osg包
💻 H
📖 第 1 页 / 共 2 页
字号:
/*******************************************************      Lightwave Object Loader for OSG  Copyright (C) 2004 Marco Jez <marco.jez@poste.it>  OpenSceneGraph is (C) 2004 Robert Osfield********************************************************/#ifndef LWO2PARSER_#define LWO2PARSER_#include "iffparser.h"#include "lwo2chunks.h"#include "lwo2read.h"#include <stdexcept>#include <vector>namespace lwo2{	class parser_error: public std::runtime_error {	public:		parser_error(const std::string &message): std::runtime_error("[LWO2 parser error] " + message) {}	};	template<typename Iter>	class Parser: public iff::GenericParser<Iter> {	public:		Parser();		Parser(std::ostream &os);		virtual ~Parser();	protected:		virtual iff::Chunk *parse_chunk_data(const std::string &tag, const std::string &context, Iter it, Iter end);		iff::Chunk *parse_subchunk(Iter &it, const std::string &context);	};	/////////////////////////////////////////////////////////////////////////	// IMPLEMENTATION OF TEMPLATE FUNCTIONS#	define LP_TMP	template<class Iter>	LP_TMP Parser<Iter>::Parser()		: iff::GenericParser<Iter>()	{	}	LP_TMP Parser<Iter>::Parser(std::ostream &os)		: iff::GenericParser<Iter>(os)	{	}	LP_TMP Parser<Iter>::~Parser()	{	}	LP_TMP iff::Chunk *Parser<Iter>::parse_chunk_data(const std::string &tag, const std::string &context, Iter it, Iter end)	{		// GLOBAL CONTEXT		if (context.empty()) {			if (tag == "FORM") {				FORM *chk = new FORM;				chk->type = read_ID4(it);				if (std::string(chk->type.id, 4) != "LWO2") {					throw parser_error("invalid file format");				}				while (it < end)					chk->data.push_back(parse_chunk(it, "FORM"));				return chk;			}		}		// FORM CONTEXT		if (context == "FORM") {			if (tag == "LAYR") {				FORM::LAYR *chk = new FORM::LAYR;				chk->number = read_U2(it);				chk->flags = read_U2(it);				chk->pivot = read_VEC12(it);				chk->name = read_S0(it);				if (it < end) {					chk->parent = read_I2(it);				} else {					chk->parent = -1;				}				return chk;			}			if (tag == "PNTS") {				FORM::PNTS *chk = new FORM::PNTS;				while (it < end) {					chk->point_location.push_back(read_VEC12(it));				}				return chk;			}			if (tag == "VMAP") {				FORM::VMAP *chk = new FORM::VMAP;				chk->type = read_ID4(it);				chk->dimension = read_U2(it);				chk->name = read_S0(it);				while (it < end) {					FORM::VMAP::mapping_type mp;					mp.vert = read_VX(it);					for (int i=0; i<chk->dimension; ++i) {						mp.value.push_back(read_F4(it));					}					chk->mapping.push_back(mp);				}				return chk;			}			if (tag == "POLS") {				FORM::POLS *chk = new FORM::POLS;				chk->type = read_ID4(it);				while (it < end) {					FORM::POLS::polygon_type pl;					U2 nvf = read_U2(it);					pl.flags = nvf >> 10;					pl.numvert = nvf & 0x03FF;					for (int i=0; i<pl.numvert; ++i)						pl.vert.push_back(read_VX(it));					chk->polygons.push_back(pl);									}				return chk;			}			if (tag == "TAGS") {				FORM::TAGS *chk = new FORM::TAGS;				while (it < end) {					std::string tags = read_S0(it);					chk->tag_string.push_back(tags);				}				return chk;			}			if (tag == "PTAG") {				FORM::PTAG *chk = new FORM::PTAG;				chk->type = read_ID4(it);				while (it < end) {					FORM::PTAG::mapping_type mp;					mp.poly = read_VX(it);					mp.tag = read_U2(it);					chk->mapping.push_back(mp);				}				return chk;			}			if (tag == "VMAD") {				FORM::VMAD *chk = new FORM::VMAD;				chk->type = read_ID4(it);				chk->dimension = read_U2(it);				chk->name = read_S0(it);				while (it < end) {					FORM::VMAD::mapping_type mp;					mp.vert = read_VX(it);					mp.poly = read_VX(it);					for (int i=0; i<chk->dimension; ++i)						mp.value.push_back(read_F4(it));					chk->mapping.push_back(mp);				}				return chk;			}			if (tag == "ENVL") {				FORM::ENVL *chk = new FORM::ENVL;				chk->index = read_VX(it);				while (it < end) {					chk->attributes.push_back(parse_subchunk(it, "FORM::ENVL"));				}				return chk;			}			if (tag == "CLIP") {				FORM::CLIP *chk = new FORM::CLIP;				chk->index = read_U4(it);				while (it < end) {					chk->attributes.push_back(parse_subchunk(it, "FORM::CLIP"));				}				return chk;			}			if (tag == "SURF") {				FORM::SURF *chk = new FORM::SURF;				chk->name = read_S0(it);				chk->source = read_S0(it);				while (it < end) {					chk->attributes.push_back(parse_subchunk(it, "FORM::SURF"));				}				return chk;			}			if (tag == "BBOX") {				FORM::BBOX *chk = new FORM::BBOX;				chk->min = read_VEC12(it);				chk->max = read_VEC12(it);				return chk;			}			if (tag == "DESC") {				FORM::DESC *chk = new FORM::DESC;				chk->description_line = read_S0(it);				return chk;			}			if (tag == "TEXT") {				FORM::TEXT *chk = new FORM::TEXT;				chk->comment = read_S0(it);				return chk;			}			if (tag == "ICON") {				FORM::ICON *chk = new FORM::ICON;				chk->encoding = read_U2(it);				chk->width = read_U2(it);				while (it < end) chk->data.push_back(read_U1(it));				return chk;			}		}		// ENVELOPE CONTEXT		if (context == "FORM::ENVL") {			if (tag == "TYPE") {				FORM::ENVL::TYPE *chk = new FORM::ENVL::TYPE;				chk->user_format = read_U1(it);				chk->type = read_U1(it);				return chk;			}			if (tag == "PRE ") {				FORM::ENVL::PRE *chk = new FORM::ENVL::PRE;				chk->type = read_U2(it);				return chk;			}			if (tag == "POST") {				FORM::ENVL::POST *chk = new FORM::ENVL::POST;				chk->type = read_U2(it);				return chk;			}			if (tag == "KEY ") {				FORM::ENVL::KEY *chk = new FORM::ENVL::KEY;				chk->time = read_F4(it);				chk->value = read_F4(it);				return chk;			}			if (tag == "SPAN") {				FORM::ENVL::SPAN *chk = new FORM::ENVL::SPAN;				chk->type = read_ID4(it);				while (it < end) chk->parameters.push_back(read_F4(it));				return chk;			}			if (tag == "CHAN") {				FORM::ENVL::CHAN *chk = new FORM::ENVL::CHAN;				chk->server_name = read_S0(it);				chk->flags = read_U2(it);				while (it < end) chk->data.push_back(read_U1(it));				return chk;			}			if (tag == "NAME") {				FORM::ENVL::NAME *chk = new FORM::ENVL::NAME;				chk->channel_name = read_S0(it);				return chk;			}		}		// CLIP CONTEXT		if (context == "FORM::CLIP") {			if (tag == "STIL") {				FORM::CLIP::STIL *chk = new FORM::CLIP::STIL;				chk->name = read_FNAM0(it);				return chk;			}			if (tag == "ISEQ") {				FORM::CLIP::ISEQ *chk = new FORM::CLIP::ISEQ;				chk->num_digits = read_U1(it);				chk->flags = read_U1(it);				chk->offset = read_I2(it);				chk->reserved = read_U2(it);				chk->start = read_I2(it);				chk->end = read_I2(it);				chk->prefix = read_FNAM0(it);				chk->suffix = read_S0(it);				return chk;			}			if (tag == "ANIM") {				FORM::CLIP::ANIM *chk = new FORM::CLIP::ANIM;				chk->filename = read_FNAM0(it);				chk->server_name = read_S0(it);				chk->flags = read_U2(it);				while (it < end) chk->data.push_back(read_U1(it));				return chk;			}			if (tag == "XREF") {				FORM::CLIP::XREF *chk = new FORM::CLIP::XREF;				chk->index = read_U4(it);				chk->string = read_S0(it);				return chk;			}			if (tag == "STCC") {				FORM::CLIP::STCC *chk = new FORM::CLIP::STCC;				chk->lo = read_I2(it);				chk->hi = read_I2(it);				chk->name = read_FNAM0(it);			}			if (tag == "TIME") {				FORM::CLIP::TIME *chk = new FORM::CLIP::TIME;				chk->start_time = read_FP4(it);				chk->duration = read_FP4(it);				chk->frame_rate = read_FP4(it);				return chk;			}			if (tag == "CONT") {				FORM::CLIP::CONT *chk = new FORM::CLIP::CONT;				chk->contrast_delta = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "BRIT") {				FORM::CLIP::BRIT *chk = new FORM::CLIP::BRIT;				chk->brightness_delta = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "SATR") {				FORM::CLIP::SATR *chk = new FORM::CLIP::SATR;				chk->saturation_delta = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "HUE ") {				FORM::CLIP::HUE *chk = new FORM::CLIP::HUE;				chk->hue_rotation = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "GAMM") {				FORM::CLIP::GAMM *chk = new FORM::CLIP::GAMM;				chk->gamma = read_F4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "NEGA") {				FORM::CLIP::NEGA *chk = new FORM::CLIP::NEGA;				chk->enable = read_U2(it);				return chk;			}			if (tag == "IFLT") {				FORM::CLIP::IFLT *chk = new FORM::CLIP::IFLT;				chk->server_name = read_S0(it);				chk->flags = read_U2(it);				while (it < end) chk->data.push_back(read_U1(it));				return chk;			}			if (tag == "PFLT") {				FORM::CLIP::PFLT *chk = new FORM::CLIP::PFLT;				chk->server_name = read_S0(it);				chk->flags = read_U2(it);				while (it < end) chk->data.push_back(read_U1(it));				return chk;			}		}		// SURFACE CONTEXT		if (context == "FORM::SURF") {			if (tag == "COLR") {				FORM::SURF::COLR *chk = new FORM::SURF::COLR;				chk->base_color = read_COL12(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "DIFF") {				FORM::SURF::DIFF *chk = new FORM::SURF::DIFF;				chk->intensity = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "LUMI") {				FORM::SURF::LUMI *chk = new FORM::SURF::LUMI;				chk->intensity = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "SPEC") {				FORM::SURF::SPEC *chk = new FORM::SURF::SPEC;				chk->intensity = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "REFL") {				FORM::SURF::REFL *chk = new FORM::SURF::REFL;				chk->intensity = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "TRAN") {				FORM::SURF::TRAN *chk = new FORM::SURF::TRAN;				chk->intensity = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "TRNL") {				FORM::SURF::TRNL *chk = new FORM::SURF::TRNL;				chk->intensity = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "GLOS") {				FORM::SURF::GLOS *chk = new FORM::SURF::GLOS;				chk->glossiness = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "SHRP") {				FORM::SURF::SHRP *chk = new FORM::SURF::SHRP;				chk->sharpness = read_FP4(it);				chk->envelope = read_VX(it);				return chk;			}			if (tag == "BUMP") {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -