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

ProBuilder Edit Poly Shape Extrusion or Ideas on How To Unextrude?

Discussion in 'World Building' started by seraphofdoom, Mar 31, 2021.

  1. seraphofdoom

    seraphofdoom

    Joined:
    Sep 29, 2020
    Posts:
    4
    Hello everyone,

    I am a first-time poster, so please let me know if I am missing any information. I am working on a research project which will make several Poly Shapes scale vertically based on data given in a .csv file.

    Is there any way to "unextrude" in order to make the Poly Shape shrink as the data drops in value, or is there any way for me to edit/access the Extrusion value of the Poly Shape script (seen in the Inspector) through my script? I noticed that raising and lowering that value gives the effect that I am looking for.

    If both of these options are unavailable, how may I "undo" the extrusion or revert the mesh to its original state so that I may extrude to a different amount with each data input?

    Thank you for your time and help!
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,406
    I wouldn't use ProBuilder (if that's what you're referring to) for this. Instead, just write a little code to reach into the Mesh and directly change the vertex positions, for vertices at the top of your shape.

    Example 2 in the docs (https://docs.unity3d.com/ScriptReference/Mesh.html) is a pretty good starting point.
     
    seraphofdoom likes this.
  3. seraphofdoom

    seraphofdoom

    Joined:
    Sep 29, 2020
    Posts:
    4

    Thank you very much! I will try this.
     
  4. seraphofdoom

    seraphofdoom

    Joined:
    Sep 29, 2020
    Posts:
    4
    Hello! I have been tinkering around with this for about a week, and I am still having some trouble. I was able to select only the top vertices of my meshes and translate them vertically, but that did not give me the result I was looking for. Here is what I want (extrusions):

    Screen Shot 2021-04-13 at 8.39.52 PM.png

    Here is what I am getting:

    Screen Shot 2021-04-13 at 8.31.36 PM.png
    and here is part of my code (It isn't optimal, but I just need it to work):
    Screen Shot 2021-04-13 at 8.44.07 PM.png
    I initially thought that perhaps my meshes were completely flat and needed dimension. However, if I start the program with extruded shapes, the side faces fly off in all directions as I am moving the slider.

    Screen Shot 2021-04-13 at 8.40.13 PM.png

    My goal is to have the extruded bar graphs move up and down as data changes with the slider. Could anyone please help move me in the right direction? Thank you!
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,406
    Your mesh should already have "sides" for each top face. Then when you change those top faces, the sides will stretch.

    Think of it this way: forget such a complex mesh, and imagine just a single bar. It's square on top, and it has rectangular sides. That's 2 triangles on top, plus 2 triangles for each side, for a total of 10 triangles for just that one bar. Anything less than that, you just don't have enough mesh to work with. And that's for just one bar.

    Your mesh will need 10 triangles per bar that you want to animate in this way. But maybe get it working with just one bar first; then I bet you'll see how to generalize it to more.
     
  6. seraphofdoom

    seraphofdoom

    Joined:
    Sep 29, 2020
    Posts:
    4

    Thank you for your reply! I think I am missing some information. I was able to move the face at the top of a regular cube vertically by changing the vertex positions. However, the sides of the cube did not stretch to stay with the face. Is that an issue with my code, or am I supposed to be editing the triangles along with the vertices?
     
unityunity