static void initialize_texture_map(Lib3dsTextureMap map)
 {
     map.flags    = Lib3dsTextureMapFlags.LIB3DS_TEXTURE_NO_TILE;
     map.percent  = 1.0f;
     map.scale[0] = 1.0f;
     map.scale[1] = 1.0f;
 }
		static void initialize_texture_map(Lib3dsTextureMap map)
		{
			map.flags=Lib3dsTextureMapFlags.LIB3DS_TEXTURE_NO_TILE;
			map.percent=1.0f;
			map.scale[0]=1.0f;
			map.scale[1]=1.0f;
		}
Exemple #3
0
		static void texture_dump(string maptype, Lib3dsTextureMap texture)
		{
			Debug.Assert(texture!=null);
			if(texture.name==null||texture.name.Length==0) return;

			Console.WriteLine("  {0}:", maptype);
			Console.WriteLine("    name:          {0}", texture.name);
			Console.WriteLine("    flags:         {0:X}", (ushort)texture.flags);
			Console.WriteLine("    percent:       {0}", texture.percent);
			Console.WriteLine("    blur:          {0}", texture.blur);
			Console.WriteLine("    scale:         ({0}, {1})", texture.scale[0], texture.scale[1]);
			Console.WriteLine("    offset:        ({0}, {1})", texture.offset[0], texture.offset[1]);
			Console.WriteLine("    rotation:      {0}", texture.rotation);
			Console.WriteLine("    tint_1:        ({0},{1},{2})", texture.tint_1[0], texture.tint_1[1], texture.tint_1[2]);
			Console.WriteLine("    tint_2:        ({0},{1},{2})", texture.tint_2[0], texture.tint_2[1], texture.tint_2[2]);
			Console.WriteLine("    tint_r:        ({0},{1},{2})", texture.tint_r[0], texture.tint_r[1], texture.tint_r[2]);
			Console.WriteLine("    tint_g:        ({0},{1},{2})", texture.tint_g[0], texture.tint_g[1], texture.tint_g[2]);
			Console.WriteLine("    tint_b:        ({0},{1},{2})", texture.tint_b[0], texture.tint_b[1], texture.tint_b[2]);
		}
        static void texture_map_write(Lib3dsChunks chunk, Lib3dsTextureMap map, Lib3dsIo io)
        {
            if (map.name == null || map.name.Length == 0)
            {
                return;
            }
            Lib3dsChunk c_chunk = new Lib3dsChunk();

            c_chunk.chunk = chunk;
            lib3ds_chunk_write_start(c_chunk, io);

            int_percentage_write(map.percent, io);

            {             // ---- CHK_MAT_MAPNAME ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAPNAME;
                c.size  = 6 + (uint)map.name.Length + 1;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_string(io, map.name);
            }

            {             // ---- CHK_MAT_MAP_TILING ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_TILING;
                c.size  = 8;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_word(io, (ushort)map.flags);
            }

            {             // ---- CHK_MAT_MAP_TEXBLUR ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_TEXBLUR;
                c.size  = 10;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_float(io, map.blur);
            }

            {             // ---- CHK_MAT_MAP_USCALE ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_USCALE;
                c.size  = 10;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_float(io, map.scale[0]);
            }

            {             // ---- CHK_MAT_MAP_VSCALE ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_VSCALE;
                c.size  = 10;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_float(io, map.scale[1]);
            }

            {             // ---- CHK_MAT_MAP_UOFFSET ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_UOFFSET;
                c.size  = 10;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_float(io, map.offset[0]);
            }

            {             // ---- CHK_MAT_MAP_VOFFSET ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_VOFFSET;
                c.size  = 10;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_float(io, map.offset[1]);
            }

            {             // ---- CHK_MAT_MAP_ANG ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_ANG;
                c.size  = 10;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_float(io, map.rotation);
            }

            {             // ---- CHK_MAT_MAP_COL1 ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_COL1;
                c.size  = 9;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_1[0] + 0.5));
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_1[1] + 0.5));
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_1[2] + 0.5));
            }

            {             // ---- CHK_MAT_MAP_COL2 ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_COL2;
                c.size  = 9;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_2[0] + 0.5));
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_2[1] + 0.5));
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_2[2] + 0.5));
            }

            {             // ---- CHK_MAT_MAP_RCOL ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_RCOL;
                c.size  = 9;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_r[0] + 0.5));
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_r[1] + 0.5));
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_r[2] + 0.5));
            }

            {             // ---- CHK_MAT_MAP_GCOL ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_GCOL;
                c.size  = 9;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_g[0] + 0.5));
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_g[1] + 0.5));
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_g[2] + 0.5));
            }

            {             // ---- CHK_MAT_MAP_BCOL ----
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_MAT_MAP_BCOL;
                c.size  = 9;
                lib3ds_chunk_write(c, io);
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_b[0] + 0.5));
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_b[1] + 0.5));
                lib3ds_io_write_byte(io, (byte)Math.Floor(255.0 * map.tint_b[2] + 0.5));
            }

            lib3ds_chunk_write_end(c_chunk, io);
        }
        static void texture_map_read(Lib3dsTextureMap map, Lib3dsIo io)
        {
            Lib3dsChunk  c = new Lib3dsChunk();
            Lib3dsChunks chunk;

            lib3ds_chunk_read_start(c, 0, io);

            while ((chunk = lib3ds_chunk_read_next(c, io)) != 0)
            {
                switch (chunk)
                {
                case Lib3dsChunks.CHK_INT_PERCENTAGE: map.percent = 1.0f * lib3ds_io_read_intw(io) / 100.0f; break;

                case Lib3dsChunks.CHK_MAT_MAPNAME:
                    map.name = lib3ds_io_read_string(io, 64);
                    lib3ds_io_log_indent(io, 1);
                    lib3ds_io_log(io, Lib3dsLogLevel.LIB3DS_LOG_INFO, "NAME={0}", map.name);
                    lib3ds_io_log_indent(io, -1);
                    break;

                case Lib3dsChunks.CHK_MAT_MAP_TILING: map.flags = (Lib3dsTextureMapFlags)lib3ds_io_read_word(io); break;

                case Lib3dsChunks.CHK_MAT_MAP_TEXBLUR: map.blur = lib3ds_io_read_float(io); break;

                case Lib3dsChunks.CHK_MAT_MAP_USCALE: map.scale[0] = lib3ds_io_read_float(io); break;

                case Lib3dsChunks.CHK_MAT_MAP_VSCALE: map.scale[1] = lib3ds_io_read_float(io); break;

                case Lib3dsChunks.CHK_MAT_MAP_UOFFSET: map.offset[0] = lib3ds_io_read_float(io); break;

                case Lib3dsChunks.CHK_MAT_MAP_VOFFSET: map.offset[1] = lib3ds_io_read_float(io); break;

                case Lib3dsChunks.CHK_MAT_MAP_ANG: map.rotation = lib3ds_io_read_float(io); break;

                case Lib3dsChunks.CHK_MAT_MAP_COL1:
                    map.tint_1[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    map.tint_1[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    map.tint_1[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    break;

                case Lib3dsChunks.CHK_MAT_MAP_COL2:
                    map.tint_2[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    map.tint_2[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    map.tint_2[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    break;

                case Lib3dsChunks.CHK_MAT_MAP_RCOL:
                    map.tint_r[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    map.tint_r[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    map.tint_r[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    break;

                case Lib3dsChunks.CHK_MAT_MAP_GCOL:
                    map.tint_g[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    map.tint_g[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    map.tint_g[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    break;

                case Lib3dsChunks.CHK_MAT_MAP_BCOL:
                    map.tint_b[0] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    map.tint_b[1] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    map.tint_b[2] = 1.0f * lib3ds_io_read_byte(io) / 255.0f;
                    break;

                default: lib3ds_chunk_unknown(chunk, io); break;
                }
            }

            lib3ds_chunk_read_end(c, io);
        }
		static void texture_map_write(Lib3dsChunks chunk, Lib3dsTextureMap map, Lib3dsIo io)
		{
			if(map.name==null||map.name.Length==0) return;
			Lib3dsChunk c_chunk=new Lib3dsChunk();

			c_chunk.chunk=chunk;
			lib3ds_chunk_write_start(c_chunk, io);

			int_percentage_write(map.percent, io);

			{ // ---- CHK_MAT_MAPNAME ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAPNAME;
				c.size=6+(uint)map.name.Length+1;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_string(io, map.name);
			}

			{ // ---- CHK_MAT_MAP_TILING ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_TILING;
				c.size=8;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_word(io, (ushort)map.flags);
			}

			{ // ---- CHK_MAT_MAP_TEXBLUR ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_TEXBLUR;
				c.size=10;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_float(io, map.blur);
			}

			{ // ---- CHK_MAT_MAP_USCALE ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_USCALE;
				c.size=10;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_float(io, map.scale[0]);
			}

			{ // ---- CHK_MAT_MAP_VSCALE ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_VSCALE;
				c.size=10;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_float(io, map.scale[1]);
			}

			{ // ---- CHK_MAT_MAP_UOFFSET ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_UOFFSET;
				c.size=10;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_float(io, map.offset[0]);
			}

			{ // ---- CHK_MAT_MAP_VOFFSET ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_VOFFSET;
				c.size=10;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_float(io, map.offset[1]);
			}

			{ // ---- CHK_MAT_MAP_ANG ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_ANG;
				c.size=10;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_float(io, map.rotation);
			}

			{ // ---- CHK_MAT_MAP_COL1 ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_COL1;
				c.size=9;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_1[0]+0.5));
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_1[1]+0.5));
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_1[2]+0.5));
			}

			{ // ---- CHK_MAT_MAP_COL2 ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_COL2;
				c.size=9;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_2[0]+0.5));
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_2[1]+0.5));
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_2[2]+0.5));
			}

			{ // ---- CHK_MAT_MAP_RCOL ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_RCOL;
				c.size=9;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_r[0]+0.5));
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_r[1]+0.5));
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_r[2]+0.5));
			}

			{ // ---- CHK_MAT_MAP_GCOL ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_GCOL;
				c.size=9;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_g[0]+0.5));
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_g[1]+0.5));
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_g[2]+0.5));
			}

			{ // ---- CHK_MAT_MAP_BCOL ----
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_MAT_MAP_BCOL;
				c.size=9;
				lib3ds_chunk_write(c, io);
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_b[0]+0.5));
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_b[1]+0.5));
				lib3ds_io_write_byte(io, (byte)Math.Floor(255.0*map.tint_b[2]+0.5));
			}

			lib3ds_chunk_write_end(c_chunk, io);
		}
		static void texture_map_read(Lib3dsTextureMap map, Lib3dsIo io)
		{
			Lib3dsChunk c=new Lib3dsChunk();
			Lib3dsChunks chunk;

			lib3ds_chunk_read_start(c, 0, io);

			while((chunk=lib3ds_chunk_read_next(c, io))!=0)
			{
				switch(chunk)
				{
					case Lib3dsChunks.CHK_INT_PERCENTAGE: map.percent=1.0f*lib3ds_io_read_intw(io)/100.0f; break;
					case Lib3dsChunks.CHK_MAT_MAPNAME:
						map.name=lib3ds_io_read_string(io, 64);
						lib3ds_io_log_indent(io, 1);
						lib3ds_io_log(io, Lib3dsLogLevel.LIB3DS_LOG_INFO, "NAME={0}", map.name);
						lib3ds_io_log_indent(io, -1);
						break;
					case Lib3dsChunks.CHK_MAT_MAP_TILING: map.flags=(Lib3dsTextureMapFlags)lib3ds_io_read_word(io); break;
					case Lib3dsChunks.CHK_MAT_MAP_TEXBLUR: map.blur=lib3ds_io_read_float(io); break;
					case Lib3dsChunks.CHK_MAT_MAP_USCALE: map.scale[0]=lib3ds_io_read_float(io); break;
					case Lib3dsChunks.CHK_MAT_MAP_VSCALE: map.scale[1]=lib3ds_io_read_float(io); break;
					case Lib3dsChunks.CHK_MAT_MAP_UOFFSET: map.offset[0]=lib3ds_io_read_float(io); break;
					case Lib3dsChunks.CHK_MAT_MAP_VOFFSET: map.offset[1]=lib3ds_io_read_float(io); break;
					case Lib3dsChunks.CHK_MAT_MAP_ANG: map.rotation=lib3ds_io_read_float(io); break;
					case Lib3dsChunks.CHK_MAT_MAP_COL1:
						map.tint_1[0]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						map.tint_1[1]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						map.tint_1[2]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						break;
					case Lib3dsChunks.CHK_MAT_MAP_COL2:
						map.tint_2[0]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						map.tint_2[1]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						map.tint_2[2]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						break;
					case Lib3dsChunks.CHK_MAT_MAP_RCOL:
						map.tint_r[0]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						map.tint_r[1]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						map.tint_r[2]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						break;
					case Lib3dsChunks.CHK_MAT_MAP_GCOL:
						map.tint_g[0]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						map.tint_g[1]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						map.tint_g[2]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						break;
					case Lib3dsChunks.CHK_MAT_MAP_BCOL:
						map.tint_b[0]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						map.tint_b[1]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						map.tint_b[2]=1.0f*lib3ds_io_read_byte(io)/255.0f;
						break;
					default: lib3ds_chunk_unknown(chunk, io); break;
				}
			}

			lib3ds_chunk_read_end(c, io);
		}