コード例 #1
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            if (!isfocused)
            {
                Client.update();
                base.OnRenderFrame(e);
                return;
            }
            //  Console.WriteLine(raycaster.Enabled.ToString());
            GL.ClearColor(backcolor.R, backcolor.G, backcolor.B, backcolor.A);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            ee += e.Time;
            fps++;

            if (ee > 1)
            {
                ee    = 0;
                Title = "StoneVox fps : " + fps.ToString();
                fps   = 0;
            }

            renderer.Render(manager.ActiveModel);

            ShaderUtil.ResetShader();

            floor.Render();

            gui.Render();

            SwapBuffers();

            Client.update();

            base.OnRenderFrame(e);
        }
コード例 #2
0
ファイル: QbMatrix.cs プロジェクト: VB6Hobbyst7/stonevox3d
        public void RenderAll(Shader shader)
        {
            if (!Visible)
            {
                return;
            }

            shader.WriteUniform("highlight", new Vector3(highlight.R, highlight.G, highlight.B));

            unsafe
            {
                fixed(float *pointer = &colors[0].R)
                {
                    ShaderUtil.GetShader("qb").WriteUniformArray("colors", colorIndex, pointer);
                }
            }

            front.Render(shader);
            back.Render(shader);
            top.Render(shader);
            bottom.Render(shader);
            left.Render(shader);
            right.Render(shader);
        }
コード例 #3
0
 static SmoothBackground()
 {
     quadInterpolation = ShaderUtil.GetShader("quad_interpolation");
     camera            = Singleton <Camera> .INSTANCE;
 }
コード例 #4
0
        protected override void OnLoad(EventArgs e)
        {
            string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            Title = String.Format("StoneVox 3D - version {0}", version);

            GL.Viewport(0, 0, Width, Height);
            Qfont_1280 = new QFont("data\\fonts\\Bigfish.ttf", 11.2f, new QFontBuilderConfiguration(true, false));
            Qfont_1400 = new QFont("data\\fonts\\Bigfish.ttf", 12f, new QFontBuilderConfiguration(true, false));
            Qfont_1920 = new QFont("data\\fonts\\Bigfish.ttf", 15, new QFontBuilderConfiguration(true, false));
            if (Width <= 1280)
            {
                Qfont = Qfont_1280;
            }
            else if (Width < 1400)
            {
                Qfont = Qfont_1400;
            }
            else
            {
                Qfont = Qfont_1920;
            }

            this.Qfont.Options.Colour = Color.White;
            //this.Qfont.Options.TransformToViewport = new TransformViewport(-1,-1,2,2);

            Scale.SetHScaling(0, Width);
            Scale.SetVScaling(0, Height);

            ShaderUtil.CreateShader("quad_interpolation", "./data/shaders/QuadInterpolation.vs", "./data/shaders/QuadInterpolation.fs");

            broadcaster = new Broadcaster();
            manager     = new QbManager(broadcaster);
            input       = new Input(this);
            camera      = new Camera(this, input, manager);
            brushes     = new BrushManager(this, input);
            floor       = new Floor(camera, broadcaster);
            gui         = new GUI(this, manager, input);
            selection   = new Selection(this, brushes, input, manager, floor, gui);
            renderer    = new Wireframe(camera, selection, floor, input);
            undoredo    = new UndoRedo(input);

            selection.GenerateVertexArray();

            if (!manager.HasModel)
            {
                manager.AddEmpty();
            }
            camera.LookAtModel(true);

            backcolor = new Color4(0, 0, 0, 0);

            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);

            int    ole_hresult = OleInitialize(IntPtr.Zero);
            IntPtr handle      = FindWindowByCaption(IntPtr.Zero, Title);

            dnd = new DragDropTarget();
            int dnd_hresult = RegisterDragDrop(handle, dnd);

            raycaster           = new Raycaster(this, camera, selection, floor, input, manager, gui);
            selection.raycaster = raycaster;

            Client.Initialized = true;
            base.OnLoad(e);
            SetForegroundWindow(WindowInfo.Handle);
        }
コード例 #5
0
ファイル: ExporterSVP.cs プロジェクト: VB6Hobbyst7/stonevox3d
        public void write(string path, string name, QbModel model)
        {
            Client.OpenGLContextThread.Add(() =>
            {
                int Wwidth  = Client.window.Width;
                int Wheight = Client.window.Height;

                int framebuffer = GL.GenBuffer();
                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, framebuffer);

                int color = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, color);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, Wwidth, Wheight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
                GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, color, 0);

                int depth = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, depth);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent24, Wwidth, Wheight, 0, PixelFormat.DepthComponent, PixelType.UnsignedByte, IntPtr.Zero);
                GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, TextureTarget.Texture2D, depth, 0);

                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);

                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, framebuffer);
                GL.DrawBuffers(1, new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0 });

                GL.ClearColor(0, 0, 0, 0);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                int minx  = 10000;
                int miny  = 10000;
                int minz  = 10000;
                int maxx  = 0;
                int maxy  = 0;
                int maxz  = 0;
                int sizex = 0;
                int sizey = 0;
                int sizez = 0;

                foreach (var matrix in model.matrices)
                {
                    if (!matrix.Visible)
                    {
                        continue;
                    }
                    if (matrix.minx < minx)
                    {
                        minx = matrix.minx;
                    }
                    if (matrix.maxx > maxx)
                    {
                        maxx = matrix.maxx;
                    }

                    if (matrix.miny < miny)
                    {
                        miny = matrix.miny;
                    }
                    if (matrix.maxy > maxy)
                    {
                        maxy = matrix.maxy;
                    }

                    if (matrix.minz < minz)
                    {
                        minz = matrix.minz;
                    }
                    if (matrix.maxz > maxz)
                    {
                        maxz = matrix.maxz;
                    }
                }

                sizex = maxx - minx;
                sizey = maxy - miny;
                sizez = maxz - minz;

                float backup = 0;

                if (sizey * 1.5f > 20)
                {
                    backup = sizey * 1.5f;
                }
                else if (sizex * 1.5f > 20)
                {
                    backup = sizex * 1.5f;
                }
                else
                {
                    backup = 20;
                }

                var centerpos = new Vector3((minx + ((maxx - minx) / 2)), (miny + ((maxy - miny) / 2)), (minz + ((maxz - minz) / 2)));
                var position  = centerpos + new Vector3(.5f, sizey * .65f, backup);
                Vector3 direction;

                Vector3.Subtract(ref centerpos, ref position, out direction);
                direction.Normalize();

                var cameraright = Vector3.Cross(direction, VectorUtils.UP);
                var cameraup    = Vector3.Cross(cameraright, direction);

                var view = Matrix4.LookAt(position, position + direction, cameraup);
                var modelviewprojection = view * Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(45), (float)Wwidth / (float)Wheight, 1, 300);

                Shader voxelShader = ShaderUtil.GetShader("qb");

                voxelShader.UseShader();
                voxelShader.WriteUniform("modelview", modelviewprojection);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                model.RenderAll(voxelShader);

                string fullpath = Path.Combine(path, name + extension);
                using (FileStream f = new FileStream(fullpath, FileMode.OpenOrCreate))
                {
                    var bit       = Screenshot.ScreenShot(ReadBufferMode.ColorAttachment0);
                    bit           = cropImage(bit, new Rectangle(Wwidth / 4, 0, Wwidth - ((Wwidth / 4) * 2), Wheight));
                    bit           = bit.ResizeImage(ResizeKeepAspect(bit.Size, 400, 400));
                    byte[] buffer = new byte[0];
                    using (MemoryStream m = new MemoryStream())
                    {
                        bit.Save(m, System.Drawing.Imaging.ImageFormat.Png);
                        buffer = m.ToArray();
                    }

                    using (BinaryWriter w = new BinaryWriter(f))
                    {
                        w.Write(version);
                        w.Write((int)buffer.Length);
                        w.Write(buffer);

                        // note - just in case i allow extending the color pattet
                        // which i probably will
                        w.Write(colorpalletflag);
                        for (int i = 0; i < 10; i++)
                        {
                            var c = Singleton <GUI> .INSTANCE.Get <EmptyWidget>(GUIID.START_COLOR_SELECTORS + i).appearence.Get <PlainBackground>("background").color;
                            w.Write(c.R);
                            w.Write(c.G);
                            w.Write(c.B);
                        }

                        w.Write(model.version);
                        w.Write(model.colorFormat);
                        w.Write(model.zAxisOrientation);
                        w.Write(model.compressed);
                        w.Write(model.visibilityMaskEncoded);

                        w.Write((uint)model.matrices.Count);

                        for (int i = 0; i < model.numMatrices; i++)
                        {
                            QbMatrix m = model.matrices[i];
                            if (!m.Visible)
                            {
                                continue;
                            }

                            int startx = Math.Min(0, m.minx);
                            int starty = Math.Min(0, m.miny);
                            int startz = Math.Min(0, m.minz);

                            int width  = (int)(Math.Abs(Math.Min(0, m.minx)) + m.maxx + 1);
                            int height = (int)(Math.Abs(Math.Min(0, m.miny)) + m.maxy + 1);
                            int length = (int)(Math.Abs(Math.Min(0, m.minz)) + m.maxz + 1);

                            if (width < m.size.X)
                            {
                                width = (int)m.size.X;
                            }

                            if (height < m.size.Y)
                            {
                                height = (int)m.size.Y;
                            }

                            if (length < m.size.Z)
                            {
                                length = (int)m.size.Z;
                            }

                            w.Write(m.name);
                            w.Write((uint)width);
                            w.Write((uint)height);
                            w.Write((uint)length);

                            w.Write((int)m.position.X);
                            w.Write((int)m.position.Y);
                            w.Write((int)m.position.Z);

                            if (model.compressed == 0)
                            {
                                Voxel voxel;
                                for (int z = startz; z < startz + length; z++)
                                {
                                    for (int y = starty; y < starty + height; y++)
                                    {
                                        for (int x = startx; x < startx + width; x++)
                                        {
                                            int zz = model.zAxisOrientation == (int)0 ? z : (int)(length - z - 1);

                                            if (m.voxels.TryGetValue(m.GetHash(x, y, zz), out voxel))
                                            {
                                                Colort c = m.colors[voxel.colorindex];
                                                w.Write((byte)(c.R * 255));
                                                w.Write((byte)(c.G * 255));
                                                w.Write((byte)(c.B * 255));
                                                w.Write(voxel.alphamask);
                                            }
                                            else
                                            {
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
                    GL.DeleteTexture(color);
                    GL.DeleteTexture(depth);
                    GL.DeleteFramebuffer(framebuffer);
                }
            });
        }
コード例 #6
0
ファイル: QbMatrix.cs プロジェクト: VB6Hobbyst7/stonevox3d
        public void Render(Shader shader)
        {
            if (!Visible)
            {
                return;
            }
            //foreach(var c in voxels.Values)
            //{
            ////    Debug.Print(c.front.ToString());
            ////    Debug.Print(c.back.ToString());
            ////    Debug.Print(c.left.ToString());
            ////    Debug.Print(c.right.ToString());
            //    Debug.Print(c.top.ToString());
            //    //Debug.Print(c.bottom.ToString());
            //}

            while (modifiedvoxels.Count > 0)
            {
                if (modifiedvoxels.TryPop(out modified))
                {
                    switch (modified.action)
                    {
                    case VoxleModifierAction.NONE:
                        break;

                    case VoxleModifierAction.ADD:
                        break;

                    case VoxleModifierAction.REMOVE:
                        break;

                    case VoxleModifierAction.RECOLOR:
                        break;
                    }
                }
            }

            shader.WriteUniform("highlight", new Vector3(highlight.R, highlight.G, highlight.B));

            unsafe
            {
                fixed(float *pointer = &colors[0].R)
                {
                    ShaderUtil.GetShader("qb").WriteUniformArray("colors", colorIndex, pointer);
                }
            }

            if (RayIntersectsPlane(ref front.normal, ref Singleton <Camera> .INSTANCE.direction))
            {
                front.Render(shader);
            }
            if (RayIntersectsPlane(ref back.normal, ref Singleton <Camera> .INSTANCE.direction))
            {
                back.Render(shader);
            }
            if (RayIntersectsPlane(ref top.normal, ref Singleton <Camera> .INSTANCE.direction))
            {
                top.Render(shader);
            }
            if (RayIntersectsPlane(ref bottom.normal, ref Singleton <Camera> .INSTANCE.direction))
            {
                bottom.Render(shader);
            }
            if (RayIntersectsPlane(ref left.normal, ref Singleton <Camera> .INSTANCE.direction))
            {
                left.Render(shader);
            }
            if (RayIntersectsPlane(ref right.normal, ref Singleton <Camera> .INSTANCE.direction))
            {
                right.Render(shader);
            }
        }