Eyeshot Ultimate 學習筆記(2)

來源:互聯網
上載者:User

標籤:

匯入模型

一般情況下,我們自己搭建模型的功力還不夠,大多都是在3Dmax中做好模型,匯出成模型檔案,然後再匯入Eyeshot視圖中。匯入的程式碼封裝括:

OpenFileDialog openFileDialog1 = new OpenFileDialog();            string theFilter = "Points|*.asc|" + "Stereolithography|*.stl|" + "WaveFront OBJ|*.obj";            theFilter += "|IGES|*.igs; *.iges|" + "STEP|*.stp; *.step";            openFileDialog1.Filter = theFilter;            openFileDialog1.Multiselect = false;            openFileDialog1.AddExtension = true;            openFileDialog1.CheckFileExists = true;            openFileDialog1.CheckPathExists = true;            if (openFileDialog1.ShowDialog() == DialogResult.OK)            {                viewportLayout1.Entities.Clear();                ReadFileAsynch rfa = null;                switch (openFileDialog1.FilterIndex)                {                    case 1:                        rfa = new ReadASC(openFileDialog1.FileName);                        break;                    case 2:                        rfa = new ReadSTL(openFileDialog1.FileName);                        break;                    case 3:                        rfa = new ReadOBJ(openFileDialog1.FileName);                        break;                    case 4:                        rfa = new ReadIGES(openFileDialog1.FileName);                        break;                    case 5:                        rfa = new ReadSTEP(openFileDialog1.FileName);                        break;                }                viewportLayout1.StartWork(rfa);            }

這裡還沒有完,因為匯入模型這個過程是非同步匯入,所以還有另外一個函數:

 private void viewportLayout1_WorkCompleted(object sender, WorkCompletedEventArgs e)        {            if (e.WorkUnit is ReadFileAsynch)//匯入檔案            {                ReadFileAsynch rfa = (ReadFileAsynch)e.WorkUnit;                Entity[] entList = rfa.Entities;                entityListClone = (Entity[])entList.Clone();                rfa.AddToScene(viewportLayout1);                viewportLayout1.SetView(viewType.Top);                viewportLayout1.ZoomFit();            }        }

這段代碼錶示如果執行的work是匯入檔案,那麼將匯入的模型呈現在視圖中,並且設定視圖角度以及模型的相對大小。

匯出模型

匯出模型的檔案只有一個,比如匯入模型時有一個.mtl檔案和一個.obj檔案,匯出模型後就只有.obj檔案了。

匯出模型的代碼如下:

                SaveFileDialog sfd = new SaveFileDialog();                string theFilter = "OBJ|*.OBJ";                theFilter += "|IGES|*.igs; *.iges|" + "STEP|*.stp; *.step";                sfd.Filter = theFilter;                string savePath = fileName;                if (sfd.ShowDialog() == DialogResult.OK)                {                    if (!string.IsNullOrEmpty(sfd.FileName))                    {                        savePath = sfd.FileName;                    }                    string extention = savePath.Substring(savePath.LastIndexOf(‘.‘) + 1).ToLower();                    switch (extention)                    {                        case "obj":                            viewportLayout1.WriteOBJ(savePath, false);                            break;                        case "igs":                            viewportLayout1.WriteIGES(savePath, false);                            break;                        case "iges":                            viewportLayout1.WriteIGES(savePath, false);                            break;                        case "stp":                            viewportLayout1.WriteSTEP(savePath, false);                            break;                        case "step":                            viewportLayout1.WriteSTEP(savePath, false);                            break;                    }                }

匯出主要的函數為WriteOBJ(),WriteIGES()之類的一系列函數。當然匯出的模型也可以繼續匯入。

Eyeshot Ultimate 學習筆記(2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.