public void addMaterial (string cle, MATERIAL m)
		{
			if (materials.ContainsKey (cle)) {
				MATERIAL mat = materials [cle];
				mat.nbUsers++;
			}
			else
				materials.Add(cle,m);
		}
示例#2
0
 public void addMaterial(string cle, MATERIAL m)
 {
     if (materials.ContainsKey(cle))
     {
         MATERIAL mat = materials [cle];
         mat.nbUsers++;
     }
     else
     {
         materials.Add(cle, m);
     }
 }
示例#3
0
 public void freeMaterial(string cle)
 {
     if (materials.ContainsKey(cle))
     {
         MATERIAL mat = materials [cle];
         mat.nbUsers--;
         if (mat.nbUsers == 0)
         {
             materials.Remove(cle);
         }
     }
 }
示例#4
0
        public void initTexture(MATERIAL m)
        {
            m.pDiffuse.userData = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, m.pDiffuse.userData);
            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);

            if (m.pDiffuse.pixelFormat.Equals(PIXEL_FORMAT.rgb))
            {
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Three, m.pDiffuse.width, m.pDiffuse.height, 0, PixelFormat.Rgb, PixelType.UnsignedByte, m.pDiffuse.pixelImage.Scan0);
            }
            else
            {
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Three, m.pDiffuse.width, m.pDiffuse.height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, m.pDiffuse.pixelImage.Scan0);
            }
        }
		public void initTexture(MATERIAL m) {
			m.pDiffuse.userData = GL.GenTexture();
			GL.BindTexture(TextureTarget.Texture2D,m.pDiffuse.userData);
			GL.TexEnv(TextureEnvTarget.TextureEnv,TextureEnvParameter.TextureEnvMode,(int)TextureEnvMode.Modulate);
			GL.TexParameter(TextureTarget.Texture2D,TextureParameterName.TextureMinFilter,(int)All.Linear);
			GL.TexParameter(TextureTarget.Texture2D,TextureParameterName.TextureMagFilter,(int)All.Linear);
			
			if(m.pDiffuse.pixelFormat.Equals(PIXEL_FORMAT.rgb)) {
				GL.TexImage2D(TextureTarget.Texture2D,0,PixelInternalFormat.Three,m.pDiffuse.width,m.pDiffuse.height,0,PixelFormat.Rgb,PixelType.UnsignedByte,m.pDiffuse.pixelImage.Scan0);
			}
			else {
				GL.TexImage2D(TextureTarget.Texture2D,0,PixelInternalFormat.Three,m.pDiffuse.width,m.pDiffuse.height,0,PixelFormat.Rgba,PixelType.UnsignedByte,m.pDiffuse.pixelImage.Scan0);
			}
			
		}
		public void readMaterial (string path, string matName)
		{
			MATERIAL m;
			if(scene.materials.TryGetValue(matName, out m)){
				m.nbUsers++;	
			}
			else {
				System.IO.StreamReader mtl = new System.IO.StreamReader(path);
				string lineMtl;
				bool Ended = false;
				m = new MATERIAL();
				while((lineMtl = mtl.ReadLine()) != null || !Ended)
				{
					if(lineMtl.StartsWith("newmtl") && lineMtl.Contains(matName)){
						lineMtl = mtl.ReadLine();
						while(!Ended)
						{
							if(lineMtl == null)
							{
								Ended = true;
							}
							else {
									if(lineMtl.StartsWith("Kd"))
									{
										m.diffuse = new float[3];
										char[] delimiterChars = {' '};
										string[] positions = lineMtl.Split(delimiterChars);
										m.diffuse[0] = float.Parse (positions[1]);
										m.diffuse[1] = float.Parse (positions[2]);
										m.diffuse[2] = float.Parse (positions[3]);
									}
									
									if(lineMtl.StartsWith("Ka"))
									{
										m.ambient = new float[3];
										char[] delimiterChars = {' '};
										string[] positions = lineMtl.Split(delimiterChars);
										m.ambient[0] = float.Parse (positions[1]);
										m.ambient[1] = float.Parse (positions[2]);
										m.ambient[2] = float.Parse (positions[3]);
									}
									
									if(lineMtl.StartsWith("Ks"))
									{
										m.specular = new float[3];
										char[] delimiterChars = {' '};
										string[] positions = lineMtl.Split(delimiterChars);
										m.specular[0] = float.Parse (positions[1]);
										m.specular[1] = float.Parse (positions[2]);
										m.specular[2] = float.Parse (positions[3]);
									}
									
									if(lineMtl.StartsWith("d"))
									{
										char[] delimiterChars = {' '};
										string[] positions = lineMtl.Split(delimiterChars);
										m.transparency = float.Parse (positions[1]);
										
									}
									if(lineMtl.StartsWith("map_Kd"))
									{
										string[] param = lineMtl.Split(' ');
										/*Bitmap bm = new Bitmap("../../blender/" +param[1]);
										m.pDiffuse.pixelImage = 
										bm.LockBits(
			            				new System.Drawing.Rectangle(0,0,bm.Width,bm.Height),
			           					System.Drawing.Imaging.ImageLockMode.ReadOnly,
			            				System.Drawing.Imaging.PixelFormat.Format24bppRgb
	        							);*/
									}
									if( lineMtl.Contains("newmtl"))
										Ended = true;

									lineMtl = mtl.ReadLine();
								}



							}
							m.name = matName;
						}
				}
				scene.addMaterial(matName,m);
			}
		}
示例#7
0
        public void readMaterial(string path, string matName)
        {
            MATERIAL m;

            if (scene.materials.TryGetValue(matName, out m))
            {
                m.nbUsers++;
            }
            else
            {
                System.IO.StreamReader mtl = new System.IO.StreamReader(path);
                string lineMtl;
                bool   Ended = false;
                m = new MATERIAL();
                while ((lineMtl = mtl.ReadLine()) != null || !Ended)
                {
                    if (lineMtl.StartsWith("newmtl") && lineMtl.Contains(matName))
                    {
                        lineMtl = mtl.ReadLine();
                        while (!Ended)
                        {
                            if (lineMtl == null)
                            {
                                Ended = true;
                            }
                            else
                            {
                                if (lineMtl.StartsWith("Kd"))
                                {
                                    m.diffuse = new float[3];
                                    char[]   delimiterChars = { ' ' };
                                    string[] positions      = lineMtl.Split(delimiterChars);
                                    m.diffuse[0] = float.Parse(positions[1]);
                                    m.diffuse[1] = float.Parse(positions[2]);
                                    m.diffuse[2] = float.Parse(positions[3]);
                                }

                                if (lineMtl.StartsWith("Ka"))
                                {
                                    m.ambient = new float[3];
                                    char[]   delimiterChars = { ' ' };
                                    string[] positions      = lineMtl.Split(delimiterChars);
                                    m.ambient[0] = float.Parse(positions[1]);
                                    m.ambient[1] = float.Parse(positions[2]);
                                    m.ambient[2] = float.Parse(positions[3]);
                                }

                                if (lineMtl.StartsWith("Ks"))
                                {
                                    m.specular = new float[3];
                                    char[]   delimiterChars = { ' ' };
                                    string[] positions      = lineMtl.Split(delimiterChars);
                                    m.specular[0] = float.Parse(positions[1]);
                                    m.specular[1] = float.Parse(positions[2]);
                                    m.specular[2] = float.Parse(positions[3]);
                                }

                                if (lineMtl.StartsWith("d"))
                                {
                                    char[]   delimiterChars = { ' ' };
                                    string[] positions      = lineMtl.Split(delimiterChars);
                                    m.transparency = float.Parse(positions[1]);
                                }
                                if (lineMtl.StartsWith("map_Kd"))
                                {
                                    string[] param = lineMtl.Split(' ');

                                    /*Bitmap bm = new Bitmap("../../blender/" +param[1]);
                                     * m.pDiffuse.pixelImage =
                                     * bm.LockBits(
                                     * new System.Drawing.Rectangle(0,0,bm.Width,bm.Height),
                                     * System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                     * System.Drawing.Imaging.PixelFormat.Format24bppRgb
                                     * );*/
                                }
                                if (lineMtl.Contains("newmtl"))
                                {
                                    Ended = true;
                                }

                                lineMtl = mtl.ReadLine();
                            }
                        }
                        m.name = matName;
                    }
                }
                scene.addMaterial(matName, m);
            }
        }