• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dman8723 · Feb 01, 2018 at 12:20 PM · painting

How to make a paint board through texture

Hi everyone, I want to making a paint board to draw a picture, I just want to make a simple drawing function like change brush color and size, redo and undo the step, how do I start to make the function to draw a line through mouse or touch pad??

I have been tried using Line Renderer, but I don't know how to use it since I only need to draw on a 2D texture

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dman8723 · Feb 05, 2018 at 06:04 PM 0
Share

I have found the code which is drawing with GL, but how can I limit drawing on a texture only?? Since I find it is not drawing on canvas or texture now

void Update() { processInput();

         if(Input.Get$$anonymous$$ouseButton(0)) {
             
             Vector3 e = GetNewPoint();
             
             if(s != Vector3.zero) {
                 for(int i = 0; i < lp.Length; i += 2) {
                     float d = Vector3.Distance(lp[i], e);
                     if(d < 1 && Random.value > 0.9f) sp = AddLine(sp, lp[i], e, false);
                 }
                 
                 lp = AddLine(lp, s, e, false);
             }
             
             s = e;
         } else {
             s = Vector3.zero;
         }
     }
     
     /** Replace the Update function with this one for a click&drag drawing option */
     void Update1() {
         processInput();
         
         Vector3 e;
         
         if(Input.Get$$anonymous$$ouseButtonDown(0)) {
             s = GetNewPoint();
         }
         
         if(Input.Get$$anonymous$$ouseButton(0)) {
             e = GetNewPoint();
             lp = AddLine(lp, s, e, true);
         }
 
         if(Input.Get$$anonymous$$ouseButtonUp(0)) {
             e = GetNewPoint();
             lp = AddLine(lp, s, e, false);
         }
     }
     
     Vector3[] AddLine(Vector3[] l, Vector3 s, Vector3 e, bool tmp) {
         int vl = l.Length;
         if(!tmp || vl == 0) l = resizeVertices(l, 2);
         else vl -= 2;
             
         l[vl] = s;
         l[vl+1] = e;
         return l;
     }
     
     Vector3[] resizeVertices(Vector3[] ovs, int ns) {
         Vector3[] nvs = new Vector3[ovs.Length + ns];
         for(int i = 0; i < ovs.Length; i++) nvs[i] = ovs[i];
         return nvs;
     }
     
     Vector3 GetNewPoint() {
         return g.transform.InverseTransformPoint(
             Camera.main.ScreenToWorldPoint(
                 new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z * -1.0f)
             )
         );
     }
 
     void OnPostRender() {
         m.SetPass(0);
         GL.Push$$anonymous$$atrix();
         GL.$$anonymous$$ult$$anonymous$$atrix(g.transform.transform.localToWorld$$anonymous$$atrix);
         GL.Begin( GL.LINES );
         GL.Color( new Color(0,0,0,0.4f) );
         
         for(int i = 0; i < lp.Length; i++) {
             GL.Vertex3(lp[i].x, lp[i].y, lp[i].z);
         }
         
         GL.Color( new Color(0,0,0,0.1f) );
         
         for(int i = 0; i < sp.Length; i++) {
             GL.Vertex3(sp[i].x, sp[i].y, sp[i].z);
         }
         
         GL.End();
         GL.Pop$$anonymous$$atrix();
     } 
     
     void OnGUI() {
         GUI.Label (new Rect (10, 10, 300, 24), "GL. Cursor keys to rotate (with Shift for slow)", labelStyle);
         int vc = lp.Length + sp.Length;
         GUI.Label (new Rect (10, 26, 300, 24), "Pushing " + vc + " vertices. 'C' to clear", labelStyle);
         
         GUI.Label (new Rect (10, Screen.height - 20, 250, 24), ".Inspired by a demo from ", labelStyle);
         if(GUI.Button (new Rect (150, Screen.height - 20, 300, 24), "mrdoob", linkStyle)) {
             Application.OpenURL("http://mrdoob.com/lab/javascript/harmony/");
         }
     }
 

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Obsessi0n · Feb 01, 2018 at 10:44 AM

You should check this out. It in 3d but sure you can convert it to 2d. http://codeartist.mx/tutorials/dynamic-texture-painting/ https://assetstore.unity.com/packages/templates/tutorials/realtime-painting-33506 https://assetstore.unity.com/packages/tools/gui/color-selector-33516

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dman8723 · Feb 01, 2018 at 04:52 PM 0
Share

I find that the asset of realtime-painting is similar to my expectation, however I want to draw with a pen not a bursh, which part should I change to draw a line??

avatar image Obsessi0n dman8723 · Feb 01, 2018 at 06:01 PM 0
Share

Check on the live tutorial the part of dynamic painting he uses an image that is a circle and fades I think if you replace it with a full color image with no transparence it will become a pen. Not sure but you should try it out.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

74 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How are trees and detail meshes placed on the terrain? 0 Answers

How to make field painter like cities skylines districts? 0 Answers

Multiplayer drawing game 0 Answers

terrain editing help 0 Answers

Why is my terrain so dark? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges