Example #1
0
        public void WriteLibrary_Materials()
        {
            // Create the list of materials used in this object
            // There is just one .mtl file we need to worry about.
            Grendgine_Collada_Library_Materials libraryMaterials = new Grendgine_Collada_Library_Materials();

            // We have our top level.
            daeObject.Library_Materials = libraryMaterials;
            int numMaterials = cgfData.MatFile.Materials.Count;

            // Now create a material for each material in the object
            Console.WriteLine("Number of materials: {0}", numMaterials);
            Grendgine_Collada_Material[] materials = new Grendgine_Collada_Material[numMaterials];
            for (int i = 0; i < numMaterials; i++)
            {
                Grendgine_Collada_Material tmpMaterial = new Grendgine_Collada_Material();
                tmpMaterial.Name = cgfData.MatFile.MaterialNameArray[i].MaterialName;
                // Create the instance_effect for each material
                tmpMaterial.Instance_Effect = new Grendgine_Collada_Instance_Effect();
                // The # in front of tmpMaterial.name is needed to reference the effect in Library_effects.
                tmpMaterial.Instance_Effect.URL = "#" + tmpMaterial.Name;
                // Need material ID here, so the meshes can reference it.  Use the chunk ID.
                tmpMaterial.ID = i.ToString();          // this is the order the materials appear in the .mtl file.  Needed for geometries.
                materials[i]   = tmpMaterial;
            }
            libraryMaterials.Material = materials;
        }
Example #2
0
        void CreateMaterials(ref SimpleCollada data)
        {
            data.Library_Materials.Material = new Grendgine_Collada_Material[1];
            Grendgine_Collada_Material m = new Grendgine_Collada_Material();

            m.ID                  = "ID3";
            m.Name                = "edge_color000255";
            m.Instance_Effect     = new Grendgine_Collada_Instance_Effect();
            m.Instance_Effect.URL = "#ID4";
            data.Library_Materials.Material[0] = m;
        }
Example #3
0
        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);
            }
        }
Example #4
0
        public Material(Grendgine_Collada_Material source, string modelPath, Batch srcBatch)
        {
            Name           = source.Name;
            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.HasTextureDiffuse)
             * {
             *  string path = "";//source.TextureDiffuse.FilePath;
             *  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 fined 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(Path.GetFileNameWithoutExtension(path), imageData);
             * }*/

            // Add vertex colors to the shader if there are any

            /*
             * if (srcBatch.VertexColors[0].Count > 0)
             * {
             *  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[2] = GXCombineColorInput.ColorPrev;
             *
             *  TevStages[0] = new TevStage(new GXCombineColorInput[] { GXCombineColorInput.RasColor, GXCombineColorInput.Zero, GXCombineColorInput.Zero, GXCombineColorInput.Zero },
             *  GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0, new GXCombineAlphaInput[] { GXCombineAlphaInput.RasAlpha, source.HasTextureDiffuse ? GXCombineAlphaInput.TexAlpha : GXCombineAlphaInput.Zero, 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++;
                }
            }
        }