Ejemplo n.º 1
0
        MessageMapContent GetMap(MessageMapRequest request)
        {
            Parameter mapParam = new Parameter(request.m_map.m_parameterReference);

            //if (mapParam.IsBitmapType) //bitmaps we can work out how to handle later
            //{
            //    return GetBitmap(mapParam, request);
            //}
            if (mapParam.IsTexmapType)
            {
                return GetTexmap(mapParam, request);
            }

            return new MessageMapContent();
        }
Ejemplo n.º 2
0
        protected const int MAP_HAS_ALPHA = (1 << 1);//!< The bitmap has an alpha channel.


        MessageMapContent GetTexmap(Parameter mapParam, MessageMapRequest request)
        {
            /* Get the map and render it into a new bitmap */

            var texmap = mapParam.GetTexmap();

            //http://docs.autodesk.com/3DSMAX/16/ENU/3ds-Max-SDK-Programmer-Guide/index.html?url=files/GUID-FD9764C9-EE84-4A1A-BC62-87AE6AF86CC1.htm,topicNumber=d30e31073
            //http://docs.autodesk.com/3DSMAX/16/ENU/3ds-Max-SDK-Programmer-Guide/index.html?url=files/GUID-FD9764C9-EE84-4A1A-BC62-87AE6AF86CC1.htm,topicNumber=d30e31073

            IBitmapInfo bmpInfo = _gi.BitmapInfo.Create();

            bmpInfo.SetType(BMM_TRUE_32);
            bmpInfo.SetWidth(request.m_width);
            bmpInfo.SetHeight(request.m_height);
            bmpInfo.SetFlags(MAP_HAS_ALPHA);
            bmpInfo.SetCustomFlag(0);
            bmpInfo.SetFirstFrame(0);
            bmpInfo.SetLastFrame(0);

            IBitmap bmp = _gi.CreateBitmapFromBitmapInfo(bmpInfo);

            texmap.RenderBitmap(0, bmp, 1.0f, request.m_filter);

            /* If the user is not requesting a filename, create a temp one to write to */

            if (!request.m_writeToFile)
            {
                request.m_filename = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName() + ".png");
            }

            /* Write the bitmap to file */

            Directory.CreateDirectory(Path.GetDirectoryName(request.m_filename));

            //The bmpInfo contains the filename - note it doesnt have to be the same bmpInfo as created above thats just the easiest way to do it here
            bmpInfo.SetName(request.m_filename);
            bmp.OpenOutput(bmpInfo);
            bmp.Write(bmpInfo, 0);
            bmp.Close(bmpInfo, 0);

            //Max prepends the filename with the sequence number, so rename afterwards
            string extension = System.IO.Path.GetExtension(request.m_filename);
            string maxfilename = request.m_filename.Substring(0, request.m_filename.Length - extension.Length) + "0000" + extension;

            /* If the user has requested a file, then rename and return this, otherwise get the data from it and delete it */

            if (request.m_writeToFile)
            {
                if (File.Exists(request.m_filename))
                {
                    File.Delete(request.m_filename);
                }
                System.IO.File.Move(maxfilename, request.m_filename);
                
                return new MessageMapFilename(request.m_filename);
            }
            else
            {
                MessageMapContent response = new MessageMapData(File.ReadAllBytes(maxfilename));
                File.Delete(maxfilename);
                return response;
            }
        }