public MaterialManager(Grendgine_Collada scene, List <Batch> batches, string modelPath) { #region List initialization m_indirectTexBlock = new List <IndirectTexturing>(); m_cullModeBlock = new List <GXCullMode>(); m_materialColorBlock = new List <Color?>(); m_channelControlBlock = new List <ChannelControl>(); m_ambientColorBlock = new List <Color?>(); m_lightingColorBlock = new List <Color?>(); m_texCoord1GenBlock = new List <TexCoordGen>(); m_texCoord2GenBlock = new List <TexCoordGen>(); m_texMatrix1Block = new List <TexMatrix>(); m_texMatrix2Block = new List <TexMatrix>(); TextureList = new List <BinaryTextureImage>(); m_tevOrderBlock = new List <TevOrder>(); m_tevColorBlock = new List <Color?>(); m_tevKonstColorBlock = new List <Color?>(); m_tevStageBlock = new List <TevStage>(); m_swapModeBlock = new List <TevSwapMode>(); m_swapTableBlock = new List <TevSwapModeTable>(); m_fogBlock = new List <Fog>(); m_alphaCompBlock = new List <AlphaCompare>(); m_blendModeBlock = new List <BlendMode>(); m_zModeBlock = new List <ZMode>(); m_zCompLocBlock = new List <bool>(); m_ditherBlock = new List <bool>(); NumColorChannelsBlock = new List <byte>(); NumTexGensBlock = new List <byte>(); NumTevSTagesBlock = new List <byte>(); Materials = new List <Material>(); #endregion Grendgine_Collada_Material[] GrendgineMaterials = scene.Library_Materials.Material; Grendgine_Collada_Effect[] Effects = scene.Library_Effects.Effect; Grendgine_Collada_Image[] Images = scene.Library_Images.Image; foreach (Batch bat in batches) { Grendgine_Collada_Material batMat = GrendgineMaterials.First(x => x.Name == bat.MaterialName || x.ID == bat.MaterialName); Grendgine_Collada_Effect batEffect = Effects.First(x => x.ID == batMat.Instance_Effect.URL.Remove(0, 1)); Grendgine_Collada_Phong phong = batEffect.Profile_COMMON[0].Technique.Phong; Material mat = new Material(phong, bat, modelPath, Images); Materials.Add(mat); } }
public Material(Grendgine_Collada_Phong source, Batch batch, string modelPath, Grendgine_Collada_Image[] textures) { MatBatch = batch; Name = batch.MaterialName; Flag = 1; IndTexEntry = new IndirectTexturing(); CullMode = GXCullMode.Back; MaterialColors = new Color?[2] { new Color(1, 1, 1, 1), new Color(1, 1, 1, 1) }; ChannelControls = new ChannelControl[4] { new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Signed, GXAttenuationFn.Spec, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.None, GXAttenuationFn.None, GXColorSrc.Register), }; AmbientColors = new Color?[2] { new Color(0.1960f, 0.1960f, 0.1960f, 0.1960f), new Color(0, 0, 0, 0) }; LightingColors = new Color?[8]; TexCoord1Gens = new TexCoordGen[8]; TexCoord2Gens = new TexCoordGen[8]; TexMatrix1 = new TexMatrix[10]; TexMatrix2 = new TexMatrix[20]; Textures = new BinaryTextureImage[8]; TevOrders = new TevOrder[16]; TevOrders[0] = new TevOrder(GXTexCoordSlot.Null, 0, GXColorChannelId.Color0A0); ColorSels = new GXKonstColorSel[16]; AlphaSels = new GXKonstAlphaSel[16]; for (int i = 0; i < 16; i++) { ColorSels[i] = GXKonstColorSel.KCSel_K0; AlphaSels[i] = GXKonstAlphaSel.KASel_K0_A; } TevColors = new Color?[4] { new Color(0, 0, 0, 1), new Color(1, 1, 1, 1), new Color(0, 0, 0, 0), new Color(1, 1, 1, 1) }; KonstColors = new Color?[4] { new Color(1, 1, 1, 1), new Color(1, 1, 1, 1), new Color(1, 1, 1, 1), new Color(1, 1, 1, 1) }; TevStages = new TevStage[16]; TevStages[0] = new TevStage(new GXCombineColorInput[] { GXCombineColorInput.Zero, GXCombineColorInput.Zero, GXCombineColorInput.Zero, GXCombineColorInput.Zero }, GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0, new GXCombineAlphaInput[] { GXCombineAlphaInput.RasAlpha, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, }, GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0); SwapModes = new TevSwapMode[16]; SwapModes[0] = new TevSwapMode(); SwapModes[1] = new TevSwapMode(); SwapTables = new TevSwapModeTable[4] { new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3) }; FogInfo = new Fog(); AlphCompare = new AlphaCompare(GXCompareType.Always, 0, GXAlphaOp.Or, GXCompareType.Always, 0); BMode = new BlendMode(GXBlendMode.None, GXBlendModeControl.One, GXBlendModeControl.Zero, GXLogicOp.Copy); ZMode = new ZMode(true, GXCompareType.LEqual, true); ZCompLoc = true; Dither = true; // Add texture to TEV stage data if there is one if (source.Diffuse.Texture != null) { string texName = source.Diffuse.Texture.Texture; string path = textures.First(x => x.ID == texName).Init_From.Replace("file://", ""); if (!Path.IsPathRooted(path)) { string modelDir = Path.GetDirectoryName(modelPath); string texPath = string.Format("{0}\\{1}", modelDir, path); if (File.Exists(texPath)) { path = texPath; } else { throw new ArgumentException(string.Format("Could not find texture \"{0}\" at \"{1}\"!", path, texPath)); } } string imageExt = Path.GetExtension(path).ToLower(); Bitmap imageData = null; switch (imageExt) { case ".png": case ".bmp": imageData = new Bitmap(path); break; case ".tga": imageData = TgaReader.Load(path); break; default: throw new ArgumentException(string.Format("Texture {0} was a {1}. Only PNG, BMP, or TGA images are supported!", path, imageExt)); } if (imageData == null) { throw new ArgumentException(string.Format("Texture {0} could not be loaded!", path)); } SetTexture(source.Diffuse.Texture, Path.GetFileNameWithoutExtension(path), imageData); } // Add vertex colors to the shader if there are any if (batch.Attributes.Contains(VertexAttributes.Color0)) { ChannelControls = new ChannelControl[4] { new ChannelControl(false, GXColorSrc.Vertex, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Vertex, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Signed, GXAttenuationFn.Spec, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.None, GXAttenuationFn.None, GXColorSrc.Register), }; TevStages[1] = TevStages[0]; TevStages[1].ColorIn[0] = GXCombineColorInput.ColorPrev; TevStages[0] = new TevStage(new GXCombineColorInput[] { GXCombineColorInput.C0, GXCombineColorInput.TexColor, GXCombineColorInput.RasColor, GXCombineColorInput.Zero }, GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0, new GXCombineAlphaInput[] { GXCombineAlphaInput.A0, GXCombineAlphaInput.TexAlpha, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, }, GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0); TevOrders[1] = new TevOrder(GXTexCoordSlot.TexCoord0, 0, GXColorChannelId.Color0A0); } foreach (ChannelControl chan in ChannelControls) { if (chan != null) { ColorChannelControlsCount++; } } foreach (TexCoordGen gen in TexCoord1Gens) { if (gen != null) { NumTexGensCount++; } } foreach (TevStage stage in TevStages) { if (stage != null) { NumTevStagesCount++; } } }