Exemple #1
0
 public NiFile()
 {
     this.header    = new NiHeader();
     this.blocks    = new List <NiObject>();
     this.rawBlocks = new List <byte[]>();
     this.blockType = new List <string>();
     this.blockSize = new List <uint>();
 }
Exemple #2
0
        public NIFReader(Stream stream)
        {
            using var reader = new BinaryReader(stream);

            Header = new NiHeader(reader);
            ReadNiObjects(reader);
            Footer = new NiFooter(reader);
            FixReferences();
        }
 private void NifSelector_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (File.Exists(NifSelector.text))
     {
         var hdr = NiHeader.Load(NifSelector.text);
         treeView.Items.Clear();
         treeView.Items.Add(CreateTreeNodes(hdr, 0));
     }
 }
Exemple #4
0
        static T GetObject <T>(NiHeader header, ObjectRef object_ref) where T : NiObject, new()
        {
            //TODO: cmp T and header.block_types[object_ref]

            T instance;

            using (MemoryStream stream = new MemoryStream(header.blocks[object_ref].data))
            {
                BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.Default);

                instance = new T();
                instance.Read(reader);
            }
            return(instance);
        }
Exemple #5
0
        public void Load(Stream source_stream)
        {
            NiHeader header = GetHeader(source_stream);

            header.Dump();

            int bt_NiTriShapeData           = header.GetBlockTypeIdxByName("NiTriShapeData");
            int bt_BSLightingShaderProperty = header.GetBlockTypeIdxByName("BSLightingShaderProperty");
            int bt_BSShaderTextureSet       = header.GetBlockTypeIdxByName("BSShaderTextureSet");
            int bt_NiSkinInstance           = header.GetBlockTypeIdxByName("NiSkinInstance");
            int bt_NiSkinPartition          = header.GetBlockTypeIdxByName("NiSkinPartition");

            int num_blocks = header.blocks.Length;

            for (int i = 0; i < num_blocks; i++)
            {
                if (header.blocks[i].type == bt_NiTriShapeData)
                {
                    NiTriShapeData triShapeData = GetObject <NiTriShapeData>(header, i);
                    triShapeData.Dump();
                }
                if (header.blocks[i].type == bt_BSLightingShaderProperty)
                {
                    BSLightingShaderProperty lightingShaderProperty = GetObject <BSLightingShaderProperty>(header, i);
                    lightingShaderProperty.Dump();
                }
                if (header.blocks[i].type == bt_BSShaderTextureSet)
                {
                    BSShaderTextureSet shaderTextureSet = GetObject <BSShaderTextureSet>(header, i);
                    shaderTextureSet.Dump();
                }
                if (header.blocks[i].type == bt_NiSkinInstance)
                {
                    NiSkinInstance skinInstance = GetObject <NiSkinInstance>(header, i);
                    skinInstance.Dump();
                    foreach (ObjectRef boneref in skinInstance.bones)
                    {
                        NiNode node = GetObject <NiNode>(header, boneref);
                        System.Console.WriteLine(header.strings[node.name]);
                    }
                }
                if (header.blocks[i].type == bt_NiSkinPartition)
                {
                    NiSkinPartition skinPartition = GetObject <NiSkinPartition>(header, i);
                    skinPartition.Dump();
                }
            }
        }
Exemple #6
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]);
 }
Exemple #7
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);
            }
Exemple #8
0
        public void Load(Stream source_stream)
        {
            BinaryReader reader = new BinaryReader(source_stream, System.Text.Encoding.Default);

            header = new NiHeader();
            header.Read(reader);

            header.SetBlocksOffset(source_stream.Position);
            //header.Dump();

            int num_blocks = header.blocks.Length;

            for (int i = 0; i < num_blocks; i++)
            {
                header.blocks[i].Read(reader);
            }

            DumpNodes();
        }
Exemple #9
0
        public NiFile(Device device, string path)
        {
            Console.WriteLine("NiFile.ctor path:{0}", path);
            this.header = NiHeader.Load(path);

            int         bt_NiTriShape   = header.GetBlockTypeIdxByName("NiTriShape");
            int         num_blocks      = header.blocks.Length;
            List <Mesh> mesh_collection = new List <Mesh>();

            for (int i = 0; i < header.blocks.Length; i++)
            {
                if (header.blocks[i].type == bt_NiTriShape)
                {
                    Mesh mesh = new Mesh(device, header, i);
                    mesh_collection.Add(mesh);
                }
            }
            this.meshes = mesh_collection.ToArray();
        }
Exemple #10
0
        //TODO: nif

        static NiHeader GetHeader(Stream source_stream)
        {
            BinaryReader reader = new BinaryReader(source_stream, System.Text.Encoding.Default);

            NiHeader header = new NiHeader();

            header.Read(reader);

            header.SetBlocksOffset(source_stream.Position);
            //header.Dump();

            int num_blocks = header.blocks.Length;

            for (int i = 0; i < num_blocks; i++)
            {
                header.blocks[i].Read(reader);
            }
            return(header);
        }
        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);
        }
Exemple #12
0
 public NiFile()
 {
     this.header = new NiHeader();
     this.blocks = new List <NiObject>();
 }
 public string GetNodeName(NiHeader hdr, Int32 string_ref)
 {
     return(string_ref != -1 ? hdr.strings[string_ref] : "(undefined)");
 }