Exemplo n.º 1
0
        public static void Blit(RenderTexture renderTexture, Material material)
        {
            BeginActive(renderTexture);

            P3dHelper.Draw(material);
            //Graphics.Blit(default(Texture), renderTexture, material);

            EndActive();
        }
Exemplo n.º 2
0
        public static void Blit(RenderTexture renderTexture, Material material)
        {
            var oldActive = RenderTexture.active;

            RenderTexture.active = renderTexture;

            P3dHelper.Draw(material);
            //Graphics.Blit(default(Texture), renderTexture, material);

            RenderTexture.active = oldActive;
        }
Exemplo n.º 3
0
        private void ExecuteCommands(List <P3dCommand> commands, bool sendNotifications, ref RenderTexture main, ref RenderTexture swap, ref Mesh preparedMesh, ref Matrix4x4 preparedMatrix)
        {
            if (swap == null)
            {
                swap = P3dHelper.GetRenderTexture(main);
            }

            if (keepUnpaintable == true)
            {
                P3dCommandReplace.BlitFast(swap, current, Color.white);
            }

            RenderTexture.active = main;

            for (var i = 0; i < commands.Count; i++)
            {
                var command = commands[i];

                if (command.Model != null)
                {
                    RenderTexture.active = swap;

                    command.Apply(main);

                    if (command.RequireMesh == true)
                    {
                        command.Model.GetPrepared(ref preparedMesh, ref preparedMatrix);

                        P3dHelper.Draw(command.Material, preparedMesh, preparedMatrix, command.Submesh, coord);
                    }
                    else
                    {
                        P3dHelper.Draw(command.Material);
                    }

                    P3dHelper.Swap(ref main, ref swap);
                }

                command.Pool();
            }

            commands.Clear();

            if (main.useMipMap == true)
            {
                main.GenerateMips();
            }

            if (sendNotifications == true)
            {
                NotifyOnModified(commands == previewCommands);
            }
        }
Exemplo n.º 4
0
        public static void Texture(RenderTexture rendertexture, Mesh mesh, int submesh, Texture texture, P3dCoord coord)
        {
            if (cachedTextureSet == false)
            {
                cachedTexture    = P3dShader.BuildMaterial("Hidden/Paint in 3D/Texture");
                cachedTextureSet = true;
            }

            P3dHelper.BeginActive(rendertexture);

            cachedTexture.SetTexture(P3dShader._Buffer, texture);
            cachedTexture.SetVector(P3dShader._BufferSize, new Vector2(texture.width, texture.height));

            P3dHelper.Draw(cachedTexture, mesh, Matrix4x4.identity, submesh, coord);

            P3dHelper.EndActive();
        }
Exemplo n.º 5
0
        private void ExecuteCommands(List <P3dCommand> commands, bool sendNotifications, ref RenderTexture main, ref RenderTexture swap, ref Mesh preparedMesh, ref Matrix4x4 preparedMatrix)
        {
            RenderTexture.active = main;

            for (var i = 0; i < commands.Count; i++)
            {
                var command = commands[i];

                RenderTexture.active = swap;

                command.Apply(main);

                if (command.RequireMesh == true)
                {
                    paintable.GetPrepared(ref preparedMesh, ref preparedMatrix);

                    P3dHelper.Draw(command.Material, preparedMesh, preparedMatrix, slot.Index, coord);
                }
                else
                {
                    P3dHelper.Draw(command.Material);
                }

                P3dHelper.Swap(ref main, ref swap);

                command.Pool();
            }

            commands.Clear();

            if (main.useMipMap == true)
            {
                main.GenerateMips();
            }

            if (sendNotifications == true)
            {
                NotifyOnModified(commands == previewCommands);
            }
        }
Exemplo n.º 6
0
        public static void White(RenderTexture rendertexture, Mesh mesh, int submesh, P3dCoord coord)
        {
            P3dHelper.BeginActive(rendertexture);

            if (mesh != null)
            {
                if (cachedWhiteSet == false)
                {
                    cachedWhite    = P3dShader.BuildMaterial("Hidden/Paint in 3D/White");
                    cachedWhiteSet = true;
                }

                GL.Clear(true, true, Color.black);

                P3dHelper.Draw(cachedWhite, mesh, Matrix4x4.identity, submesh, coord);
            }
            else
            {
                GL.Clear(true, true, Color.white);
            }

            P3dHelper.EndActive();
        }
        private void Render(P3dCommand command, P3dScene.Mat mat, P3dScene.Image image, P3dScene.Obj obj, int subMesh)
        {
            var oldActive = RenderTexture.active;

            if (image.Current == null)
            {
                if (image.Width > 0 && image.Height > 0 && image.Pixels != null && image.Pixels.Length > 0)
                {
                    var texture = new Texture2D(1, 1);

                    if (texture.LoadImage(image.Pixels) == true)
                    {
                        var desc = mat.Desc;

                        desc.width  = image.Width;
                        desc.height = image.Height;

                        image.Current = P3dHelper.GetRenderTexture(mat.Desc);

                        P3dPaintReplace.BlitFast(image.Current, texture, Color.white);
                    }
                    else
                    {
                        image.Current = P3dHelper.GetRenderTexture(mat.Desc);

                        P3dPaintReplace.BlitFast(image.Current, default(Texture), default(Color));
                    }

                    DestroyImmediate(texture);
                }
                else
                {
                    image.Current = P3dHelper.GetRenderTexture(mat.Desc);

                    P3dPaintReplace.BlitFast(image.Current, default(Texture), default(Color));
                }
            }

            var swap = P3dHelper.GetRenderTexture(image.Current.descriptor);

            if (command.Preview == true)
            {
                if (image.Preview == null)
                {
                    image.Preview = P3dHelper.GetRenderTexture(image.Current.descriptor);

                    P3dPaintReplace.BlitFast(image.Preview, image.Current, Color.white);
                }

                P3dPaintReplace.BlitFast(swap, image.Preview, Color.white);

                command.Apply(image.Preview);
            }
            else
            {
                P3dPaintReplace.BlitFast(swap, image.Current, Color.white);

                command.Apply(image.Current);
            }

            RenderTexture.active = swap;

            if (command.RequireMesh == true)
            {
                P3dHelper.Draw(command.Material, obj.Mesh, obj.Matrix, subMesh, obj.Coord);
            }
            else
            {
                P3dHelper.Draw(command.Material);
            }

            RenderTexture.active = oldActive;

            if (command.Preview == true)
            {
                P3dHelper.ReleaseRenderTexture(image.Preview);

                image.Preview = swap;

                previewDrawn = true;
            }
            else
            {
                P3dHelper.ReleaseRenderTexture(image.Current);

                image.Current = swap;
            }

            paintedGroups.Add(command.Priority);             // Group is stored in priority
        }