Ejemplo n.º 1
0
 public static string GetNiNodeName(this NiHeader hdr, int id)
 {
     try
     {
         int typeIndex = hdr.GetBlockTypeIdxByName("NiNode");
     }
     catch (System.Exception)
     {
         return("");
     }
     //Console.WriteLine("BT idx 'NiNode': {0}", bt_NiNode);
     if (id >= hdr.blocks.Length)
     {
         return("");
     }
     return(hdr.strings[hdr.GetObject <NiNode>(id).name]);
 }
Ejemplo n.º 2
0
        public Mesh(Device device, NiHeader header, ObjectRef triShape_ref)
        {
            this.header       = header;
            this.triShape_ref = triShape_ref;

            NiTriShape triShape = header.GetObject <NiTriShape>(triShape_ref);

            Matrix triShape_local_m;

            ToMatrix(triShape.local, out triShape_local_m);

            var triShape_data = header.GetObject <NiTriShapeData>(triShape.data);

            shader_property = header.GetObject <BSLightingShaderProperty>(triShape.shader_property);
            var shader_texture_set = header.GetObject <BSShaderTextureSet>(shader_property.texture_set);
            var skin_instance      = header.GetObject <NiSkinInstance>(triShape.skin_instance);

            skin_data = header.GetObject <NiSkinData>(skin_instance.data);
            var skin_partition = header.GetObject <NiSkinPartition>(skin_instance.skin_partition);

            albedoMap_path = Path.GetFileName(shader_texture_set.textures[0]);

            num_bones = skin_instance.num_bones;
            bones     = skin_instance.bones;

            submeshes = new SubMesh[skin_partition.num_skin_partitions];
            for (int part_i = 0; part_i < skin_partition.num_skin_partitions; part_i++)
            {
                ref SkinPartition part = ref skin_partition.skin_partitions[part_i];

                // create submesh vertices/uvs from part.vertex_map

                Vector3[] positions = new Vector3[part.num_vertices];
                Vector2[] uvs       = new Vector2[part.num_vertices];

                for (int i = 0; i < part.num_vertices; i++)
                {
                    ushort x = part.vertex_map[i];
                    Vector3.TransformCoordinate(ref triShape_data.vertices[x], ref triShape_local_m, out positions[i]);
                    uvs[i] = triShape_data.uvs[x];
                }

                submeshes[part_i] = new SubMesh(device, positions, uvs, part.vertex_weights, part.bone_indices, part.triangles, part.bones);
            }
Ejemplo n.º 3
0
        TreeViewItem CreateTreeNodes(NiHeader hdr, int nodeIndex)
        {
            if (nodeIndex >= hdr.blocks.Length)
            {
                MessageBox.Show("Node (" + nodeIndex.ToString() + ") out of range.");
                return(null);
            }
            NiNode node = null;

            try
            {
                node = hdr.GetObject <NiNode>(nodeIndex);
            }
            catch (Exception)
            {
                return(null);
            }

            TreeViewItem branch    = new TreeViewItem();
            var          textBlock = new TextBlock()
            {
                Text = hdr.GetNiNodeName(nodeIndex),
            };

            textBlock.IsHitTestVisible = false;
            branch.Header = textBlock;


            if (node != null && node.children.Length > 0)
            {
                foreach (var childIndex in node.children)
                {
                    var subBranch = CreateTreeNodes(hdr, childIndex);
                    if (subBranch != null)
                    {
                        branch.Items.Add(subBranch);
                    }
                }
            }
            return(branch);
        }