private void parseMaterialList(BinaryReader br, String path) { // the number of Vertexes int num = br.ReadInt32 (); Log.Debug("PMD", "MATERIAL: " + num.ToString()); if (num > 0) { int acc = 0; Material = new Material[num]; for (int i = 0; i < num; i++) { Material m = new Material(); m.diffuse_color = Util.ReadFloats(br, 4); m.power = br.ReadSingle(); m.specular_color = Util.ReadFloats(br, 3); m.emmisive_color = Util.ReadFloats(br, 3); m.toon_index = (byte)(br.ReadByte() + 1); m.edge_flag = br.ReadByte(); m.face_vert_count = br.ReadInt32(); m.texture = Util.ReadString(br, 20); m.face_vert_offset = acc; acc = acc + m.face_vert_count; Material[i] = m; } Log.Debug("PMD", "CHECKSUM IN MATERIAL: " + acc.ToString()); } else { Material = null; } }
private void reconstructMaterial1(Material mat, int offset, Dictionary<Dictionary<int, int>, byte[]> rename_pool, int max_bone) { var rename = new Dictionary<int, int>(); int acc = 0; for (int j = offset; j < mat.face_vert_count; j += 3) { int acc_prev = acc; acc = renameBone1(rename, mat.face_vert_offset + j + 0, acc); acc = renameBone1(rename, mat.face_vert_offset + j + 1, acc); acc = renameBone1(rename, mat.face_vert_offset + j + 2, acc); if (acc > max_bone) { RenderList mat_new = buildNewMaterial(mat, offset, j, rename, rename_pool, acc_prev); RenderLists.Add(mat_new); reconstructMaterial1(mat, j, rename_pool, max_bone); return; } } RenderList mat_new2 = buildNewMaterial(mat, offset, mat.face_vert_count, rename, rename_pool, max_bone); RenderLists.Add(mat_new2); }
private RenderList buildNewMaterial(Material mat_orig, int offset, int count, Dictionary<int, int> rename, Dictionary<Dictionary<int, int>, byte[]> rename_pool, int max_bone) { RenderList mat = new RenderList(); mat.material = mat_orig; mat.face_vert_offset = mat_orig.face_vert_offset + offset; mat.face_vert_count = count - offset; mat.bone_num = rename.Count; // find unoverwrapped hash foreach(var pool in rename_pool) { var map = pool.Key; var bb = pool.Value; // check mapped foreach(var entry in rename) { if(map.ContainsKey(entry.Key)) { bb = null; } } // find free byte buffer if(bb != null) { rename_pool.Remove(map); mat.weight = bb; buildBoneRenamedWeightBuffers(mat, rename, max_bone); foreach (var i in rename) { map [i.Key] = i.Value; } // map.putAll(rename); rename_pool[map] = bb; Log.Debug("PMD", "Reuse buffer"); return mat; } } // allocate new buffer Log.Debug("PMD", "Allocate new buffer"); allocateWeightBuffer(mat, rename); buildBoneRenamedWeightBuffers(mat, rename, max_bone); var new_map = new Dictionary<int, int>(rename); rename_pool[new_map] = mat.weight; Log.Debug("PMD", "rename Bone for Material #" + mat.material.face_vert_offset + ", bones " + offset.ToString()); foreach (var b in rename) { Log.Debug("PMD", String.Format("ID {0}: bone {1}", b.Value, b.Key)); } return mat; }