- for tri_index, tri in enumerate(data.loop_triangles):
- if tri.material_index != material_id:
- continue
-
- for j in range(3):
- vert = data.vertices[tri.vertices[j]]
- li = tri.loops[j]
- vi = data.loops[li].vertex_index
-
- co = vert.co
- norm = data.loops[li].normal
- uv = (0,0)
- colour = (255,255,255,255)
- groups = [0,0,0,0]
- weights = [0,0,0,0]
-
- if data.uv_layers:
- uv = data.uv_layers.active.data[li].uv
-
- if data.vertex_colors:
- colour = data.vertex_colors.active.data[li].color
- colour = (int(colour[0]*255.0),\
- int(colour[1]*255.0),\
- int(colour[2]*255.0),\
- int(colour[3]*255.0))
-
- # WEight groups
- #
- if armature_def:
- weight_groups = sorted( data.vertices[vi].groups, key = \
- lambda a: a.weight, reverse=True )
- tot = 0.0
- for ml in range(3):
- if len(weight_groups) > ml:
- g = weight_groups[ml]
- name = obj.vertex_groups[g.group].name
- weight = g.weight
-
- weights[ml] = weight
- groups[ml] = armature_def['bones'].index(name)
- tot += weight
-
- if len(weight_groups) > 0:
- inv_norm = (1.0/tot) * 65535.0
- for ml in range(3):
- weights[ml] = int( weights[ml] * inv_norm )
- weights[ml] = min( weights[ml], 65535 )
- weights[ml] = max( weights[ml], 0 )
-
- TOLERENCE = 4
- m = float(10**TOLERENCE)
-
- key = (int(co[0]*m+0.5),\
- int(co[1]*m+0.5),\
- int(co[2]*m+0.5),\
- int(norm[0]*m+0.5),\
- int(norm[1]*m+0.5),\
- int(norm[2]*m+0.5),\
- int(uv[0]*m+0.5),\
- int(uv[1]*m+0.5),\
- colour[0],\
- colour[1],\
- colour[2],\
- colour[3],\
- weights[0],\
- weights[1],\
- weights[2],\
- weights[3],\
- groups[0],\
- groups[1],\
- groups[2],\
- groups[3])
-
- if key in boffa:
- indice_buffer += [boffa[key]]
- else:
- index = c_uint32(sm.vertex_count)
- sm.vertex_count += 1
-
- boffa[key] = index
- indice_buffer += [index]
-
- v = mdl_vert()
- v.co[0] = co[0]
- v.co[1] = co[2]
- v.co[2] = -co[1]
- v.norm[0] = norm[0]
- v.norm[1] = norm[2]
- v.norm[2] = -norm[1]
- v.uv[0] = uv[0]
- v.uv[1] = uv[1]
- v.colour[0] = colour[0]
- v.colour[1] = colour[1]
- v.colour[2] = colour[2]
- v.colour[3] = colour[3]
- v.weights[0] = weights[0]
- v.weights[1] = weights[1]
- v.weights[2] = weights[2]
- v.weights[3] = weights[3]
- v.groups[0] = groups[0]
- v.groups[1] = groups[1]
- v.groups[2] = groups[2]
- v.groups[3] = groups[3]
-
- vertex_buffer += [v]
-
- for i in range(3):
- sm.bbx[0][i] = min( sm.bbx[0][i], v.co[i] )
- sm.bbx[1][i] = max( sm.bbx[1][i], v.co[i] )
-
- sm.indice_count += 1
-
- if sm.vertex_count == 0:
- for j in range(2):
- for i in range(3):
- sm.bbx[j][i] = 0
-
- submesh_buffer += [sm]
- node.submesh_count += 1
- header.submesh_count += 1
- header.vertex_count += sm.vertex_count
- header.indice_count += sm.indice_count
-
- mesh_cache[obj.data.name] = node
-
- # Process entity data
- # ==================================================================
- node.offset = entdata_length
-
- if classtype != 'k_classtype_none':
- disptype = classtype
+ co = vert.co
+ norm = data.loops[li].normal
+ uv = (0,0)
+ colour = (255,255,255,255)
+ groups = [0,0,0,0]
+ weights = [0,0,0,0]
+
+ # Uvs
+ #
+ if data.uv_layers:
+ uv = data.uv_layers.active.data[li].uv
+
+ # Vertex Colours
+ #
+ if data.vertex_colors:
+ #{
+ colour = data.vertex_colors.active.data[li].color
+ colour = (int(colour[0]*255.0),\
+ int(colour[1]*255.0),\
+ int(colour[2]*255.0),\
+ int(colour[3]*255.0))
+ #}
+
+ # Weight groups: truncates to the 3 with the most influence. The
+ # fourth bone ID is never used by the shader so it is
+ # always 0
+ #
+ if armature_def:
+ #{
+ src_groups = [_ for _ in data.vertices[vi].groups \
+ if obj.vertex_groups[_.group].name in \
+ armature_def['bones']]
+
+ weight_groups = sorted( src_groups, key = \
+ lambda a: a.weight, reverse=True )
+ tot = 0.0
+ for ml in range(3):
+ #{
+ if len(weight_groups) > ml:
+ #{
+ g = weight_groups[ml]
+ name = obj.vertex_groups[g.group].name
+ weight = g.weight
+
+ weights[ml] = weight
+ groups[ml] = armature_def['bones'].index(name)
+ tot += weight
+ #}
+ #}
+
+ if len(weight_groups) > 0:
+ #{
+ inv_norm = (1.0/tot) * 65535.0
+ for ml in range(3):
+ #{
+ weights[ml] = int( weights[ml] * inv_norm )
+ weights[ml] = min( weights[ml], 65535 )
+ weights[ml] = max( weights[ml], 0 )
+ #}
+ #}
+
+ # Add vertex and expand bound box
+ #
+ index = encoder_vertex_push( vertex_reference, co, \
+ norm, \
+ uv, \
+ colour, \
+ groups, \
+ weights )
+ g_encoder['data']['indice'] += [index]
+ #}
+ #}
+
+ # How many unique verts did we add in total
+ #
+ sm.vertex_count = len(g_encoder['data']['vertex']) - sm.vertex_start
+ sm.indice_count = len(g_encoder['data']['indice']) - sm.indice_start
+
+ # Make sure bounding box isn't -inf -> inf if no vertices
+ #
+ if sm.vertex_count == 0:
+ for j in range(2):
+ for i in range(3):
+ sm.bbx[j][i] = 0