Esempio n. 1
0
        public async override Task GenerateVisual(object typeInstance, Type neosType, bool force = false)
        {
            LogixNode targetInstance = typeInstance as LogixNode;
            Category  typeCategory   = GetCategory(neosType);
            string    typeSafeName   = GetSafeName(neosType);

            if (!(force || NeedsVisual(typeSafeName, typeCategory)))
            {
                return;
            }

            await BuildLogiXUI(targetInstance);

            Canvas logixVisual = VisualSlot.GetComponentInChildren <Canvas>();
            float  aspectRatio = logixVisual.Size.Value.y / logixVisual.Size.Value.x;

            VisualCaptureCamera.OrthographicSize.Value = logixVisual.Size.Value.y / 20.0f;
            Bitmap2D logixImage = await VisualCaptureCamera.RenderToBitmap(new int2(128, (int)(128.0 * aspectRatio)));

            foreach (string path in typeCategory.Paths)
            {
                Directory.CreateDirectory($"{WikiAssetGenerator.BasePath}\\Logix\\{path}\\");
                logixImage.Save($"{WikiAssetGenerator.BasePath}\\Logix\\{path}\\{typeSafeName}Node.png", 100, true);
            }
        }
        public async override Task GenerateVisual(object typeInstance, Type neosType, bool force = false)
        {
            Component targetInstance = typeInstance as Component;
            Category  typeCategory   = GetCategory(neosType);
            string    typeSafeName   = GetSafeName(neosType);

            if (!(force || NeedsVisual(typeSafeName, typeCategory)))
            {
                return;
            }

            Rect bounds = await BuildComponentUI(targetInstance);

            double aspectRatio = (bounds.height + 5.0) / bounds.width;

            VisualSlot.LocalPosition = new float3(0, ((((bounds.height / 2.0f) - bounds.Center.y) / 2.0f) + 5.0f) * 0.1f, 0.5f);
            VisualCaptureCamera.OrthographicSize.Value = (bounds.height + 5) / 20.0f;
            await new ToWorld();
            Bitmap2D componentImage = await VisualCaptureCamera.RenderToBitmap(new int2(400, (int)(400 * aspectRatio)));

            foreach (string path in typeCategory.Paths)
            {
                Directory.CreateDirectory($"{WikiAssetGenerator.BasePath}\\Components\\{path}\\");
                componentImage.Save($"{WikiAssetGenerator.BasePath}\\Components\\{path}\\{typeSafeName}Component.png", 100, true);
            }
            VisualSlot.DestroyChildren();
        }
Esempio n. 3
0
        protected override void UpdateTextureData(Bitmap2D tex2D)
        {
            tex2D.Clear(color.White);
            height = tex2D.Size.y;
            width  = tex2D.Size.x;
            rangeX = max.Value.x - min.Value.x;
            rangeY = max.Value.y - min.Value.y;

            CreateNewton(tex2D);
        }
Esempio n. 4
0
 public override void Dispose()
 {
     if (_graph != null)
     {
         _graph.Dispose();
     }
     _graph = null;
     Destroy(_image);
     _image = null;
     base.Dispose();
 }
Esempio n. 5
0
        private async void CaptureImage()
        {
            Camera componentCamera = Slot.GetComponent <Camera>();

            if (componentCamera != null)
            {
                double aspectRatio     = ((double)lastContent.RectTransform.BoundingRect.height + 5.0) / (double)lastContent.RectTransform.BoundingRect.width;
                Slot   componentVisual = Slot.FindChild(S => S.Name == "Visual");
                componentVisual.LocalPosition          = new float3(0, ((((lastContent.RectTransform.BoundingRect.height / 2.0f) - lastContent.RectTransform.BoundingRect.Center.y) / 2.0f) + 5.0f) * 0.001f, 0.5f);
                componentCamera.OrthographicSize.Value = (lastContent.RectTransform.BoundingRect.height + 5) / 2000.0f;
                Bitmap2D logixTex = await componentCamera.RenderToBitmap(new int2(512, (int)(512.0f * aspectRatio)));

                logixTex.Save($"{BasePath}Data\\CustomCapture{CaptureIndex}.png", 100, true);
            }
        }
        private void CreateJuliaGpu(Bitmap2D tex2D)
        {
            int[] iterArray = new int[width * height];
            GpuRef.ComputeJulia(iterArray, width, height, min.Value.x, min.Value.y, rangeX, rangeY, customConstant.Value[0], customConstant.Value[1]);
            float colorToUse;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    colorToUse = iterArray[y * width + x] / maxIterations;
                    tex2D.SetPixel(x, y, new color(colorToUse, colorToUse, colorToUse)); //depending on the number of iterations, color a pixel.
                }
            }
        }
        protected override void UpdateTextureData(Bitmap2D tex2D)
        {
            height = tex2D.Size.y;
            width  = tex2D.Size.x;
            rangeX = max.Value.x - min.Value.x;
            rangeY = max.Value.y - min.Value.y;

            try
            {
                CreateMandelbrotGpu(tex2D);
            }
            catch (DllNotFoundException)
            {
                CreateMandelbrot(tex2D);
            }
        }
        protected override void UpdateTextureData(Bitmap2D tex2D)
        {
            tex2D.Clear(color.White);
            height = tex2D.Size.y;
            width  = tex2D.Size.x;
            rangeX = max.Value.x - min.Value.x;
            rangeY = max.Value.y - min.Value.y;

            try
            {
                CreateJuliaGpu(tex2D);
            }
            catch (DllNotFoundException)
            {
                CreateJulia(tex2D);
            }
        }
Esempio n. 9
0
        private void CreateNewton(Bitmap2D tex2D)
        {
            Complex coords;
            int     iterations;
            Complex epsilon;
            float   colorToUse;
            double  magSquared;

            const double cutoff = 0.00000000001;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    coords     = ConvertPixToCoords(x, y);
                    iterations = 0;

                    do
                    {
                        epsilon = -(F(coords) / dFdx(coords));
                        coords += epsilon;
                        iterations++;
                        magSquared = Math.Pow(Complex.Abs(epsilon), 2);
                    }while (magSquared > cutoff && iterations < maxIterations);

                    if (iterations < maxIterations)
                    {
                        colorToUse = 0;
                        if (Math.Abs(coords.Real + .5) < .001 && Math.Abs(coords.Imaginary + .866) < .001)
                        {
                            colorToUse = 0;
                        }
                        else if (Math.Abs(coords.Real - 1) < .001 && Math.Abs(coords.Imaginary) < .001)
                        {
                            colorToUse = .5f;
                        }
                        else if (Math.Abs(coords.Real + .5) < .001 && Math.Abs(coords.Imaginary - .866) < .001)
                        {
                            colorToUse = 1;
                        }
                        tex2D.SetPixel(x, y, new color(colorToUse, colorToUse, colorToUse)); //depending on the number of iterations, color a pixel.
                    }
                }
            }
        }
Esempio n. 10
0
        // ----------------------------------------------------------------------------
        // Protected & Private Methods
        // ----------------------------------------------------------------------------

        protected override GameObject CreateChildren()
        {
            _fpsColors = new Color?[3];

            GameObject container = new GameObject();

            container.name = "GraphView";
            container.transform.SetParent(_statsMonitor.transform, false);

            _graph = new Bitmap2D(10, 10, _statsMonitor.colorGraphBG);

            _image = container.AddComponent <RawImage>();
            _image.rectTransform.sizeDelta = new Vector2(10, 10);
            _image.color   = Color.white;
            _image.texture = _graph.texture;

            /* Calculate estimated memory ceiling for application. */
            int sysMem = SystemInfo.systemMemorySize;

            if (sysMem <= 1024)
            {
                _memCeiling = 512;
            }
            else if (sysMem > 1024 && sysMem <= 2048)
            {
                _memCeiling = 1024;
            }
            else
            {
                _memCeiling = 2048;
            }

            gameObject = container;

            var element = container.AddComponent <LayoutElement>();

            element.preferredHeight = _statsMonitor.GraphHeight;
            return(container);
        }
        public override async Task GenerateVisual(object typeInstance, Type neosType, bool force = false)
        {
            SyncObject targetInstance = typeInstance as SyncObject;
            string     typeSafeName   = GetSafeName(neosType);

            if (!(force || NeedsVisual(typeSafeName)))
            {
                return;
            }

            Rect bounds = await BuildSyncMemberUI(targetInstance);

            double aspectRatio = (bounds.height + 5.0) / bounds.width;

            VisualSlot.LocalPosition = new float3(0, ((((bounds.height / 2.0f) - bounds.Center.y) / 2.0f) + 5.0f) * 0.1f, 0.5f);
            VisualCaptureCamera.OrthographicSize.Value = (bounds.height + 5) / 20.0f;
            await new ToWorld();
            Bitmap2D componentImage = await VisualCaptureCamera.RenderToBitmap(new int2(400, (int)(400 * aspectRatio)));

            componentImage.Save($"{WikiAssetGenerator.BasePath}\\SyncTypes\\{typeSafeName}SyncType.png", 100, true);
            VisualSlot.DestroyChildren();
        }
        private void CreateJulia(Bitmap2D tex2D)
        {
            double2 coords;
            int     iterations;
            double  realZ  = 0;
            double  imagZ  = 0;
            double  realZ2 = 0;
            double  imagZ2 = 0;
            double  realC  = customConstant.Value[0];
            double  imagC  = customConstant.Value[1];
            float   colorToUse;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    coords = ConvertPixToCoords(x, y);
                    realZ  = coords[0] + realC;
                    imagZ  = coords[1] + imagC;

                    iterations = 0;
                    while (iterations < maxIterations)
                    {
                        iterations++;
                        realZ2 = realZ * realZ;
                        imagZ2 = imagZ * imagZ;
                        if (realZ2 + imagZ2 > 4)
                        {
                            break;
                        }
                        imagZ = 2 * realZ * imagZ + imagC;
                        realZ = realZ2 - imagZ2 + realC;
                    }
                    colorToUse = iterations / maxIterations;
                    tex2D.SetPixel(x, y, new color(1 - colorToUse, 1 - colorToUse, 1 - colorToUse)); //depending on the number of iterations, color a pixel.
                }
            }
        }
Esempio n. 13
0
 //Record one frame of the head camera for each user
 public void RecordVision()
 {
     foreach (var item in visual_recorders)
     {
         RefID         user_id       = item.Key;
         VideoRecorder videoRecorder = item.Value;
         if (videoRecorder != null && cameras[user_id] != null)
         {
             Task task = metagen_comp.StartTask((Func <Task>)(async() =>
             {
                 Bitmap2D bmp = await cameras[user_id].RenderToBitmap(camera_resolution);
                 visual_recorders[user_id].WriteFrame(bmp.ConvertTo(CodeX.TextureFormat.BGRA32).RawData);
                 //UniLog.Log(DateTime.UtcNow.ToMillisecondTimeString());
             }));
             //TODO: sync video
             //task.Wait();
             //World currentWorld = metagen_comp.World;
             //FrooxEngine.RenderSettings renderSettings = cameras[user_id].GetRenderSettings(camera_resolution);
             //byte[] data = currentWorld.Render.Connector.Render(renderSettings).Result;
             //Bitmap2D bmp = new Bitmap2D(data, renderSettings.size.x, renderSettings.size.y, renderSettings.textureFormat, false, true, (string)null);
             //visual_recorders[user_id].WriteFrame(bmp.ConvertTo(CodeX.TextureFormat.BGRA32).RawData);
         }
         else
         { //something was null:P
             bool vis_rec_null = false;
             bool camera_null  = false;
             if (visual_recorders[user_id] == null)
             {
                 vis_rec_null = true;
             }
             if (cameras[user_id] == null)
             {
                 camera_null = true;
             }
             UniLog.Log("OwO. These things were null: " + (camera_null ? "Camera" : "") + (vis_rec_null ? "Visual recorder" : ""));
         }
     }
 }