Beispiel #1
0
        }//_UpdateMaterialTextureInfo()

        private bool _UpdateAtlasTexturesFromMaterialList()
        {
            if (m_textureAtlasInfo == null || m_textureAtlasInfo.m_alistTextureInfo == null ||
                m_alistMaterials == null)
            {
                return(false);
            }//if

            if (m_textureAtlasInfo.m_alistTextureInfo.Count == m_alistMaterials.Count)
            {
                int iTextrCount = m_alistMaterials.Count;
                for (int iTextr = 0; iTextr < iTextrCount; iTextr += 1)
                {
                    KStdMaterialInfo stdMtrlInfo = ( KStdMaterialInfo )m_alistMaterials[iTextr];
                    KTextureInfo     textrInfo   = ( KTextureInfo )m_textureAtlasInfo.m_alistTextureInfo[iTextr];

                    textrInfo.m_image = stdMtrlInfo.m_image;
                    if (textrInfo.m_image != null && textrInfo.m_bIsRotateCcw == true)
                    {
                        textrInfo.RotateImage(90);
                        //textrInfo.SwapWidthHeight();
                    }//if

                    m_textureAtlasInfo.m_alistTextureInfo[iTextr] = textrInfo;
                } //for
            }     //if

            return(true);
        }//_UpdateAtlasTexturesFromMaterialList()
Beispiel #2
0
        }//_UpdateAtlasTexturesFromMaterialList()

        /// @brief  find material from material list.
        /// @date   jintaeks on 2013-11-05, 20:38
        private bool _FindStdMaterialInfo(ref KStdMaterialInfo stdMtrlInfo_, string strMaterialName_)
        {
            strMaterialName_ = strMaterialName_.ToLower();
            foreach (KStdMaterialInfo stdMtrlInfo in m_alistMaterials)
            {
                string strMtrlName = stdMtrlInfo.m_strMaterialName.ToLower();
                if (strMtrlName == strMaterialName_)
                {
                    // set [out] parameter. jintaeks on 2013-11-04, 13:59
                    stdMtrlInfo_ = stdMtrlInfo;
                    return(true);
                } //if
            }     //foreach

            return(false);
        }//_FindStdMaterialInfo()
Beispiel #3
0
        }//panelTextureCanvas_Invalidated()

        private void _UpdateMaterialPictureBox(int iMtrl_)
        {
            if (iMtrl_ != -1 && iMtrl_ < m_alistMaterials.Count)
            {
                KStdMaterialInfo stdMtrl = ( KStdMaterialInfo )m_alistMaterials[iMtrl_];
                //pictureBoxCurrentTexture.Image = stdMtrl.m_image;

                int iWidth  = pictureBoxCurrentTexture.Width;
                int iHeight = pictureBoxCurrentTexture.Height;

                if (stdMtrl.m_image != null)
                {
                    pictureBoxCurrentTexture.Image = new Bitmap(iWidth, iHeight);
                    Graphics.FromImage(pictureBoxCurrentTexture.Image).DrawImage(stdMtrl.m_image, 0, 0, iWidth, iHeight);
                } //if
            }     //if
        }         //_UpdateMaterialPictureBox()
Beispiel #4
0
        }//LoadDsuMaterialInfo()

        public static void LoadMaterialTextures(ref ArrayList alistMaterials_, ETextureType eTextureType_, string strAlternativePath_, bool bLoadTexture_)
        {
            for (int iMtrl = 0; iMtrl < alistMaterials_.Count; ++iMtrl)
            {
                KStdMaterialInfo stdMtrl = new KStdMaterialInfo();
                stdMtrl = ( KStdMaterialInfo )alistMaterials_[iMtrl];
                //KStdMaterialInfo stdMtrl = ( KStdMaterialInfo )alistMaterials_[iMtrl];
                string strTextureFileName = "";
                bool   bIsFileExist       = false;
                switch (eTextureType_)
                {
                case ETextureType.DIFFUSE:
                    strTextureFileName = stdMtrl.m_strDiffuseTextureName;
                    break;

                case ETextureType.BUMP:
                    strTextureFileName = stdMtrl.m_strBumpTextureName;
                    break;

                case ETextureType.SPECULAR:
                    strTextureFileName = stdMtrl.m_strSpecularTextureName;
                    break;

                case ETextureType.GLOSSINESS:
                    strTextureFileName = stdMtrl.m_strGlossinessTextureName;
                    break;
                }//switch

                // check file existence in original path.
                if (System.IO.File.Exists(strTextureFileName) == false)
                {
                    // when texture file is not exist in original path
                    // try to load alternative path which is program was executed.
                    // - jintaeks on 2013-11-04, 21:09
                    string strFileName = Path.GetFileName(strTextureFileName);
                    string strFilePath = strAlternativePath_ + "\\" + strFileName;
                    if (System.IO.File.Exists(strFilePath) == true)
                    {
                        strTextureFileName = strFilePath;
                        switch (eTextureType_)
                        {
                        case ETextureType.DIFFUSE:
                            stdMtrl.m_strDiffuseTextureName = strTextureFileName;
                            break;

                        case ETextureType.BUMP:
                            stdMtrl.m_strBumpTextureName = strTextureFileName;
                            break;

                        case ETextureType.SPECULAR:
                            stdMtrl.m_strSpecularTextureName = strTextureFileName;
                            break;

                        case ETextureType.GLOSSINESS:
                            stdMtrl.m_strGlossinessTextureName = strTextureFileName;
                            break;
                        } //switch
                        bIsFileExist = true;
                    }     //if
                }
                else
                {
                    bIsFileExist = true;
                }//if.. else..

                if (bIsFileExist == true && bLoadTexture_ == true)
                {
                    // test original Image control. jintaeks on 2013-11-04, 20:28
                    //strTextureFileName = @"F:\techsupport\source\DsuAtlasMaxPlugin\Build001_Test01_Dif01.jpg"; // test
                    //stdMtrl.m_image = Image.FromFile( strTextureFileName );

                    FIBITMAP fiBitmap = FreeImage.LoadEx(strTextureFileName);
                    //FreeImage.SetTransparent( fiBitmap, false );
                    //stdMtrl.m_image = FreeImage.GetBitmap( fiBitmap );
                    Image img = FreeImage.GetBitmap(fiBitmap);
                    //img = Utility.SetImageOpacity( img, 1 );
                    stdMtrl.m_image = img;
                }
                else
                {
                    stdMtrl.m_image = null;
                }//if.. else..

                // update material info. jintaeks on 2013-11-04, 21:09
                alistMaterials_[iMtrl] = stdMtrl;
            } //foreach
        }     //LoadMaterialTextures()
Beispiel #5
0
        private bool _ApplyAtlasInfo()
        {
            // step 1. write atlas info to file.
            //
            string strObjectName = Path.GetFileNameWithoutExtension(m_strOdmFileName);
            // construct "odm.a" filename.
            string strAtlasFileName = m_strOdmFileName;

            strAtlasFileName += ".a";

            StreamWriter sw = new StreamWriter(strAtlasFileName, false, Encoding.Default);
            string       strData;
            string       strOutput = "";

            strData    = String.Format("Version = {0}\r\n", m_strOdmaFileVersion);
            strOutput += strData;
            strData    = String.Format("Object = {0}\r\n", strObjectName);
            strOutput += strData;
            strData    = String.Format("Width = {0}\r\n", m_textureAtlasInfo.m_iAtlasWidth);
            strOutput += strData;
            strData    = String.Format("Height = {0}\r\n", m_textureAtlasInfo.m_iAtlasHeight);
            strOutput += strData;

            int iTextrCount = m_alistMaterials.Count;

            Debug.Assert(m_alistMaterials.Count == m_textureAtlasInfo.m_alistTextureInfo.Count);
            if (m_alistMaterials.Count != m_textureAtlasInfo.m_alistTextureInfo.Count)
            {
                Clipboard.SetText("DsuAtlasTextureLocator : material error");
                MessageBox.Show("DsuAtlasTextureLocator : material error");
                return(false);
            }//if

            for (int iTextr = 0; iTextr < iTextrCount; iTextr += 1)
            {
                KStdMaterialInfo stdMtrlInfo = ( KStdMaterialInfo )m_alistMaterials[iTextr];
                KTextureInfo     textrInfo   = ( KTextureInfo )m_textureAtlasInfo.m_alistTextureInfo[iTextr];

                strData = String.Format("Material = {0}, {1}, {2}, {3}, {4}, {5}\r\n"
                                        , textrInfo.m_strMtrlName
                                        , textrInfo.m_iLeft
                                        , textrInfo.m_iTop
                                        , textrInfo.m_iWidth
                                        , textrInfo.m_iHeight
                                        , textrInfo.m_bIsRotateCcw == true ? "true" : "false");
                strOutput += strData;

                if (stdMtrlInfo.m_strDiffuseTextureName.Length >= 1)
                {
                    strData    = String.Format("Diffuse = {0}\r\n", stdMtrlInfo.m_strDiffuseTextureName);
                    strOutput += strData;
                }//if

                if (stdMtrlInfo.m_strBumpTextureName.Length >= 1)
                {
                    strData    = String.Format("Bump = {0}\r\n", stdMtrlInfo.m_strBumpTextureName);
                    strOutput += strData;
                }//if

                if (stdMtrlInfo.m_strSpecularTextureName.Length >= 1)
                {
                    strData    = String.Format("SpecularLevel = {0}\r\n", stdMtrlInfo.m_strSpecularTextureName);
                    strOutput += strData;
                }//if

                if (stdMtrlInfo.m_strGlossinessTextureName.Length >= 1)
                {
                    strData    = String.Format("Glossiness = {0}\r\n", stdMtrlInfo.m_strGlossinessTextureName);
                    strOutput += strData;
                } //if
            }     //foreach

            sw.Write(strOutput);
            sw.Close();

            // step 2. copy atlas data to clipboard.
            //
            Clipboard.SetText(strOutput);

            return(true);
        }//_ApplyAtlasInfo()