Beispiel #1
0
        //Generate procedural textures
        private static void prepareTextures(textureManager texMgr, string path)
        {
            //At this point, at least one sampler exists, so for now I assume that the first sampler
            //is always the diffuse sampler and I can initiate the mixing process
            Console.WriteLine("Procedural Texture Detected: " + path);
            CallBacks.Log(string.Format("Parsing Procedural Texture"));

            TkProceduralTextureList template = NMSUtils.LoadNMSTemplate(path, ref Common.RenderState.activeResMgr) as TkProceduralTextureList;

            List <TkProceduralTexture> texList = new List <TkProceduralTexture>(8);

            for (int i = 0; i < 8; i++)
            {
                texList.Add(null);
            }
            ModelProcGen.parse_procTexture(ref texList, template, ref Common.RenderState.activeResMgr);

            Common.CallBacks.Log("Proc Texture Selection");
            for (int i = 0; i < 8; i++)
            {
                if (texList[i] != null)
                {
                    string partNameDiff = texList[i].Diffuse;
                    Common.CallBacks.Log(partNameDiff);
                }
            }

            Common.CallBacks.Log("Procedural Material. Trying to generate procTextures...");

            for (int i = 0; i < 8; i++)
            {
                TkProceduralTexture ptex = texList[i];
                //Add defaults
                if (ptex == null)
                {
                    baseLayersUsed[i]  = 0.0f;
                    alphaLayersUsed[i] = 0.0f;
                    continue;
                }

                string partNameDiff   = ptex.Diffuse;
                string partNameMask   = ptex.Mask;
                string partNameNormal = ptex.Normal;

                TkPaletteTexture paletteNode = ptex.Palette;
                string           paletteName = paletteNode.Palette.ToString();
                string           colorName   = paletteNode.ColourAlt.ToString();
                Vector4          palColor    = palette[paletteName][colorName];
                //Randomize palette Color every single time
                //Vector3 palColor = Model_Viewer.Palettes.get_color(paletteName, colorName);

                //Store pallete color to Recolouring List
                reColourings[i] = new float[] { palColor[0], palColor[1], palColor[2], palColor[3] };
                if (ptex.OverrideAverageColour)
                {
                    avgColourings[i] = new float[] { ptex.AverageColour.R, ptex.AverageColour.G, ptex.AverageColour.B, ptex.AverageColour.A }
                }
                ;

                //Create Palette Option
                PaletteOpt palOpt = new PaletteOpt();
                palOpt.PaletteName = paletteName;
                palOpt.ColorName   = colorName;
                palOpts[i]         = palOpt;
                Console.WriteLine("Index {0} Palette Selection {1} {2} ", i, palOpt.PaletteName, palOpt.ColorName);
                Console.WriteLine("Index {0} Color {1} {2} {3} {4}", i, palColor[0], palColor[1], palColor[2], palColor[3]);

                //DIFFUSE
                if (partNameDiff == "")
                {
                    //Add White
                    baseLayersUsed[i] = 0.0f;
                }
                else if (!texMgr.hasTexture(partNameDiff))
                {
                    //Configure the Diffuse Texture
                    try
                    {
                        Texture tex = new Texture(partNameDiff);
                        tex.palOpt    = palOpt;
                        tex.procColor = palColor;
                        //Store to master texture manager
                        Common.RenderState.activeResMgr.texMgr.addTexture(tex);

                        //Save Texture to material
                        difftextures[i]    = tex;
                        baseLayersUsed[i]  = 1.0f;
                        alphaLayersUsed[i] = 1.0f;
                    }
                    catch (System.IO.FileNotFoundException)
                    {
                        //Texture Not Found Continue
                        Console.WriteLine("Diffuse Texture " + partNameDiff + " Not Found, Appending White Tex");
                        CallBacks.Log(string.Format("Diffuse Texture {0} Not Found", partNameDiff));
                        baseLayersUsed[i] = 0.0f;
                    }
                }
                else
                //Load texture from dict
                {
                    Texture tex = texMgr.getTexture(partNameDiff);
                    //Save Texture to material
                    difftextures[i]   = tex;
                    baseLayersUsed[i] = 1.0f;
                }

                //MASK
                if (partNameMask == "")
                {
                    //Skip
                    alphaLayersUsed[i] = 0.0f;
                }
                else if (!texMgr.hasTexture(partNameMask))
                {
                    //Configure Mask
                    try
                    {
                        Texture texmask = new Texture(partNameMask);
                        //Store to master texture manager
                        Common.RenderState.activeResMgr.texMgr.addTexture(texmask);
                        //Store Texture to material
                        masktextures[i]    = texmask;
                        alphaLayersUsed[i] = 0.0f;
                    }
                    catch (System.IO.FileNotFoundException)
                    {
                        //Mask Texture not found
                        Console.WriteLine("Mask Texture " + partNameMask + " Not Found");
                        CallBacks.Log(string.Format("Mask Texture {0} Not Found", partNameMask));
                        alphaLayersUsed[i] = 0.0f;
                    }
                }
                else
                //Load texture from dict
                {
                    Texture tex = texMgr.getTexture(partNameMask);
                    //Store Texture to material
                    masktextures[i]    = tex;
                    alphaLayersUsed[i] = 1.0f;
                }


                //NORMALS
                if (partNameNormal == "")
                {
                    //Skip
                }
                else if (!texMgr.hasTexture(partNameNormal))
                {
                    try
                    {
                        Texture texnormal = new Texture(partNameNormal);
                        //Store to master texture manager
                        Common.RenderState.activeResMgr.texMgr.addTexture(texnormal);
                        //Store Texture to material
                        normaltextures[i] = texnormal;
                    }
                    catch (System.IO.FileNotFoundException)
                    {
                        //Normal Texture not found
                        CallBacks.Log(string.Format("Normal Texture {0} Not Found", partNameNormal));
                    }
                }
                else
                //Load texture from dict
                {
                    Texture tex = texMgr.getTexture(partNameNormal);
                    //Store Texture to material
                    normaltextures[i] = tex;
                }
            }
        }
Beispiel #2
0
        public static Dictionary <string, Dictionary <string, Vector4> > createPalettefromBasePalettes()
        {
            Dictionary <string, Dictionary <string, Vector4> > newPal;

            newPal = new Dictionary <string, Dictionary <string, Vector4> >();

            GcPaletteList template;

            try {
                template = NMSUtils.LoadNMSTemplate("METADATA\\SIMULATION\\SOLARSYSTEM\\COLOURS\\BASECOLOURPALETTES.MBIN",
                                                    ref MVCore.Common.RenderState.activeResMgr) as GcPaletteList;
            } catch (Exception ex) {
                CallBacks.Log("Using Default Palettes");
                return(createPalette());
            }

            TkPaletteTexture tkpt = new TkPaletteTexture();
            GcPaletteData    gcpd = new GcPaletteData();

            for (int i = 0; i < template.Palettes.Length; i++)
            {
                string pal_name = ((TkPaletteTexture.PaletteEnum)i).ToString();
                CallBacks.Log(string.Format("Palette {0} NumColors {1}", pal_name, template.Palettes[i].NumColours));
                newPal[pal_name] = new Dictionary <string, Vector4>();

                //Generate Bitmap for palette
                Bitmap bmp = new Bitmap(64, 1);

                for (int j = 0; j < template.Palettes[i].Colours.Length; j++)
                {
                    Colour colour = template.Palettes[i].Colours[j];

                    //Console.WriteLine("Color {0} {1} {2} {3} {4}",
                    //j, colour.R, colour.G, colour.B, colour.A);

                    //bmp.SetPixel(j, 0, Color.FromArgb((int)(colour.A * 255),
                    //                                    (int)(colour.R * 255),
                    //                                    (int)(colour.G * 255),
                    //                                    (int)(colour.B * 255)));
                }

                Vector4 primary, alt1, alt2, alt3, alt4, matchg, unique, none;
                int     index        = 0;
                int     index1       = 0;
                int     index2       = 0;
                int     index3       = 0;
                int     index4       = 0;
                int     unique_index = 0;
                none = new Vector4(1.0f, 1.0f, 1.0f, 0.0f);

                switch (template.Palettes[i].NumColours)
                {
                case GcPaletteData.NumColoursEnum.Inactive:     //Inactive
                    //Test by not saving anything
                    break;

                case GcPaletteData.NumColoursEnum._1:     //1 Color - All colors should be the same
                    index        = 0;
                    index1       = index;
                    index2       = index;
                    index3       = index;
                    index4       = index;
                    unique_index = 0;
                    break;

                case GcPaletteData.NumColoursEnum._4:     //4 Color
                case GcPaletteData.NumColoursEnum._8:     //8 Color NOTE: Not enough samples for that
                    index        = get_active_palette_index(4);
                    index1       = index + 1;
                    index2       = index + 2;
                    index3       = index + 3;
                    unique_index = get_active_palette_index(1);
                    break;

                case GcPaletteData.NumColoursEnum._16:     //16 Color
                    //Align to groups of 2
                    index        = get_active_palette_index(2);
                    index1       = index + 1;
                    index2       = get_active_palette_index(2);
                    index3       = index2 + 1;
                    index4       = get_active_palette_index(2);
                    unique_index = get_active_palette_index(1);
                    break;

                case GcPaletteData.NumColoursEnum.All:     //All
                    index        = get_active_palette_index(1);
                    index1       = get_active_palette_index(1);
                    index2       = get_active_palette_index(1);
                    index3       = get_active_palette_index(1);
                    index4       = get_active_palette_index(1);
                    unique_index = get_active_palette_index(1);
                    break;
                }

                //Set Colors
                primary = colour_to_vec4(template.Palettes[i].Colours[index]);
                alt1    = colour_to_vec4(template.Palettes[i].Colours[index1]);
                alt2    = colour_to_vec4(template.Palettes[i].Colours[index2]);
                alt3    = colour_to_vec4(template.Palettes[i].Colours[index3]);
                alt4    = colour_to_vec4(template.Palettes[i].Colours[index4]);
                matchg  = primary;
                unique  = colour_to_vec4(template.Palettes[i].Colours[unique_index]);
                none    = primary;

                //save the colors to the dictionary
                newPal[pal_name]["Primary"]      = primary;
                newPal[pal_name]["Alternative1"] = alt1;
                newPal[pal_name]["Alternative2"] = alt2;
                newPal[pal_name]["Alternative3"] = alt3;
                newPal[pal_name]["Alternative4"] = alt4;
                newPal[pal_name]["Unique"]       = unique;
                //Add MatchGround option
                newPal[pal_name]["MatchGround"] = new Vector4(0.5f, 0.427f, 0.337f, 0.0f);
                newPal[pal_name]["None"]        = none;

                //bmp.Save("Temp\\" + pal_name + ".bmp", ImageFormat.Bmp);
            }

            return(newPal);
        }