Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jc_lvngstn · Nov 09, 2011 at 08:53 PM · terrainmesh

Skew an imported mesh?

Using Unity free, I have a situation where I want to conform a mesh to a slope...which would be skewing the y coordinates. I -don't- want to rotate it so that it fits the normal of the slope. Picture a segment of a brick wall...if you wanted to be able to dynamically place these on a terrain, it would need to skew, rotating it would leave weird gaps at the intersections.

https://docs.google.com/drawings/d/1t9iN0A8sVbJwPhTt5CZSS9FDycHyCYpjWTkh7z91xuc/edit?hl=en_US

The only way I can think to do this with an imported mesh would be to create a new mesh from the original, and for each y coordinate in its vertices, translate the y coordinate value appropriately.

Anyone know of a better way? I'm assuming I can easily create a new mesh from an imported one...haven't tried it yet, though :)

[1]: http://docs.google.com/drawings/d/1t9iN0A8sVbJwPhTt5CZSS9FDycHyCYpjWTkh7z91xuc/edit?hl=en_US

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Nov 09, 2011 at 10:06 PM

Well, i guess the easiest way to accomplish that is to modify a copied Mesh with a custom skew-matrix. Something like this:

 1 0 0 0
 S 1 0 0
 0 0 1 0
 0 0 0 1

where S is the tangens of the desired angle. This will skew coordinates along the x axis. So when the x coordinate increases it also increases the y coordinate. Íf S is 1.0f it would exactly by 45°.

Instead of the tangens you can of course use a x-y or x-z ratio. If one point is at 0,0,0 and the furthest point is at 100,0,0 which should be skewed upwards to 100,20,0 just do:

 S = 20.0f / 100.0f;

Just keep in mind that scheme:

         1 0 0 0 --> x out
         0 1 0 0 --> y out
         0 0 1 0 --> z out
         0 0 0 1 --> w out
 x in ___| | | |
 y in _____| | |
 z in _______| |
 w in _________|

Well, it's just basic matrix-math but a lot get confused with rows and columns since it depends on the multiplication order. However unity only supports this way. Also keep in mind that the skewing will happen around 0,0,0

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Nov 09, 2011 at 10:16 PM 0
Share

Also keep in $$anonymous$$d that skewing a mesh will distort / skew the texture that's on the mesh since the texture coordinates are linked to the vertices.

avatar image jc_lvngstn · Nov 09, 2011 at 10:27 PM 0
Share

Crap. So a brick wall that looks fine on flat ground will have distorted bricks?

avatar image Bunny83 · Nov 09, 2011 at 10:32 PM 0
Share

It just follows your skewing... So if you have a wall with a brick texture it will still follow the same mesh. Texture coordinates are not bound to world-points, they are bound to your vertices. You will still see the same part of the texture.

If your texture contains a square pattern, the square-pattern will turn into a rhombus-pattern.

avatar image Bunny83 · Nov 09, 2011 at 10:39 PM 0
Share

It's possible to reverse the skewing but that needs a bit more fiddling to keep the texture in place. It only would help if you use tileable textures of course since your mesh is "growing" in height there is more surface to fill. (To be mathematically correct the area would stay the same, but it is more spreaded ;)).

avatar image Chevara · Mar 13, 2014 at 07:47 AM 0
Share

How to apply this to a GameObject such as an Unity Cube in a script ? And will the collider follow ? If not how ?

Show more comments
avatar image
2

Answer by DaveA · Nov 09, 2011 at 10:02 PM

You could probably construct a skew matrix. Google what that is, and see http://unity3d.com/support/documentation/ScriptReference/Matrix4x4.html

If you need it to skew other-than around 0,0,0 you can first move it to 0,0,0, skew it, then move it back (and you do this by concatenating the matrices, not making calls to MoveTo or Translate, of course)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jc_lvngstn · Nov 09, 2011 at 10:13 PM 0
Share

Just to be clear: I will still need to apply the matrix against each vertex in the mesh, is this correct? I saw this documentation, but wasn't sure how to apply that to a model in script. You can modify the rotation, scale, etc...but I haven't seen how to apply a matrix to an entire object.

avatar image Bunny83 · Nov 09, 2011 at 10:27 PM 0
Share

Yes, you have to modify each vertex because you can't set the matrix of a transform. Transform.localToWorld$$anonymous$$atrix is read only because it get generated out of it's localPosition / localRotation / localScale.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Terrain Craters 2 Answers

Questions about render distance in an open world game 0 Answers

How would i go about meshing over several objects? 1 Answer

Need Pointer: How to create 2D map in Unity? 1 Answer

Box Collider on Trees Are Not Rotating When Painted to Terrain 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges