Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    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. YousifRagab

    YousifRagab

    Joined:
    Oct 30, 2015
    Posts:
    18
    Thanks a lot for your help, I used live decals and made the decal rotate in a direction to always face the camera, now it works flawlessly.
     
    Darkcoder likes this.
  2. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    1 - I'm not sure what would cause this, perhaps iOS sends different touch data to Unity than Android, and somehow the touch code in P3dInputManager causes it to detect touches incorrectly. You could add some extra code into P3dHitScreenBase.cs:LateUpdate to output what finger down & up states are being registered to see if/when something unexpected happens. The actual undo/redo states are generated from P3dHitScreen.cs:paintSmooth & PaintInterval, so you can test when those get called as well. I'm currently waiting for the new Macbook Air to come out and once it does I'll try and see what's going on, but for now I can only test with Android.

    2 - Perhaps there are different default framerate locks on each platform?

    Paint in 3D currently doesn't have any perspective projection paint tools, only orthographic, so it's not possible to get it to look the same as your scenario. Also, the paint doesn't have any depth mapping capabilities, so your text could 'shine through' solid objects in your scenario, though you do have control over the normal it can apply to. There would be no falloff issues like you describe though.
     
  3. neapolitanstudios

    neapolitanstudios

    Joined:
    Feb 17, 2011
    Posts:
    69
    I think this is most likely based on my tests. I have solved the issue though. I turned off savestate in the p3dpaint component and activated it in p3dPaintableTexture on select. It seems to work well now.
     
    Darkcoder likes this.
  4. DJ_DiX

    DJ_DiX

    Joined:
    Aug 1, 2017
    Posts:
    9
    Dont know, asked this befor or not, but - how resolve problem with paint with fast-moving objects?

    1. If drawing plane moves past the camera - we have "breaked" line

    2. BUT(!) If we move the camera along the drawing plane - we have "normal" line, without "jumps".

    Who know how to fix this?
    (pic1)
     
    Last edited: Jun 14, 2021
  5. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    The P3dHitScreen component implements smoothing using the mouse/finger position, so fast movements or low FPS are smoothed out when it applies paint using screen positions. In your first scenario, the object being painted is moved, so the mouse/finger smoothing has no effect. This is because the fast movement or low FPS from your object movement isn't known by the painting component, and so there's no way to automatically smooth this out. To make painting smooth in this scenario you would have to replace P3dHitScreen with your own component that raycasts against your object, records the hit points on the object, converts these to the local space of your object, and then performs smoothing using this local data, and then applies paint using smoothed points.

    I recommend modifying your game design so that you don't need to paint objects with high precision that move like this.
     
    DJ_DiX likes this.
  6. DJ_DiX

    DJ_DiX

    Joined:
    Aug 1, 2017
    Posts:
    9
    Thanks for answer!
    One more question - where i can limit touch count (need limit to 1)?
    Cant find any property for this(
     
  7. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    167
    We bought the plugin hoping to use it for AR - it says it's heavily optimized. But when looking into the code - it's crawling with things like GetComponent, comparison to null and Camera.main in Update. Simply putting the P3DHitScreen script into the scene drops FPS to less than 30 in the editor. Enabling mirroring and using particles painting in the game drops the FPS to 1-2 (AR tracking stops completely!). Also, the code itself has a lot of garbage - bad naming, unused fields and functions. I'd suggest you use Rider, which suggests HUNDREDS of improvements of the existing code, which can reduce it in volume drastically and the performance can be improved just by removing GetComponents from Update and stuff.

    Also, a crucial function that we need is the way to show preview in AR by raycasting from the center of the screen on to the mesh. I tried looking into the code to implement it myself, but it's just too huge, I started improving the code for an hour and gave up - it's just too much.
     
  8. gliealonso

    gliealonso

    Joined:
    Oct 21, 2018
    Posts:
    85
    Hi there,

    I'm using URP on my project, and the paint nearby doesn't work with a URP material, only if I change it to PaintIn3D/Solid.

    How can I fix that?

    Many thanks,
    Gabriel.
    upload_2021-6-16_14-31-34.png
     
  9. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    There's no setting for this currently. You can edit P3dHitScreenBase.cs HandleFingerDown(line 229+) and return from the method if fingers.Count is above 1, though the mouse hover is a finger too so you may have to write a little more complex code to factor that in. I'll add it in when I can.


    The code is heavily optimized where it matters. GetComponent is mainly used in places where you can optionally specify a camera or something, and if none is set then it will find it for you. I could probably cache these to save some time, but I don't think it's important. In the editor GetComponent is more expensive and allocates garbage (it doesn't at runtime). If you have examples of actual garbage allocation that isn't just cached then let me know specifically what you're referring to. If your AR scenario is running at 1-2 FPS then you're likely using poor settings for P3dHitScreen, or your textures are too high resolution. You can read the documentation HERE for the main techniques to optimize things.

    To paint at the center of the screen you can use the setup shown in the "31 Center Screen" demo scene. Even if you wanted to implement this yourself you would just need to perform a raycast and then call P3dPaintDecal's HandleHitPoint method, which shouldn't take an hour.


    You have to paint the _BaseMap, see HERE.
     
    DJ_DiX likes this.
  10. DJ_DiX

    DJ_DiX

    Joined:
    Aug 1, 2017
    Posts:
    9
    T.y. for answer! ^^
     
    Darkcoder likes this.
  11. unity_1cewWbGw8rRVxw

    unity_1cewWbGw8rRVxw

    Joined:
    Jun 6, 2018
    Posts:
    7
    ok i am interested in purchasing this but i want to know that when we are painting something Is there a callback that paint is completed or not?
     
  12. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    It depends how you define 'completed'. If your texture begins as transparent and you paint in the color+alpha, then you could use the P3dChannelCounter component to detect how much of the alpha channel % has been painted. The P3dChangeCounterEvent component can then be used to fire an event when this reaches the desired %.
     
  13. Jonsi

    Jonsi

    Joined:
    May 21, 2013
    Posts:
    44
    Hi there. This asset looks great. Is there a quick guide anywhere as to how you could use this in a Unity 2D project?I'm used to just working with 2D Sprites rather than MeshRenderers. Is this asset suitable for use in a 2D project? E.g. a painting/colouring mobile app (colouring in and adding stickers). Many thanks.
     
  14. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    No, it's for 3D object painting only. You can layer 3D into 2D though since they're basically the same, Unity just hid the sorting settings.
     
  15. DJ_DiX

    DJ_DiX

    Joined:
    Aug 1, 2017
    Posts:
    9
    What about supporting "New Input System" of Unity?
     
  16. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    The example components should already automatically work with the new input system package. The only exception is the VR components, which are more difficult to make work with both systems automatically.
     
    DJ_DiX likes this.
  17. Image3d

    Image3d

    Joined:
    Jun 20, 2008
    Posts:
    134
    Hi...is possible to paint over any shader ?

    The idea is to use it to paint over Lux Water Shaders, to create specific foam effects over the water shader using mask painting
     
    Last edited: Jun 26, 2021
  18. Thoronnim_Crystalia

    Thoronnim_Crystalia

    Joined:
    Jan 24, 2017
    Posts:
    27
    Hi all!!

    First of all, compliments for your great and brilliant asset!

    My question: how can I count updated pixels when the BlendMode in PaintSphere is set as ReplaceCustom with a specific texture?

    I mean, I'm not interested in how many pixels have a specific Color (like ColorCounter does properly), but how many pixels have been updated with the new texture.

    I tried ChangeCounter component as well, but the Count remains 0 even I painted several parts of the mesh (maybe I missed some property to be configured properly... I don't know...)

    Could you please support me on this?
    Thank you in advance!
     
  19. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    As long as the shader uses more or less unmodified mesh UV data matching these requirements, then it should work. For a water mask map you may be able to set up a plane/quad to be paintable, and use the painted texture from that to apply to your water.


    Yes you want to use the P3dChangeCounter. You must set the reference Texture+Color in this component that you want to compare against. In your scenario this should match your ReplaceCustom settings, where a result of 0 different pixels means they match.
     
    Thoronnim_Crystalia likes this.
  20. Thoronnim_Crystalia

    Thoronnim_Crystalia

    Joined:
    Jan 24, 2017
    Posts:
    27
    Yes!!
    I just configured the component as you suggested and it seems working as expected!
    Thank you so much for your fast and perfect answer!
     
    Darkcoder likes this.
  21. klvo

    klvo

    Joined:
    Mar 24, 2013
    Posts:
    30
    Hi there!

    I am doing a multi touch implementation, where the speed of the fingers affect the opacity and size of the painting by changing values on P3D Paint Sphere.

    What could be a good way to approach handling the speed of each separate finger to affect the painting it is doing in this way without affecting what the other fingers are painting? Right now the opacity and size are applied to all simultaneiusly.

    Thanks in advance
     
  22. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    So you want to be able to give each finger its unique painting settings? If so, the easiest approach would be to modify P3dHitScreenBase to include something like a finger index setting. You would then modify the HandleFingerDown method so that the finger only gets added to the fingers list if it matches this index. You would then need to create one P3dHitScreen component for each possible finger with a different index, and it should work. I'll consider adding this to a future version, as I can see it being useful.
     
  23. klvo

    klvo

    Joined:
    Mar 24, 2013
    Posts:
    30
    Thanks for the answer, I will try implementing this.
    Cheers!
     
    Darkcoder likes this.
  24. Danielsantalla

    Danielsantalla

    Joined:
    Jan 7, 2015
    Posts:
    62
    Hi! is there any way to implement "Undo" with P3D Hit between? I want to be able to do Undo/Redo in a VR environment
     
  25. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    You have to manually call the "P3dStateManager.StoreAllStates();" method when you want to be able to undo/redo actions performed after the call. Making this automatic would be possible, but it would likely lead to more issues than not.

    Consider the VR Pen demo scene for example, each pen is 'on' all the time, so when should the undo state be stored? If it's when you pick up the pen then undo could potentially remove everything you've painted. If it's stored just before you first paint a new surface then this could potentially create many undo/redo states when you draw one thing like 'hello', and even more if this drawing is done across multiple objects or your controller shakes a bit and causes the lines to break up.
     
    DJ_DiX likes this.
  26. Rewaken

    Rewaken

    Joined:
    Mar 24, 2015
    Posts:
    102
    Hello, Im facing following problem. I'm trying to paint walls in my game. I added paintable, paintabletexture,material cloner to it. It paints well but sometimes it just lost albedo ref of the material. I guess because p3d create its own instance ?
    It turns completely white or just dark black shade even after clearing state/ copy slots problem still persists(both in editor and runtime) only solution remain is to manually add texture again.
    Here's an example image
     

    Attached Files:

    • sss.png
      sss.png
      File size:
      555 KB
      Views:
      24
  27. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    It's hard to tell what the issue is from your description and screenshot alone. You can try copy+pasting only this problem GameObject into a new scene and see if the issue persists. If not, there must be some other script interfering with it. The P3dMaterialCloner will clone the specified material slot when activated, so it's possible you have some other script that's changing the material. If this is intended behavior you can always call the P3dPaintableTexture component's UpdateMaterial method.
     
  28. Rewaken

    Rewaken

    Joined:
    Mar 24, 2015
    Posts:
    102
    Hello I will try to debug it more to give more info about it. I tried painting decal on the walls Im controlling its position with mouse but when I rotate the mouse decal's shape changes here is an example image.
     

    Attached Files:

  29. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    This is due to the P3dPaintDecal component's Wrap setting, which you can set to 0. You can also adjust the P3dHitScreen component's settings like RotateTo = Normal.
     
  30. Rewaken

    Rewaken

    Joined:
    Mar 24, 2015
    Posts:
    102
    Thanks it fixed the issue.
    Yesterday Unity editor crashed, crash wasn't related to p3d but due to some preview package. But after that Im getting following error
    Code (CSharp):
    1. Material 'PolygonOffice_Material_01_A(Clone)' with Shader 'Standard' doesn't have a texture property ''
    2. UnityEngine.Material:GetTexture (string)
    3. PaintIn3D.P3dPaintableTexture:Activate () (at Assets/PaintIn3D/InGame/Scripts/P3dPaintableTexture.cs:890)
    4. PaintIn3D.P3dPaintable:Activate () (at Assets/PaintIn3D/InGame/Scripts/P3dPaintable.cs:143)
    5. PaintIn3D.P3dPaintable:Start () (at Assets/PaintIn3D/InGame/Scripts/P3dPaintable.cs:268)
    Do I need to delete the material ?
     
  31. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    Check your P3dPaintableTexture's Slot setting, it sounds like the texture name is null/empty? It should be like _MainTex or something.
     
  32. Danielsantalla

    Danielsantalla

    Joined:
    Jan 7, 2015
    Posts:
    62
    Hello everyone. Thanks @Darkcoder for being so helpful. I'm making a VR game that uses the plugin for the oculus quest. By oculus request, the game should be always at 72fps and currently the game is rock solid there. However, at the moment of painting, I get dips in my fps (I go down to 50fps) when painting over an unlit shader. Are there tips or is there any way to minimize/optimize the fps cost of painting to a _MainTex? Thanks!
     
  33. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    Yes, the main optimization techniques are detailed HERE.
     
  34. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    162
    Hi! Do you have possibility to paint per channel? If I want to paint only on R-channel (or G/B/A) of texture without changing others.
     
  35. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    Yes, each paint component has the Blend Mode / Channels setting, which can be used to do this:

    upload_2021-7-20_16-16-37.png

    You can set them to 0 and that channel won't be modified.
     
  36. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    162
    Great! Thank you!
     
    Darkcoder likes this.
  37. Legendary_keith

    Legendary_keith

    Joined:
    Apr 21, 2015
    Posts:
    15
    Hello,

    I can't see my object in VR when I use the paint 3D/solid shader. It just becomes invisible.

    It works when i run it in the editor on my pc, but after i build the apk to test it in my vr headset (oculus quest 2), it becomes invisible. I could only see the shadow from that object
     
    Last edited: Jul 23, 2021
  38. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    167

    Oh, I missed your answer, thank you! I will definitely try all of these!
     
    Darkcoder likes this.
  39. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    162
    @Darkcoder Hi! Just bought the asset and tried to paint in Editor.

    I entered play mode and it started to spam errors like this.

    Code (CSharp):
    1. Assertion failed on expression: 'm->CanAccessFromScript()'
    2. System.Reflection.MethodBase:Invoke (object,object[])
    3. PaintIn3D.P3dHitScreen_InEditor:IntersectRayMesh (UnityEngine.Ray,UnityEngine.Mesh,UnityEngine.Matrix4x4,UnityEngine.RaycastHit&) (at Assets/PaintIn3D/InEditor/Scripts/P3dHitScreen_InEditor.cs:104)
    4. PaintIn3D.P3dHitScreen_InEditor:DoQuery (UnityEngine.Vector2,UnityEngine.Camera&,UnityEngine.Ray&,UnityEngine.RaycastHit&,UnityEngine.RaycastHit2D&) (at Assets/PaintIn3D/InEditor/Scripts/P3dHitScreen_InEditor.cs:38)
    5. PaintIn3D.P3dHitScreenBase:PaintAt (PaintIn3D.P3dPointConnector,PaintIn3D.P3dHitCache,UnityEngine.Vector2,UnityEngine.Vector2,bool,single,object) (at Assets/PaintIn3D/InGame/Scripts/P3dHitScreenBase.cs:265)
    6. PaintIn3D.P3dHitScreen:RecordAndPaintAt (PaintIn3D.P3dHitScreen/Link,UnityEngine.Vector2,UnityEngine.Vector2,bool,single,object) (at Assets/PaintIn3D/InGame/Scripts/P3dHitScreen.cs:299)
    7. PaintIn3D.P3dHitScreen:HandleFingerUpdate (PaintIn3D.P3dInputManager/Finger,bool,bool) (at Assets/PaintIn3D/InGame/Scripts/P3dHitScreen.cs:138)
    8. PaintIn3D.P3dHitScreenBase:LateUpdate () (at Assets/PaintIn3D/InGame/Scripts/P3dHitScreenBase.cs:162)
    9. PaintIn3D.P3dHitScreen_InEditor:LateUpdate () (at Assets/PaintIn3D/InEditor/Scripts/P3dHitScreen_InEditor.cs:93)
    I use Unity 2021.1.15f1 and HDRP 11.
     
  40. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    Does the issue go away if you open PaintIn3D/Shared/Resources/P3D Decal.cginc, and comment out line 89: // discard;
    And/or PaintIn3D/Shared/Resources/P3D Sphere.cginc, and comment out line 76: // discard;


    I just made a new project in Unity 2021.1.15f1 with the HDRP 11 template and Paint in 3D 1.11.6, and the in-editor painting works as expected without errors.

    I'm not sure what would cause this error exactly. The in-editor painting relies on the private UnityEditor.HandleUtility.IntersectRayMesh method to allow painting without colliders, and the C# code for that at least doesn't seem to have changed since Unity 2019.

    Perhaps there's some internal change to the method, and/or some additional project setting you have that causes this to break. Without being to replicate this it's hard to say what that might be though.
     
    Camarent likes this.
  41. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    162
    I found what it caused. I need to mark Read/Write enable in fbx import settings and this message goes away. So need to not forget disable it afterwards to reduce memory footprint in runtime.
    It actually does not prevent painting but it spams errors.
     
  42. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    162
    @Darkcoder I have one more question. I tried to make custom groups. I duplicated existed one for that and change index, shaders, etc. I do not know why but this new group does not work. It appears in menu and do not produce any errors but when I am trying to paint it just dont paint anything.

    After a lot of trying I found that if I change group index to 0 it will work. So all other group except with 0 index does not work. I checked with other prepared presets and it is all the same. Tested with Unity 2020.3.15/2021.1.15 and HDRP.
     
  43. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    Aha, I'll see if I can make some sort of warning in the paint window to make this issue clearer. I made a card for it HERE.

    Do the other groups that come with Paint in 3D work for you? If so, this seems very strange. Internally the group is just an int, so there shouldn't be any issue as long as both the paint component and paintable texture have matching groups you can see in the inspector. I've sometimes noticed the group name doesn't update when changing the group asset name, but that's only an issue in the inspector for the group itself and doesn't always occur. The group functionality as far as I know is unaffected by this.
     
  44. Razouille

    Razouille

    Joined:
    Jan 25, 2013
    Posts:
    42
    Hello there, I wanted to know if there is anything special to make the plugin works on mobile ? I have a paintable script on a mesh, with paintable texture component a material cloner. On the manager I got a Hit Screen component and a Paint Sphere component with a Substractive mode. It works well inside the editor but not at all on mobile (Android), what should I do to make it work inside the build ?
    (the idea is to "erase" this mesh to let the one behind appear)
    upload_2021-7-29_11-9-25.png

    EDIT : I tried a build with the scene "50 Channel Counter" which is the example I took to build my scene, as there is a "Clear" option, and it's not working too @Darkcoder :-( (same for simple colors)

    EDIT 2 : Actually I downloaded the last update of the plugin "19th of July" with a touch fix and it's working fine now :)
     
    Last edited: Jul 29, 2021
    Darkcoder likes this.
  45. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    162
    Sometimes other groups does not work, sometimes they do. I can try to make project that reproduce an error because I am not sure what is a cause. If so how can I send it to you?
     
  46. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    A test project would be great, you can send it via private message or email (see PaintIn3D/GUIDE).
     
  47. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    162
    Ok! :) Can you help me to find Channels settings for in-Editor painting? I saw it on game component but not sure how to do it in Paint 3D window.
     
  48. ShockWave2048

    ShockWave2048

    Joined:
    Mar 15, 2015
    Posts:
    26
    Hi PaintIn3D!!!
    Can i paint directly to Texture2D, without work with TempBuffer XXXX ?
    I need blur texture in realtime.
    Thanks for answer!
     
  49. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,666
    No, GPUs can only manipulate RenderTextures quickly, which is why they're used. You can get a Texture2D from the P3dPaintableTexture by calling its .GetReadableCopy() method.

    If you only need to blur the whole texture and keep it as a Tetxure2D then you should use the CPU by manually getting the pixel data, blurring it, and then writing the data back.
     
    ShockWave2048 likes this.
  50. ShockWave2048

    ShockWave2048

    Joined:
    Mar 15, 2015
    Posts:
    26
    Thanks for answer!
     
    Darkcoder likes this.
unityunity