Ejemplo n.º 1
0
        private static ToolResult MakeTransparent(string alphaFile, string textureFile, string outputFile)
        {
            bool   success = ImageUtilsShared.MakeTransparent(alphaFile, textureFile, outputFile);
            string message = MessageBoxConstants.GetMessageExecutionCreation(success, outputFile);

            return(new ToolResult(message, success));
        }
Ejemplo n.º 2
0
        private static ToolResult NegativePicture(string fileName, string outputFile)
        {
            bool   success = ImageUtilsShared.NegativePicture(fileName, outputFile);
            string message = MessageBoxConstants.GetMessageExecutionCreation(success, outputFile);

            return(new ToolResult(message, success));
        }
Ejemplo n.º 3
0
        private static ToolResult MirrorTexture(string fileName, string outputFile, bool horizontal, bool vertical)
        {
            bool   success = ImageUtilsShared.MirrorTexture(fileName, horizontal, vertical, outputFile);
            string message = MessageBoxConstants.GetMessageExecutionCreation(success, outputFile);

            return(new ToolResult(message, success));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Delete all groups that use textures from a given list (compare the textures)
        /// </summary>
        /// <param name="objData">Data parsed from the obj file</param>
        /// <param name="mtlData">Data parsed from the mtl file</param>
        /// <param name="listFileName">List of textures that should be matched</param>
        public static bool DeleteMatchingGroups(ObjData objData, MtlData mtlData, List <string> listFileName)
        {
            if (mtlData == null)
            {
                return(false);
            }

            List <BitmapStoreData> imgList = BitmapStoreData.GetListBitmapStoreData(listFileName);

            var tupleTextureMaterials = MtlUtils.GetTupleDictTextureMaterials(mtlData);

            // Dictionary that associate every texture to a list of materials
            Dictionary <string, List <int> > dictTextureMaterials = tupleTextureMaterials.Item1;
            // List of materials without any texture
            List <int> untexturedMaterials = tupleTextureMaterials.Item2;

            // Dictionary that associate every material to a list of groups
            Dictionary <string, List <int> > dictMaterialGroups = ObjUtils.GetDictMaterialGroups(objData);

            // Dictionary that associate every texture to a list of groups
            Dictionary <string, List <int> > dictTextureGroups = ObjUtils.GetDictTextureGroups(objData, mtlData,
                                                                                               dictTextureMaterials, dictMaterialGroups);

            List <ObjectObj>   newObjectsList   = new List <ObjectObj>();
            List <MaterialMtl> newMaterialsList = new List <MaterialMtl>();

            string srcDir = System.IO.Path.GetDirectoryName(mtlData.FilePath);

            foreach (KeyValuePair <string, List <int> > keyValue in dictTextureGroups)
            {
                List <int> groups = keyValue.Value;
                if (groups != null)
                {
                    if (groups.Count >= 1) // Should always be the case
                    {
                        string texturePath = keyValue.Key;

                        if (!System.IO.Path.IsPathRooted(texturePath)) // Not an absolute path
                        {
                            texturePath = System.IO.Path.Combine(srcDir, texturePath);
                        }

                        System.Drawing.Bitmap img = ImageUtilsShared.CreateBitmap(texturePath);
                        if (img != null)
                        {
                            BitmapStoreData bmpData = new BitmapStoreData(img);
                            if (bmpData.BData != null)
                            {
                                if (!ImageUtilsShared.SamePictures(imgList, bmpData)) // Not the same image
                                {
                                    // We can keep all these groups and materials

                                    foreach (int groupId in groups)
                                    {
                                        ObjectObj objectObj = objData.ObjectsList[groupId];
                                        newObjectsList.Add(objectObj); // Insert the object in the list
                                    }

                                    if (dictTextureMaterials.TryGetValue(keyValue.Key, out List <int> materials))
                                    {
                                        if (materials != null)
                                        {
                                            foreach (int materialId in materials)
                                            {
                                                MaterialMtl materialMtl = mtlData.MaterialsList[materialId];
                                                newMaterialsList.Add(materialMtl); // Insert the material in the list
                                            }
                                        }
                                    }
                                }
                                bmpData.UnlockBits();
                            }
                        }
                    }
                }
            }

            foreach (int materialId in untexturedMaterials) // The untextured materials
            {
                MaterialMtl materialMtl = mtlData.MaterialsList[materialId];
                newMaterialsList.Add(materialMtl); // Insert material in the list
                if (dictMaterialGroups.TryGetValue(materialMtl.NewMtl, out List <int> groups))
                {
                    if (groups != null)
                    {
                        foreach (int groupId in groups)
                        {
                            ObjectObj objectObj = objData.ObjectsList[groupId];
                            newObjectsList.Add(objectObj); // Insert the object in the list
                        }
                    }
                }
            }
            BitmapStoreData.BitmapDataUnlock(imgList);

            objData.ObjectsList   = newObjectsList;
            mtlData.MaterialsList = newMaterialsList;
            return(true);
        }