Esempio n. 1
0
    private void RenderCollision2D <T>(Type type) where T : Collider2D
    {
        T[]   colliders = UnityEngine.Object.FindObjectsOfType <T>();
        Color color     = ColliderColor(type);

        AddToRenderList2D(colliders);

        switch (type)
        {
        case Type.Boxes:
            Box2D.Render(colliderList2D, color, EdgeAlpha, color, FaceAlpha, IsSet(Flags.NoDepth));
            Box2D.Render(triggerList2D, triggerColor, EdgeAlpha, triggerColor, FaceAlpha, IsSet(Flags.NoDepth));
            break;

        case Type.Spheres:
            Circle2D.Render(colliderList2D, color, EdgeAlpha, color, FaceAlpha, IsSet(Flags.NoDepth));
            Circle2D.Render(triggerList2D, triggerColor, EdgeAlpha, triggerColor, FaceAlpha, IsSet(Flags.NoDepth));
            break;

        case Type.Meshes:
            if (typeof(T) == typeof(EdgeCollider2D))
            {
                Edge2D.Render(colliderList2D, color, EdgeAlpha, color, FaceAlpha, IsSet(Flags.NoDepth));
                Edge2D.Render(triggerList2D, triggerColor, EdgeAlpha, triggerColor, FaceAlpha, IsSet(Flags.NoDepth));
            }
            else
            {
                Mesh2D.Render(colliderList2D, color, EdgeAlpha, color, FaceAlpha, IsSet(Flags.NoDepth));
                Mesh2D.Render(triggerList2D, triggerColor, EdgeAlpha, triggerColor, FaceAlpha, IsSet(Flags.NoDepth));
            }
            break;
        }

        guiColliderCount[(int)type] += colliderList2D.Count + triggerList2D.Count;
    }
Esempio n. 2
0
    void Update()
    {
        Polygon2D polygonA = Polygon2DList.CreateFromGameObject(sliceableA)[0].ToWorldSpace(sliceableA.transform);
        Polygon2D polygonB = Polygon2DList.CreateFromGameObject(sliceableB)[0].ToWorldSpace(sliceableB.transform);

        Polygon2D MergedPolygon = Merge2D.Merge(polygonA, polygonB);

        if (resultObject != null)
        {
            UnityEngine.Object.Destroy(resultObject);
        }

        if (MergedPolygon != null)
        {
            //UnityEngine.Object.Destroy(sliceableA.gameObject);
            //UnityEngine.Object.Destroy(sliceableB.gameObject);


            resultObject = new GameObject("Merged Polygon");
            MergedPolygon.CreatePolygonCollider(resultObject);

            Mesh2D mesh = resultObject.AddComponent <Mesh2D>();
            mesh.material = OutputMaterial;

            resultObject.AddComponent <ColliderLineRenderer2D>();
        }
    }
Esempio n. 3
0
    void MakeShape()
    {
        float angle      = 0.0f;
        float deltaAngle = 360.0f / NumShapeVertices;
        float u          = 0.0f;
        float deltaU     = 1f / NumShapeVertices;

        shape               = new Mesh2D();
        shape.vertices      = new Mesh2D.Vertex[NumShapeVertices];
        shape.lineSegements = new Vector2Int[NumShapeVertices];

        Vector2 pStart = new Vector2(Mathf.Cos(angle) * radius, Mathf.Sin(angle) * radius);

        angle                   += deltaAngle;
        shape.vertices[0]        = new Mesh2D.Vertex();
        shape.vertices[0].point  = pStart;
        shape.vertices[0].normal = pStart.normalized;
        shape.vertices[0].u      = u;
        u += deltaU;

        for (int i = 1; i < NumShapeVertices; ++i)
        {
            Vector2 p1 = new Vector2(Mathf.Cos(angle) * radius, Mathf.Sin(angle) * radius);
            angle                   += deltaAngle;
            shape.vertices[i]        = new Mesh2D.Vertex();
            shape.vertices[i].point  = p1;
            shape.vertices[i].normal = p1.normalized;
            shape.vertices[i].u      = u;
            u += deltaU;

            shape.lineSegements[i] = new Vector2Int(i - 1, i);
        }
    }
Esempio n. 4
0
 public SpriteRenderer(Texture texture, Shader shader, Mesh2D mesh)
 {
     Transform = new Transform();
     Texture   = texture;
     Shader    = shader;
     Mesh      = mesh;
 }
Esempio n. 5
0
        protected override void Initialize()
        {
            shader  = new Shader("Resources/Shaders/vertex.shader", "Resources/Shaders/fragment.shader");
            texture = new Texture("Resources/Graphics/test1.png");
            var mesh = new Mesh2D(vertices, indices);

            sprite = new SpriteRenderer(texture, shader, mesh);
        }
Esempio n. 6
0
        public Text(FreetypeFont Font, string Text, Vector2 Position, Quaternion Rotation, Color Color)
        {
            this.Font     = Font;
            this.String   = Text;
            this.Position = Position;
            this.Rotation = Rotation;
            this.Color    = Color;

            Mesh = new Mesh2D();
        }
Esempio n. 7
0
        public override void Initialize()
        {
            base.Initialize();

            Material mat = ResourceManger.Instance.Get <Material> (matUrl);

            meshRenderer.material = mat;

            Mesh2D.CreateVecticeMesh(meshFilter, Vectices);
            Mesh2D.CreateColorMaterial(meshRenderer, Color);
            meshCollider.sharedMesh = meshFilter.mesh;
        }
Esempio n. 8
0
        public NineSlice(Texture NineSlice, float Border)
        {
            this.Border = Border;

            Color    = Color.White;
            Rotation = Quaternion.Identity;
            Position = Vector2.Zero;
            Size     = new Vector2(50, 50);

            Texture = NineSlice;
            Mesh    = new Mesh2D();

            Boxes = new List <Tuple <int, AABB> >();
        }
Esempio n. 9
0
        //This is called when the app has set up all the platform/context/etc. code
        //This is also where you'd load any global assets, etc.
        //Basically, don't interact with the Rise API until this is called
        static void Init()
        {
            logo = new Texture2D("Assets/rise_logo.png", true);
            star = new Texture2D("Assets/star.png", true);

            mesh = new Mesh2D();

            var shader = new Shader(Shader.Basic2D);

            material = new Material(shader);

            Screen.ClearColor = 0x1e4e50ff;

            Console.WriteLine("WIDTH: " + Screen.Width);
            Console.WriteLine("WINDOW_WIDTH: " + Screen.Width);
        }
Esempio n. 10
0
        private void RefreshSelectionMesh()
        {
            if (m_SelectionMesh != null)
            {
                m_SelectionMesh.CleanupMeshes();
            }
            MeshBuilder mb = new MeshBuilder();

            if (_selectedItem != null)
            {
                mb.Add(0, new MeshBuilder.Rectangle(_selectedItem.Position, Color.white), false);
            }
            else if (_selectedGroup != null)
            {
                mb.Add(0, new MeshBuilder.Rectangle(_selectedGroup.Position, Color.white * 0.8f), false);
            }
            m_SelectionMesh = mb.CreateMesh();
        }
Esempio n. 11
0
        private void RefreshGroupMesh(Group group)
        {
            if (m_SelectionGroupMesh != null)
            {
                m_SelectionGroupMesh.CleanupMeshes();
            }

            MeshBuilder mb = new MeshBuilder();

            foreach (Item item in group.Items)
            {
                Rect r     = item.Position;
                var  color = item.Color;
                mb.Add(0, new MeshBuilder.Rectangle(r, color, color * 0.75f, color * 0.5f, color * 0.75f), true);
            }

            m_SelectionGroupMesh = mb.CreateMesh();
        }
Esempio n. 12
0
        private void RefreshMesh()
        {
            if (m_Mesh != null)
            {
                m_Mesh.CleanupMeshes();
            }

            MeshBuilder mb = new MeshBuilder();

            foreach (Group group in _groups.Values)
            {
                Rect r     = group.Position;
                var  color = group.Color;
                mb.Add(0, new MeshBuilder.Rectangle(r, color, color * 0.75f, color * 0.5f, color * 0.75f), true);
            }

            m_Mesh = mb.CreateMesh();
        }
Esempio n. 13
0
 public void CleanupMeshes()
 {
     if (m_Mesh != null)
     {
         m_Mesh.CleanupMeshes();
     }
     m_Mesh = null;
     if (m_SelectionMesh != null)
     {
         m_SelectionMesh.CleanupMeshes();
     }
     m_SelectionMesh = null;
     if (m_SelectionGroupMesh != null)
     {
         m_SelectionGroupMesh.CleanupMeshes();
     }
     m_SelectionGroupMesh = null;
 }
Esempio n. 14
0
    override public void OnInspectorGUI()
    {
        Mesh2D script = target as Mesh2D;

        script.triangulation = (PolygonTriangulator2D.Triangulation)EditorGUILayout.EnumPopup("Triangulation Type", script.triangulation);

        script.material = (Material)EditorGUILayout.ObjectField(script.material, typeof(Material), true);

        script.materialScale  = EditorGUILayout.Vector2Field("Material Scale", script.materialScale);
        script.materialOffset = EditorGUILayout.Vector2Field("Material Offset", script.materialOffset);

        script.sortingLayerName = EditorGUILayout.TextField("Sorting Layer Name", script.sortingLayerName);
        script.sortingOrder     = EditorGUILayout.IntField("Sorting Order", script.sortingOrder);

        if (GUILayout.Button("Update Mesh"))
        {
            script.Initialize();
        }
    }
Esempio n. 15
0
        public NineSlice(Texture NineSlice, float BorderTop, float BorderBottom, float BorderLeft, float BorderRight)
        {
            this.BorderTop    = BorderTop;
            this.BorderBottom = BorderBottom;
            this.BorderLeft   = BorderLeft;
            this.BorderRight  = BorderRight;

            BorderTopScale = BorderBottomScale = BorderLeftScale = BorderRightScale = 1;

            Color    = Color.White;
            Rotation = Quaternion.Identity;
            Position = Vector2.Zero;
            Size     = new Vector2(50, 50);

            Texture = NineSlice;
            Mesh    = new Mesh2D();

            Boxes = new List <Tuple <int, AABB> >();
        }
Esempio n. 16
0
        // Use this for initialization
        public override void Initialize()
        {
            base.Initialize();
            if (Image == null)
            {
                return;
            }

            Material mat = ResourceManger.Instance.Get <Material> (matUrl);

            meshRenderer.material = mat;

            Vector3 size = new Vector3(Image.width, 1, Image.height);

            Mesh2D.CreateTextureMesh(meshFilter, size);
            Mesh2D.CreateTextureMaterial(meshRenderer, Image);

            meshCollider.sharedMesh = meshFilter.mesh;

            TouchListener.Instance.AddDispatch(this.gameObject, OnTouchMe);
        }
Esempio n. 17
0
    private void setMeshComponent()
    {
        Mesh2D tMesh = findChild <Mesh2D>("mesh");

        if (tMesh == null)
        {
            switch (mType)
            {
            case AccessoryType.lie:
                tMesh = this.createChild <LieMesh>();
                break;

            case AccessoryType.stand:
                tMesh = this.createChild <StandMesh>();
                break;
            }
            tMesh.name = "mesh";
            return;
        }
        switch (mType)
        {
        case AccessoryType.lie:
            if (tMesh is StandMesh)
            {
                tMesh = tMesh.gameObject.AddComponent <LieMesh>();
                Destroy(tMesh.GetComponent <StandMesh>());
            }
            break;

        case AccessoryType.stand:
            if (tMesh is LieMesh)
            {
                tMesh = tMesh.gameObject.AddComponent <StandMesh>();
                Destroy(tMesh.GetComponent <LieMesh>());
            }
            break;
        }
    }
Esempio n. 18
0
        static void Init()
        {
            int screenW = Screen.Width;
            int screenH = Screen.Height;

            Texture.DefaultMinFilter = TextureFilter.Nearest;
            Texture.DefaultMagFilter = TextureFilter.Nearest;

            //Load assets
            var shader2D    = Shader.FromFile("Assets/basic_2d.glsl");
            var shader3D    = Shader.FromFile("Assets/basic_3d_nobuffer.glsl");
            var shaderG     = Shader.FromFile("Assets/basic_3d_gbuffer.glsl");
            var shaderDepth = Shader.FromFile("Assets/basic_3d_depth.glsl");
            var shaderPos   = Shader.FromFile("Assets/basic_3d_position.glsl");
            var pinkSquare  = new Texture2D("Assets/pink_square.png", true);
            var mesh        = Mesh3D.CreateBox(Vector3.One, Color4.White);
            //var mesh = Mesh3D.CreateSphere(0.5f, 10, Color4.White);
            //var mesh = Mesh3D.CreateCylinder(0.5f, 1f, 10, true);
            //var mesh = Mesh3D.CreateCone(0.5f, 2f, 10);

            //Create the g-buffer
            var gDepth  = new Texture2D(screenW, screenH, TextureFormat.Depth);
            var gColor  = new Texture2D(screenW, screenH, TextureFormat.RGB);
            var gNormal = new Texture2D(screenW, screenH, TextureFormat.RGB16F);
            var gZ      = new Texture2D(screenW, screenH, TextureFormat.R32F);
            var gBuffer = new RenderTarget(screenW, screenH, gDepth, gColor, gNormal, gZ);

            //View
            var scene      = new Scene(screenW, screenH);
            var viewRot    = false;
            var viewRotPos = Vector2.Zero;

            //Create a model
            var cube = new Model(mesh, pinkSquare);

            cube.Scale = new Vector3(2f, 0.75f, 1f);
            scene.Add(cube);

            //Create a model
            cube          = new Model(mesh, pinkSquare);
            cube.Scale    = new Vector3(0.75f);
            cube.Position = new Vector3(0f, 0.5f, -2f);
            scene.Add(cube);

            //Draw to buffer
            var draw = new DrawCall(gBuffer, new Material(shaderG));

            //Draw to screen
            int w        = screenW / 2;
            int h        = screenH / 2;
            var toScreen = new DrawCall(new Material(shaderPos));

            toScreen.Mesh = Mesh2D.CreateRect(new Rectangle(0, 0, w, h));
            toScreen.Material.SetMatrix4x4("Matrix", Matrix4x4.CreateOrthographic(0f, screenW, 0, screenH, -1f, 1f));
            toScreen.Material.SetTexture("ZBuffer", gDepth);

            App.OnUpdate += Update;
            App.OnRender += Render;
            Update();
            void Update()
            {
                //Pivoting
                if (viewRot)
                {
                    var move = Mouse.Position - viewRotPos;
                    if (move != Vector2.Zero)
                    {
                        scene.ViewAngle += move * 6f * Time.Delta;
                        viewRotPos       = Mouse.Position;
                    }
                    if (!Mouse.LeftDown)
                    {
                        viewRot = false;
                    }
                }
                else if (Mouse.LeftPressed)
                {
                    viewRot    = true;
                    viewRotPos = Mouse.Position;
                }

                //Zooming
                if (Mouse.ScrollY != 0)
                {
                    scene.ViewDist -= Mouse.ScrollY * 10f * Time.Delta;
                }
            }

            void Render()
            {
                int modelID   = draw.Material.GetIndex("ModelMatrix");
                int mvpID     = draw.Material.GetIndex("ModelViewProjectionMatrix");
                int textureID = draw.Material.GetIndex("Texture");

                draw.Clear(0x1f171fff);
                foreach (var model in scene.Models)
                {
                    draw.Material.SetMatrix4x4(modelID, model.Matrix);
                    draw.Material.SetMatrix4x4(mvpID, model.MvpMatrix);
                    draw.Material.SetTexture(textureID, model.Texture);
                    draw.Mesh = model.Mesh;
                    draw.Perform(PrimitiveType.Triangles);
                }

                //toScreen.Perform(Color3.Black);
                gBuffer.BlitTextureTo(null, 0, BlitFilter.Linear, new RectangleI(0, h, w, h));
                gBuffer.BlitTextureTo(null, 1, BlitFilter.Linear, new RectangleI(w, h, w, h));
                gBuffer.BlitTextureTo(null, 2, BlitFilter.Linear, new RectangleI(w, 0, w, h));

                toScreen.Material.SetMatrix4x4("ProjMatrix", scene.ProjMatrix);
                toScreen.Material.SetMatrix4x4("ViewMatrix", scene.ViewMatrix);
                toScreen.Perform(PrimitiveType.Triangles);
            }
        }
Esempio n. 19
0
        //static OpenGLDevice NuklearDev;

        static void Main(string[] args)
        {
            /*IBWFile F = IBWLoader.Load("dataset/ibw/Image0018.ibw");
             *
             * for (int i = 0; i < F.Depth; i++) {
             *      Bitmap Bmp = new Bitmap(F.Width, F.Height);
             *
             *      int D_Dim = i;
             *
             *      float Min = float.MaxValue;
             *      float Max = float.MinValue;
             *
             *      for (int y = 0; y < F.Height; y++) {
             *              for (int x = 0; x < F.Width; x++) {
             *                      float Flt = (float)F.GetData(x, y, D_Dim) * 1000000000;
             *
             *                      Min = Math.Min(Min, Flt);
             *                      Max = Math.Max(Max, Flt);
             *              }
             *      }
             *
             *      float Offset = -Min;
             *      float OffsetMax = Max + Offset;
             *      float ScaleVal = 255.0f / OffsetMax;
             *
             *      Min = float.MaxValue;
             *      Max = float.MinValue;
             *
             *      for (int y = 0; y < F.Height; y++) {
             *              for (int x = 0; x < F.Width; x++) {
             *                      float Flt = ((float)F.GetData(x, y, D_Dim) * 1000000000 + Offset) * ScaleVal;
             *
             *                      int Clr = (int)Flt;
             *                      Bmp.SetPixel(x, F.Height - y - 1, System.Drawing.Color.FromArgb(255, Clr, Clr, Clr));
             *              }
             *      }
             *
             *      Bmp.Save("test_" + i + ".png");
             * }
             *
             *
             * File.WriteAllText("text_data.txt", F.NoteData);
             *
             *
             * Console.WriteLine("Done!");
             * Console.ReadLine();
             * return;//*/



            const float Scale = 0.9f;

            ClearColor = new FishGfx.Color(60, 80, 100);

            RenderAPI.GetDesktopResolution(out int W, out int H);
            RWind = new RenderWindow((int)(W * Scale), (int)(H * Scale), "Vector PFM");

            Console.WriteLine("OpenGL {0}", RenderAPI.Version);
            Console.WriteLine("Running on {0}", RenderAPI.Renderer);

            // Load shader programs
            Shader_DrawRayCast = new ShaderProgram(new ShaderStage(ShaderType.VertexShader, "data/default3d.vert"),
                                                   new ShaderStage(ShaderType.FragmentShader, "data/defaultRayCast.frag"));
            Shader_DrawRayCast.Uniforms.Camera.SetPerspective(RWind.GetWindowSizeVec());
            Shader_DrawRayCast.Uniforms.Camera.Position   = new Vector3(0, 300, 0);
            Shader_DrawRayCast.Uniforms.Camera.PitchClamp = new Vector2(-80, 80);

            Shader_DrawFlat = new ShaderProgram(new ShaderStage(ShaderType.VertexShader, "data/default3d.vert"),
                                                new ShaderStage(ShaderType.FragmentShader, "data/defaultFlatColor.frag"));
            Shader_DrawFlat.Uniforms.Camera = Shader_DrawRayCast.Uniforms.Camera;

            Shader_Screen = new ShaderProgram(new ShaderStage(ShaderType.VertexShader, "data/default.vert"),
                                              new ShaderStage(ShaderType.FragmentShader, "data/default.frag"));
            Shader_Screen.Uniforms.Camera.SetOrthogonal(0, 0, 1, 1);

            Shader_Textured = new ShaderProgram(new ShaderStage(ShaderType.VertexShader, "data/default3d.vert"),
                                                new ShaderStage(ShaderType.FragmentShader, "data/default.frag"));
            Shader_Textured.Uniforms.Camera = Shader_DrawRayCast.Uniforms.Camera;

            //NuklearDev = new OpenGLDevice(RWind.GetWindowSizeVec());
            //NuklearAPI.Init(NuklearDev);

            RWind.OnMouseMoveDelta += (Wnd, X, Y) => Shader_DrawRayCast.Uniforms.Camera.Update(new Vector2(-X, -Y));
            RWind.OnKey            += OnKey;
            //RWind.OnMouseMove += (Wnd, X, Y) => NuklearDev.OnMouseMove((int)X, (int)Y);

            RWind.OnMouseMoveDelta += (Wnd, X, Y) => {
                if (LeftMouse)
                {
                    const float MoveSpeed = 1.0f;

                    if (X != 0 || Y != 0)
                    {
                        Camera Cam = Shader_DrawRayCast.Uniforms.Camera;

                        if (X != 0)
                        {
                            Cam.Position -= Cam.WorldRightNormal * MoveSpeed * -X;
                        }

                        if (Y != 0)
                        {
                            Cam.Position += Cam.WorldUpNormal * MoveSpeed * -Y;
                        }

                        RecalcCamera();
                    }
                }
                else if (RightMouse)
                {
                    DesiredPivotDistance += Y;
                    RecalcCamera();
                }
            };

            HMap = new Terrain();
            HMap.LoadFromImage(Image.FromFile("dataset/data2/heightmap.png"), 100);
            //HMap.LoadFromImage(Image.FromFile("dataset/height_test.png"), 10);
            //HMap.LoadFromImage(Image.FromFile("dataset/owl.png"), 100);


            DesiredPivotDistance = float.PositiveInfinity;
            CameraPivot          = new Vector3(HMap.Width / 2, HMap.GetHeight(HMap.Width / 2, HMap.Height / 2), HMap.Height / 2);
            RecalcCamera();

            PinMesh = new Mesh3D {
                PrimitiveType = PrimitiveType.Triangles
            };
            PinMesh.SetVertices(GfxUtils.LoadObj("data/models/pin/pin.obj"));

            PinTexture = Texture.FromFile("data/models/pin/pin_mat.png");

            Mesh3D Vectors = new Mesh3D {
                PrimitiveType = PrimitiveType.Lines
            };

            {
                //Vertex3[] Verts = new Vertex3[HMap.Width * HMap.Height * 2];
                List <Vertex3> Verts = new List <Vertex3>();

                for (int i = 0; i < HMap.Width * HMap.Height * 2; i += 2)
                {
                    int X = (i / 2) % HMap.Width;
                    int Y = (i / 2) / HMap.Width;

                    const int Density = 2;
                    if (X % Density != 0 || Y % Density != 0)
                    {
                        continue;
                    }

                    float Height = HMap.GetHeight(X, Y);

                    Verts.Add(new Vertex3(new Vector3(X, Height - 0.5f, Y), FishGfx.Color.Black));
                    Verts.Add(new Vertex3(new Vector3(X, Height + 20, Y), FishGfx.Color.White));
                }

                Vectors.SetVertices(Verts.ToArray());
            }

            RWind.GetWindowSize(out int WindowWidth, out int WindowHeight);
            RenderTexture Screen = new RenderTexture(WindowWidth, WindowHeight);

            RayCastingTexture = Screen.CreateNewColorAttachment(1);

            Background = Texture.FromFile("data/background.png");

            Mesh2D ScreenQuad = new Mesh2D();

            ScreenQuad.SetVertices(new Vertex2[] {
                new Vertex2(new Vector2(0, 0), new Vector2(0, 0)),
                new Vertex2(new Vector2(0, 1), new Vector2(0, 1)),
                new Vertex2(new Vector2(1, 1), new Vector2(1, 1)),
                new Vertex2(new Vector2(1, 0), new Vector2(1, 0))
            });
            ScreenQuad.SetElements(new uint[] { 0, 1, 2, 0, 2, 3 }.Reverse().ToArray());

            Stopwatch SWatch = Stopwatch.StartNew();
            float     Dt     = 0;

            while (!RWind.ShouldClose)
            {
                Update(Dt);

                // Draw the world onto a render texture including the ray casting buffer
                Screen.Bind(0, 1);
                {
                    Shader_DrawRayCast.Bind();
                    Gfx.Clear(FishGfx.Color.Transparent);

                    /*Gfx.EnableCullFace(false);
                     * HMap.Draw();
                     * Gfx.EnableCullFace(true);*/

                    // Draw back face
                    Gfx.CullFront();
                    Texture Orig = HMap.OverlayTexture;
                    HMap.OverlayTexture = Background;
                    HMap.Draw();

                    // Draw front face
                    Gfx.CullBack();
                    HMap.OverlayTexture = Orig;
                    HMap.Draw();

                    Shader_DrawRayCast.Unbind();
                }
                Screen.Unbind();

                // Draw other stuff
                Screen.Bind(0);
                {
                    Shader_DrawFlat.Bind();
                    Vectors.Draw();
                    Shader_DrawFlat.Unbind();

                    Shader_Textured.Bind();
                    Shader_Textured.SetModelMatrix(Matrix4x4.CreateScale(2) * Matrix4x4.CreateTranslation(CameraPivot));
                    PinTexture.BindTextureUnit();
                    PinMesh.Draw();
                    PinTexture.UnbindTextureUnit();
                    Shader_Textured.Unbind();
                }
                Screen.Unbind();

                // Draw render texture and GUI to screen
                Shader_Screen.Bind();
                {
                    Gfx.Clear(ClearColor);
                    Gfx.EnableDepthDest(false);

                    if (FunctionMode == 1)
                    {
                        Screen.Color.BindTextureUnit();
                    }
                    else if (FunctionMode == 2)
                    {
                        RayCastingTexture.BindTextureUnit();
                    }

                    ScreenQuad.Draw();
                    //NuklearAPI.Frame(DrawGUI);
                    Gfx.EnableDepthDest(true);
                }
                Shader_Screen.Unbind();

                // Swap buffers, do magic
                RWind.SwapBuffers();
                Events.Poll();

                while (SWatch.ElapsedMilliseconds / 1000.0f < 1.0f / 60.0f)
                {
                    ;
                }
                Dt = SWatch.ElapsedMilliseconds / 1000.0f;
                SWatch.Restart();
            }
        }
Esempio n. 20
0
    // Use this for initialization
    void Start()
    {
        // INIT  ---  ---  INIT  ---  ---  INIT
        System.DateTime previousTime = System.DateTime.Now;
        meshUsed = new Mesh2D <int, int>(points.ToArray(), false);
        System.TimeSpan delta = System.DateTime.Now - previousTime;
        Debug.Log("***");
        Debug.Log(string.Format("*** INIT *** {0} secondes OU {1} milliseconds *** INIT",
                                delta.TotalSeconds, delta.TotalMilliseconds));


        // TRIANGULATION  ---  ---  TRIANGULATION  ---  ---  TRIANGULATION
        previousTime = System.DateTime.Now;
        meshUsed.Construct();
        delta = System.DateTime.Now - previousTime;
        Debug.Log("***");
        Debug.Log(string.Format("*** TRIANGULATION *** {0} secondes OU {1} milliseconds *** TRIANGULATION",
                                delta.TotalSeconds, delta.TotalMilliseconds));

        Vec3 pos;

        // Avoid infinite because safe not used some Insert method (needed for testing)
        if (points.Count > 10)
        {
            // LOCATE  ---  ---  LOCATE  ---  ---  LOCATE
            // points >= 10 | seed 154
            pos = new Vec3(0.72 * boundaries[0], 0.546 * boundaries[1], 0.0);
            // var newGo = GameObject.Instantiate(shapes[0]);
            // newGo.name = "PointLocated";
            // newGo.transform.SetParent(transform);
            // newGo.transform.position = pos.AsVector3();
            // newGo.transform.localScale = new Vector3(5.0f, 5.0f, 5.0f);
            // // Color
            // var meshR = newGo.GetComponent<MeshRenderer>();
            // if (meshR != null)
            // {
            //     meshR.materials[0].color = Color.green;
            // }
            // Start locate
            previousTime = System.DateTime.Now;
            var edge = meshUsed.Locate(pos, safe: true);

            delta = System.DateTime.Now - previousTime;
            Debug.Log("***");
            Debug.Log(string.Format("*** LOCATE *** {0} secondes OU {1} milliseconds *** LOCATE",
                                    delta.TotalSeconds, delta.TotalMilliseconds));
            Debug.Log("Point is inside: " + meshUsed.InsideConvexHull(pos));
            Debug.Log("Edge origin is: " + edge.Origin);


            // INSERT  ---  ---  INSERT  ---  ---  INSERT
            // points >= 10 | seed 154
            previousTime = System.DateTime.Now;
            pos          = new Vec3(1.1 * boundaries[0], 0.8 * boundaries[1], 0.0);
            bool result = meshUsed.Insert(pos, safe: true);
            Debug.Log("Site outside --> Not added: " + !result);
            pos    = new Vec3(0.72265633333 * boundaries[0], 0.54732506667 * boundaries[1], 0.0);
            result = meshUsed.Insert(pos);
            Debug.Log("Site already existing --> Not added: " + !result);
            pos    = new Vec3(0.76666666666667 * boundaries[0], pos.Y, pos.Z);
            result = meshUsed.Insert(pos);
            Debug.Log("Inside convex Hull --> Added: " + result);
            delta = System.DateTime.Now - previousTime;
            Debug.Log("***");
            Debug.Log(string.Format("*** INSERT *** {0} secondes OU {1} milliseconds *** INSERT",
                                    delta.TotalSeconds, delta.TotalMilliseconds));
        }

        // DRAWING  ---  ---  DRAWING  ---  ---  DRAWING
        previousTime = System.DateTime.Now;

        // Draw Delaunay
        var triangles = meshUsed.Triangles().ToList();

        if (D_faces)
        {
            TriangleDrawer.DrawFace(triangles, transform, mat, gradient);
        }
        if (D_lines)
        {
            TriangleDrawer.DrawLine(triangles, transform, mat, Color.black, lineScale);
        }
        if (D_points)
        {
            TriangleDrawer.DrawPoints(triangles, transform, shapes[0], Color.red, 1.1f * scale);
        }

        // Get faces
        List <Face <int, int> > faces = meshUsed.Faces(celltype, Mathf.Max(boundaries) * 5.0, true)
                                        // .InsideHull()
                                        // .FiniteBounds()
                                        // .Finite()
                                        // .Bounds()
                                        // .AtInfinity()
                                        // .CenterCloseTo(new Vec3(boundaries[0] / 2.0, boundaries[1] / 2.0, 0.0), 50.0)
                                        // .CloseTo(new Vec3(boundaries[0] / 2.0, boundaries[1] / 2.0, 0.0), 50.0)
                                        // .Inside(Vec3.Zero, new Vec3(boundaries[0] * 0.25, boundaries[1] * 1.0, 1.0))
                                        // .Inside(Vec3.Zero, new Vec3(boundaries[0] * 0.25, boundaries[1] * 0.5, 1.0))
                                        .ToList();

        float nbCells   = (float)faces.Count;
        int   indcolor2 = 0;

        foreach (Face <int, int> face in faces)
        {
            var color = gradient.Evaluate(indcolor2 / nbCells);

            if (V_faces)
            {
                face.DrawFace(transform, mat, color);
            }
            if (V_lines)
            {
                face.DrawLine(transform, mat, Color.white, lineScale, loop: true);
            }
            if (V_points)
            {
                face.DrawPoints(transform, shapes[1], mat, Color.blue, 0.8f * scale);
            }
            // if (V_circles)
            // {
            //     face.DrawCircumCercle(transform, mat, color);
            // }

            indcolor2++;
        }

        delta = System.DateTime.Now - previousTime;
        Debug.Log("***");
        Debug.Log(string.Format("*** DRAWING *** {0} secondes OU {1} milliseconds *** DRAWING",
                                delta.TotalSeconds, delta.TotalMilliseconds));
        Debug.Log("Points count : " + points.Count);
        Debug.Log("Triangle count : " + triangles.Count / 3);
        Debug.Log("Face count : " + nbCells);
    }
Esempio n. 21
0
    private static void test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 gets the example 2D data and writes it to a file.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    20 October 2014
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int          element_num   = 0;
        int          element_order = 0;
        const string gmsh_filename = "example_2d.msh";
        int          m             = 0;
        int          node_num      = 0;

        Console.WriteLine("");
        Console.WriteLine("TEST01:");
        Console.WriteLine("  Get example 2D data, write to a file.");
        //
        //  Get sizes.
        //
        Mesh2D.gmsh_mesh2d_node_size_example(ref node_num, ref m);

        Mesh2D.gmsh_mesh2d_element_size_example(ref element_num, ref element_order);
        //
        //  Print the sizes.
        //
        Console.WriteLine("");
        Console.WriteLine("  Number of nodes = " + node_num + "");
        Console.WriteLine("  Spatial dimension = " + m + "");
        Console.WriteLine("  Number of elements = " + element_num + "");
        Console.WriteLine("  Order of elements = " + element_order + "");
        //
        //  Get the data.
        //
        double[] node_x = Mesh2D.gmsh_mesh2d_node_data_example(node_num, m);

        int[] element_node = Mesh2D.gmsh_mesh2d_element_data_example(element_num, element_order);
        //
        //  Print some of the data.
        //
        typeMethods.r8mat_transpose_print_some(m, node_num, node_x,
                                               1, 1, m, 10, "  Coordinates for first 10 nodes:");

        typeMethods.i4mat_transpose_print_some(element_order, element_num, element_node,
                                               1, 1, element_order, 10, "  Node connectivity of first 10 elements:");
        //
        //  Write the GMSH file.
        //
        Mesh2D.gmsh_mesh2d_write(gmsh_filename, m, node_num, node_x,
                                 element_order, element_num, element_node);

        Console.WriteLine("");
        Console.WriteLine("  Wrote example data to file \"" + gmsh_filename + "\"");
    }