Tanoda
ClipPainter.cs
Go to the documentation of this file.
2using UnityEngine;
3
5{
6 public class ClipPainter : MonoBehaviour
7 {
8 [SerializeField] private bool grab = true;
9
10 [SerializeField] private Brush brush;
11
12 [SerializeField] private GrabArea.GrabTextureWrapMode wrapMode = GrabArea.GrabTextureWrapMode.Repeat;
13
14 private RenderTexture t;
15 private RaycastHit hitInfo;
16
17 private void OnGUI()
18 {
19 GUI.Box(new Rect(0, 0, 300, 320), "");
20 GUI.Box(new Rect(0, 0, 300, 300), "Grab Texture");
21 if (t != null)
22 GUI.DrawTexture(new Rect(0, 0, 300, 300), t);
23 grab = GUI.Toggle(new Rect(0, 300, 300, 20), grab, "Grab");
24 }
25
26 public void Awake()
27 {
28 t = new RenderTexture(brush.BrushTexture.width, brush.BrushTexture.height, 0);
29 }
30
31 private void Update()
32 {
33 if (Input.GetMouseButtonDown(0))
34 {
35 var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
36 if (Physics.Raycast(ray, out hitInfo))
37 {
38 var d = hitInfo.transform.GetComponent<InkCanvas>();
39 if (d != null && !grab) d.Paint(brush, hitInfo);
40 if (grab)
41 {
42 GrabArea.Clip(brush.BrushTexture, brush.Scale,
43 hitInfo.transform.GetComponent<MeshRenderer>().sharedMaterial.mainTexture,
44 hitInfo.textureCoord, brush.RotateAngle, wrapMode, t);
45 brush.BrushTexture = t;
46 brush.ColorBlending = Brush.ColorBlendType.UseBrush;
47 grab = false;
48 }
49 }
50 }
51 }
52 }
53}
Class managing brush information.
Definition: Brush.cs:11
float RotateAngle
Rotate angle of the brush.
Definition: Brush.cs:168
float Scale
The size of the brush. It takes a range from 0 to 1.
Definition: Brush.cs:159
ColorBlendType ColorBlending
Color synthesis method.
Definition: Brush.cs:206
ColorBlendType
Color synthesis method.
Definition: Brush.cs:16
Texture BrushTexture
Brush texture.
Definition: Brush.cs:131
Texture paint to canvas. To set the per-material.
Definition: InkCanvas.cs:23
bool Paint(Brush brush, Vector3 worldPos, Func< PaintSet, bool > materialSelector=null, Camera renderCamera=null)
Paint processing that use world-space surface position.
Definition: InkCanvas.cs:793
Definition: ClipPainter.cs:5