GreasePencil.cs
1 using System.Collections.Generic; 2 using System.Runtime.CompilerServices; 3 using Unity.Mathematics; 4 using UnityEngine; 5 6 // This file defines the ScriptableObject that will hold the deserialized 7 // Grease Pencil data. This allows the data to be saved as a persistent 8 // asset in your Unity project, making it easy to reference in other 9 // components and scenes. 10 [CreateAssetMenu(fileName = "GreasePencilData", menuName = "Grease Pencil/Grease Pencil Data", order = 1)] 11 public class GreasePencilSO : ScriptableObject 12 { 13 // The main data object that holds all the information from the JSON. 14 public GreasePencilData data; 15 } 16 17 [System.Serializable] 18 public class GreasePencilData 19 { 20 public List<MaterialData> materials; 21 public List<LayerData> layers; 22 } 23 24 25 //TODO move into gp namespace 26 [System.Serializable] 27 public class MaterialData 28 { 29 public string name; 30 public float[] stroke_color; 31 public float[] fill_color; 32 public float[] fill_mix_color; 33 public float[] fill_uv_rot_scale; 34 public float[] fill_uv_offset; 35 public float[] alignment_rot; 36 public float stroke_texture_mix; 37 public float stroke_u_scale; 38 public float fill_texture_mix; 39 public int flag; 40 } 41 42 [System.Serializable] 43 public class GreasePencilMaterial 44 { 45 public string name; 46 public Color stroke_color; 47 public Color fill_color; 48 public Color fill_mix_color; 49 public float4 fill_uv_rot_scale; 50 public float2 fill_uv_offset; 51 public float2 alignment_rot; 52 public float stroke_texture_mix; 53 public float stroke_u_scale; 54 public float fill_texture_mix; 55 public int flag; 56 } 57 58 [System.Serializable] 59 public class LayerData 60 { 61 public string name; 62 public float[] tint_color; 63 public float tint_factor; 64 public float opacity; 65 public List<FrameData> frames; 66 67 //Update when adding triangle/fill support 68 public List<int3> Triangles() 69 { 70 return new List<int3>(); 71 } 72 } 73 74 [System.Serializable] 75 public class FrameData 76 { 77 public int frame_number; 78 public List<StrokeData> strokes; 79 } 80 81 [System.Serializable] 82 public class StrokeData 83 { 84 public int material_index; 85 public float aspect_ratio; 86 public bool cyclic; 87 public int end_cap; 88 public int start_cap; 89 public float softness; 90 public float[] fill_color; 91 public float fill_opacity; 92 public List<PointData> points; 93 } 94 95 [System.Serializable] 96 public class PointData 97 { 98 public float[] position; 99 public float radius; 100 public float opacity; 101 public float rotation; 102 public float[] vertex_color; 103 104 public Vector3 Position => new Vector3(position[0], position[1], position[2]); 105 public Vector4 VertexColor => new Vector4(vertex_color[0], vertex_color[1], vertex_color[2], vertex_color[3]); 106 }