]> git.tdb.fi Git - libs/gl.git/commitdiff
Load VertexFormat for Mesh as an array of VertexComponents
authorMikko Rasa <tdb@tdb.fi>
Sun, 2 Sep 2012 17:14:20 +0000 (20:14 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 2 Sep 2012 17:14:20 +0000 (20:14 +0300)
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
source/mesh.cpp
source/mesh.h
source/vertexformat.cpp
source/vertexformat.h

index 0d2e66ab442206b9f2454baa0ffe2e37f7557cb3..135ed1098de2981c14899441485386f6cd6d0b63 100644 (file)
@@ -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
index 0e58aa269a1bbdb7679aa36737f0a79ecdb95663..508054a521346ac45e394848fb0c7ec11f0fe799 100644 (file)
@@ -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<VertexComponent> &c)
 {
-       obj.vertices.reset(f);
+       if(c.empty())
+               throw invalid_argument("No vertex components");
+
+       VertexFormat fmt;
+       for(vector<VertexComponent>::const_iterator i=c.begin(); i!=c.end(); ++i)
+               fmt = (fmt, *i);
+       obj.vertices.reset(fmt);
        load_sub(obj.vertices);
 }
 
index 698ae60e53686dacf2210a5ac9d068a301a7a12e..83f2fb0734d3bf31b16e2756977bb53a78d21214 100644 (file)
@@ -27,7 +27,7 @@ public:
        public:
                Loader(Mesh &);
        private:
-               void vertices(VertexFormat);
+               void vertices(const std::vector<VertexComponent> &);
                void batch(PrimitiveType);
                void winding(FaceWinding);
        };
index 146fc68095be688e4c974c3aefbccf89c71b0b7e..1de430870d6a328d363b169f0fb53125bde2614a 100644 (file)
@@ -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<string> parts = split(conv.get(), '_');
-       for(vector<string>::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<string>::iterator i=parts.begin(); i!=parts.end(); ++i)
-               f = (f, lexical_cast<VertexComponent>(*i));
-}
-
 } // namespace GL
 } // namespace Msp
index 95e9b2c5bc42fd299283201ffa6a8c725697fb57..9be98160b0bb0d23ef62358d150aa6e670d254d2 100644 (file)
@@ -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