Exemplo n.º 1
0
        public GFModel(H3DModel mdl, H3DDict <H3DLUT> H3DLUTs) : this()
        {
            Name = mdl.Name;

            foreach (H3DBone Bone in mdl.Skeleton)
            {
                Skeleton.Add(new GFBone(Bone, mdl.Skeleton));
            }

            foreach (H3DMaterial Material in mdl.Materials)
            {
                H3DMesh Mesh = null;
                foreach (H3DMesh M in mdl.Meshes)
                {
                    if (mdl.Materials[M.MaterialIndex] == Material)
                    {
                        Mesh = M;
                        break;
                    }
                }
                Materials.Add(new GFMaterial(Material, Mesh));
            }

            Transform = mdl.WorldTransform;

            PokemonBBoxGen.CreateModelBBox(mdl);
            H3DMetaDataValue BBox       = mdl.MetaData[mdl.MetaData.Find(PokemonBBoxGen.BBOX_MIN_MAX)];
            List <float>     BBoxMinMax = (List <float>)BBox.Values;

            BBoxMinVector = new Vector4(BBoxMinMax[0], BBoxMinMax[1], BBoxMinMax[2], 1);
            BBoxMaxVector = new Vector4(BBoxMinMax[3], BBoxMinMax[4], BBoxMinMax[5], 1);

            foreach (H3DLUT LUT in H3DLUTs)
            {
                if (LUT.Name.Equals(DefaultLUTName))
                {
                    foreach (H3DLUTSampler Sampler in LUT.Samplers)
                    {
                        LUTs.Add(new GFLUT()
                        {
                            Type  = GetLUTType(Sampler.Name, mdl.Materials),
                            Name  = Sampler.Name,
                            Table = Sampler.Table
                        });
                    }
                }
            }

            foreach (H3DMesh Mesh in mdl.Meshes)
            {
                Meshes.Add(new GFMesh(Mesh, mdl));
            }
        }
Exemplo n.º 2
0
        private static void CreateMetaDataAndAddValue(H3DMesh Mesh, H3DMetaDataValue Value)
        {
            if (Mesh.MetaData == null)
            {
                Mesh.MetaData = new H3DMetaData();
            }
            int Find = Mesh.MetaData.Find(Value.Name);

            if (Find != -1)
            {
                Mesh.MetaData.Remove(Mesh.MetaData[Find]);
            }
            Mesh.MetaData.Add(Value);
        }
Exemplo n.º 3
0
        private void listViewCustom1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewCustom1.SelectedItems.Count > 0)
            {
                btnScrolDown.Enabled = true;
                btnScrollUp.Enabled  = true;
                btnEdit.Enabled      = true;
                btnRemove.Enabled    = true;

                SelectedData = MetaData[listViewCustom1.SelectedIndices[0]];
            }
            else
            {
                SelectedData         = null;
                btnScrolDown.Enabled = false;
                btnScrollUp.Enabled  = false;
                btnEdit.Enabled      = false;
                btnRemove.Enabled    = false;
            }
        }
Exemplo n.º 4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (MetaData == null)
            {
                MetaData = new H3DMetaData();
            }

            H3DMetaDataValue userDataNew = new H3DMetaDataValue();

            userDataNew.Type = H3DMetaDataType.Integer;
            userDataNew.SetValue(new int[0]);
            SelectedData = userDataNew;
            bool IsEdited = EditData();

            if (IsEdited)
            {
                MetaData.Add(SelectedData);
                LoadUserData(SelectedData);
            }
        }
Exemplo n.º 5
0
        public GFMesh(H3DMesh Mesh, H3DModel Parent) : this()
        {
            if (Mesh.NodeIndex >= 0 && Mesh.NodeIndex < Parent.MeshNodesTree.Count)
            {
                Name = Parent.MeshNodesTree.Find(Mesh.NodeIndex);
            }
            else
            {
                Name = "Mesh_" + Parent.Meshes.IndexOf(Mesh);
            }

            if (Mesh.MetaData.Find(PokemonBBoxGen.BBOX_MIN_MAX) == -1)
            {
                PokemonBBoxGen.CreateModelBBox(Parent);
            }
            H3DMetaDataValue BBox       = Mesh.MetaData[Mesh.MetaData.Find(PokemonBBoxGen.BBOX_MIN_MAX)];
            List <float>     BBoxMinMax = (List <float>)BBox.Values;

            BBoxMinVector = new Vector4(BBoxMinMax[0], BBoxMinMax[1], BBoxMinMax[2], 1);
            BBoxMaxVector = new Vector4(BBoxMinMax[3], BBoxMinMax[4], BBoxMinMax[5], 1);

            BoneIndicesPerVertex = 4;

            int SubMeshIdx             = 0;
            List <PICAVertex> Vertices = Mesh.GetVertices().ToList();

            foreach (H3DSubMesh SubMesh in Mesh.SubMeshes)
            {
                string MaterialName;
                if (Mesh.MaterialIndex >= 0 && Mesh.MaterialIndex < Parent.Materials.Count)
                {
                    MaterialName = Parent.Materials[Mesh.MaterialIndex].Name;
                }
                else
                {
                    MaterialName = null;
                }
                SubMeshes.Add(new GFSubMesh(SubMesh, Mesh, Vertices, MaterialName));
                SubMeshIdx++;
            }
        }
Exemplo n.º 6
0
        private void LoadUserData(H3DMetaDataValue item)
        {
            ListViewItem listItem = new ListViewItem();

            listItem.Text = item.Name;
            listItem.SubItems.Add(item.Type.ToString());

            string value = "";

            switch (item.Type)
            {
            case H3DMetaDataType.ASCIIString:
            case H3DMetaDataType.UnicodeString:
                foreach (var val in item.Values)
                {
                    value += $" {val.ToString()}";
                }
                break;

            case H3DMetaDataType.Single:
                foreach (float val in item.Values)
                {
                    value += $" {val.ToString()}";
                }
                break;

            case H3DMetaDataType.Integer:
                foreach (int val in item.Values)
                {
                    value += $" {val.ToString()}";
                }
                break;
            }
            listItem.SubItems.Add(value);

            listViewCustom1.Items.Add(listItem);
        }
Exemplo n.º 7
0
        public void MergeH3D(H3D Scene)
        {
            foreach (object SourceData in Scene.SourceData)
            {
                if (SourceData is GFModelPack)
                {
                    MergeGFModelPack((GFModelPack)SourceData);
                }
                else if (SourceData is GFShader)
                {
                    GFShader Sha = (GFShader)SourceData;
                    if (Sha.HasVertexShader)
                    {
                        Console.WriteLine("Merging vertex shader: " + Sha.Name);
                        VertexShaders.Add(Sha);
                    }
                    else
                    {
                        Console.WriteLine("Merging material shader: " + Sha.Name);
                        MaterialShaders.Add(Sha);
                    }
                }
            }
            Models.Clear();
            Textures.Clear();

            Dictionary <uint, GFShader> ShaderHashesOriginal = new Dictionary <uint, GFShader>();
            Dictionary <uint, GFShader> ShaderHashes         = new Dictionary <uint, GFShader>();

            List <string> UsedVertexShaders   = new List <string>();
            List <string> UsedMaterialShaders = new List <string>();

            foreach (GFShader Shader in MaterialShaders)
            {
                uint Hash = GetTexEnvConfigHash(Shader);
                if (!ShaderHashes.ContainsKey(Hash))
                {
                    Console.WriteLine("Adding existing shader " + Shader.Name);
                    ShaderHashesOriginal.Add(Hash, Shader);
                    ShaderHashes.Add(Hash, Shader);
                }
            }

            foreach (H3DModel Model in Scene.Models)
            {
                GFModel GFM = new GFModel(Model, Scene.LUTs);

                foreach (H3DMaterial Material in Model.Materials)
                {
                    bool             IsAllowOriginalShader = false;
                    uint             Hash       = GetTexEnvConfigHash(Material.MaterialParams);
                    H3DMetaDataValue OriginHash = Material.MaterialParams.MetaData.Get("OriginMaterialHash");
                    if (OriginHash != null)
                    {
                        IsAllowOriginalShader = (int)OriginHash.Values[0] == Hash && ShaderHashesOriginal.ContainsKey(Hash);
                    }

                    if (!IsAllowOriginalShader)
                    {
                        GFShader Shader;
                        if (ShaderHashes.ContainsKey(Hash))
                        {
                            Shader = ShaderHashes[Hash];
                        }
                        else
                        {
                            Shader = new GFShader(Material, Material.Name + "_SHA");
                            Console.WriteLine("Generating shader " + Shader.Name);
                            ShaderHashes.Add(GetTexEnvConfigHash(Shader), Shader);
                            AddUnique(MaterialShaders, Shader);
                        }

                        foreach (GFMaterial GFMat in GFM.Materials)
                        {
                            if (GFMat.Name == Material.Name)
                            {
                                GFMat.ShaderName     = Shader.Name;
                                GFMat.FragShaderName = Shader.Name;
                                break;
                            }
                        }
                    }
                }

                foreach (GFMaterial Mat in GFM.Materials)
                {
                    if (!UsedVertexShaders.Contains(Mat.VtxShaderName))
                    {
                        UsedVertexShaders.Add(Mat.VtxShaderName);
                    }
                    if (!UsedMaterialShaders.Contains(Mat.FragShaderName))
                    {
                        UsedMaterialShaders.Add(Mat.FragShaderName);
                    }
                }

                AddUnique(Models, GFM);
            }

            for (int i = 0; i < MaterialShaders.Count; i++)
            {
                if (!UsedMaterialShaders.Contains(MaterialShaders[i].Name))
                {
                    Console.WriteLine("Removing unused shader " + MaterialShaders[i].Name);
                    MaterialShaders.RemoveAt(i);
                    i--;
                }
            }
            for (int i = 0; i < VertexShaders.Count; i++)
            {
                if (!UsedVertexShaders.Contains(VertexShaders[i].Name))
                {
                    Console.WriteLine("Removing unused shader " + VertexShaders[i].Name);
                    VertexShaders.RemoveAt(i);
                    i--;
                }
            }

            foreach (H3DTexture Texture in Scene.Textures)
            {
                AddUnique(Textures, new GFTexture(Texture));
            }
        }