Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Using 3D mesh with 2D autotile rules

Discussion in '2D Experimental Preview' started by awesomedata, Sep 17, 2020.

  1. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    I find that my meshes are rotated at weird angles, don't have materials, etc. when I tried this.

    Has anyone managed to get properly-placed 3D meshes / tiles when placing 2D tiles in the scene view? Not sure I fully grasp what to do. Maybe it has something to do with the matrix? (I'm not a math person.)
    Anyway, I essentially want to use the 2D tilemap and ruletiles as a prototype for placing 3D tiles in the scene view (and maybe even remove the "sprite" that is displayed from the palette in the scene view.

    Has anyone achieved this yet, or would it just be better to write my own tool for this? -- I planned to do that at some point, but damn -- I just wish Unity's tools were more flexible. D:
     
    NotaNaN likes this.
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    You may find that using the Grid component, parent to the Tilemap, more suits your needs because it sounds like you're stripping out the core reason to use the Tilemap in particular. Do you mainly want to use the brushes in the Editor? There some examples of custom brushes which could conceivably be adapted to not work with tiles at all. The RuleTile would need a rework if exclusively for non-tiles. Do you want a palette but for 3D prefabs?

    https://github.com/Unity-Technologies/2d-extras/tree/master/Editor/Brushes/PrefabBrushes
     
    Last edited: Sep 18, 2020
  3. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Essentially I'm just replacing the 2D tile graphics w/3D tile mesh graphics (w/height info).

    Ultimately I want 3D tiles that use the 2D autotile rules -- i.e. 3D corners, walls, centers, etc. (placed on a 2D X/Z grid) that place the correct neighboring 3D tile when painting.
    Pretty simple really. Overall, I just want the 2D tile functionality to be translated to 3D meshes (i.e. modular tiles) for prototyping purposes.

    A palette w/3D tile icons (to help pick the 3D autotiles from a 2D palette) would be useful, but not strictly necessary. I don't know how "mutable" this system is, but my experience with Unity's API is that they don't like you doing stuff with it that they don't expect (i.e. turning a 2D tile / palette system into a 3D tile system / palette). But as I haven't delved into this too much yet, I don't know for sure how time-consuming it will be to "convert" the system.

    Ideally, I don't need to place gameobjects/prefabs -- I want to place 3D level geometry/collision instances that autotile. I can go with placing prefabs though -- as long as they autotile on a 2D grid (which would be my preference).
     
  4. DoctorShinobi

    DoctorShinobi

    Joined:
    Oct 5, 2012
    Posts:
    219
    @awesomedata
    The code that decides the game object's orientation after spawning is this:
    gameObjectRotation = Quaternion.LookRotation(new Vector3(transform.m02, transform.m12, transform.m22), new Vector3(transform.m01, transform.m11, transform.m21));


    You can find it in this file: https://github.com/Unity-Technologies/2d-extras/blob/master/Runtime/Tiles/RuleTile/RuleTile.cs

    I'm the one who originally wrote the code that lets you spawn game objects using rule tiles, so this is my fault. I think I wrote it this way because it worked for me using the default grid orientation for 2D objects(and I didn't realize it might not work in other configurations or for 3D objects).

    This package is open source, so you can try playing with this line until you manage to get something that works for you. It's best to solve it in a way that works for as many configurations as possible and then pull request it at the repo. That way you won't need to reimplement it every time you update, and others can enjoy your fix too.

    Also, I think @ChuanXin manages that package, so it might be worth speaking with them.
     
  5. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Thanks for your hard work dude.

    Speaking of github -- I was looking at one of the branches, and one has something to do with "swizzle" -- I was wondering if is this a branch that was modified to support what I'm looking for? (i.e. 3d object tiles?)


    If not, then I guess I'm out of luck.

    I don't fool with github clients much -- I'm more of an artist/designer, and only a programmer when I absolutely have to be. Before taking this on, I was almost _certain_ the autotiles package supported 3D autotiles (on a 2D plane) since I saw a video of Unity devs having it working at one point.

    Either way, right now, I can't get to it since I'm involved in a particularly heady project. I can't step away to implement this feature the way it really should be implemented -- I'd only signed up for a slight detour of light programming.
    But I did try to get in touch with @ChuanXin by posting to the repo for this reason, but no dice. I wonder if he'd actually be bothered to implement this?

    Like you said, it really needs that option for everyone though. With all the modular tile assets and even Unity doing its "Snaps" asset store stuff, I don't see why everything has to be manually-placed in the Editor for prototyping anymore. Just seems like a waste to leave this tool hidden in the bowels of github, only halfway supporting modular 3D tiles. :(
     
    NotaNaN likes this.
  6. DoctorShinobi

    DoctorShinobi

    Joined:
    Oct 5, 2012
    Posts:
    219
    https://github.com/Unity-Technologies/2d-extras/commit/f5f7a8f98eaffc20daea6098fdcfd0845b70bf79
    Looking at this file in the branch does make it seem like it was fixed, so it's probably a good idea to give it a try.
    This branch is 4 months old though, so I do wonder how comes it wasn't merged back into the master branch?
     
    NotaNaN and awesomedata like this.
  7. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    That's what I was curious about as well -- it _seemed_ like it fixed what you were talking about, but I wasn't sure since matrices and I really don't mix well.

    I do plan to see if that branch solves my issue, but I really want an easier way to extend this package at some point.
    It's too useful not to.