コード例 #1
0
ファイル: MaterialReader.cs プロジェクト: dankar/zombies
        private void ProcessItem(XmlReader reader)
        {
            reader.MoveToContent();

            Material tmpMaterial = new Material();

            tmpMaterial.name = reader.GetAttribute("displayname");
            tmpMaterial.type = reader.GetAttribute("type");

            if (reader.ReadToFollowing("ambient"))
            {
                reader.MoveToContent();
                tmpMaterial.ambient.R = (float)Convert.ToDouble(reader.GetAttribute("r").Replace(".", ","));
                tmpMaterial.ambient.G = (float)Convert.ToDouble(reader.GetAttribute("g").Replace(".", ","));
                tmpMaterial.ambient.B = (float)Convert.ToDouble(reader.GetAttribute("b").Replace(".", ","));
                tmpMaterial.ambient.A = (float)Convert.ToDouble(reader.GetAttribute("a").Replace(".", ","));
            }
            if (reader.ReadToFollowing("specular"))
            {
                reader.MoveToContent();
                tmpMaterial.specular.R = (float)Convert.ToDouble(reader.GetAttribute("r").Replace(".", ","));
                tmpMaterial.specular.G = (float)Convert.ToDouble(reader.GetAttribute("g").Replace(".", ","));
                tmpMaterial.specular.B = (float)Convert.ToDouble(reader.GetAttribute("b").Replace(".", ","));
                tmpMaterial.specular.A = (float)Convert.ToDouble(reader.GetAttribute("a").Replace(".", ","));
            }
            if (reader.ReadToFollowing("diffuse"))
            {
                reader.MoveToContent();
                tmpMaterial.diffuse.R = (float)Convert.ToDouble(reader.GetAttribute("r").Replace(".", ","));
                tmpMaterial.diffuse.G = (float)Convert.ToDouble(reader.GetAttribute("g").Replace(".", ","));
                tmpMaterial.diffuse.B = (float)Convert.ToDouble(reader.GetAttribute("b").Replace(".", ","));
                tmpMaterial.diffuse.A = (float)Convert.ToDouble(reader.GetAttribute("a").Replace(".", ","));
            }
            if (reader.ReadToFollowing("emissive"))
            {
                reader.MoveToContent();
                tmpMaterial.emission.R = (float)Convert.ToDouble(reader.GetAttribute("r").Replace(".", ","));
                tmpMaterial.emission.G = (float)Convert.ToDouble(reader.GetAttribute("g").Replace(".", ","));
                tmpMaterial.emission.B = (float)Convert.ToDouble(reader.GetAttribute("b").Replace(".", ","));
                tmpMaterial.emission.A = (float)Convert.ToDouble(reader.GetAttribute("a").Replace(".", ","));
            }
            if (reader.ReadToFollowing("shininess"))
            {
                reader.MoveToContent();
                tmpMaterial.shininess = (float)Convert.ToDouble(reader.GetAttribute("value").Replace(".", ","));
            }
            if (reader.ReadToFollowing("texture"))
            {
                reader.MoveToContent();
                tmpMaterial.LoadTexture(reader.GetAttribute("file"));
            }
            this.lstMaterial.Add(tmpMaterial);
        }
コード例 #2
0
ファイル: MaterialEditor.cs プロジェクト: dankar/zombies
        public MaterialEditor(object ml,object blocks)
        {
            InitializeComponent();

            this.lstMaterial = (List<Material>)ml;
            this.lstBlocks = (List<Block>)blocks;
            this.mvDefault = new MaterialViewer();
            this.mvDefault.Parent = this.gbPreview;
            this.mvDefault.Location = new Point(8, 19);
            this.mvDefault.Size = new Size(266, 254);
            this.mvDefault.Connect();
            this.material = new Material();
        }
コード例 #3
0
ファイル: Material.cs プロジェクト: dankar/zombies
 public void CopyTo(Material m)
 {
     m.diffuse = this.diffuse;
     m.specular = this.specular;
     m.emission = this.emission;
     m.ambient = this.ambient;
     m.shininess = this.shininess;
     m.name = this.name;
     m.texture = this.texture;
     m.texture_filename = this.texture_filename;
     m.texture_loaded = this.texture_loaded;
     m.type = this.type;
     m.bumpmap = this.bumpmap;
     m.bumpmap_filename = this.bumpmap_filename;
     m.bumpmap_loaded = this.bumpmap_loaded;
 }
コード例 #4
0
ファイル: MaterialEditor.cs プロジェクト: dankar/zombies
 private void NewMaterial()
 {
     Material nm = new Material() ;
     bool f = true;
     string name = "New Material";
     int it = 1;
     while (f)
     {
         f = false;
         foreach (Material m in lstMaterial)
         {
             if (m.name == name && it == 1)
             {
                 f = true;
                 it++;
                 break;
             }
             else if (m.name == name + " " + it.ToString())
             {
                 f = true;
                 it++;
                 break;
             }
         }
     }
     if (it < 2)
     {
         nm.name = "New Material";
     }
     else
     {
         nm.name = "New Material " + it.ToString();
     }
     lstMaterial.Add(nm);
     UpdateMaterialList();
     SelectMaterial(nm.name);
 }
コード例 #5
0
ファイル: MaterialViewer.cs プロジェクト: dankar/zombies
 public void SetMaterial(Material m)
 {
     this.material = m;
 }
コード例 #6
0
ファイル: MaterialViewer.cs プロジェクト: dankar/zombies
        private void glDrawBlock(Material mat)
        {
            float[] diffuse = new float[] { mat.diffuse.R, mat.diffuse.G, mat.diffuse.B, mat.diffuse.A };
            float[] ambient = new float[] { mat.ambient.R, mat.ambient.G, mat.ambient.B, mat.ambient.A };
            float[] specular = new float[] { mat.specular.R, mat.specular.G, mat.specular.B, mat.specular.A };
            float[] emission = new float[] { mat.emission.R, mat.emission.G, mat.emission.B, mat.emission.A };
            float shininess = mat.shininess;

            if (mat.texture_loaded)
            {
                mat.texture.Bind();
            }
            GL.glMaterialfv(GL.GL_FRONT,GL.GL_DIFFUSE, diffuse);
            GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, specular);
            GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, ambient);
            GL.glMaterialfv(GL.GL_FRONT, GL.GL_EMISSION, emission);
            GL.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, ref shininess);

            GL.glutSolidSphere(2.5f, 50, 50);
        }
コード例 #7
0
ファイル: 3DView.cs プロジェクト: dankar/zombies
        private void glDrawBlock(int px,int py,int pz,int sx,int sy,int sz, bool selected,string m)
        {
            Material mat = new Material();
            this.FindMaterial(m).CopyTo(mat);

            if (selected)
            {
                mat.ambient.R = 0.0f;
                mat.ambient.G = 1.0f;
                mat.ambient.B = 1.0f;
                mat.diffuse.R = 0.0f;
                mat.diffuse.G = 1.0f;
                mat.diffuse.B = 1.0f;
            }

            float[] diffuse = new float[] { mat.diffuse.R, mat.diffuse.G, mat.diffuse.B, mat.diffuse.A };
            float[] ambient = new float[] { mat.ambient.R, mat.ambient.G, mat.ambient.B, mat.ambient.A };
            float[] specular = new float[] { mat.specular.R, mat.specular.G, mat.specular.B, mat.specular.A };
            float[] emissive = new float[] { mat.emission.R, mat.emission.R, mat.emission.R, mat.emission.R };
            float shininess = mat.shininess;

            GL.glBegin(GL.GL_QUADS);
                // Bottom
                if (sy > 0)
                    { GL.glNormal3f(0.0f, -1.0f, 0.0f); }
                else
                    { GL.glNormal3f(0.0f, 1.0f, 0.0f); }
                GL.glMaterialfv(GL.GL_FRONT,GL.GL_DIFFUSE, diffuse);
                GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, specular);
                GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, ambient);
                GL.glMaterialfv(GL.GL_FRONT, GL.GL_EMISSION, emissive);
                GL.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, ref shininess);
                GL.glVertex3f(px, py, pz);
                GL.glVertex3f(px+sx, py, pz);
                GL.glVertex3f(px+sx, py, pz+sz);
                GL.glVertex3f(px, py, pz+sz);
                // Left
                if (sx > 0)
                    { GL.glNormal3f(-1.0f, 0.0f, 0.0f); }
                else
                    { GL.glNormal3f(1.0f, 0.0f, 0.0f); }
                GL.glVertex3f(px, py, pz);
                GL.glVertex3f(px, py+sy, pz);
                GL.glVertex3f(px, py+sy, pz + sz);
                GL.glVertex3f(px, py, pz + sz);
                // Top
                if (sy > 0)
                    {GL.glNormal3f(0.0f, 1.0f, 0.0f);}
                else
                    {GL.glNormal3f(0.0f, -1.0f, 0.0f);}
                GL.glVertex3f(px, py+sy, pz);
                GL.glVertex3f(px + sx, py + sy, pz);
                GL.glVertex3f(px + sx, py + sy, pz + sz);
                GL.glVertex3f(px, py + sy, pz + sz);
                // Right
                if (sx > 0)
                    { GL.glNormal3f(1.0f, 0.0f, 0.0f); }
                else
                    { GL.glNormal3f(-1.0f, 0.0f, 0.0f); }
                GL.glVertex3f(px + sx, py, pz);
                GL.glVertex3f(px + sx, py + sy, pz);
                GL.glVertex3f(px + sx, py + sy, pz + sz);
                GL.glVertex3f(px + sx, py, pz + sz);
                // Back
                if (sz > 0)
                    { GL.glNormal3f(0.0f, 0.0f, -1.0f); }
                else
                    { GL.glNormal3f(0.0f, 0.0f, 1.0f); }
                GL.glVertex3f(px, py, pz);
                GL.glVertex3f(px, py + sy, pz);
                GL.glVertex3f(px + sx, py + sy, pz);
                GL.glVertex3f(px + sx, py, pz);
                // Front
                if (sz > 0)
                    { GL.glNormal3f(0.0f, 0.0f, 1.0f); }
                else
                    { GL.glNormal3f(0.0f, 0.0f, -1.0f); }
                GL.glVertex3f(px, py, pz+sz);
                GL.glVertex3f(px, py + sy, pz + sz);
                GL.glVertex3f(px + sx, py + sy, pz + sz);
                GL.glVertex3f(px + sx, py, pz + sz);
            GL.glEnd();
        }
コード例 #8
0
ファイル: 3DView.cs プロジェクト: dankar/zombies
 private Material FindMaterial(string m)
 {
     Material retmat = new Material();
     foreach (Material i in this.material) if (i.name == m) { retmat = i; break; };
     return retmat;
 }
コード例 #9
0
ファイル: MaterialEditor.cs プロジェクト: dankar/zombies
 private void SelectMaterial(string name)
 {
     foreach (Material m in lstMaterial)
     {
         if (m.name == name)
         {
             txtAA.Text = m.ambient.A.ToString();
             txtAR.Text = m.ambient.R.ToString();
             txtAG.Text = m.ambient.G.ToString();
             txtAB.Text = m.ambient.B.ToString();
             txtSA.Text = m.specular.A.ToString();
             txtSR.Text = m.specular.R.ToString();
             txtSG.Text = m.specular.G.ToString();
             txtSB.Text = m.specular.B.ToString();
             txtEA.Text = m.emission.A.ToString();
             txtER.Text = m.emission.R.ToString();
             txtEG.Text = m.emission.G.ToString();
             txtEB.Text = m.emission.B.ToString();
             m.CopyTo(this.material);
             this.selected_material = m;
             txtShine.Text = m.shininess.ToString();
             txtTexture.Text = m.texture_filename;
             txtBumpMap.Text = m.bumpmap_filename;
             txtName.Text = m.name;
             this.mvDefault.SetMaterial(this.material);
             int i=0;
             for(i=0;i<tsMatSel.Items.Count;i++){
                  if(tsMatSel.Items[i].ToString() == name){
                      break;
                  }
             }
             this.tsMatSel.SelectedIndex = i;
             break;
         }
     }
 }