Search Unity

[Released] Mobile Paint (with multi-touch)

Discussion in 'Assets and Asset Store' started by mgear, Aug 16, 2014.

  1. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Yes, that seems to be a bug, what happens is:
    - At GetScreenshot(), it creates texture with Screen width&height (could use canvas texture size)
    - Then it reads full screen with ReadPixels (should read from canvas area only, not from 0,0 - ..)

    I'll fix for next version
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Yes, currently it seems to be too complicated for the next update ((requires big changes to add all the different control options), have to leave it for later.

    Easiest way should be to have separate zoom/pan mode, cannot draw in that mode so its easy to catch gestures.
     
  3. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Great! Really love the support you're giving. Any idea when the next update will be live?
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Actually I can post the fix snippet here soon soon, as the next update is still probably few weeks away. bit delayed.
     
  5. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    That would be awesome :D again thanks for your awesome support!
     
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Temporary fix for screenshot, have to clean that up for next update (and this would only work if the fullscreen quad is used, not with custom mesh etc.
    Code (CSharp):
    1.         public Texture2D GetScreenshot()
    2.         {
    3.             HideUI();
    4.  
    5.             cam.Render();
    6.             Mesh go_Mesh = GetComponent<MeshFilter>().mesh;
    7.             var topLeft = cam.WorldToScreenPoint(go_Mesh.vertices[0]);
    8.             var topRight= cam.WorldToScreenPoint(go_Mesh.vertices[3]);
    9.             var bottomRight = cam.WorldToScreenPoint(go_Mesh.vertices[2]);
    10.             var image = new Texture2D((int)(bottomRight.x-topLeft.x),(int)(bottomRight.y-topRight.y), TextureFormat.ARGB32, false);
    11.             image.ReadPixels(new Rect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y), 0, 0);
    12.             image.Apply(false);
    13.  
    14.             ShowUI();
    15.             return image;
    16.         }
     
  7. jjdomain

    jjdomain

    Joined:
    Sep 11, 2015
    Posts:
    93
    If you can have that configuration option (separate zoom/pan; tap-to-fill only; no drawing) in the next update that would be much appreciated!
     
  8. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    That should be easier to do, will try to add!
     
  9. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Also one note about smooth brush edges,
    adding Antialias image effect on the camera also helps.

    examples:

    512x512 resolution canvas, no image effects
    512512_noaa.jpg

    512x512 resolution canvas, FXAA3 image effect (parameters 0,0,4)
    512512_fxaa.jpg
     
  10. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Great Thanks!

    Though I think I know what i'm doing wrong. I checked out the Canvas_Size_From_Panel scene in the NewUI map. And it seems that is what I need to get my screenshots functioning correctly. But when I attach a Panel as a reference area I can't draw on it :(. Any idea what could cause this?
     
  11. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Disable image component from the panel, because it stops the drawing code either at
    if (eventSystem.IsPointerOverGameObject()) return;
    or it might block the drawing raycast itself.

    In that scene see "PanelAreaReference" gameobject, it has image disabled.
     
  12. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hmm it seems to work, when I make a panel and it's fullscreen I can draw on it. When I change the size of the panel to:
    Left: 125
    Right: 125
    Top: 10
    Bottom: 10

    I can't draw on the panel :(

    These are the referenceCorner vectors debugged from my scene:
    1: (125.0, 10.0, 0.0)
    2: (125.0, 475.0, 0.0)
    3: (521.0, 475.0, 0.0)
    4: (521.0, 10.0, 0.0)

    Any idea what could cause this problem?
     
  13. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    hmm.. seems to work here, can you post scene & reference panel inspector screenshot?

    paint_ref.jpg
     
  14. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Here you go :) Again thx for the quick response and helping me out!



     
  15. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Ok, for some reason it seems to get culled from camera.. documentation says:
    "Assigning triangles will automatically Recalculate the bounding volume.", but it still seems to need RecalculateBounds() anyways..

    This should fix it:
    Open file: MobilePaint.cs

    // FIND LINE (its inside void CreateFullScreenQuad())
    Code (CSharp):
    1. go_Mesh.RecalculateNormals();
    // ADD THIS LINE AFTER IT
    Code (CSharp):
    1. go_Mesh.RecalculateBounds();
     
  16. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Great! It's working perfectly now! When taking the picture it still has some white space to the left and right (so it takes makes a screenshot slightly bigger than the canvas size) but I think we can manage that for now :)
     
  17. xiaomaza

    xiaomaza

    Joined:
    Apr 4, 2015
    Posts:
    9
    Hi,mgear,Why do I download the 1.9 version is 1.8?
     

    Attached Files:

    • 1.9.png
      1.9.png
      File size:
      485.4 KB
      Views:
      863
  18. jjdomain

    jjdomain

    Joined:
    Sep 11, 2015
    Posts:
    93
    Are we getting close to a release with the separate zoom/pan (tap-to-fill only; no drawing) configuration?
    Thanks!
     
  19. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Sorry missed these,

    hmm.. that is bit strange, for me it downloads v1.9 and readme has v1.9 (tested just now)
    Are you using Unity5 ? Did you try to hit update & reimport in the Unity builtin asset store?
     
  20. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Soon :) It is basically working, just need to test it on couple mobiles and do some tidying for the store submission.
    Demo scene has tap to fill mode and zoom/pan mode buttons.
     
  21. Polywick-Studio

    Polywick-Studio

    Joined:
    Aug 13, 2014
    Posts:
    307
    Q: How do you save the canvas and re-load it back?

    I try to load a file saved from GetCanvasAsTexture()

    Code (CSharp):
    1. public void UpdatePixel(string sName)
    2.         {
    3.             var s = File.ReadAllBytes(sName);
    4.  
    5.             Texture2D tex = new Texture2D(2, 2);
    6.             tex.alphaIsTransparency = true;
    7.             tex.LoadImage(s);
    8.             tex.alphaIsTransparency = true;
    9.  
    10.             pixels = tex.GetRawTextureData();
    11.            
    12.             Update();
    13.  
    14.         }
    15.  
    but it loads out strange.
     
  22. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
  23. Polywick-Studio

    Polywick-Studio

    Joined:
    Aug 13, 2014
    Posts:
    307
    Please provide a way, to save the canvas (without mask) and apply back the canvas onto a mask.

    resolutionSlider = 1 causes the PNG to be saved with both canvas and mask.

    I want it to be saved without mask.
     
  24. xiaomaza

    xiaomaza

    Joined:
    Apr 4, 2015
    Posts:
    9
    Sorry,my unity3d is 4.6.4:D
     
  25. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Yeah..scenes are for 5.1 or later.. not likely to update the 4.x version anymore.

    You'll need to open the scenes in 5, and see what settings are used, then create the same scene in 4.x..
     
  26. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Eraser now works with 2 modes
    - Erase with background color
    - Erase/restore canvas image (see gif below, the image modified by drawing, then restored with eraser)

    Also, from now on starting to add issues & request to github
    (so they are easier to keep track, and users can add them there also)
    https://github.com/unitycoder/UnityMobilePaint/issues


     
  27. xiaomaza

    xiaomaza

    Joined:
    Apr 4, 2015
    Posts:
    9
    Hi,mgear,
    this script in “scene_SaveLoadScreenshotFile” seems to have lost,that is in new version1.95 LostScript.png .
     
  28. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
  29. xiaomaza

    xiaomaza

    Joined:
    Apr 4, 2015
    Posts:
    9
  30. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hi Mgear, any news on saving the canvastexture and reloading it as a canvastexture? I'm trying to get it to work but it doesn't save the image as the size it was suppose to save it? When reloading the texture onto the canvas it's not fullscreen (the original is) it's missing a part of the left side.
     
  31. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    having limited internet access this couple of weeks, will check it after that..
    You could check what resolution images it tries to use by adding Debug.Log into those
    SetCanvasImage() and GetCanvasAsTexture(), are they same or different..

    logged issue here https://github.com/unitycoder/UnityMobilePaint/issues/12
     
  32. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    tested with few different settings, seems to work on simple scenes.
    Can you post screenshot from your mobilepaint inspector? (so i can test with same values)
     
  33. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392

    Hey there

    have you found out whether the moving-out-of-the-slider-when-brush-size-change event has a fix?

    It's the only issue I have with MP. Otherwise everything's great.
     
  34. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442

    unfortunately not yet, going to test this soon, if can somehow cancel the slider drag on pointerexit:
    http://docs.unity3d.com/ScriptReference/UI.Selectable.OnPointerExit.html
     
    Last edited: Jan 29, 2016
  35. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    temporary fix for pc:
    Code (CSharp):
    1. // FIND LINE in void MousePaint()
    2.  if (eventSystem.IsPointerOverGameObject()) return;
    Code (CSharp):
    1. // ADD THIS LINE AFTER IT
    2.  if (eventSystem.currentSelectedGameObject!=null) return;
     
  36. theLaymaster

    theLaymaster

    Joined:
    Apr 20, 2015
    Posts:
    8
    Hi MGear,
    In the InitializeEverything() method, there is a conditional that is producing clones of the linePreviewCircle transform. The reason this is a problem is that I have built a page changer that calls InitializeEverything() with each new page. Click through a bunch of pages and you get a new clone with every click. Eventually you get a crash in Android at around 12 clones. I believe this is the code in the method that does it:


    Code (CSharp):
    1.         if (previewLineCircle)
    2.                 {
    3.                     // duplicate rounded circle
    4.                     previewLineCircleStart = Instantiate(previewLineCircle) as Transform;
    5.                    
    6.                     // reset pos
    7.                     previewLineCircleStart.position = Vector3.one*99999;
    8.                     previewLineCircle.position = Vector3.one*99999;
    9.                 }
    I find that if I do this:
    Code (CSharp):
    1.         if (!previewLineCircle)
    2.                 {
    3. // ...etc
    4.                 }
    It works the way I need it. It also makes more sense to me.

    Is there any reason I shouldn't do this? Meaning, am I creating problems somewhere else that I haven't run into? Thanks for having a look.
     
  37. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hi mgear, I saw that the latest version includes some code to allow panning and zooming, is this feature fully available in 1.95? Or are you still developing this feature? We are in the progress of getting really in to the drawing things now (UI is done) and we would like to create some sort of endless drawing :). Though we're not really sure how to accomplish it, it might be easier done when images can be scrolled/panned or zoomed :)
     
  38. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Yeah, that looks like a bug.
    added to https://github.com/unitycoder/UnityMobilePaint/issues/18

    That previewline object is only needed, if line drawing is used, so if you are not using linemode.

    You can remove reference to the "linePreviewCircle" gameobject,
    that would do the same as your script modification. I'll fix for next update.

    previewlines.jpg (set the reference to "none")
     
    theLaymaster likes this.
  39. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Not immediately.. but taking requests of course.

    Endless drawing.. if simple lines would be enough, probably drawing lines as meshes would be lighter than full bitmaps?
    Multiple canvases is not really supported yet, that might had been good idea, load older canvases when they are coming near viewport, and save them when going too far..
     
  40. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    Hello there

    Will this fix work for iOS?


    Thanks
     
  41. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Doesn't work (tested on android, but would be same on ios)

    Would have to find something similar to that for each touch after this line,
    Code (CSharp):
    1. if (eventSystem.IsPointerOverGameObject(touch.fingerId)) return;
    *Actually it did seemed to work just now:
    // FIND LINES
    Code (CSharp):
    1. while (i < Input.touchCount)
    2. {
    3. touch = Input.GetTouch(i);
    4. if (eventSystem.IsPointerOverGameObject(touch.fingerId)) return;
    5. i++;
    6. }

    // ADD THIS LINE AFTER THOSE LINES ( after last } )
    Code (CSharp):
    1. if (eventSystem.currentSelectedGameObject != null) return
     
    Last edited: Feb 14, 2016
  42. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    Awesome

    Thanks for your support.

    I've added those lines and it works great!


    Thanks again
     
  43. theLaymaster

    theLaymaster

    Joined:
    Apr 20, 2015
    Posts:
    8
    Thanks, yo.
    The cloning is fixed but I still have the crashing problem on Android. I guess that wasn't the issue. I'll submit my latest discovery below.
     
  44. theLaymaster

    theLaymaster

    Joined:
    Apr 20, 2015
    Posts:
    8
    Hey mgear,

    Crashing (likely) associated with setTexture() and texture changes:

    on Android, getting crashes after page changes, which call new textures.

    Code (CSharp):
    1.     void switchCanvas() {
    2.         canvasRenderer = FindCanvas.drawingCanvas;
    3.         //unitycoder_mobilepaint.ClearImage ();
    4.         yourNewTexture = textures[index];
    5.         canvasRenderer.material.SetTexture(targetTexture, yourNewTexture);
    6.     }

    Anyway -- from -logcat on the console, System Out of Memory Error after about twenty calls or so. The setTexture() method is cited in the dump as well.

    I've been exploring different methods from mobilePaint where the commented line is. InitializeEverything is the most expensive.

    On the profiler, the button that calls the above function creates an EventSystem.Update() spike that takes 96-98% of CPU mem for 440-480ms. Pretty nasty. And the only thing it's really doing is switching that texture. The GPU is calling RenderTexture.SetActive on this spike.

    On PC, the mem usage is bad, but it doesn't crash. On Android, it dies after 20 or so calls. It varies a bit.
    Any ideas? Would setTexture() be creating a memory leak in Android? Or is it just that my PC mem is larger?


    Let me know if you need more specifics. Just trying to keep it brief. Thanks!
     
  45. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Ok, i'll check it today.
    https://github.com/unitycoder/UnityMobilePaint/issues/19

    *It seems that at least texture count keeps increasing on every initialize call, checking more..

    temporary fix, not yet sure if it breaks something else..but texture count doesnt increase anymore then:

    // FIND LINE
    Code (CSharp):
    1. drawingTexture = new Texture2D(texWidth, texHeight, TextureFormat.RGBA32, false);
    // CHANGE TO
    Code (CSharp):
    1. if (drawingTexture==null)
    2. {
    3.     drawingTexture = new Texture2D(texWidth, texHeight, TextureFormat.RGBA32, false);
    4. }
     
    Last edited: Feb 17, 2016
  46. theLaymaster

    theLaymaster

    Joined:
    Apr 20, 2015
    Posts:
    8
    I don't see the drawingText variable in my scripts. Is that new?

    I noted you mention InitializeEverything in the bug title. I have found that this happens with or without calling it.

    Are there any optimization quidelines worth knowing? The textures are 2048x1536, still set to nearest POT in the inspector. I get the crash even with greatly reduced quality in the project settings.

    EDIT: looking through the code, I see "tex", which looks to be the older version of the same thing. Testing now. I would update the code to the latest, but I'm way into the shipping timeline and there are number of custom dependencies at this point. Keeping the options open as a last resort though.
     
    Last edited: Feb 17, 2016
  47. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    yes, some variables were renamed in recent updates,
    better not update in the last minute (or at least test first in separate project).

    you can see from Profiler, Memory panel, if "Textures" count keeps increasing every call, then it could be this same issue.

    if adding that if () doesnt help, you can also email me your project so i can test directly on that,
    or check which version it is, so maybe i can check on that version.
     
    theLaymaster likes this.
  48. theLaymaster

    theLaymaster

    Joined:
    Apr 20, 2015
    Posts:
    8
    Aha. Yes, Texture count is increasing with each increment. And this is happening on a PC. So it's just that the PC has more mem. So for some reason the old tex is not being removed. In the API, setTexture does not have the equiv of "remove" or "reset".

    mgear, is this something that is not happening on newer versions of mobilepaint? I will set up a test proj with the latest script and a stripped implementation of this functionality to test.

    Thanks very much for your time on this.
     
  49. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    Current asset store version still has that (but that temporary fix should help for now),
    but there has been several other fixes in recent updates:
    https://github.com/unitycoder/UnityMobilePaint/wiki/Release-Notes
     
  50. theLaymaster

    theLaymaster

    Joined:
    Apr 20, 2015
    Posts:
    8
    SOLVED
    here's what I did.
    Added this to MobilePaint.cs after the ClearImage() method:
    Code (CSharp):
    1.     public void killCurrentMainTex() {
    2.             if (tex != null) {
    3.                 Texture2D.DestroyImmediate(tex, true);
    4.             }
    5.         }
    In the latest version "tex" is called "drawingTexture", I believe.

    Then on my artswitcher script, I have a function like this:
    Code (CSharp):
    1.     void switchCanvas() {
    2.         mobilepaint.killCurrentMainTex ();
    3.         yourNewTexture = textures[index];
    4.         drawingCanvas.material.SetTexture(targetTexture, yourNewTexture);
    5.         mobilepaint.InitializeEverything();
    6.     }
    Of course all the references have to be set up on the switcher to make it work. But it seems to work. Texture count is staying the same with the switch.



    (I've been meaning to have a close look at the latest updates for a while now. One of these minutes, I promise! Looks like some handy new stuff in there.)

    Thanks again for your help on this, mgear!
     
    Last edited: Feb 20, 2016
    mgear likes this.