1

I am making 3d virtual keyboard and the keys are made from rectangular prism meshes with rounded corners / beveled edges. I made the mesh with blender and it works fine. Except that depending on device orientation etc the aspect ratio of the keys change. I have just been achieving this by doing a scale transform but it distorts the corner rounding.

In 2d this is handled with scale 9 algorithms which scale the middle and the length of the sides but not the corners.

Is there a common way of doing this in unity?

Maybe there is an easy way to render something with rounded corners after a transform on a regular cube?

Or to specify the way that a mesh scales with some areas remaking static?

Or building my own mesh with code? Is there a good example of this? Building a mesh of a rectangular prism seems doable - but rounding the corners seems like a formidable task.

maZZZu
  • 3,585
  • 2
  • 17
  • 21
Korimako
  • 359
  • 3
  • 13

1 Answers1

0

All depends on how much bevelling is needed. If it just a little, it is possible to do this with a shader without touching the mesh. You can do post processing like in the accepted answer of this question which links to this paper.

Other option for small beveling is to use Relief Mapping like in this question. It is probably easier to make dynamic changes to the Relief Mapping texture than to the model.

If multiple pixels of beveling is needed, I think the mesh needs to be modified. (Hopefully someone proofs I'm wrong and tells about some weird scaling.) Making whole mesh from a script is quite easy with Mesh once you get used to it. But depending on the amount of 3D experience, it might take lot of time to get the round edges working correctly.

Another idea is to make one model for the corners, one model for the edges and one model for the sides. Then you can use 6 instances of corners, 6 instances of stretched edges and 6 scaled sides to make a complete cube out of them.

Community
  • 1
  • 1
maZZZu
  • 3,585
  • 2
  • 17
  • 21
  • 1
    I also saw this package which has a rounded cube primitive - not sure if it could be instantiated as a rectangular box or not, but they provide the code... https://www.assetstore.unity3d.com/en/#!/content/7382 – Korimako Nov 05 '14 at 00:17