Search Unity

Paint In 3D ✍️ Paint In Editor✏️ Paint In 2D

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

  1. Tu-Le

    Tu-Le

    Joined:
    Jun 5, 2015
    Posts:
    14

    Here is my case.
    - 1 paintableTexture
    - 1 PaintSphere
    - 1 P3dColor
    -1 P3dColorCounter
    - i use material Window_Glass in example
    - When i change color of PaintSphere, and ColorCounter by the cyan color i only paint a small sphere and counter go to max value. but when i change to Orange color its return to true value
     
  2. Tu-Le

    Tu-Le

    Joined:
    Jun 5, 2015
    Posts:
    14
    Oh i just remove component ColorCounter and re-add and the problem gone
     
    Darkcoder likes this.
  3. noahx

    noahx

    Joined:
    Nov 22, 2010
    Posts:
    77
    Hi. Basic question, how do you add more materials to Paint? I see these that come by default by I want to use my own materials/textures to paint them on objects, but I can't find how to add them to show up there:
    upload_2023-1-10_22-9-34.png

    Thanks.
     
  4. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    There is a little guide in the documentation HERE on how to add more.
     
  5. bill18ization

    bill18ization

    Joined:
    Jan 29, 2013
    Posts:
    8
    Hi. I know that this is a plugin for 3D objects but is there a way to paint 2D objects as well? For example, if the user takes a screenshot of the app, I would like to allow them to paint on the image.
     
  6. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    No, only Skinned/Mesh Renderer can be painted. You could make a flat plane/quad that works similar to 2D.
     
  7. bill18ization

    bill18ization

    Joined:
    Jan 29, 2013
    Posts:
    8
    Thanks for the reply. I have got a couple more questions.

    1. Do you have a scene with all the different brushes laid out as part of the UI similar to how you find it in 3D painting software so that I can drop a mesh into the scene and start working on it rightaway?
    2. Can meshes be painted when they are being animated?
    3. Are there any known limitations to this tool?
     
  8. neapolitanstudios

    neapolitanstudios

    Joined:
    Feb 17, 2011
    Posts:
    75
    @Darkcoder I'm having issues with Paint Nearby, Paint Decals and Splat Map materials. I have them all working individually. I can get decals working in the Paint Nearby example (37) I can have Paint Nearby work with Splat Maps with Paint Sphere, but the second I try to add a Paint Decal component the whole thing falls apart.

    Is using paint nearby/decals and Splat Map materials something that's supported?
     
  9. spirit_2

    spirit_2

    Joined:
    Jul 16, 2021
    Posts:
    3
    Hi there. This is great plugin! Thanks a lot!
    I have an annoying issue when I paint inside of local masks, though. Is there any other way than writing a shader to resolve this?
     
  10. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Assuming you're talking about the in-game painting features:

    1 - No, all the demo scene brushes are just example. Many of the demo scenes are also configured to show a specific feature, and it wouldn't make sense or even work if they were all combined into the same scene.

    2 - Yes. If you're doing in-game painting with a P3dHit__ component that uses raycasts (like P3dHitScreen), then your animated mesh will need colliders that math or are close enough to the mesh surface as it's animating.

    3 - Like what?


    Are you isolating the color channels properly? Splat maps require you to specifically paint one channel at a time, and optionally erase/decrease/subtract the other channels. This is easy to do with P3dPaintSphere since you specify the exact color/channels, but with decals this is typically done via texture so it's not always so simple. What you might want to do is to only set the decal's Shape texture, and leaving the Texture blank. This means you're only painting the Color, which is easy to control.

    What issue?
     
  11. spirit_2

    spirit_2

    Joined:
    Jul 16, 2021
    Posts:
    3
    Oh :D I forgot to attach the picture. The issue is the dark edges
     

    Attached Files:

  12. neapolitanstudios

    neapolitanstudios

    Joined:
    Feb 17, 2011
    Posts:
    75
    I realized the issue was the normal settings (normal front and normal back). Adjusting those made the paint appear; however, it doesn’t create the pattern of the decal. It’s distorted as if it isn’t been drawn correctly. I assume hitnearby and hitcollisions draw based on the direction the object is traveling in/impacts the paint object?

    Basically, I’m trying to paint a trail behind a moving player with a splatter pattern. It’s mostly working, but the decal is being distorted when it’s painted (I can attach something when I’m at my machine). It’s not a UV issue as I’m drawing on a flat plane that takes up the entire in sheet. Are there any ideas/examples you have to remove the decal distortion?

    /Edit - Figured it out. I needed to rotate the decal object to project onto the ground (similar to the PaintNearby example)
     
    Last edited: Feb 5, 2023
    Darkcoder likes this.
  13. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    This issue is called 'texture bleeding'. Your texture there is using bilinear blending, which means the pixels in your texture will be smoothly blended together to look nice. The downside is that since your mask means you only paint pixels that are definitely inside the circle shape, the pixels that are outside are 'bleeding' in at the edges. Fixing this depends on your exact scenario. For example, you could have the paint mask be 1 pixel thicker than the actual visual mask used in the shader, but again this depends on what you're doing.
     
    spirit_2 likes this.
  14. Tu-Le

    Tu-Le

    Joined:
    Jun 5, 2015
    Posts:
    14
    Hello, i want my TexturePainter have Unlit shader. is it possible?
     
  15. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Paint in 3D works with any shader that uses textures that are applied to the mesh using UV data (i.e. most shaders). Your Unlit shader is probably supported too. If you open up the "01 Basic Setup" demo scene, then you should be able to just swap out the spaceship's material with your unlit one, and it should immediately work. If not, you may need to change the P3dPaintableTexture component's Slot setting, so instead of painting the _MainTex, it paints the main texture of your Unlit shader (e.g. _BaseMap for URP/HDRP), but for most shaders this is _MainTex. There is a dropdown next to this Slot setting that allows you to pick any texture in the shader.
     
    Tu-Le likes this.
  16. Tu-Le

    Tu-Le

    Joined:
    Jun 5, 2015
    Posts:
    14
    thanks. i just realize i can use normal shader not only p3d shader lol
     
  17. Tu-Le

    Tu-Le

    Joined:
    Jun 5, 2015
    Posts:
    14
    @Darkcoder did the p3d mask support invert mask?
     
  18. Lewnatic

    Lewnatic

    Joined:
    Sep 29, 2012
    Posts:
    209
    So have run into a very odd issue when using P3D Model components and swap their paintable target via code in game.

    Here is my setup:
    I got two base meshs. Both bases have a paintable, texture and a clone material component attached. Both base mesh share the same texture because its packed into an atlas, but have obviously different mesh colliders. So I swap the colliders to work with both bases. This works fine.

    Then I have additive meshs like clothing, hair etc for both base meshs.
    Those clothings use the P3d Model component and they needs to be disabled/enabled depending on the base mesh selection. Most of those additive meshs share the same texture to draw into as well.

    The problem starts with cloths or objects that are compatible with both base meshs. For example hair.
    I now have a hair mesh that is used in both . The hair mesh uses the p3d Model component and I swap its p3d paintable target via code depending on which gender is selected.

    The strange thing now is that .... painting the hair itself is working, as I can see when I look at the painted texture, but the preview dot and the painted progress is not appearing anymore. So it seems like the issue really is only the preview and the preview dot missing! I checked the paint tools hit component, and preview is active too!

    Findings:
    So it seems like swapping the paintable target in an p3d Model component via code seems to disable the preview dots and strokes of the active paint tool.

    Question:
    Is there a way to force or refresh the preview dots to show again?

    I am trying to solve this for multiple days now.
     
    Last edited: Feb 15, 2023
  19. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Could you prepare a very simple demo scene that reproduces this issue, and send it to me via email or private message?
     
  20. Realgar

    Realgar

    Joined:
    Sep 30, 2012
    Posts:
    52
    Hi @Darkcoder I've been using P3D for a while, (remember, I asked you how to engrave rocks :) Now I would like to be able to save a game, and reload it with the paints in place... At least for one game session, not necessarily when you quit Unity and restart it. I need to be able to save and reload the scene, somehow. How can I do to keep the textures from one scene to another? thank you very much in advance
     
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Paint in 3D comes with a basic save/load system you can enable with the P3dPaintableTexture component's SaveLoad & SaveName settings ("39 Auto Save Load" demo scene). This works when the paintable GameObject is destroyed or activated, which includes changing scenes. You can also manually call it with this component's Save/Load functions, which can be called from C#, or via UI events.
     
  22. Realgar

    Realgar

    Joined:
    Sep 30, 2012
    Posts:
    52
    Thank you very much !
     
    Darkcoder likes this.
  23. spirit_2

    spirit_2

    Joined:
    Jul 16, 2021
    Posts:
    3
    Thanks for detailed explanation. I'm kinda newbie with shaders and just getting familiar with Shader Graph. Could you maybe point me to a direction... I don't know, my scenario it should look nice and blend like it would do in Photoshop.
    A second texture, if it isn't made from the first one wouldn't be an option for me, but I guess there's a way to contract or expand mask on runtime to forbid painting on its edges.
     
  24. linenum

    linenum

    Joined:
    Nov 16, 2020
    Posts:
    57
    Hi I'm trying to set up a P3D Paintable in game/dynamically where the slices of the original object are independently paintable. So far the pieces display the painted material but they can't be painted - only the original object can be painted (which updates the appearance of the slices).

    I'm using the open source plugin Ezy Slice to slice cubes into pieces. If after slicing I set the cube to SetActive(false) the painted material stays on the pieces. If I delete the cube the appearance of the slices disappears (as well as the preview image of the materials in the inspector for the slices). I made it so that pieces can be sliced into sub-pieces, etc. I want to be able to paint the sliced pieces but the best I can manage is to set the original cube to active and then paint it (which then paints all of the pieces that were sliced from the cube - and slices of slices). Does it have something to do with cloning the material? In the inspector in game I had clicked "Add Paintable Texture" and "Add Material Cloner".
     
    Last edited: Feb 22, 2023
  25. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Masks in Photoshop are pixel-perfect, so it's not really comparable. Well, you could always disable texture filtering (point filtering), but then your scene wouldn't look as good. Yes, you would need to expand/contract the mask at runtime with some special code.

    In this scenario you must slice the object before you make it paintable (or at least before you activate the paintable components). Assuming the slicing operation clones the original object, it will likely break things if you slice the object after it's been activated.
     
    spirit_2 likes this.
  26. linenum

    linenum

    Joined:
    Nov 16, 2020
    Posts:
    57
    Thanks for your reply. Slicing doesn't clone the original object. It creates two new objects with only a mesh renderer, mesh filter and materials. It adds a second material for the exposed surface (if it doesn't already exist).
    Then my code adds the components SliceableObject, Rigidbody and MeshCollider (so that it can use physics and be sliced again).
    At the moment the original object can be painted. When sliced the slices show the painted texture. I want the slices to be able to have clones of the painted texture that can be painted.
     
    Last edited: Feb 24, 2023
  27. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I see. Then it sounds like the slices are being given the same material as the original. This is fine as long as you then use P3dMaterialCloner, P3dPaintableTexture, etc the same as the original and then activate them. Then each slice will have its own unique material and texture.

    The p3dPaintableTexture component's Advanced/Existing setting allows you to control if/how the texture in the slot is used when activated, and by default this will copy the texture data there. In your scenario this texture data will be what you've already painted, so it should make a copy of that. If not, you can always manually call the P3dPaintableTexture component's Replace or Clear method with the .Current texture from your original object's P3dPaintableTexture.
     
  28. linenum

    linenum

    Joined:
    Nov 16, 2020
    Posts:
    57
    Darkcoder:
    Thanks I got it to work....
    I just did this:
    Code (CSharp):
    1. slicedObj.AddComponent<P3dPaintable>();
    2. P3dPaintableTexture paintableTexture = slicedObj.AddComponent<P3dPaintableTexture>();
    3. slicedObj.AddComponent<P3dMaterialCloner>();
    The original object has a PaintableTexture that is 64x64 and has point filter mode. The slices copy the texture but use 512x512 and auto for filter.
    I'd like it to use 64x64 without initially using 512x512.
    I tried:
    paintableTexture.Texture.filterMode = FilterMode.Point;
    But it is giving a null reference exception....
     
    Last edited: Feb 26, 2023
  29. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I believe there is a setting that lets you override the default filter mode when the paint able texture gets activated. Before activation there will be no texture. You can check the Advanced settings in the inspector to see what they are. I'm out of town for the next week so I can't say exactly off the top of my head.
     
  30. linenum

    linenum

    Joined:
    Nov 16, 2020
    Posts:
    57
    Darkcoder:
    I got it to work:
    Code (CSharp):
    1. paintableTexture.Filter = P3dPaintableTexture.FilterType.Point;
    2. paintableTexture.Width = 64;
    3. paintableTexture.Height = 64;
    Thanks for making it be so easy to customize....
     
    Last edited: Feb 26, 2023
    Darkcoder likes this.
  31. ray2fr

    ray2fr

    Joined:
    May 5, 2013
    Posts:
    6
    Hello, I just started using your asset, latest version 2.0.3 (can provide invoice number if needed), and I find it amazing!

    I have an issue though : I have a custom object with unsuitable UV, but i am still able to paint it in-game thanks to the overlay technique depicted in the documentation, exactly as in the "08 Overlay" demo scene by setting up my model exactly as the provided demo horse model.

    While this works fine for in-game painting, I am, however, unable to do in-editor painting : nothing visible seems to happen when I try to paint the demo horse model from the 08 Overlay scene (while keeping its setup as is), nor my own model.
    And I'd like to do so because in-editor painting provides really convenient tools and options.
    The only models I can "in-editor" paint are models with suitable UV's without using the overlay technique.

    What am I missing ? Is "in-editor painting" maybe not targetting the correct overlay material or UV channel ?

    Or, in simpler words: how can I in-editor paint the demo horse in the "08 overlay" scene ?

    Thanks in advance for your help !
     
  32. Realgar

    Realgar

    Joined:
    Sep 30, 2012
    Posts:
    52
    Hello, this is definitely a dumb question, but when I turn on autosave textures, with a name, it works fine to keep paints from scene to scene, but how can I clear them when I restart the whole application in windows ? Or is there a script that would reset or erase all P3D textures when launching the game? Thanks in advance !
     
  33. ray2fr

    ray2fr

    Joined:
    May 5, 2013
    Posts:
    6
    Hello @Darkcoder , any answer to my question above ?
    Thanks in advance !
     
  34. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I tested this and it looks like the in-editor painting is only capable of painting the first UV channel. I'll see if I can fix it.


    I believe the P3dPaintableTexture component has the ClearSave method. You'll probably need to make a custom script to call it though.
     
  35. Realgar

    Realgar

    Joined:
    Sep 30, 2012
    Posts:
    52
    Thank you ! So I'm going to make a script that will erase all the objects.
     
    Darkcoder likes this.
  36. ray2fr

    ray2fr

    Joined:
    May 5, 2013
    Posts:
    6
    Thanks a lot for your answer !
    This is what I was thinking too. If it helps, I noticed however that I can in-editor paint the "Erase (Albedo)" material on that horse, and then repaint other materials on places where I used that Erase material. That’s my workflow right now...
     
  37. Nrike458

    Nrike458

    Joined:
    Oct 6, 2019
    Posts:
    37
    So, I've searched through the forums, and looked through the documentation, and was wondering if there has been any changes since the 2018 post on the topic of layers. I'm looking at trying to do layers in my game, kinda like photoshop and other 2d programs, and was wondering if there is a better way to do things than adding a bunch of materials. Has there been any developments in that field?
    Also, is there a way to store and save previous undo states for closing and re-opening the program? I'm thinking of maybe storing a copy of the material for that undo state, but I'm not quite sure if that would work.
    Any input would be appreciated!
     
  38. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Actually, the issue was that the in-editor painting materials didn't paint the alpha, which is the A channel of the albedo texture. The overlay scene requires you to paint the alpha to 'reveal' the new paint, whereas most other scenes don't. I'll fix this and send you a new build shortly.


    The easiest way to implement layers without multiple materials is to make one P3dPaintableTexture component for each layer. You then need to make a custom component that swaps the texture group based on which layer you currently want to paint. Finally you manually composite the textures together (e.g. with Blit) and apply it to your material's texture slot(s).

    You can access all undo/redo data from the P3dPaintableTexture's States list. This stores either full texture snapshots, or local commands, depending on your UndoRedo setting. This will require some custom code to save/load.
     
  39. Nrike458

    Nrike458

    Joined:
    Oct 6, 2019
    Posts:
    37
    Perfect, I think I understand what to look for on that. Finally, is there an easy way to share player made materials? I know you can save them and edit them later, and they save with a name. I peaked through the code, and it looks like it saves to a binary file, correct? So theoretically, sharing a player made design would be as simple as sending those binary files, correct?
     
  40. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    The P3dPaintableTexture component has a method called something like GetPngData which gives you a byte array you can send over the network. You can then call the LoadData method I think to do the inverse on each client. The save/load system internally uses PlayerPrefs by default, but you can change that if desired.
     
  41. Nrike458

    Nrike458

    Joined:
    Oct 6, 2019
    Posts:
    37
    Awesome! Thanks for your speedy replies! I will take a look and see what I can create!
     
    Darkcoder likes this.
  42. Analyst578

    Analyst578

    Joined:
    Oct 9, 2019
    Posts:
    3
    Can I get some help ? I am trying to make an app using your plugin and my goal is to make drawable board which I created and spray paintable wall too but I have no idea how to make any object to be affected by the different paintings like if you can guide me please thanks , I cant convert or make the gameobject react to the example scenes even if i copy paste the components or replace the mesh or textures
     
  43. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Maybe your mesh isn't suitable for painting? There's a guide in the documentation showing you the requirements, and how to check if your mesh meets them, and how to work around it.
     
  44. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    I buy this one hoping to have a unify solution for mesh painting, both texture and vertex.
    But just found out it only does texture painting, oof my bad haha.
    I have a skinned mesh character and want to paint its vertex data to support some shader features, as Blender is unfortunately does not let user paint vertex color's Alpha. Their vertex color only has 3 value RGB.
    Do you consider making a vertex painting feature someday?
     
  45. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Vertex painting is an entirely separate code set, so none of the existing features would be compatible unless I rewrite them all. Very few people need vertex painting compared to texture painting, so I have no plans to implement it.
     
  46. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    Totally understandable.
    I'm glad we have a texture painting solution too, thank you for this.
     
    Darkcoder likes this.
  47. jacobian

    jacobian

    Joined:
    Jul 20, 2015
    Posts:
    17
    Hi
    Bought your app last week.

    var paintableTexture = objOfImportance.GetComponent<P3dPaintableTexture>();
    var png = paintableTexture.GetPngData();
    File.WriteAllBytes($"{dirPath}{Path.DirectorySeparatorChar}{fileName}.png", png);

    The above is working fine on pc but on android its giving me an images that is partially black, seems like some sort of race condition???

    upload_2023-3-25_16-47-15.png
     
  48. jacobian

    jacobian

    Joined:
    Jul 20, 2015
    Posts:
    17
    Seems it might just be a urp thing with saving render textures
     
  49. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Does this issue occur in the save load example scene? Which exact version of Unity and Paint in 3D are you using?
     
  50. jacobian

    jacobian

    Joined:
    Jul 20, 2015
    Posts:
    17