private static void SubmitAll(P3dCommand command, bool preview, int layerMask, int groupMask, P3dModel model, P3dPaintableTexture paintableTexture)
 {
     if (model != null)
     {
         if (paintableTexture != null)
         {
             Submit(command, model, paintableTexture, preview);
         }
         else
         {
             SubmitAll(command, preview, model, groupMask);
         }
     }
     else
     {
         if (paintableTexture != null)
         {
             Submit(command, paintableTexture.CachedPaintable, paintableTexture, preview);
         }
         else
         {
             SubmitAll(command, preview, layerMask, groupMask);
         }
     }
 }
示例#2
0
 private static void DoSubmitAll(P3dCommand command, Vector3 position, float radius, int layerMask, P3dGroup group, P3dModel targetModel, P3dPaintableTexture targetTexture)
 {
     if (targetModel != null)
     {
         if (targetTexture != null)
         {
             Submit(command, targetModel, targetTexture);
         }
         else
         {
             SubmitAll(command, targetModel, group);
         }
     }
     else
     {
         if (targetTexture != null)
         {
             Submit(command, targetTexture.CachedPaintable, targetTexture);
         }
         else
         {
             SubmitAll(command, position, radius, layerMask, group);
         }
     }
 }
示例#3
0
        /// <summary>This will add a paint command to this texture's paint stack. The paint stack will be executed at the end of the current frame.</summary>
        public void AddCommand(P3dCommand command)
        {
            if (command.Preview == true)
            {
                command.Index = previewCommands.Count;

                previewCommands.Add(command);
            }
            else
            {
                command.Index = paintCommands.Count;

                paintCommands.Add(command);

                if (state == StateType.LocalCommandCopy && command.Preview == false)
                {
                    var localCommand = command.SpawnCopyLocal(transform);

                    localCommand.Index = localCommands.Count;

                    localCommands.Add(localCommand);
                }
            }

            if (OnAddCommand != null)
            {
                OnAddCommand(command);
            }
        }
示例#4
0
        private static void SubmitAll(P3dCommand command, Vector3 position, float radius, int layerMask, P3dGroup group)
        {
            var models = P3dModel.FindOverlap(position, radius, layerMask);

            for (var i = models.Count - 1; i >= 0; i--)
            {
                SubmitAll(command, models[i], group);
            }
        }
        private static void SubmitAll(P3dCommand command, bool preview, P3dModel model, int groupMask)
        {
            var paintableTextures = P3dPaintableTexture.Filter(model, groupMask);

            for (var i = paintableTextures.Count - 1; i >= 0; i--)
            {
                Submit(command, model, paintableTextures[i], preview);
            }
        }
        private static void SubmitAll(P3dCommand command, bool preview, int layerMask, int groupMask)
        {
            var models = P3dModel.FindOverlap(command.Position, command.Radius, layerMask);

            for (var i = models.Count - 1; i >= 0; i--)
            {
                SubmitAll(command, preview, models[i], groupMask);
            }
        }
示例#7
0
        private static void SubmitAll(P3dCommand command, P3dModel model, P3dGroup group)
        {
            var paintableTextures = P3dPaintableTexture.Filter(model, group);

            for (var i = paintableTextures.Count - 1; i >= 0; i--)
            {
                Submit(command, model, paintableTextures[i]);
            }
        }
        public static void Submit(P3dCommand command, P3dModel model, P3dPaintableTexture paintableTexture, bool preview)
        {
            var copy = command.SpawnCopy();

            copy.Model   = model;
            copy.Groups  = -1;
            copy.Preview = preview;

            paintableTexture.AddCommand(copy);
        }
        public static void Submit(P3dCommand command, P3dModel model, P3dPaintableTexture paintableTexture)
        {
            var copy = command.SpawnCopy();

            if (copy.Blend.Index == P3dBlendMode.REPLACE_ORIGINAL)
            {
                copy.Blend.Color   = paintableTexture.Color;
                copy.Blend.Texture = paintableTexture.Texture;
            }

            paintableTexture.AddCommand(copy);
        }
        public static P3dCommand Submit(P3dCommand command, P3dModel model, P3dPaintableTexture paintableTexture)
        {
            var copy = command.SpawnCopy();

            copy.Apply(paintableTexture);

            copy.Model   = model;
            copy.Submesh = model.GetSubmesh(paintableTexture);

            paintableTexture.AddCommand(copy);

            return(copy);
        }
示例#11
0
        public static int Compare(P3dCommand a, P3dCommand b)
        {
            var delta = a.Priority.CompareTo(b.Priority);

            if (delta > 0)
            {
                return(1);
            }
            else if (delta < 0)
            {
                return(-1);
            }

            return(a.Index.CompareTo(b.Index));
        }
示例#12
0
        public static void Submit(P3dCommand command, P3dModel model, P3dPaintableTexture paintableTexture, bool preview)
        {
            var copy = command.SpawnCopy();

            copy.Model   = model;
            copy.Groups  = -1;
            copy.Preview = preview;

            if (copy.Blend.Index == P3dBlendMode.REPLACE_ORIGINAL)
            {
                copy.Blend.Color   = paintableTexture.Color;
                copy.Blend.Texture = paintableTexture.Texture;
            }

            paintableTexture.AddCommand(copy);
        }
        public static void Clone(P3dCommand command, int clonerIndex, int matrixIndex)
        {
            if (matrixIndex == 0)
            {
                MatrixCount = tempPosMatrices.Count;
            }

            var posMatrix = tempPosMatrices[matrixIndex];
            var rotMatrix = tempRotMatrices[matrixIndex];

            tempCloners[clonerIndex].Transform(ref posMatrix, ref rotMatrix);

            tempPosMatrices.Add(posMatrix);
            tempRotMatrices.Add(rotMatrix);

            command.Transform(posMatrix, rotMatrix);
        }
示例#14
0
        public static void SubmitAll(P3dCommand command, bool preview, int layerMask, int groupMask, P3dModel model = null, P3dPaintableTexture paintableTexture = null, List <P3dTransform> repeaters = null, List <P3dCommand> commands = null)
        {
            command.Model   = null;
            command.Groups  = groupMask;
            command.Preview = preview;

            if (commands != null)
            {
                commands.Add(command.SpawnCopy());

                // Repeat paint?
                BuildRepeaters(command.Matrix, repeaters);

                for (var r = 0; r < RepeaterCount; r++)
                {
                    for (var m = 0; m < MatrixCount; m++)
                    {
                        command.SetLocation(Repeat(r, m));

                        commands.Add(command.SpawnCopy());
                    }
                }
            }
            else
            {
                SubmitAll(command, preview, layerMask, groupMask, model, paintableTexture);

                // Repeat paint?
                BuildRepeaters(command.Matrix);

                for (var r = 0; r < RepeaterCount; r++)
                {
                    for (var m = 0; m < MatrixCount; m++)
                    {
                        command.SetLocation(Repeat(r, m));

                        SubmitAll(command, preview, layerMask, groupMask, model, paintableTexture);
                    }
                }
            }
        }
示例#15
0
        public static void SubmitAll(P3dCommand command, Vector3 position, float radius, int layerMask, P3dGroup group, P3dModel targetModel, P3dPaintableTexture targetTexture)
        {
            DoSubmitAll(command, position, radius, layerMask, group, targetModel, targetTexture);

            // Repeat paint?
            P3dClone.BuildCloners();

            for (var c = 0; c < P3dClone.ClonerCount; c++)
            {
                for (var m = 0; m < P3dClone.MatrixCount; m++)
                {
                    var copy = command.SpawnCopy();

                    P3dClone.Clone(copy, c, m);

                    DoSubmitAll(copy, position, radius, layerMask, group, targetModel, targetTexture);

                    copy.Pool();
                }
            }
        }
        /// <summary>This will add a paint command to this texture's paint stack. The paint stack will be executed at the end of the current frame.</summary>
        public void AddCommand(P3dCommand command)
        {
            // If this is a real paint command, strip out all previously added preview commands
            if (command.Preview == false)
            {
                for (var i = commands.Count - 1; i >= 0; i--)
                {
                    var lastCommand = commands[i];

                    if (lastCommand.Preview == false)
                    {
                        break;
                    }

                    lastCommand.Pool();

                    commands.RemoveAt(i);
                }
            }

            commands.Add(command);

            if (state == StateType.LocalCommandCopy && command.Preview == false)
            {
                var localCommand = command.SpawnCopy();

                localCommand.Matrix = transform.worldToLocalMatrix * localCommand.Matrix;

                localCommands.Add(localCommand);
            }

            if (OnAddCommand != null)
            {
                OnAddCommand(command);
            }
        }
        public void Paint(P3dCommand command, List <P3dWindowPaintable> paintables)
        {
            var commandMaterial = command.Material;

            //if (bounds.Intersects(lastBounds) == true)
            {
                for (var i = PaintableTextures.Count - 1; i >= 0; i--)
                {
                    var paintableTexture = PaintableTextures[i];
                    var renderTexture    = paintableTexture.PreparePaint();                     // Prepare the paint regardless, to sync undo states

                    if (P3dHelper.IndexInMask(paintableTexture.Group, command.Groups) == true)
                    {
                        var oldActive = RenderTexture.active;
                        var swap      = default(RenderTexture);

                        RenderTexture.active = renderTexture;

                        if (true)                         // TODO
                        {
                            swap = P3dHelper.GetRenderTexture(renderTexture.width, renderTexture.height, renderTexture.depth, renderTexture.format);

                            P3dHelper.Blit(swap, renderTexture);

                            commandMaterial.SetTexture(P3dShader._Buffer, swap);
                        }

                        command.Apply();

                        if (command.RequireMesh == true)
                        {
                            for (var j = paintables.Count - 1; j >= 0; j--)
                            {
                                var otherP = paintables[j];

                                for (var k = otherP.PaintableTextures.Count - 1; k >= 0; k--)
                                {
                                    var otherT = otherP.PaintableTextures[k];

                                    if (otherT.OldTexture == paintableTexture.OldTexture)
                                    {
                                        switch (otherT.Channel)
                                        {
                                        case P3dChannel.UV: commandMaterial.SetVector(P3dShader._Channel, new Vector4(1.0f, 0.0f, 0.0f, 0.0f)); break;

                                        case P3dChannel.UV2: commandMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 1.0f, 0.0f, 0.0f)); break;

                                        case P3dChannel.UV3: commandMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 0.0f, 1.0f, 0.0f)); break;

                                        case P3dChannel.UV4: commandMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); break;
                                        }

                                        commandMaterial.SetPass(0);

                                        Graphics.DrawMeshNow(otherP.lastMesh, otherP.lastMatrix, otherT.MaterialIndex);
                                    }
                                }
                            }
                        }
                        else
                        {
                            Graphics.Blit(default(Texture), renderTexture, commandMaterial);
                        }

                        RenderTexture.active = oldActive;

                        if (swap != null)
                        {
                            P3dHelper.ReleaseRenderTexture(swap);
                        }
                    }
                }
            }
        }
示例#18
0
        public void Paint(P3dGroup group, P3dCommand command)
        {
            var commandMaterial = command.Material;

            //if (bounds.Intersects(lastBounds) == true)
            {
                for (var i = PaintableTextures.Count - 1; i >= 0; i--)
                {
                    var paintableTexture = PaintableTextures[i];
                    var renderTexture    = paintableTexture.PreparePaint();                     // Prepare the paint regardless, to sync undo states

                    if (paintableTexture.Group == group)
                    {
                        var oldActive = RenderTexture.active;
                        var swap      = default(RenderTexture);

                        RenderTexture.active = renderTexture;

                        if (command.RequireSwap == true)
                        {
                            swap = P3dHelper.GetRenderTexture(renderTexture.width, renderTexture.height, renderTexture.depth, renderTexture.format);

                            P3dHelper.Blit(swap, renderTexture);

                            commandMaterial.SetTexture(P3dShader._Buffer, swap);
                        }

                        command.Apply();

                        if (command.RequireMesh == true)
                        {
                            switch (paintableTexture.Channel)
                            {
                            case P3dChannel.UV: commandMaterial.SetVector(P3dShader._Channel, new Vector4(1.0f, 0.0f, 0.0f, 0.0f)); break;

                            case P3dChannel.UV2: commandMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 1.0f, 0.0f, 0.0f)); break;

                            case P3dChannel.UV3: commandMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 0.0f, 1.0f, 0.0f)); break;

                            case P3dChannel.UV4: commandMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); break;
                            }

                            commandMaterial.SetPass(0);

                            Graphics.DrawMeshNow(lastMesh, lastMatrix, paintableTexture.MaterialIndex);
                        }
                        else
                        {
                            Graphics.Blit(default(Texture), renderTexture, commandMaterial);
                        }

                        RenderTexture.active = oldActive;

                        if (swap != null)
                        {
                            P3dHelper.ReleaseRenderTexture(swap);
                        }
                    }
                }
            }
        }
        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
        }