Пример #1
0
        public QuadNode(string text, v4?size = null, m4x4?position = null, NodeStyle?style = null)
            : base(size ?? new v4(50, 50, 0, 0), Guid.NewGuid(), text, position, style)
        {
            Size = Style.AutoSize ? PreferredSize(SizeMax) : Size;

            // Create a texture for drawing the node content into
            Surf = new Surface(Size.xi, Size.yi);

            // Create a quad model
            var ldr = new LdrBuilder();

            ldr.Rect("node", Colour32.White, EAxisId.PosZ, Size.x, Size.y, true, (float)Style.CornerRadius, v4.Origin);
            Gfx = new View3d.Object(ldr, false, null, null);
            Gfx.SetTexture(Surf.Surf);
        }
Пример #2
0
        public FormView3d()
        {
            InitializeComponent();
            m_view3d = new View3dControl
            {
                Name        = "m_view3d",
                BorderStyle = BorderStyle.FixedSingle,
                Dock        = DockStyle.Fill,
            };
            Controls.Add(m_view3d);
            m_demo_objs = m_view3d.Window.CreateDemoScene();

            m_view3d.Camera.ResetView();
            m_view3d.Camera.Lookat(new v4(10f, 10f, 5f, 1f), v4.Origin, v4.YAxis);

            // Simple create object
            m_obj0     = new View3d.Object("*Box test FFFFFFFF {1 2 3}", false, null);
            m_obj0.O2P = m4x4.Transform(0.5f, -0.3f, 0.2f, new v4(-0.3f, 1.2f, 0.5f, 1f));
            m_view3d.Window.AddObject(m_obj0);

            m_obj0.ShowNormals = true;
            m_view3d.Window.Diag.NormalsLength = 0.5f;
            m_view3d.Window.Diag.NormalsColour = Colour32.Yellow;

            // Create a texture and assign it to an object
            m_tex0 = new View3d.Texture(100, 100, new View3d.TextureOptions {
                GdiCompatible = true
            });
            using (var tex = new View3d.Texture.Lock(m_tex0, discard: true))
            {
                tex.Gfx.Clear(Color.DarkBlue);
                tex.Gfx.FillEllipse(Brushes.RoyalBlue, 10, 10, 80, 80);
                tex.Gfx.DrawString("Paul Rulz", SystemFonts.DefaultFont, Brushes.Black, new PointF(30, 40));
            }
            m_view3d.Window.RestoreRT();
            m_obj0.SetTexture(m_tex0);

            // Create object via callback
            m_obj1 = new View3d.Object("net", 0xFF0000FF, 20, 20, 1, CreateOnlyCB, null);
            m_view3d.Window.AddObject(m_obj1);

            // Create an object with a texture from a rendered scene
            m_obj2     = new View3d.Object("*Box Rt FFFFFFFF {0.7 0.9 0.4}", false, null);
            m_obj2.O2P = m4x4.Transform(-0.5f, 0.4f, 0.6f, new v4(0.5f, -0.2f, -0.3f, 1f));
            m_view3d.Window.AddObject(m_obj2);

            // Create a texture and use it as a render target
            m_tex2 = new View3d.Texture(200, 200, new View3d.TextureOptions
            {
                Format        = View3d.EFormat.DXGI_FORMAT_R8G8B8A8_UNORM,
                Mips          = 1U,
                Filter        = View3d.EFilter.D3D11_FILTER_MIN_MAG_MIP_LINEAR,
                AddrU         = View3d.EAddrMode.D3D11_TEXTURE_ADDRESS_CLAMP,
                AddrV         = View3d.EAddrMode.D3D11_TEXTURE_ADDRESS_CLAMP,
                BindFlags     = View3d.EBindFlags.D3D11_BIND_SHADER_RESOURCE | View3d.EBindFlags.D3D11_BIND_RENDER_TARGET,
                MiscFlags     = View3d.EResMiscFlags.NONE,
                ColourKey     = 0,
                HasAlpha      = false,
                GdiCompatible = false,
                DbgName       = "Test RT",
            });
            m_view3d.Paint += (s, a) =>
            {
                // Make sure 'm_obj' is not rendered (because it uses the texture we're rendering to)
                m_view3d.Window.RemoveObject(m_obj2);
                m_view3d.Window.SetRT(m_tex2, null, false);
                m_view3d.Window.AddObject(m_obj2);
            };
            m_obj2.SetTexture(m_tex2);

            // Create a gizmo for moving objects in the scene
            // Position it at the origin of m_obj0 and scale by 2
            m_giz = new View3d.Gizmo(View3d.Gizmo.EMode.Scale, m_obj0.O2P * m4x4.Scale(0.1f, v4.Origin));
            m_giz.Attach(m_obj0);
            m_giz.Moved += (s, a) =>
            {
                m_status.SetStatusMessage(msg: "Gizmo", display_time: TimeSpan.FromSeconds(2));
            };
            m_view3d.Window.AddGizmo(m_giz);

            m_btn_translate.Click += (s, a) => m_giz.Mode = View3d.Gizmo.EMode.Translate;
            m_btn_rotate.Click    += (s, a) => m_giz.Mode = View3d.Gizmo.EMode.Rotate;
            m_btn_scale.Click     += (s, a) => m_giz.Mode = View3d.Gizmo.EMode.Scale;

            // Create an object from buffers created in C#
            {
                var verts = new View3d.Vertex[]
                {
                    new View3d.Vertex(new v4(1f, 1f, 0f, 1f), 0xFFFF0000),
                    new View3d.Vertex(new v4(2f, 0f, 0f, 1f), 0xFF00FF00),
                    new View3d.Vertex(new v4(3f, 1f, 0f, 1f), 0xFF0000FF),
                };
                var indcs = new ushort[]
                {
                    0, 1, 2
                };
                var nuggets = new View3d.Nugget[]
                {
                    new View3d.Nugget(View3d.ETopo.TriList, View3d.EGeom.Vert | View3d.EGeom.Colr)
                };
                m_obj3 = new View3d.Object("Obj3", 0xFFFFFFFF, 3, 3, 1, verts, indcs, nuggets, null);
                m_view3d.Window.AddObject(m_obj3);
            }
        }