Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        private int[] buildBoneRenameMap(RenderList mat, Dictionary<int, int> rename, int max_bone)
        {
            int[] rename_map = new int[Bone.Length];
            for (int i = 0; i < Bone.Length; i++) {
                rename_map[i] = 0; // initialize
            }
            foreach (var b in rename) {
                if (b.Value < max_bone) {
                    rename_map[b.Key] = b.Value;
                }
            }

            return rename_map;
        }
Exemplo n.º 3
0
        private void buildBoneRenamedWeightBuffers(RenderList mat, Dictionary<int, int> rename, int max_bone)
        {
            buildBoneRenameInvMap(mat, rename, max_bone);

            int[] map = buildBoneRenameMap(mat, rename, max_bone);

            short[] weight = new short[3];
            for (int i = mat.face_vert_offset; i < mat.face_vert_offset + mat.face_vert_count; i++) {
                int pos = (0x0000ffff & Index[i]);
                weight [0] = Weight [pos * 3 + 0];
                weight [1] = Weight [pos * 3 + 1];
                weight [2] = Weight [pos * 3 + 2];

                mat.weight[pos * 3 + 0] = (byte)map[weight[0]];
                mat.weight[pos * 3 + 1] = (byte)map[weight[1]];
                mat.weight[pos * 3 + 2] = (byte) weight[2];
            }
        }
Exemplo n.º 4
0
 private void buildBoneRenameInvMap(RenderList mat, Dictionary<int, int> rename, int max_bone)
 {
     mat.bone_inv_map = new int[max_bone];
     for (int i = 0; i < max_bone; i++) {
         mat.bone_inv_map[i] = -1; // initialize
     }
     foreach (var b in rename) {
         if (b.Value < max_bone) {
             mat.bone_inv_map[b.Value] = b.Key;
         }
     }
 }
Exemplo n.º 5
0
 private void allocateWeightBuffer(RenderList mat, Dictionary<int, int> rename)
 {
     mat.weight = new byte[Weight.Length];
 }