Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Paint In 3D ️️✏️ In Game & In Editor & Skinned Mesh Painting

Discussion in 'Assets and Asset Store' started by Darkcoder, Jul 10, 2018.

  1. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    If you set the P3dHitScreen component's Spacing setting to 0 as you have done, then on mobile the decal should preview while your finger is touching the screen, and apply once you release your finger. This should work the same as on desktop, where holding the mouse or key (F) paints a preview, and when you release it applies the paint. You want the paint component to not paint, but instead remember where you were touching the screen, and only apply when you click a button? This sounds like a pretty game specific feature, and you may have to modify the P3dHitScreen code yourself to implement this.


    You can use the GetPngData and LoadFromData methods to manually handle the save/load.


    You can project decals that can be moved and reordered using the 'live painting' system, which is shown in the "55 Live Painting" demo scene. With this setup you can move and rotate the decals using standard Transform modifications, so it's very easy to use. One thing to keep in mind is that this live paint is re-applied every frame, so once you enter the game and no longer need live editing of the decals, I recommend you apply them, and then disable or remove them so you have no runtime overhead.


    Which exact Unity version, Paint in 3D version, and mobile device are you using?
     
  2. robert12342

    robert12342

    Joined:
    Jun 11, 2018
    Posts:
    29
    Do you want to add this as an example in the future?) It sounds complicated to me
     
  3. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    I'll consider it. I'm not happy with the way P3dHitScreen currently works, as it's a little complex. I'll try and think up a way to simplify it and split it up into different more purpose specific components.
     
  4. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    697
    This will be fun.
    First try.)

    1.JPG

    2.JPG





    Is there a wa to get a directional flow towards "world space direction" so
    that they have a flow in the right dirtection on vertical and horizontal car exterior surfaces?

    I found this example

    DirectionalFlow.JPG

    It uses flow down.
     
    Last edited: Dec 19, 2020
  5. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    Looks great, you should add some kind of particle effect when they hit to make it look better, and maybe a custom splat shaped decal :)

    Currently the flow is only local based on the flow/normal map you specify. I plan to add a way to make it in world space, but there are a few other things I want to do first.
     
    keeponshading likes this.
  6. XB23

    XB23

    Joined:
    Sep 12, 2018
    Posts:
    9

    I'm using unity 2019.4.15, paint in 3D 1.9.4 but I will update that (I miss the update) and I'm using a surface studio 2
     
  7. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    You should try the latest version. I have almost the same CPU and GPU as the Surface Studio 2, and I experience no issues with 2019.4.15f1 with Paint in 3D 1.9.13. You can try it in a new project. If you still experience issues let me know the demo scenes you experience issues with, the render pipeline you're using, and any other build settings and such you've changed.
     
  8. Anubis_V2

    Anubis_V2

    Joined:
    Dec 11, 2020
    Posts:
    5
    I'm using a pen for Surface studio with an eraser, I check if i'm using the eraser, put SetActive(false) on all colors except erase.
    I got no problem to draw with the pen and to erase on side but if i erase the center of my screen, all my drawing vanishe.

    Have you any idea ?
     
  9. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458

    Does this issue occur in the example scenes with erase too? Or only your specific setup?
     
  10. marcos

    marcos

    Joined:
    Oct 18, 2009
    Posts:
    589
    Is there a way to sample vertex colours to generate a texture?

    Would love to be able to generate AO to vertex colour (using another asset), and then sample the colours to export a texture at runtime.

    If not, consider this a feature request instead! :~)
     
  11. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    Good idea, I also considered UV baking, AO, bevels, etc. However, these are all kind of outside the scope of painting in 3D, so it may be better suited to a separate asset. I’ll think about it next year!
     
  12. Anubis_V2

    Anubis_V2

    Joined:
    Dec 11, 2020
    Posts:
    5

    I've add the erase system on the first exemple scene, it erase the spaceship but i don't have the problem who clear all my drawing.
    In my programm, drawing positions are sent to an other user who redraw (with good radius/color), it's working with drawing but my eraser seems bugged...

    I'll check the information sent by the erase mode but if you have another idea i'll take it !
     
  13. Anubis_V2

    Anubis_V2

    Joined:
    Dec 11, 2020
    Posts:
    5

    I find my mistakes, i called two times my eraser and put radius to 300++ ><
     
    Darkcoder likes this.
  14. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    Good to hear :D
     
  15. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    302
    Hi.

    I'm trying to do an experiment, which I don't know if it's possible.

    A vehicle makes tire marks through trail renderer. And I would like those marks to become part of the texture. That is to say, that instead of being objects they become painted.

    Could you make the car wheels the "brushes" to paint those marks on the terrain and save the result as the overall terrain texture?

    If it can't be ... can someone help me with any suggestions?

    Thank you.
     
  16. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    Yes, this can be done.

    Check out the "32 Nearby Painting" demo scene. This shows you how to paint every pixel within the radius of the red sphere. You can copy+paste this "Paint" GameObject onto your car, and delete the P3dSpiral component (this is used to move the object around in this example). You can then set a TileTexture that looks like a skid mark or something depending on how you want it to look. You can also replace P3dPaintSphere with P3dPaintDecal if you want to paint decals that have a direction.
     
  17. robert12342

    robert12342

    Joined:
    Jun 11, 2018
    Posts:
    29
    Hi, how can I record this data so that I can then apply it to another player in multiplayer? This will be much easier for the server than sending a Texture upload_2020-12-28_16-14-16.png
     
  18. Anubis_V2

    Anubis_V2

    Joined:
    Dec 11, 2020
    Posts:
    5
    Hello, i have a button to clean my drawing using
    Code (CSharp):
    1.         public void ClearAll(Texture texture, Color color)
    2.         {
    3.             if (activated == true)
    4.             {
    5.                 for (var i = paintableTextures.Count - 1; i >= 0; i--)
    6.                 {
    7.                     paintableTextures[i].Clear(texture, color);
    8.                 }
    9.             }
    10.         }
    But when i call the undo / redo methods i lost the last drawing before my clean.
    On first pic i erase all and use undo and i have the pic 2

    Have a nice day !
     

    Attached Files:

    • 1.PNG
      1.PNG
      File size:
      101.4 KB
      Views:
      26
    • 2.PNG
      2.PNG
      File size:
      98 KB
      Views:
      24
    • Param.PNG
      Param.PNG
      File size:
      19.1 KB
      Views:
      26
  19. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    The "67 Simulated Multiplayer" demo scene shows you what this might look like. The actual networking code would depend on your networking plugin though, and I can't help you there.


    You must call the StoreState() method on your P3dPaintableTexture before performing any changes you want to be able to undo. If you're doing a global paint operation then you can call P3dStateManager.StoreAllStates, which is used by all the example painting tools before they apply.
     
  20. robert12342

    robert12342

    Joined:
    Jun 11, 2018
    Posts:
    29
    And where are the points where the player draws stored?
     
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    They're not stored, the paint is baked into the textures. If you enable the P3dPaintableTexture component's UndoRedo = LocalCommandCopy, then each texture stores every P3dCommand used to paint it though. This can also be accessed from the OnAddCommand event, and you can use the AddCommand method, but this is much more advanced.
     
  22. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    Hey everyone,

    Tomorrow I'm going to be interviewed by TheMessyCoder on Twitch, check it out if you'd like!

    carlosWilkes.jpg
     
  23. fad0505

    fad0505

    Joined:
    Jun 11, 2019
    Posts:
    1
    hi! i just bought this asset but i couldnt find how can i put an event trigger for the scene.. for example it triggers something after the canvas has been paint.anyone know about it?
     
  24. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    The P3dPaintableTexture component has the OnModified event, which can be hooked into from code. Just keep in mind this only tells you if you painted within range of the mesh, and so it's possible that no pixels have actually been modified. If you need an inspector event rather than just a C# one then let me know.

    If you want to detect when pixels have actually been painted, then you must use the P3dChangeCounter component, but this currently doesn't expose any event for detecting an arbitrary change. If you need this then let me know.
     
  25. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    Hey everyone,

    Version 1.9.14 of Paint in 3D is now out!
    • Fixed Texture Pressure modifier errors.
    • Fixed Texture Random modifier errors.
    • Made in-editor painting only begin after you switch to the paint tab.
    • Added Unload Paint Brush button to in-editor paint tab.
    Enjoy :)
     
  26. AuriMoogle

    AuriMoogle

    Joined:
    Jun 4, 2018
    Posts:
    6
    I'm really flashed from your plugin! I can't remember the last time I saw clean code in an asset store product. It was super easy to integrate our custom input handling. I just needed to derive from P3dInputManager and override the update method.

    The only thing that bugged me a while is the fact that I couldn't draw on my 3D object in my game scene. But my object worked in your 'Basic Setup' scene, meaning it was correctly setup. After a bit of debugging, I realized that you reject the fingers that started over GUI. In our case, the paintable 3D objects are part of the GUI. This caused all fingers starting on top of the 3D object to be rejected from painting. I removed the checks and now everything is working like a charm. :)

    Feature Request: Add a setting to disable the 'StartedOverGui' checks
     
  27. restush96

    restush96

    Joined:
    May 28, 2019
    Posts:
    28
    Hello, does paint in 3D is like Vroid that can save the texture after painted?
     
  28. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    When you say your paintable objects are part of the GUI, do you mean your GUI is in world space?

    The whole UI and touch screen interaction code is something I want to improve this year. P3dHitScreen is a bit of a monolith already, which makes adding cool new features difficult.


    No idea what Vroid is, but yes you can save/load your paint both in editor and in game. For the in game painting this can be set up to be automatic, and there is even an example scene showing this off :)
     
  29. restush96

    restush96

    Joined:
    May 28, 2019
    Posts:
    28
    @Darkcoder Hmm I see. I mean I want to use this to draw my mesh using UModeler on the asset store rather than using Substance Painter.
     
  30. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    I see. As long as UModeler can generate UV maps that have no tiling or overlapping (i.e. similar to lightmap UVs), then yes this can be done. Just keep in mind Paint in 3D is no way near as advanced at Substance Painter. Maybe one day it will be, but they have a huge team of developers and many years of a head start!
     
  31. restush96

    restush96

    Joined:
    May 28, 2019
    Posts:
    28
    @Darkcoder Ahh I see. However, I do not propose the feature like Substance Painter, I feel like if your team can have a major update that can draw on UV map like Vroid. http://prntscr.com/x6olyn
     
  32. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    upload_2021-1-19_4-0-2.png

    Hello, sadly I am chronically sick so I was looking for videos or very forward tutorials on how to accomplish my painting objective. Unfortunately I did not find any tutorials with depth for what I want to do. I wasn't sure if maybe I just have to sit down and do a lot of messing around to figure things out. The worst part is I am always in pain so I can only do so much for a small amount of time. This is why I was looking for a video tutorial.

    I am advanced with programming and recently discovered a problem with displaying meshes onto another mesh (my terrain). I want to show an explosion texture on top of an area where a rocket or cannon projectile would impact. I did accomplish this however some of the calls within Unity cause GC. I remembered I bought this Paint asset during the holidays and thought maybe I could easily accomplish the same thing but avoid this GC issue.

    I just want to paint onto my mesh, an explosion. The explosion texture is called "blackSmoke" and there is 16 separate meshes of terrain. The reason is because I created code to deform the terrain during gameplay and this all works great but I just need more detail, hence an explosion decal maybe? I would like help setting this up if possible. I just want to paint downwards onto a terrain mesh with code during real-time. I have the code to find the position and which terrain meshes are hit from a projectile. I just need to know what components, and how to set it up to accomplish my goal, Thank you.
     
  33. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    Here is another picture of the terrain meshes, they are meshes (not Unity terrain) and do have a mesh collider. Just wanted to be clear incase this mattered.
    upload_2021-1-19_4-17-6.png
     
  34. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    Interesting. This kind of painting view might already be possible with some kind of dual mesh setup where they both use the same texture (similar to the in-game Atlas Painting example). I'll see if I can make an example of it.


    If you let me know which features you'd like to see videos on I can prioritize them. I plan to make some new videos very soon, though I also want to make some major changes to P3dHitScreen and would rather not make any videos instantly obsolete so maybe I'll do that first.

    Most GC alloc should only be when you first paint an object, because this can fill up certain lists. It should then re-use them and not cause any. If you show me pictures of your profiler after the scene has 'warmed up', it would help so I can see if they can be eliminated.
     
    restush96 likes this.
  35. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    What components do I need to paint a texture directly down onto another mesh? Maybe I need it to be decal? The explosion texture is called "blackSmoke". Where do I serialize this, what script?

    I just need to know what script and function to use to paint onto the terrain during real-time. I just want to paint downwards, on top of the terrain mesh, that simple.
     
  36. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    Like this but this is my code.
    upload_2021-1-19_10-3-58.png
     
  37. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    Assuming you want to paint from a 3D point like a Transform instead of the mouse, you can use the P3dHitNearby+P3dPaintDecal components to do this. The "55 Live Painting", "56 Apply", and "57 Translate" demo scenes show you one way to set this up.

    If you want to do this from code then you only need the P3dPaintDecal component. You can then manually call its "HandleHitPoint" method with the position, rotation, etc you want. The "74 Paint From Code" demo scene covers this in more detail with example code.
     
  38. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    I have to say, you have a lot of scenes which is awesome. Unfortunately I still couldn't get any painting onto my meshes. No idea why but maybe you know why. I even tried changing the shader to the one the spaceship uses and still no painting. I tried making prefabs from the InGame scenes of painting, and dragging them into my scene, still no paint with "live paint" showing on my meshes.

    upload_2021-1-20_4-26-58.png upload_2021-1-20_4-29-36.png
    No idea what to do from here...
     
  39. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    upload_2021-1-20_4-33-33.png
    If the live doesn't work, maybe that explains why the line I wrote doesn't work either. I get the debug log, but definitely no painting. I copied the scene of "74 paint with code" best I could.
     
  40. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    Seems to be a problem with the shader, I changed to P3D Solid SRP and could see something, but it was blurry and wasn't looking as good as the example of the space ship.
     
  41. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    upload_2021-1-20_4-58-11.png
    upload_2021-1-20_5-0-42.png
    Example of changing the shader to P3D Solid SRP
     
  42. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    You can click the Analyze Mesh button to see how much of the mesh UV area you're using.

    Based on your picture it looks like your mesh is way too big, and your P3dPaintableTexture resolution is too low. Remember that the mesh texture pixels are being painted here, so if your mesh is 100x100 meter with a 512x512 texture then each pixel will be 20x20cm. If you need to paint a terrain you should only be painting a splat map that you then enhance with some kind of tiled detail texture.
     
  43. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    I'm not sure the Analyze mesh is helpful for me in this case.
    upload_2021-1-22_11-44-27.png
    Also again, nothing works with the simple lit shader URP I am using. I switched to your shader P3D Solid SRP and then I can see something. How do I address this? I need to use my texture.
     
  44. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    upload_2021-1-22_11-46-26.png
    upload_2021-1-22_11-48-43.png
    Also the paintable texture size is 16384 by 16384, seems insane. I set it to that and I can kind of see less blurry. I tried less but it was still blurry, not sure if I need to set other settings.
     
  45. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    Might be an issue with the fact these are CHUNKS of pieces... no idea.
     
  46. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    Oh right, the URP lit shader has a fake _MainTex slot that doesn't do anything. You need to make your texture slot use the _BaseMap slot. This is mentioned in the docs HERE.

    Also, the mesh analysis shows you're only using 6.25% of your UV space. This means with a 16384^2 texture (268,435,456 pixels), you're wasting 251,658,240 pixels, because you can never paint them. Since your mesh is just a 2D grid you can easily adjust the UV so it uses 100% of the space.
     
  47. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    I don't know why but after using _BaseMap slot, everytime I exit play mode, the base map slot becomes empty and makes the terrain black. I tried a lot of options, but it just keeps doing that.
    upload_2021-1-23_4-18-18.png
    The _BaseMap slot did work for finally showing a decal. How do I deal with black problem? Am I supposed to write code to set it back after exiting play mode? I would think that isn't necessary.

    Also I am not sure I understand, "Since your mesh is just a 2D grid you can easily adjust the UV so it uses 100% of the space." In the Analyze mesh, all options are disabled. The mesh is part of an .asset file so I can't open it into blender and uv it by hand. Because it is a chunk, it should be only using a portion anyway. I'm confused what to do here.
     
  48. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    The attached package shows painting in URP with the Lit shader, and it appears to work as expected. This was tsted with Unity 2019.4.13f1.

    The Analyze Mesh tool just shows you what your mesh UV looks like, it doesn't have any tools to modify the mesh. You must modify it using something else, or better you first generate your mesh so that it has good UVs that maximise the UV area used.
     

    Attached Files:

  49. ZaCkOX

    ZaCkOX

    Joined:
    Oct 14, 2017
    Posts:
    17
    Ok, I think I understand what you mean now. I need to make sure there isn't 1 material for all chunks. I need to make sure there is as many materials as there is chunks, one per chunk and that will maximize the area. The reason this didn't exist before was because the chunk script could make different sizes and changing the material(s) real-time like that is quite expensive for waiting. I was also using a different asset at the time. It was Mega Splat, but I stopped using it because I had trouble with the seams between chunks. That was before I realized it was a bug within Unity terrain. I eventually got it working by doing my own meshes, looks seamless. I will have to go back to a splat map and try to do what you are suggesting. This will take some time but I'll try to come back and reply when I get there, Thank you.
     
  50. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,458
    Ah, if it was using such little space due to atlasing then you can still do this (see: "Atlas Painting" demo scene). It might be faster if the mesh is split up, though I haven't benchmarked such an extreme scenario to be sure. But yes, you should use splat mapping either way.
     
unityunity