Ejemplo n.º 1
0
        public unsafe HRESULT Draw(Direct3DTexture9 texture, D3DRECT?rect, D3DXVECTOR3?center, D3DXVECTOR3?position, D3DCOLOR color)
        {
            D3DRECT     vRect     = rect.HasValue ? rect.Value : default(D3DRECT);
            D3DXVECTOR3 vCenter   = center.HasValue ? center.Value : default(D3DXVECTOR3);
            D3DXVECTOR3 vPosition = position.HasValue ? position.Value : default(D3DXVECTOR3);

            return(Draw(
                       texture,
                       rect.HasValue ? (IntPtr)(void *)&vRect : IntPtr.Zero,
                       center.HasValue ? (IntPtr)(void *)&vCenter : IntPtr.Zero,
                       position.HasValue ? (IntPtr)(void *)&vPosition : IntPtr.Zero,
                       color));
        }
Ejemplo n.º 2
0
        void ExportToObj(lwGeomObjInfo geom, string obj_name, string pathtomodel, ExportGroup group, ExportObjInfo info)
        {
            System.IO.StreamWriter objwriter = info.objwriter;
            System.IO.StreamWriter mtlwriter = info.mtlwriter;

            int startvertex   = info.totalvertexes;
            int startnormal   = info.totalnormals;
            int starttexcoord = info.totaltexcoord;
            int startindex    = info.totalindexes;

            bool texcoordexist = false;
            bool normalexist   = false;

            lock (threadLock)
            {
                for (int i = 0; i < geom.mesh.header.vertex_num; i++)
                {
                    D3DXVECTOR3 pos = geom.mesh.vertex_seq[i];
                    pos = pos * geom.header.mat_local;

                    if (checkBox5.Checked)
                    {
                        float z = -pos.y;
                        pos.y = pos.z;
                        pos.z = z;
                    }

                    objwriter.WriteLine("v {0:0.0000} {1:0.0000} {2:0.0000}", pos.x, pos.y, pos.z);
                    info.totalvertexes++;
                }

                if ((geom.mesh.header.fvf & 0x10) != 0)
                {
                    normalexist = true;
                    for (int i = 0; i < geom.mesh.header.vertex_num; i++)
                    {
                        objwriter.WriteLine("vn {0:0.0000} {1:0.0000} {2:0.0000}", geom.mesh.normal_seq[i].x, geom.mesh.normal_seq[i].y, geom.mesh.normal_seq[i].z);
                        info.totalnormals++;
                    }
                }
                if ((geom.mesh.header.fvf & 0x100) != 0 || (geom.mesh.header.fvf & 0x200) != 0 || (geom.mesh.header.fvf & 0x300) != 0 || (geom.mesh.header.fvf & 0x400) != 0)
                {
                    texcoordexist = true;
                    for (int i = 0; i < geom.mesh.header.vertex_num; i++)
                    {
                        if (checkBox4.Checked)
                        {
                            objwriter.WriteLine("vt {0:0.0000} {1:0.0000}", geom.mesh.texcoord0_seq[i].x, 1 - geom.mesh.texcoord0_seq[i].y);
                        }
                        else
                        {
                            objwriter.WriteLine("vt {0:0.0000} {1:0.0000}", geom.mesh.texcoord0_seq[i].x, geom.mesh.texcoord0_seq[i].y);
                        }
                        info.totaltexcoord++;
                    }
                }
            }

            for (int i = 0; i < geom.mesh.header.subset_num; i++)
            {
                string mtlname = obj_name;
                lock (threadLock)
                {
                    objwriter.WriteLine("\ng {0}_{1}", mtlname, i);
                    objwriter.WriteLine("usemtl {0}-{1}\n", mtlname, i);
                    objwriter.WriteLine("s off");

                    for (int j = 0; j < geom.mesh.subset_seq[i].primitive_num * 3; j += 3)
                    {
                        objwriter.Write("f ");
                        for (int k = 0; k < 3; k++)
                        {
                            uint facevertex   = (uint)(geom.mesh.index_seq[j + k + geom.mesh.subset_seq[i].start_index] + startvertex) + 1;
                            uint facenormal   = (uint)(geom.mesh.index_seq[j + k + geom.mesh.subset_seq[i].start_index] + startnormal) + 1;
                            uint facetexcoord = (uint)(geom.mesh.index_seq[j + k + geom.mesh.subset_seq[i].start_index] + starttexcoord) + 1;
                            if (normalexist && texcoordexist)
                            {
                                objwriter.Write("{0}/{1}/{2} ", facevertex, facetexcoord, facenormal);
                            }
                            else if (normalexist && !texcoordexist)
                            {
                                objwriter.Write("{0}//{2} ", facevertex, facenormal);
                            }
                            else if (!normalexist && texcoordexist)
                            {
                                objwriter.Write("{0}/{1} ", facevertex, facetexcoord);
                            }
                            else
                            {
                                objwriter.Write("{0} ", facevertex);
                            }
                        }
                        objwriter.Write("\n");
                    }

                    mtlwriter.WriteLine("newmtl {0}-{1}", mtlname, i);
                    mtlwriter.WriteLine("Ka {0} {1} {2}", geom.mtl_seq[i].mtl.amb.r, geom.mtl_seq[i].mtl.amb.g, geom.mtl_seq[i].mtl.amb.b);
                    mtlwriter.WriteLine("Kd {0} {1} {2}", geom.mtl_seq[i].mtl.dif.r, geom.mtl_seq[i].mtl.dif.g, geom.mtl_seq[i].mtl.dif.b);
                    mtlwriter.WriteLine("Ks {0} {1} {2}", geom.mtl_seq[i].mtl.spe.r, geom.mtl_seq[i].mtl.spe.g, geom.mtl_seq[i].mtl.spe.b);

                    string newtexturepath = RelativePath(System.IO.Path.GetDirectoryName(textBox1.Text) + "\\", System.IO.Path.GetDirectoryName(textBox2.Text) + "\\");
                    mtlwriter.WriteLine("map_Kd {0}", newtexturepath + CutString(geom.mtl_seq[i].tex_seq[0].file_name));
                }

                if (checkBox2.Checked)
                {
                    string path = System.IO.Path.GetDirectoryName(pathtomodel).Replace("\\model\\", "\\texture\\");
                    System.Drawing.Bitmap bmp = parentForm.LoadBitmaByTextureName(path + "\\" + CutString(geom.mtl_seq[i].tex_seq[0].file_name));
                    bmp.Save(System.IO.Path.GetDirectoryName(textBox2.Text) + "\\" + CutString(geom.mtl_seq[i].tex_seq[0].file_name));
                }
                else
                {
                    string path     = System.IO.Path.GetDirectoryName(pathtomodel).Replace("\\model\\", "\\texture\\");
                    string filename = parentForm.GetRightTextureName(path + "\\" + CutString(geom.mtl_seq[i].tex_seq[0].file_name));

                    if (filename != null)
                    {
                        System.IO.File.Copy(filename, System.IO.Path.GetDirectoryName(textBox2.Text) + "\\" + CutString(geom.mtl_seq[i].tex_seq[0].file_name), true);
                    }
                }
            }
        }