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
tan = None
bino = None
group = None
+ weight = None
for v in mesh.vertices:
if v.normal!=normal:
st.sub.append(Statement("normal", *v.normal))
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)<mesh.max_groups_per_vertex:
- group_attr.append((0, 0.0))
- group_attr = list(itertools.chain(*group_attr))
- if group_attr!=group:
- st.sub.append(Statement("generic", 0, *group_attr))
- group = group_attr
+ v_group = [g.group for g in v.groups]
+ v_weight = [g.weight for g in v.groups]
+ if v_group!=group:
+ st.sub.append(Statement("group", *v_group))
+ group = v_group
+ if v_weight!=weight:
+ st.sub.append(Statement("weight", *v_weight))
+ weight = v_weight
st.sub.append(Statement("vertex", *v.co))
statements.append(st)
class VertexGroup:
def __init__(self, group):
- self.group = group.group
- self.weight = group.weight
+ if group:
+ self.group = group.group
+ self.weight = group.weight
+ else:
+ self.group = 0
+ self.weight = 0.0
class Face:
# Clone basic data
self.vertices = [Vertex(v) for v in mesh.vertices]
- for v in self.vertices:
- v.groups = [VertexGroup(g) for g in v.groups]
+ if self.vertex_groups:
+ for v in self.vertices:
+ v.groups = [VertexGroup(g) for g in v.groups]
self.faces = [Face(f) for f in mesh.polygons]
self.edges = [Edge(e) for e in mesh.edges]
self.use_auto_smooth = mesh.use_auto_smooth
self.auto_smooth_angle = mesh.auto_smooth_angle
+ self.max_groups_per_vertex = mesh.max_groups_per_vertex
# Clone only the desired UV layers
if mesh.use_uv=='NONE' or not mesh.uv_layers:
progress.pop_task()
def prepare_vertex_groups(self, obj):
+ if not self.vertex_groups:
+ return
+
for v in self.vertices:
if v.groups:
weight_sum = sum(g.weight for g in v.groups)
weight_scale = weight_sum/sum(g.weight for g in v.groups)
for g in v.groups:
g.weight *= weight_scale
+ while len(v.groups)<self.max_groups_per_vertex:
+ v.groups.append(VertexGroup(None))
if obj.parent and obj.parent.type=="ARMATURE":
armature = obj.parent.data
void color(const Color &c)
{ attrib(get_attribute_semantic(COLOR4_FLOAT), Vector4(c.r, c.g, c.b, c.a)); }
+ void group(int g0)
+ { group(g0, 0, 0, 0); }
+
+ void group(int g0, int g1)
+ { group(g0, g1, 0, 0); }
+
+ void group(int g0, int g1, int g2)
+ { group(g0, g1, g2, 0); }
+
+ void group(int g0, int g1, int g2, int g3)
+ { attrib(get_attribute_semantic(GROUP4), Vector4(g0, g1, g2, g3)); }
+
+ void weight(float w0)
+ { weight(w0, 0, 0, 0); }
+
+ void weight(float w0, float w1)
+ { weight(w0, w1, 0, 0); }
+
+ void weight(float w0, float w1, float w2)
+ { weight(w0, w1, w2, 0); }
+
+ void weight(float w0, float w1, float w2, float w3)
+ { attrib(get_attribute_semantic(WEIGHT4), Vector4(w0, w1, w2, w3)); }
+
void generic(unsigned i, float x)
{ generic(i, x, 0, 0, 1); }
add("generic", static_cast<void (Loader::*)(unsigned, float, float, float, float)>(&Loader::generic));
add("tangent", static_cast<void (Loader::*)(float, float, float)>(&Loader::tangent));
add("binormal", static_cast<void (Loader::*)(float, float, float)>(&Loader::binormal));
+ add("group", static_cast<void (Loader::*)(int)>(&Loader::group));
+ add("group", static_cast<void (Loader::*)(int, int)>(&Loader::group));
+ add("group", static_cast<void (Loader::*)(int, int, int)>(&Loader::group));
+ add("group", static_cast<void (Loader::*)(int, int, int, int)>(&Loader::group));
+ add("weight", static_cast<void (Loader::*)(float)>(&Loader::weight));
+ add("weight", static_cast<void (Loader::*)(float, float)>(&Loader::weight));
+ add("weight", static_cast<void (Loader::*)(float, float, float)>(&Loader::weight));
+ add("weight", static_cast<void (Loader::*)(float, float, float, float)>(&Loader::weight));
add("vertex2", static_cast<void (Loader::*)(float, float)>(&Loader::vertex));
add("vertex3", static_cast<void (Loader::*)(float, float, float)>(&Loader::vertex));
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<VertexAttribute>(GROUP1+(str[5]-'1'));
+ else if(str.size()==7 && !str.compare(0, 6, "WEIGHT") && str[6]>='1' && str[6]<='4')
+ a = static_cast<VertexAttribute>(WEIGHT1+(str[6]-'1'));
else if(str.size()>=9 && !str.compare(0, 8, "TEXCOORD") && str[8]>='1' && str[8]<='4')
{
if(str.size()==9)
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,