Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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

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

  1. O-H-42

    O-H-42

    Joined:
    Jul 15, 2020
    Posts:
    4
    Hello.
    I'm looking into using this Paint Asset in Hololens2.

    There was mention of VR support, but is it possible to use it in AR games and coexist with MRTKv2?
    If they are possible, how can I use them?

    Thank you very much.
     
  2. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Paint in 3D works with all VR and AR systems, but there are no integration examples except for Unity's XR system. At the most basic level no code is required to support other systems: you can just use the P3dHitBetween component which allows you to paint a sphere or decal at the first hit point between the two Transforms you specify.

    Assuming MRTKv2 comes with an example that places an object at your hands, or has some kind of tool example you can grab then you can use these transforms and it will work with Paint in 3D quite easily. If you need this painting to only activate when you perform a specific gesture then you would need to write a simple script to detect that gesture and then toggle the P3dHitBetween component.

    The rest of the setup is the same, which you can copy from any of the example scenes.
     
  3. wonderscope_rob

    wonderscope_rob

    Joined:
    Feb 20, 2016
    Posts:
    11
    I'm using LocalCommandCopy in this instance. Is there a way to rebuild the undo queue or similar in order to fix any problems with ordering?

    Or is there something I need to be aware of when using LocalCommandCopy and adding undo steps & undoing through script?
     
  4. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    This bug will be fixed in the next version coming out very soon (probably later today).

    [Edit] Update is now out!
     
    Last edited: Nov 9, 2021
  5. Abnormalia_

    Abnormalia_

    Joined:
    Jul 23, 2013
    Posts:
    72
    I want to play random marker sounds while it's drawing, where is better to hook my code?
     
  6. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    You can make a component that implements the IHit and IHitPoint + IHitLine interfaces (in PaintIn3D namespace). You can then add this new component alongside your P3dHit___ components, and it will receive the interface method calls like any other paint component. You can then play a sound when one gets called, and stop playing if none of them get called for some time, etc. Just keep in mind there is no explicit start and stopped paint method.
     
  7. villaman

    villaman

    Joined:
    Apr 21, 2021
    Posts:
    58
    ok, thanks. I managed to figure out how to do the triangulation. However, when I looked at the "Triangle" demo scene it looks like it works off the actual mesh triangulation. Do I need to convert my triangulation to a mesh in order to paint it? If yes, I guess that's equivalent to just painting a fully fleshed out GameObject that has the appropriate shape (i.e. Rectangle MINUS Polygon). Or maybe I'm missing something? The triangle demo scene seems more to do with how to paint distinctly the triangles of a mesh.
     
  8. O-H-42

    O-H-42

    Joined:
    Jul 15, 2020
    Posts:
    4
    Thank you for your reply. I'm going to buy it and try to use.
     
    Darkcoder likes this.
  9. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Ok forget I mentioned the triangle painting demo scene. You just need to call the P3dPaintSphere component's HandleHitTriangle method once for each triangle you want to paint. This method takes 3 world space positions for the triangle corners. Calculating the coordinates for these triangles doesn't require any meshes, it could all be done using constrained delaunay triangulation as I mentioned before, but there is no code in Paint in 3D to do this part so you're on your own here.
     
  10. GreaterHawkeye

    GreaterHawkeye

    Joined:
    Apr 13, 2017
    Posts:
    31
    It might be an issue on my side but I still cannot make it work :(
    Exact same issue as before: I paint 2 strokes, then undo, then paint 1 stroke, then undo => it removes the two strokes at once. I'm using the last version 1.11.12
     
  11. wonderscope_rob

    wonderscope_rob

    Joined:
    Feb 20, 2016
    Posts:
    11
    Can confirm after updating I still have the issue with 1.11.12
     
  12. villaman

    villaman

    Joined:
    Apr 21, 2021
    Posts:
    58
    ok, thanks. As I mentioned, I've already got the triangulation going using Constrained Delauney Triangulation.

    I looked up the P3dPaintSphere/HandleHitTriangle method and saw this:

    "HandleHitTriangle
    bool preview, int priority, float pressure, int seed, Vector3 positionA, Vector3 positionB, Vector3 positionC, Quaternion rotation

    This method paints all pixels between three points using the shape of a sphere."

    What does it mean to paint between three points "using the shape of the sphere"? Also what's the purpose of the rotation and seed arguments in this method?

    thanks
     
  13. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    I can't replicate the issue. Please check out the UndoAllTest package I uploaded before (F1 to undo, F2 to redo), and let me know what I must do to replicate the issue.


    The sphere shape will be extruded between the 3 points. A line for example would extrude a sphere along one line thus making a capsule, and the a triangle would be like extruding out one point of that capsule making a kind of rounded triangle.

    The rotation is mainly for use with the P3dPaintDecal version of this method, but it's also used for sphere painting because the sphere can be scaled with the Scale setting. The Seed is used for the paint modifiers if you have any.
     
  14. KateKomar

    KateKomar

    Joined:
    Dec 9, 2020
    Posts:
    7
    Hello!
    Is painting available for meshes with blend shapes?
     
  15. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Yes, I just tested it on Windows, Android, and iOS without issue.
     
  16. GreaterHawkeye

    GreaterHawkeye

    Joined:
    Apr 13, 2017
    Posts:
    31
    Here's a video of the issue in action :
     
  17. Lemovision

    Lemovision

    Joined:
    Apr 6, 2020
    Posts:
    32
    Hi I may have uncovered a bug happening only in WebGL builds (runs fine in editor or desktop build)
    Actually I got stuck with this error which delayed my project for a whole week
    Originally I thought this was a Visual Scripting bug because it was showing up in the error



    Then I had to dismantle each game object one by one and build again to find the culprit
    I eventually found out all errors do go away after removing some of the P3D "tools" game objects
    Each have their own HitScreen and PaintSphere/PaintDecal with different settings for each tool
    To replicate a normal painting app, where you would have different brushes and pens etc
    So it seems there's a limit of those P3D components that can run at the same time in WebGL?
    If I have one or two it's fine, and more than that the build just crashes with those errors
    Even in the demo scene Chalkboard for example, I noticed the same error when building WebGL
    Are you able to replicate the issue, or is it just me?
     
  18. drbatuira

    drbatuira

    Joined:
    May 4, 2020
    Posts:
    21
    Hi!

    Several questions were answered with the forum, but one remained.

    Scenario 1: I have a car with a UV map separated into 3 islands, 1 for each side and 1 for the roof


    Scenario 2: the same car, separated into multiple islands (1 for each car part)

    Could I mirror the painting?
    What I want to do is paint a symbol on the driver's door, that same symbol must be painted on the door on the other side.

    If I write the word "Car" on the glass, it must appear on the other side, also written "Car", not "raC" lol.

    UV map mirroring is not valid as I can mirror the symbol and then customize each side (mirroring turns on and off based on the setting)

    I'm a developer, no problems if you need to modify, just tell me the way please.

    @Darkcoder , thanks.
     
    Last edited: Nov 20, 2021
  19. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Oops, I forgot to set it to Local Command Copy. Yeah I can replicate this issue, I'll dig into the code again.


    I just made a WebGL build in an empty Unity 2021.1.15f1 project with just Paint in 3D, and the Chalk Board scene works fine on Windows 10 Edge and iPad Air: Unity WebGL Player | webgl_test (carloswilkes.com).

    Keep in mind I had to set this web.config file which Unity nicely doesn't generate for you: Unity 2020.2 WebGL - both async and sync fetching of the wasm failed Error - Unity Answers

    The only mirroring feature built into Paint in 3D is the one seen in the "26 Mirror" and 2 other demo scenes after this. These only mirror paint across a plane though, what you want is some kind of translation of painting, which isn't possible with the built in components. It's easy enough to implement this though:

    1 - Make a new component based on the P3dCloneMirror code.
    2 - Change the implementation of the Transform method to do what you need.
    3 - Add this component to your scene, and it should work.

    Step 2 should be something like: posMatrix = Matrix4x4.Translate(Vector3.right * offset) * posMatrix;

    Where offset is a float equal to half the width of your car. You might want to add some logic to invert the offset value if you paint on the other side of the car though. You would have to extract the current position from the posMatrix to see which side is being painted on.
     
    GreaterHawkeye likes this.
  20. Lemovision

    Lemovision

    Joined:
    Apr 6, 2020
    Posts:
    32
    Thanks for testing
    I also did another test with a fresh project too with the base 3D pipeline, and it works indeed
    And then another fresh one using URP (which I use for my project) and got the same error again
    Could you try once more a webgl build with URP?

    Not implemented: Class::FromIl2CppType
    MethodAccessException: Attempt to access method 'System.IDisposable.Dispose' on type '' failed.
     
    Last edited: Nov 21, 2021
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    I'll check it out tomorrow.
     
    Lemovision likes this.
  22. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    65
    Hello.

    I am making a game where players create tanks from blocks, which the players can paint.

    You recently gave me advice on making a triplanar shader in Shader Graph that integrates with Paint in 3D, to make a continuous texture for all the blocks (so seams don't show between them).

    This all works well, as I can now paint across blocks, and under most conditions the seams between the painted blocks are invisible.



    However, when looking at the tank from certain angles, the seams between the blocks are visible (example in the image below):



    Would you have any advice on how I can fix this, so that the seams are never visible?

    I have followed the instructions in your manual - for example, I have used the 'Fix Seams' function on all the models used. And all the blocks are positioned so that there are no gaps between them, and they also don't overlap.

    The visible seams appear when the face they are on is rotated so that it is nearly inline with the direction of the light from the light source (if the face was rotated just a few more degrees it would be in shade). I have tried to show this in the diagram below:



    The project is made in URP.

    I appreciate any suggestions. Thank you for your help.
     
  23. drbatuira

    drbatuira

    Joined:
    May 4, 2020
    Posts:
    21
    Sorry to intrude, but I think it might be something else.
    Tried to see ambient occlusion?
    I think it's not about the product, but the texture, normal, light, something like that.
     
  24. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    It's hard to see what the issue is exactly from that screenshot alone. If it's due to seams then this is likely due to mip mapping. Mip mapping is where the actual texture rendered on screen lowers in resolution based on camera distance or surface slope - this is done to reduce aliasing and improve performance. When you paint a seam fixed mesh the paint is drawn outside the edges of your texture UV by a few pixels. If your texture has mip mapping then at certain angles and distances this texture can reduce in resolution so much that these seams 'bleed' into the main part of your mesh (think of it as blurring the texture, and the edges bleeding in). If this is the issue then the only ways to avoid this are:

    a) disable mip-maps in your P3dPaintableTexture settings.
    b) increase the Border (thickness) setting in the P3dSeamFixer tool settings, and rebuild the seam fixed mesh. (keep in mind the Auto Seam Fix tool has no settings for this, so you must do it manually).
    c) Arrange your mesh UVs so that these seams only exist at the very edges of your texture, then you can set the P3dPaintableTexture.WrapU/V to Clamp. This may require you to split up your mesh though.
    d) Use a custom shader that does manual mip mapping and manually prevent sample points from exiting UV islands.
     
  25. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    I tested the same settings out in a new URP project and it works on desktop and iPad (see the same link again).
     
  26. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    65
    Hello - thank you for your suggestions. I tried them, but it did not have an effect, so it does not seem to be due to the mip mapping.

    I tried to do some tweaking of settings, and it seems to be due to the URP shadows settings. Specifically the light source settings. I adjusted the depth value of the real time shadow bias, which fixed the problem (you cannot see the individual blocks anymore). However, I had to increase it quite a way (from the default setting of 0.05 to 4.7) to get rid of the effect.

    I read that having the bias settings too high can have negative visual effects on your game. Do you think it might have any negative effects on using Paint in 3D? If so, now that I know it is due to shadows, do you know of a better way to fix things?

    Appreciate your help.
     
  27. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    65
    It was indeed something to do with the light. Thank you for your suggestion :)
     
  28. GreaterHawkeye

    GreaterHawkeye

    Joined:
    Apr 13, 2017
    Posts:
    31
    Hi @Darkcoder ! Hope I'm not being too pushy, I just wanted to know if you had time to check the undo/redo stuff? :)
    I saw the 1.11.12 change logs saying the command order is fixed but I think this version still has the bug? Thanks!
     
  29. LegacySystem

    LegacySystem

    Joined:
    Jan 28, 2021
    Posts:
    10
    Hi,
    We couldn't make it work with blend shapes. Is there something we must take into account?
     
  30. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Ah I see, yes shadows would also cause an issue like this. Since Paint in 3D only deals with the painting of textures, it doesn't matter how your scene is rendered, so shadow settings have no impact on it. i.e. this issue would appear with your block configuration even without Paint in 3D.


    Not yet. The command order bug should be fixed, but I think this issue is something different. It seems like the commands themselves are disappearing or something, maybe I made a mistake with the undo/redo state recording itself when using local commands.


    Can you send me an e-mail or private message with the mesh so I can test it myself? Also, let me know the exact version of Unity and which devices you experience the issue with.
     
    DromoDesigner likes this.
  31. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,569
    question, is able to "erase" areas? I want to paint transparent, basically simulate like I did a hole into the mesh.
     
  32. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Yes, the "45 Painting Holes" demo scene shows you how to do this :)
     
  33. Lemovision

    Lemovision

    Joined:
    Apr 6, 2020
    Posts:
    32
    Okay so I'm officially clueless how to solve my problem now T_T
    probably just a mysterious curse from the Unity gods then
    Currently I'm on 2021.1.0 so probably not a huge difference but who knows...
    I guess I'll try to use 2021.1.15 as in your test
     
  34. Lemovision

    Lemovision

    Joined:
    Apr 6, 2020
    Posts:
    32
    So I installed and tried a new project with Unity 2021.1.15, and unlike 2021.1.0 this time the Chalkboard WebGL build works indeed with URP
    Ideally I would rather not update my project to later versions yet because of couples of Known Issues in 2021.1.15f1
    (Mostly the "Touch Input not working in editor", which I use for testing on my touchscreen monitor)

    Sorry to bother you but could you have one last test of a WebGL build of that Chalkboard scene?
    With URP template on Unity 2021.1.0f1, which seems to be the problematic combo
    Sry probably I should have mentioned that version earlier
     
    Last edited: Nov 27, 2021
  35. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Unless the stack trace indicates it's something to do with my code there isn't anything I can fix. The error mentions Unity.VisualScripting so you can try copy and pasting that code over from the working version?
     
  36. Lemovision

    Lemovision

    Joined:
    Apr 6, 2020
    Posts:
    32
    The Visual Scripting error is just on my project, and probably just a consequence of the first error

    But as I explained it's the same first error below on a blank new project with only P3D, for example Chalkboard demo
    And there's no Visual Scripting there at all just blank URP project with P3D
    Is there anything below familiar related to what your code does?

    Not implemented: Class::FromIl2CppType
    MethodAccessException: Attempt to access method 'System.IDisposable.Dispose' on type ''emsc.emsc" failed.

    I also did a build (of same new 2021.1.0f1 URP project with chakboard scene) with full stacktrace and it looks like this

     
  37. Lemovision

    Lemovision

    Joined:
    Apr 6, 2020
    Posts:
    32
    Okay! I finally debugged my project at last
    So I eventually found a version of Unity in 2021.1.28,
    which as the last in 2021.1 line doesn't have a ton of know issues and touch problem like 2021.1.15
    I migrated my project to that, and now P3D works again for me, even in URP WebGL build

    You might still wanna look into the issue with 2021.1.0 and webgl/urp
    As other people might runs into the problem (although very specific combo)
    Because I still think it was not related to my project nor visual scripting
    Since it also was reproducible on fresh p3d project
    Presumably with scenes with many tools... I think?
    As for my 2021.1.0 project, the bug started to appear when I made more p3d tools
     
  38. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Glad you found a build that works. The first error looks like something in the UI is breaking. The Chalkboard demo scene has more UI elements than most other scenes, so that may have something to do with it. However, Paint in 3D isn't doing anything special with the UI, it's just Buttons and CanvasGroups. Even if the 'solution' would be to reduce the amount of buttons or something, it's not really something I care to fix if it only happens with a few specific versions of Unity that they've now seem to have fixed.
     
  39. leejewitt

    leejewitt

    Joined:
    Jun 5, 2020
    Posts:
    21
    On the zombie decal video would it be possible to use the gradual fade but in reverse to mimic a blood soak effect?
     
  40. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    The Gradual Fade setup can be used for any kind of painting. I'm not sure what you mean by doing it in reverse though, that would just cause the blood to fade away and disappear?

    The Gradual Fade setup is two textures, where you paint texture A, and texture B gradually transitions to texture A, and the actual material renders texture B. Therefore you could configure the painting to paint on both texture A and B with different settings. This allows you to immediately paint something (e.g. blood), and then have it gradually fade to the final state (e.g. soaked blood).
     
  41. leejewitt

    leejewitt

    Joined:
    Jun 5, 2020
    Posts:
    21
    OK thanks when I say in reverse I thought it only faded a texture over time. Didn't know there were extra settings.

    Am guessing its not possible to do it on a decal tho so it fades in from were decal was drawn.

    What I would like to do is draw decal texture of a wound and a second decal at same time that fades in but coveres a bigger area around wound as the soak affect
     
  42. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Yes it works with decals, and all other painting modes. You can do the effect you describe if you paint both textures as I mentioned. In this example the currently visible albedo uses the DUMMY group, and the future/revealed albedo uses the Albedo group. To get your effect you can configure two decals that paint each of these groups, and use a different decal size or texture or whatever you want.
     
  43. leejewitt

    leejewitt

    Joined:
    Jun 5, 2020
    Posts:
    21

    OK. Thanks think I will buy asset and have play around. So if I understand correctly I setup up character as in documentation with paintable texture and material cloner.

    Then from script I can use p3d.paintdecal on raycast hit to paint. How do I add the gradual fade component to decal though or does that component go on the character then I access that somehow. But I don't know how if would get the position of were to start fading the texture in.

    Sorry for the long questions lol but documentation doesn't go in to that much detail about decals.

    Also would the flow painting work aswell for decal?
     
  44. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    You would probably want to copy+paste the GameObject from the Delayed Appearance demo scene so you have a setup that works, and then gradually change things like the mesh one step at a time to match what you need. Setting this up from scratch without experience with the asset would be very difficult to understand because this is a relatively complex setup (but not that complex). The whole texture is faded across to the other texture, so it doesn't matter where you paint, it doesn't need to know anything.

    The decals that you paint can later be modified with the flow blending mode yes. Perhaps you're thinking of this as a traditional decal placement asset, but it's actually a texture painting asset that has decal painting. This difference allows for much greater flexibility that is not possible with decals alone.
     
  45. Danielsantalla

    Danielsantalla

    Joined:
    Jan 7, 2015
    Posts:
    72
    Hi there. Continuing on this issue, I wasn't able to save it properly, it always fails when saving the texture. Do you know by any chance if I can use EasySave for saving paintings to pngs? I'm not sure what's happening behind the scenes in your plugin. When you save a material and convert that into a texture, how is that done?
     
  46. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    When you save a texture it converts the current RenderTexture state into a readable Texture2D, which can then be converted into a byte array with the EncodeToPNG() method. The paintable texture's GetPngData() method combines this all in one. You can then save this data manually however you like (EasySave probably has some method to do this), and then you can load it later using the inverse. To load this byte array back you can use the paintable texture's LoadFromData() method, which basically pastes this png data into the Texture2D, and then the GPU writes it over the current RenderTexture.
     
  47. dageddy

    dageddy

    Joined:
    Jun 6, 2021
    Posts:
    1
    I appreciate some help/advise.

    On URP, using the "Isolate Tools" as a example. Each color stroke will "overwrite" any previous one. I tried changing the blend mode, opacity and hardness, hoping to make the colors mix in a more natural way. If I paint a blue stroke over a yellow one, the result should be green etc. The "Multiply RGB Inverse" blend mode sort of achieves that but mixing other colors don't result in any change (red and yellow still looks red) so I suspect this is not the right way.

    Thank you.
     
  48. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    This is how RGB additive colors work, see HERE. This is the same as Photoshop, etc.
     
  49. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    65
    Hello,

    I am making a game where players build vehicles from blocks. At the moment the player can paint the blocks using Paint in 3D and it all works well.

    When the vehicle is finished, I would like to combine all the meshes of the blocks to optimise the game, using CombineMeshes().

    However, when I do this, the painted marks and the underneath material both disappear.

    Is there any way to keep the paint marks after combining the meshes?

    Thank you for your advice.
     
  50. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    You would have to combine the textures as well (i.e. texture atlas), and adjust the UVs of each mesh so match the new combined texture mapping. This would require quite a bit of custom code.
     
    DromoDesigner likes this.
unityunity