From 43c6495ff3d14a85ee5de169a80fdacf13b7147e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 2 Sep 2012 20:14:20 +0300 Subject: [PATCH] Load VertexFormat for Mesh as an array of VertexComponents The single-token approach made indexed attributes rather ugly. Loading each component separately also gives better diagnostics in case of erroneous tokens. --- blender/io_mspgl/export_mesh.py | 14 +++++++------- source/mesh.cpp | 10 ++++++++-- source/mesh.h | 2 +- source/vertexformat.cpp | 20 -------------------- source/vertexformat.h | 1 - 5 files changed, 16 insertions(+), 31 deletions(-) diff --git a/blender/io_mspgl/export_mesh.py b/blender/io_mspgl/export_mesh.py index 0d2e66ab..135ed109 100644 --- a/blender/io_mspgl/export_mesh.py +++ b/blender/io_mspgl/export_mesh.py @@ -286,19 +286,19 @@ class MeshExporter: if self.object: out_file.begin("mesh") - fmt = "NORMAL3" + fmt = ["NORMAL3"] if texunits: for i, u in texunits: if u.unit==0: - fmt += "_TEXCOORD2" + fmt.append("TEXCOORD2") else: - fmt += "_TEXCOORD2%d"%u.unit + fmt.append("TEXCOORD2_%d"%u.unit) if self.tbn_vecs: - fmt += "_ATTRIB33_ATTRIB34" + fmt += ["ATTRIB3_3", "ATTRIB3_4"] if self.export_groups: - fmt += "_ATTRIB%d5"%(self.max_groups*2) - fmt += "_VERTEX3" - out_file.begin("vertices", fmt) + fmt.append("ATTRIB%d_5"%(self.max_groups*2)) + fmt.append("VERTEX3") + out_file.begin("vertices", *fmt) normal = None uvs = [None]*len(texunits) tan = None diff --git a/source/mesh.cpp b/source/mesh.cpp index 0e58aa26..508054a5 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -130,9 +130,15 @@ Mesh::Loader::Loader(Mesh &m): add("winding", &Loader::winding); } -void Mesh::Loader::vertices(VertexFormat f) +void Mesh::Loader::vertices(const vector &c) { - obj.vertices.reset(f); + if(c.empty()) + throw invalid_argument("No vertex components"); + + VertexFormat fmt; + for(vector::const_iterator i=c.begin(); i!=c.end(); ++i) + fmt = (fmt, *i); + obj.vertices.reset(fmt); load_sub(obj.vertices); } diff --git a/source/mesh.h b/source/mesh.h index 698ae60e..83f2fb07 100644 --- a/source/mesh.h +++ b/source/mesh.h @@ -27,7 +27,7 @@ public: public: Loader(Mesh &); private: - void vertices(VertexFormat); + void vertices(const std::vector &); void batch(PrimitiveType); void winding(FaceWinding); }; diff --git a/source/vertexformat.cpp b/source/vertexformat.cpp index 146fc680..1de43087 100644 --- a/source/vertexformat.cpp +++ b/source/vertexformat.cpp @@ -165,25 +165,5 @@ void operator>>(const LexicalConverter &conv, VertexComponent &c) throw lexical_error(format("conversion of '%s' to VertexComponent", str)); } -// XXX This will go away eventually -void operator>>(const LexicalConverter &conv, VertexFormat &f) -{ - vector parts = split(conv.get(), '_'); - for(vector::iterator i=parts.begin(); i!=parts.end(); ++i) - { - if(*i=="COLOR4UB") - *i = "COLOR4_UBYTE"; - else if(i->size()==7 && !i->compare(0, 5, "COLOR") && (*i)[6]=='F') - *i = i->substr(0, 6)+"_FLOAT"; - else if(i->size()>=10 && !i->compare(0, 8, "TEXCOORD")) - *i = i->substr(0, 9)+"_"+i->substr(9); - else if(i->size()>=8 && !i->compare(0, 6, "ATTRIB")) - *i = i->substr(0, 7)+"_"+i->substr(7); - } - - for(vector::iterator i=parts.begin(); i!=parts.end(); ++i) - f = (f, lexical_cast(*i)); -} - } // namespace GL } // namespace Msp diff --git a/source/vertexformat.h b/source/vertexformat.h index 95e9b2c5..9be98160 100644 --- a/source/vertexformat.h +++ b/source/vertexformat.h @@ -68,7 +68,6 @@ inline unsigned get_stride(const VertexFormat &f) { return f.stride(); } void operator>>(const LexicalConverter &, VertexComponent &); -void operator>>(const LexicalConverter &, VertexFormat &); } // namespace GL } // namespace Msp -- 2.43.0