From: Mikko Rasa Date: Sun, 28 Mar 2021 09:46:33 +0000 (+0300) Subject: Fix and improve vertex group support X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;ds=sidebyside;h=e1d07383b29e8581230b50f45606192d1f21f5dd;p=libs%2Fgl.git Fix and improve vertex group support Some parts of the export code had gotten out of sync in 306be12. Groups and weights now have dedicated attributes instead of using an arbitrary generic attribute. They're also separate attributes, allowing up to four groups per vertex. --- diff --git a/blender/io_mspgl/export_mesh.py b/blender/io_mspgl/export_mesh.py index 0d27a71c..68d93cbc 100644 --- a/blender/io_mspgl/export_mesh.py +++ b/blender/io_mspgl/export_mesh.py @@ -77,7 +77,8 @@ class MeshExporter: st.append(Token("TANGENT3")) st.append(Token("BINORMAL3")) if mesh.vertex_groups: - st.append(Token("GENERIC{}_0".format(mesh.max_groups_per_vertex*2))) + st.append(Token("GROUP{}".format(mesh.max_groups_per_vertex))) + st.append(Token("WEIGHT{}".format(mesh.max_groups_per_vertex))) st.append(Token("VERTEX3")) normal = None @@ -86,6 +87,7 @@ class MeshExporter: tan = None bino = None group = None + weight = None for v in mesh.vertices: if v.normal!=normal: st.sub.append(Statement("normal", *v.normal)) @@ -108,13 +110,14 @@ class MeshExporter: st.sub.append(Statement("binormal", *v.bino)) bino = v.bino if mesh.vertex_groups: - group_attr = [(group_index_map[g.group], g.weight*v.group_weight_scale) for g in v.groups[:mesh.max_groups_per_vertex]] - while len(group_attr)(&Loader::generic)); add("tangent", static_cast(&Loader::tangent)); add("binormal", static_cast(&Loader::binormal)); + add("group", static_cast(&Loader::group)); + add("group", static_cast(&Loader::group)); + add("group", static_cast(&Loader::group)); + add("group", static_cast(&Loader::group)); + add("weight", static_cast(&Loader::weight)); + add("weight", static_cast(&Loader::weight)); + add("weight", static_cast(&Loader::weight)); + add("weight", static_cast(&Loader::weight)); add("vertex2", static_cast(&Loader::vertex)); add("vertex3", static_cast(&Loader::vertex)); diff --git a/source/core/vertexformat.cpp b/source/core/vertexformat.cpp index 5d026e2e..2ce02e2e 100644 --- a/source/core/vertexformat.cpp +++ b/source/core/vertexformat.cpp @@ -120,6 +120,10 @@ void operator>>(const LexicalConverter &conv, VertexAttribute &a) a = TANGENT3; else if(str=="BINORMAL3") a = BINORMAL3; + else if(str.size()==6 && !str.compare(0, 5, "GROUP") && str[5]>='1' && str[5]<='4') + a = static_cast(GROUP1+(str[5]-'1')); + else if(str.size()==7 && !str.compare(0, 6, "WEIGHT") && str[6]>='1' && str[6]<='4') + a = static_cast(WEIGHT1+(str[6]-'1')); else if(str.size()>=9 && !str.compare(0, 8, "TEXCOORD") && str[8]>='1' && str[8]<='4') { if(str.size()==9) diff --git a/source/core/vertexformat.h b/source/core/vertexformat.h index 93794c35..0dbde9f9 100644 --- a/source/core/vertexformat.h +++ b/source/core/vertexformat.h @@ -27,7 +27,14 @@ enum VertexAttribute NORMAL3 = 18, TANGENT3 = 26, BINORMAL3 = 34, - // Attributes 5 and 6 reserved for vertex groups and weights + GROUP1 = 40, + GROUP2, + GROUP3, + GROUP4, + WEIGHT1 = 48, + WEIGHT2, + WEIGHT3, + WEIGHT4, TEXCOORD1 = 56, TEXCOORD2, TEXCOORD3,