Skip to content

Commit

Permalink
Merge pull request #4 from KPDwyer/v030
Browse files Browse the repository at this point in the history
V030
  • Loading branch information
KPDwyer authored Mar 25, 2017
2 parents 6fd585d + 87a03b5 commit eb4fbfe
Show file tree
Hide file tree
Showing 29 changed files with 1,597 additions and 789 deletions.
Binary file added Gallery/Perlin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Gallery/perlin2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ By Defining shapes relative to the canvas, you can rescale the canvas at will to

SpriteMaker isn't meant to make fullscale art assets, but I like to push what I can do with it
![Man](Gallery/Man.png)

SpriteMaker can be used to make Noise maps right in the editor (more noise coming soon). Noise can also be a neat effect for static textures.
![Perlin](Gallery/perlin2.png)
![Perlin Two](Gallery/Perlin.png)

31 changes: 15 additions & 16 deletions Roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,34 @@
5. Add Draw Command Functionality
6. Remove Draw Command Functionality
7. Draw Commands: Fill, Rectangle, Circle, Rounded Rectangle
8. Rearrange Draw Command
9. Hide Draw Command
10. Blend Modes
11. Collapse Views
12. Auto previes
13. Saving, Loading, Serialization of Scriptable Objects (working files)
14. Undo
15. Noise Draw Commands: Perlin

##In Progress

**v 0.2**

1. Rearrange Draw Command
2. Hide Draw Command
3. Blend Modes
4. Collapse View
5. Visibility Toggle
6. Auto preview

##Planned
##In Progress

**v 0.3**
1. Gradient Fill
2. Voronoi
3. Fixes to RoundedRect sizing
4. Other Noise

1. Save and load DrawCommand Queues

##As Needed

1. N-Gon Draw Command
2. Line Draw Command
3. Star Draw Command
4. Perlin Noise Draw Command
5. Gradient Fill Draw Command
4. Gradient Fill Draw Command


##Research Required

1. Masking
2. Effects (Blur, Glow, Invert)
3. Undo
3. N-Gon visual Editor
254 changes: 152 additions & 102 deletions SpriteMaker/Assets/SpriteMaker/Editor/BaseDrawCommand.cs
Original file line number Diff line number Diff line change
@@ -1,120 +1,170 @@
using UnityEngine;
using UnityEditor;
namespace SpriteMaker{

/// <summary>
/// Base Draw Command. Subclass this to create custom draw commands
/// </summary>
public class BaseDrawCommand {

/// <summary>
/// Types of Draw Commands. Need to update when creating a new Draw Command
/// </summary>
public enum DrawCommandType {
Fill = 0,
Circle = 1,
Rect = 2,
RoundedRect = 3
}

/// <summary>
/// Blendmode Enums. Updatewhen adding a blend mode.
/// </summary>
public enum BlendMode
{
Opacity = 0,
Additive = 1,
Subtract = 2,
Multiply = 3
}


public BlendMode blendMode;
public string Name;
public bool Visible = true;
public bool Hidden = false;

private Color cachedColor;

/// <summary>
/// Override this function to implement the drawing fucntion of a custom Draw Command
/// </summary>
/// <returns>The Canvas after the Draw Command has executed</returns>
/// <param name="_input">The Canvas before the Draw COmmand has executed</param>
/// <param name="_width">Width of image in pixels</param>
/// <param name="_height">Height of image in pixels</param>
public virtual Color[] DrawToColorArray(Color[] _input, int _width, int _height)
{
//some draw code here
//for when we add blend modes

return _input;

}

/// <summary>
/// override this function to draw custom inputs for your draw commands.
/// </summary>
public virtual void DrawControls()
{
blendMode = (BaseDrawCommand.BlendMode)EditorGUILayout.EnumPopup (blendMode);

}

/// <summary>
/// Helper function to appropriately blend a new pixel with the canvas' pixel.
/// Please use this rather than editing the array directly to support BlendModes
/// </summary>
/// <returns>The blended color value.</returns>
/// <param name="_pixel">Pixel to be blended</param>
/// <param name="_canvas">Canvas Pixel to blend too</param>
protected Color BlendPixelToCanvas(Color _pixel, Color _canvas)
{
cachedColor = _canvas;
switch (blendMode){
case BlendMode.Opacity:

cachedColor.a = _pixel.a + _canvas.a;

cachedColor.r = (_pixel.r * _pixel.a) + ((1 - _pixel.a) * _canvas.r);
cachedColor.g = (_pixel.g * _pixel.a) + ((1 - _pixel.a) * _canvas.g);
cachedColor.b = (_pixel.b * _pixel.a) + ((1 - _pixel.a) * _canvas.b);

break;
case BlendMode.Additive:
namespace SpriteMaker
{
[System.Serializable]
/// <summary>
/// Base Draw Command. Subclass this to create custom draw commands
/// </summary>
public class BaseDrawCommand
{

/// <summary>
/// Types of Draw Commands. Need to update when creating a new Draw Command
/// </summary>

public enum DrawCommandType
{
Fill = 0,
Circle = 1,
Rect = 2,
RoundedRect = 3,
Perlin = 4
}


/// <summary>
/// Blendmode Enums. Updatewhen adding a blend mode.
/// </summary>
public enum BlendMode
{
Opacity = 0,
Additive = 1,
Subtract = 2,
Multiply = 3,
Replace = 4
}

public BlendMode blendMode;
public DrawCommandType myType;
public string Name;
public bool Visible = true;
public bool Hidden = false;

private Color cachedColor;

/// <summary>
/// when we serialize a draw command, it stores its data here so it gets serialized properly.
/// Unity doesn't nattively support serializing derived classes, so this class has to hold the data from derived classes
/// derived Draw Commands are responsible for storing and retrieving serialized data
/// </summary>
[System.Serializable]
public struct SerializedData
{
public float[] serializedFloats;
public Color[] serializedColors;
[SerializeField]
public Gradient[] serializedGradients;
};

public SerializedData data;

/// <summary>
/// Override this function to implement the drawing fucntion of a custom Draw Command
/// </summary>
/// <returns>The Canvas after the Draw Command has executed</returns>
/// <param name="_input">The Canvas before the Draw COmmand has executed</param>
/// <param name="_width">Width of image in pixels</param>
/// <param name="_height">Height of image in pixels</param>
public virtual Color[] DrawToColorArray(Color[] _input, int _width, int _height)
{
//some draw code here
//for when we add blend modes

return _input;

}

/// <summary>
/// override this function to draw custom inputs for your draw commands.
/// </summary>
public virtual void DrawControls()
{
blendMode = (BaseDrawCommand.BlendMode)EditorGUILayout.EnumPopup(blendMode);

}

/// <summary>
/// Helper function to appropriately blend a new pixel with the canvas' pixel.
/// Please use this rather than editing the array directly to support BlendModes
/// </summary>
/// <returns>The blended color value.</returns>
/// <param name="_pixel">Pixel to be blended</param>
/// <param name="_canvas">Canvas Pixel to blend too</param>
protected Color BlendPixelToCanvas(Color _pixel, Color _canvas)
{
cachedColor = _canvas;
switch (blendMode)
{
case BlendMode.Opacity:

cachedColor.a = _pixel.a + _canvas.a;

cachedColor.r = (_pixel.r * _pixel.a) + ((1 - _pixel.a) * _canvas.r);
cachedColor.g = (_pixel.g * _pixel.a) + ((1 - _pixel.a) * _canvas.g);
cachedColor.b = (_pixel.b * _pixel.a) + ((1 - _pixel.a) * _canvas.b);

break;
case BlendMode.Additive:

cachedColor.a = _pixel.a + _canvas.a;
cachedColor.a = _pixel.a + _canvas.a;

cachedColor.r = Mathf.Min((_pixel.r * _pixel.a) + _canvas.r, 1.0f);
cachedColor.g = Mathf.Min((_pixel.g * _pixel.a) + _canvas.g, 1.0f);
cachedColor.b = Mathf.Min((_pixel.b * _pixel.a) + _canvas.b, 1.0f);

cachedColor.r = Mathf.Min((_pixel.r * _pixel.a) + _canvas.r,1.0f);
cachedColor.g = Mathf.Min((_pixel.g * _pixel.a) + _canvas.g,1.0f);
cachedColor.b = Mathf.Min((_pixel.b * _pixel.a) + _canvas.b,1.0f);

break;

break;
case BlendMode.Subtract:
cachedColor.a = _pixel.a + _canvas.a;

case BlendMode.Subtract:
cachedColor.a = _pixel.a + _canvas.a;
cachedColor.r = Mathf.Max(_canvas.r - (_pixel.r * _pixel.a), 0.0f);
cachedColor.g = Mathf.Max(_canvas.g - (_pixel.g * _pixel.a), 0.0f);
cachedColor.b = Mathf.Max(_canvas.b - (_pixel.b * _pixel.a), 0.0f);

cachedColor.r = Mathf.Max(_canvas.r - (_pixel.r * _pixel.a),0.0f);
cachedColor.g = Mathf.Max(_canvas.g - (_pixel.g * _pixel.a),0.0f);
cachedColor.b = Mathf.Max(_canvas.b - (_pixel.b * _pixel.a),0.0f);
break;

break;
case BlendMode.Multiply:
cachedColor.a = Mathf.Min(_pixel.a + _canvas.a, 1.0f);

case BlendMode.Multiply:
cachedColor.a = Mathf.Min (_pixel.a + _canvas.a, 1.0f);
cachedColor.r = Mathf.Lerp(_canvas.r, _canvas.r * (_pixel.r), _pixel.a);
cachedColor.g = Mathf.Lerp(_canvas.g, _canvas.g * (_pixel.g), _pixel.a);
cachedColor.b = Mathf.Lerp(_canvas.b, _canvas.b * (_pixel.b), _pixel.a);

cachedColor.r = Mathf.Lerp (_canvas.r, _canvas.r * (_pixel.r),_pixel.a);
cachedColor.g = Mathf.Lerp (_canvas.g, _canvas.g * (_pixel.g),_pixel.a);
cachedColor.b = Mathf.Lerp (_canvas.b, _canvas.b * (_pixel.b),_pixel.a);
break;
case BlendMode.Replace:

cachedColor.a = _pixel.a;

break;
}
cachedColor.r = _pixel.r;
cachedColor.g = _pixel.g;
cachedColor.b = _pixel.b;

return cachedColor;
}
break;
}

return cachedColor;
}

/// <summary>
/// Called before serializing this draw call. Derived classes must extend this and populate SerializaedData to be correctly serialized;
/// </summary>
public virtual void OnBeforeSerialize()
{
}

}
/// <summary>
/// Called after serializing or anytime a BaseDrawCommand must be cast to a derived type. builds derivedclass from data in SerializedData
/// use this to populate properties from serializeddata
/// </summary>
/// <param name="bd">Bd.</param>
public virtual void PopulateFromBase(BaseDrawCommand bd)
{

blendMode = bd.blendMode;
}

}
}
Loading

0 comments on commit eb4fbfe

Please sign in to comment.