public Scene() { type = TYPES.MODEL; texMgr = new textureManager(); //Init Animation Stuff skinMats = new float[256 * 16]; jointDict = new Dictionary <string, Joint>(); }
public static Material Parse(string path, textureManager input_texMgr) { //Load template //Try to use libMBIN to load the Material files TkMaterialData template = NMSUtils.LoadNMSTemplate(path, ref Common.RenderState.activeResMgr) as TkMaterialData; #if DEBUG //Save NMSTemplate to exml template.WriteToExml("Temp\\" + template.Name + ".exml"); #endif //Make new material based on the template Material mat = new Material(template); mat.texMgr = input_texMgr; mat.init(); return(mat); }
public void init(textureManager input_texMgr) { texMgr = input_texMgr; texUnit = new MyTextureUnit(Name); //Save texture to material switch (Name) { case "mpCustomPerMaterial.gDiffuseMap": case "mpCustomPerMaterial.gDiffuse2Map": case "mpCustomPerMaterial.gMasksMap": case "mpCustomPerMaterial.gNormalMap": prepTextures(); break; default: CallBacks.Log("Not sure how to handle Sampler " + Name); break; } }
public void copyFrom(Scene input) { base.copyFrom(input); //Copy base stuff gobject = input.gobject; texMgr = input.texMgr; }
//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; } } }
public static void combineTextures(string path, Dictionary <string, Dictionary <string, Vector4> > pal_input, ref textureManager texMgr) { clear(); palette = pal_input; //Contruct .mbin file from dds string[] split = path.Split('.'); //Construct main filename string temp = split[0] + "."; string mbinPath = temp + "TEXTURE.MBIN"; prepareTextures(texMgr, mbinPath); //Init framebuffer int tex_width = 0; int tex_height = 0; int fbo_tex = -1; int fbo = -1; bool fbo_status = setupFrameBuffer(ref fbo, ref fbo_tex, ref tex_width, ref tex_height); if (!fbo_status) { CallBacks.Log("Unable to mix textures, probably 0x0 textures...\n"); return; } Texture diffTex = mixDiffuseTextures(tex_width, tex_height); diffTex.name = temp + "DDS"; Texture maskTex = mixMaskTextures(tex_width, tex_height); maskTex.name = temp + "MASKS.DDS"; Texture normalTex = mixNormalTextures(tex_width, tex_height); normalTex.name = temp + "NORMAL.DDS"; revertFrameBuffer(fbo, fbo_tex); //Add the new procedural textures to the textureManager texMgr.addTexture(diffTex); texMgr.addTexture(maskTex); texMgr.addTexture(normalTex); }