Ejemplo n.º 1
0
        }//GetRecommendedAtlasWidthHeight()

        public static bool CreateTextureAtlasInfo(ref KTextureAtlasInfo textureAtlasInfo_, ETextureType eTextureType_, ArrayList alistStdMtrlInfo_)
        {
            // create new texture atlas info.
            //
            textureAtlasInfo_ = new KTextureAtlasInfo();
            textureAtlasInfo_.m_alistTextureInfo = new ArrayList();

            int iTotalWidth  = 0;
            int iTotalHeight = 0;

            // set atlas texture info.
            //
            foreach (KStdMaterialInfo stdMtrlInfo in alistStdMtrlInfo_)
            {
                KTextureInfo textrInfo;
                {
                    textrInfo.m_strMtrlName        = "";
                    textrInfo.m_strTextureFileName = "";
                    textrInfo.m_iLeft        = 0;
                    textrInfo.m_iTop         = 0;
                    textrInfo.m_iWidth       = 0;
                    textrInfo.m_iHeight      = 0;
                    textrInfo.m_image        = null;
                    textrInfo.m_bIsRotateCcw = false;
                }//block

                textrInfo.m_strMtrlName        = stdMtrlInfo.m_strMaterialName;
                textrInfo.m_strTextureFileName = stdMtrlInfo.GetTextureFileName(eTextureType_);
                Debug.Assert(stdMtrlInfo.m_image != null);
                //if( stdMtrlInfo.m_image == null )
                //{
                //    //return false;
                //    continue;
                //}//if

                textrInfo.m_image = stdMtrlInfo.m_image;
                if (stdMtrlInfo.m_image != null)
                {
                    textrInfo.m_iWidth  = stdMtrlInfo.m_image.Width;
                    textrInfo.m_iHeight = stdMtrlInfo.m_image.Height;
                    textrInfo.m_iLeft   = 0;
                    textrInfo.m_iTop    = 0;

                    iTotalWidth  += textrInfo.m_iWidth;
                    iTotalHeight += textrInfo.m_iHeight;
                }//if

                textureAtlasInfo_.m_alistTextureInfo.Add(textrInfo);
            }//foreach

            // set texture type, atlas width, and atlas height.
            //
            textureAtlasInfo_.m_eTextureType = eTextureType_;
            GetRecommendedAtlasWidthHeight(ref textureAtlasInfo_.m_iAtlasWidth, ref textureAtlasInfo_.m_iAtlasHeight
                                           , iTotalWidth / 2, iTotalHeight / 2);

            textureAtlasInfo_.AutoAdjustTexturePosition();

            return(true);
        }//CreateTextureAtlasInfo()
Ejemplo n.º 2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        // function members
        //
        public FormAtlasMain()
        {
            InitializeComponent();

            m_alistMaterials         = null;// new ArrayList();
            m_strOdmFileName         = "";
            m_eCurrentTextureType    = ETextureType.DIFFUSE;
            m_iSelectedMaterialIndex = -1;

            m_iSelectedAtlasTextureIndex = -1;
            m_textureAtlasInfo           = null;
            m_eIsTextureLocatingMode     = ETextureLocatingMode.NONE;
            //m_pntPickMouseOffset;
            m_fAtlasZoomRatio   = 1.0f;
            m_pntAtlasLeftTop.X = 0;
            m_pntAtlasLeftTop.Y = 0;
        }//FormAtlasMain
Ejemplo n.º 3
0
        }//CreateTextureAtlasInfo()

        /// <summary>
        /// load .odm.a file
        /// jintaeks on 2013-11-12, 17:19
        /// </summary>
        /// <param name="textureAtlasInfo_"></param>
        /// <param name="strOdmaFilePath_"></param>
        /// <returns></returns>
        public static bool LoadExistingAtlasInfo(ref KTextureAtlasInfo textureAtlasInfo_, string strOdmaFilePath_)
        {
            if (textureAtlasInfo_ == null)
            {
                return(false); // invalid atlas info.
            }//if

            if (System.IO.File.Exists(strOdmaFilePath_) == false)
            {
                MessageBox.Show("파일이 존재하지 않습니다. \nPath : " + strOdmaFilePath_);
                return(false);
            }//if

            int    iParseMode = 0;
            string strLine    = "";
            // you must set 'Encoding.Default' to read Korean Hangul text from file. jintaeks on 2013-11-04, 14:48
            StreamReader file = new StreamReader(strOdmaFilePath_, Encoding.Default);

            while ((strLine = file.ReadLine()) != null)
            {
                strLine.Trim();

                if (strLine.Length <= 0)
                {
                    continue;
                }//if

                if (iParseMode == 0)
                {
                    int    iStrLength      = strLine.Length;
                    int    iEqualSignIndex = strLine.IndexOf("=");
                    string strName         = strLine.Substring(0, iEqualSignIndex);
                    strName = strName.Trim();
                    strName = strName.ToLower();

                    int    iRemainedTextLenght = iStrLength - iEqualSignIndex - 1;
                    string strData             = strLine.Substring(iEqualSignIndex + 1, iRemainedTextLenght);

                    if (strName == "width")
                    {
                        textureAtlasInfo_.m_iAtlasWidth = Convert.ToInt32(strData);
                    }
                    else if (strName == "height")
                    {
                        textureAtlasInfo_.m_iAtlasHeight = Convert.ToInt32(strData);
                    }
                    else if (strName == "material")
                    {
                        string[] astrMtrlInfo = strData.Split(new char[] { ',' });

                        if (astrMtrlInfo.Length == 6)
                        {
                            for (int iDataIndex = 0; iDataIndex < 6; iDataIndex += 1)
                            {
                                astrMtrlInfo[iDataIndex] = astrMtrlInfo[iDataIndex].Trim();
                            }//for

                            int  iTextrInfoIndex  = 0;
                            bool bIsFindTextrInfo = textureAtlasInfo_.FindTextureInfo(ref iTextrInfoIndex, astrMtrlInfo[0]);
                            Debug.Assert(bIsFindTextrInfo == true);
                            if (bIsFindTextrInfo == true)
                            {
                                KTextureInfo textrInfo         = new KTextureInfo();
                                bool         bIsGetTextureInfo = textureAtlasInfo_.GetTextureInfo(ref textrInfo, iTextrInfoIndex);
                                if (bIsGetTextureInfo == true)
                                {
                                    textrInfo.m_iLeft        = Convert.ToInt32(astrMtrlInfo[1]);
                                    textrInfo.m_iTop         = Convert.ToInt32(astrMtrlInfo[2]);
                                    textrInfo.m_iWidth       = Convert.ToInt32(astrMtrlInfo[3]);
                                    textrInfo.m_iHeight      = Convert.ToInt32(astrMtrlInfo[4]);
                                    astrMtrlInfo[5]          = astrMtrlInfo[5].ToLower();
                                    textrInfo.m_bIsRotateCcw = String.Compare(astrMtrlInfo[5], "true") == 0;

                                    if (textrInfo.m_bIsRotateCcw == true)
                                    {
                                        textrInfo.RotateImage(90);
                                    }//if

                                    textureAtlasInfo_.SetTextureInfo(iTextrInfoIndex, textrInfo);
                                } //if
                            }     //if
                        }
                    }             //if.. else if..
                }                 //if
            }                     //while

            file.Close();

            return(true);
        }//LoadExistingAtlasInfo()