예제 #1
0
        private void RebuildFromCommands()
        {
            P3dPaintReplace.Blit(current, texture, color);

            var localToWorldMatrix = transform.localToWorldMatrix;

            for (var i = 0; i <= stateIndex; i++)
            {
                var paintableState = paintableStates[i];
                var commandCount   = paintableState.Commands.Count;

                for (var j = 0; j < commandCount; j++)
                {
                    var worldCommand = paintableState.Commands[j].SpawnCopy();

                    worldCommand.SetLocation(localToWorldMatrix * worldCommand.Matrix);

                    AddCommand(worldCommand);
                }
            }

            ExecuteCommands(false);

            NotifyOnModified(false);
        }
예제 #2
0
 /// <summary>This allows you to clear all pixels in this paintable texture with the specified color and texture.</summary>
 public void Clear(Texture texture, Color color)
 {
     if (activated == true)
     {
         P3dPaintReplace.Blit(current, texture, color);
     }
 }
예제 #3
0
        /// <summary>This method will resize the current texture state with the specified width and height.
        /// NOTE: This component must be activated.</summary>
        public bool Resize(int width, int height, bool copyContents = true)
        {
            if (activated == true)
            {
                if (current.width != width || current.height != height)
                {
                    var descriptor = current.descriptor;

                    descriptor.width  = width;
                    descriptor.height = height;

                    var newCurrent = P3dHelper.GetRenderTexture(descriptor);

                    if (copyContents == true)
                    {
                        P3dPaintReplace.Blit(newCurrent, current, Color.white);

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

                    P3dHelper.ReleaseRenderTexture(current);

                    current = newCurrent;

                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        public void Activate()
        {
            if (activated == false)
            {
                UpdateMaterial();

                if (material != null)
                {
                    var finalWidth   = width;
                    var finalHeight  = height;
                    var finalTexture = material.GetTexture(slot.Name);

                    CachedPaintable.ScaleSize(ref finalWidth, ref finalHeight);

                    if (texture != null)
                    {
                        finalTexture = texture;
                    }

                    if (string.IsNullOrEmpty(shaderKeyword) == false)
                    {
                        material.EnableKeyword(shaderKeyword);
                    }

                    var desc = new RenderTextureDescriptor(width, height, format, 0);

                    desc.autoGenerateMips = false;

                    if (mipMaps == MipType.ForceOn)
                    {
                        desc.useMipMap = true;
                    }
                    else if (mipMaps == MipType.Auto && P3dHelper.HasMipMaps(finalTexture) == true)
                    {
                        desc.useMipMap = true;
                    }

                    current = P3dHelper.GetRenderTexture(desc);

                    P3dPaintReplace.Blit(current, finalTexture, color);

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

                    material.SetTexture(slot.Name, current);

                    activated = true;

                    if (string.IsNullOrEmpty(saveName) == false)
                    {
                        Load();
                    }

                    NotifyOnModified(false);
                }
            }
        }
예제 #5
0
            public void Resize()
            {
                foreach (var slot in Slots)
                {
                    if (slot.Texture != null)
                    {
                        if (slot.Texture.width != Width || slot.Texture.height != Height)
                        {
                            var desc           = slot.Texture.descriptor; desc.width = Width; desc.height = Height;
                            var resizedTexture = P3dHelper.GetRenderTexture(desc);

                            P3dPaintReplace.Blit(resizedTexture, slot.Texture, Color.white);

                            P3dHelper.ReleaseRenderTexture(slot.Texture);

                            slot.Texture = resizedTexture;
                        }
                    }
                }
            }
예제 #6
0
        private void WriteThumbnailTex(RenderTexture texture, P3dPaintMaterial.Slot paintSlot, P3dShaderTemplate.Write write)
        {
            if (paintSlot != null)
            {
                P3dPaintReplace.Blit(texture, paintSlot.Texture, paintSlot.Color);
            }
            else
            {
                var group = P3dGroupData.GetGroupData(write.SourceGroup);

                if (group != null)
                {
                    P3dPaintReplace.Blit(texture, group.DefaultTexture, group.DefaultColor);
                }
                else
                {
                    P3dPaintReplace.Blit(texture, default(Texture), default(Color));
                }
            }
        }
예제 #7
0
        public void Activate()
        {
            if (activated == false)
            {
                UpdateMaterial();

                if (material != null)
                {
                    var finalWidth   = width;
                    var finalHeight  = height;
                    var finalTexture = material.GetTexture(slot.Name);

                    CachedPaintable.ScaleSize(ref finalWidth, ref finalHeight);

                    if (texture != null)
                    {
                        finalTexture = texture;
                    }

                    if (string.IsNullOrEmpty(shaderKeyword) == false)
                    {
                        material.EnableKeyword(shaderKeyword);
                    }

                    current = P3dHelper.GetRenderTexture(finalWidth, finalHeight, 0, format);

                    P3dPaintReplace.Blit(current, finalTexture, color);

                    material.SetTexture(slot.Name, current);

                    activated = true;

                    if (string.IsNullOrEmpty(saveName) == false)
                    {
                        Load();
                    }

                    NotifyOnModified(false);
                }
            }
        }
예제 #8
0
        public void UpdateMergedLayers(Layer currentLayer)
        {
            foreach (var mat in Mats)
            {
                foreach (var mergedLayer in mat.MergedLayers.Values)
                {
                    mergedLayer.Dirty = true;

                    if (mergedLayer.Layer != currentLayer)
                    {
                        mergedLayer.Clear();

                        mergedLayer.Layer = currentLayer;
                    }
                }

                if (mat.Template != null)
                {
                    foreach (var slot in mat.Template.Slots)
                    {
                        mat.UpdateMergedLayers(slot.WriteR.SourceGroup);
                        mat.UpdateMergedLayers(slot.WriteG.SourceGroup);
                        mat.UpdateMergedLayers(slot.WriteB.SourceGroup);
                        mat.UpdateMergedLayers(slot.WriteA.SourceGroup);
                    }
                }

                foreach (var pair in mat.MergedLayers)
                {
                    var group       = pair.Key;
                    var mergedLayer = pair.Value;

                    if (mergedLayer.Dirty == true)
                    {
                        mergedLayer.Clear();
                    }
                    else
                    {
                        var currentLayerIndex = Layers.IndexOf(currentLayer);

                        if (mergedLayer.Under == null)
                        {
                            mergedLayer.Under = P3dHelper.GetRenderTexture(mat.Desc);

                            var groupData = P3dGroupData.GetGroupData(group);

                            if (groupData != null)
                            {
                                P3dPaintReplace.Blit(mergedLayer.Under, groupData.DefaultTexture, groupData.DefaultColor);
                            }
                            else
                            {
                                P3dPaintReplace.Blit(mergedLayer.Under, default(Texture), default(Color));
                            }

                            for (var i = 0; i < currentLayerIndex; i++)
                            {
                                TryBlendInto(ref mergedLayer.Under, Layers[i], mat.Id, group);
                            }
                        }

                        // Last layer?
                        if (currentLayerIndex == Layers.Count - 1)
                        {
                            if (mergedLayer.Above != null)
                            {
                                mergedLayer.Above = P3dHelper.ReleaseRenderTexture(mergedLayer.Above);
                            }
                        }
                        else
                        {
                            if (mergedLayer.Above == null)
                            {
                                mergedLayer.Above = P3dHelper.GetRenderTexture(mat.Desc);

                                P3dPaintReplace.Blit(mergedLayer.Above, default(Texture), default(Color));

                                for (var i = currentLayerIndex + 1; i < Layers.Count; i++)
                                {
                                    TryBlendInto(ref mergedLayer.Above, Layers[i], mat.Id, group);
                                }
                            }
                        }

                        if (mergedLayer.Final == null)
                        {
                            mergedLayer.Final = P3dHelper.GetRenderTexture(mat.Desc);
                        }

                        P3dPaintReplace.Blit(mergedLayer.Final, mergedLayer.Under, Color.white);

                        TryBlendInto(ref mergedLayer.Final, currentLayer, mat.Id, group);

                        if (mergedLayer.Above != null)
                        {
                            mergedLayer.Final = P3dPaintFill.Blit(mergedLayer.Final, P3dBlendMode.AlphaBlend, mergedLayer.Above, Color.white, 1.0f, 0.0f);
                        }
                    }
                }
            }
        }