Exemple #1
0
        protected override LoadReturnCode OnLoad(ref string errorMessage)
        {
            RhinoApp.Initialized += RhinoApp_Initialized;
            RcCore.It.InitializeResourceManager();

            // code got moved to separate DLL so use that to register from.
            var rccoreass = typeof(RcCore).Assembly;

            RenderContent.RegisterContent(rccoreass, Id);

            RenderContent.ContentFieldChanged += RenderContentOnContentFieldChanged;

            var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";

            RcCore.It.PluginPath = path;
            var kernelPath = Path.Combine(path, "RhinoCycles");

            RcCore.It.KernelPath = kernelPath;
            var appPath = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);

            RcCore.It.AppPath            = appPath;
            kernelPath                   = RcCore.GetRelativePath(appPath, kernelPath);
            RcCore.It.KernelPathRelative = kernelPath;

            var dataPath = SettingsDirectory;
            var userPath = Path.Combine(dataPath, "..", "data");

            userPath = RcCore.GetCanonicalizedPath(userPath);

            RcCore.It.DataUserPath = userPath;

            CSycles.path_init(RcCore.It.KernelPath, RcCore.It.DataUserPath);

            if (RhinoApp.RunningOnVMWare())
            {
                CSycles.debug_set_opencl_device_type(0);
            }
            else
            {
                CSycles.debug_set_opencl_device_type(RcCore.It.EngineSettings.OpenClDeviceType);
            }
            CSycles.debug_set_opencl_kernel(RcCore.It.EngineSettings.OpenClKernelType);
            CSycles.debug_set_opencl_single_program(RcCore.It.EngineSettings.OpenClSingleProgram);
            CSycles.debug_set_cpu_kernel(RcCore.It.EngineSettings.CPUSplitKernel);

            RcCore.It.Initialised = false;
            AsyncInitialise();

            m_page = new ViewportPropertiesPage();

            RhinoView.SetActive += RhinoView_SetActive;

            return(LoadReturnCode.Success);
        }
        public void HandleWallpaper(ViewInfo view, bool scaleToFit)
        {
            var file = Rhino.Render.Utilities.FindFile(RhinoDoc.ActiveDoc, view.WallpaperFilename);

            bool modifiedWallpaper = false;

            modifiedWallpaper |= m_old_hidden != view.WallpaperHidden | m_old_grayscale != view.ShowWallpaperInGrayScale;
            modifiedWallpaper |= m_old_scaletofit != scaleToFit;
            modifiedWallpaper |= !m_old_wallpaper.Equals(file);
            Modified          |= modifiedWallpaper;

            if (string.IsNullOrEmpty(file) || !File.Exists(file))
            {
                RcCore.OutputDebugString($"{file} not found, clearing and returning\n");
                Wallpaper.Clear();
                WallpaperSolid = Color1;
                return;
            }

            if (!modifiedWallpaper)
            {
                return;
            }

            m_old_hidden     = view.WallpaperHidden;
            m_old_grayscale  = view.ShowWallpaperInGrayScale;
            m_old_scaletofit = scaleToFit;
            m_old_wallpaper  = file ?? "";
            var crc = Rhino.RhinoMath.CRC32(27, System.Text.Encoding.UTF8.GetBytes(m_old_wallpaper));

            RcCore.OutputDebugString($"Handling wallpaper, reading {file}\n");
            try
            {
                int near, far;
                var screenport = view.Viewport.GetScreenPort(out near, out far);
                var bottom     = screenport.Bottom;
                var top        = screenport.Top;
                var left       = screenport.Left;
                var right      = screenport.Right;

                // color matrix used for conversion to gray scale
                ColorMatrix cmgray = new ColorMatrix(
                    new[] {
                    new[] { 0.3f, 0.3f, 0.3f, 0.0f, 0.0f },
                    new[] { .59f, .59f, .59f, 0.0f, 0.0f },
                    new[] { .11f, .11f, .11f, 0.0f, 0.0f },
                    new[] { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f },
                    new[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
                }
                    );
                ColorMatrix cmcolor = new ColorMatrix(
                    new[] {
                    new[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f },
                    new[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
                    new[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f },
                    new[] { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f },
                    new[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
                }
                    );
                ImageAttributes attr = new ImageAttributes();
                attr.SetColorMatrix(view.ShowWallpaperInGrayScale ? cmgray : cmcolor);

                var    w           = Math.Abs(right - left);
                var    h           = Math.Abs(bottom - top);
                var    viewport_ar = (float)w / h;
                Bitmap bm          = new Bitmap(file);
                var    image_ar    = (float)bm.Width / bm.Height;

                int nw = 0;
                int nh = 0;
                int x  = 0;
                int y  = 0;
                if (image_ar > viewport_ar)
                {
                    x  = 0;
                    nw = w;
                    nh = (int)(w / image_ar);
                    y  = (int)(h * 0.5 - nh * 0.5);
                }
                else
                {
                    y  = 0;
                    nh = h;
                    nw = (int)(h * image_ar);
                    x  = (int)(w * 0.5 - nw * 0.5);
                }

                Bitmap newBitmap = new Bitmap(w, h);

                var col = Color.Aqua;
                if (Color1 != Color.Empty)
                {
                    col = Color1;
                }
                var brush  = new SolidBrush(col);
                var p      = new Point(x, y);
                var bmsize = new Size(nw, nh);
                if (scaleToFit)
                {
                    bmsize = new Size(w, h);
                    p      = new Point(0, 0);
                }
                using (Graphics g = Graphics.FromImage(newBitmap))
                {
                    g.FillRectangle(brush, new Rectangle(Point.Empty, newBitmap.Size));
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    if (!view.WallpaperHidden)
                    {
                        g.DrawImage(bm, new Rectangle(p, bmsize), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel, attr);
                    }
                }
                var wallpaperbm = BitmapConverter.ReadByteBitmapFromBitmap(crc, newBitmap.Size.Width, newBitmap.Size.Height, newBitmap);
                wallpaperbm.ApplyGamma(Gamma);
                Wallpaper.TexByte = wallpaperbm.Data;
                if (RcCore.It.EngineSettings.SaveDebugImages)
                {
                    wallpaperbm.SaveBitmaps();
                }
                Wallpaper.TexWidth  = newBitmap.Width;
                Wallpaper.TexHeight = newBitmap.Height;
                Wallpaper.Name      =
                    $"{file}_{newBitmap.Width}x{newBitmap.Height}_{view.WallpaperHidden}_{view.ShowWallpaperInGrayScale}_{scaleToFit}_{id}";
            }
            catch (Exception e)
            {
                RcCore.OutputDebugString($"wallpaper failure: {e.Message}.\n");
                Wallpaper.Clear();
            }
        }
 public void ViewportLoggerCallback(string msg)
 {
     RcCore.OutputDebugString($"{msg}\n");
 }
 public void TriggerChangesReady()
 {
     RcCore.OutputDebugString("Triggering changes, changequeue applied everything\n");
     ChangesReady?.Invoke(this, EventArgs.Empty);
 }