- Home /
Vertex World Rotation?
increasing a vertex.x on a mesh is the same as changing it's transform.position.x if the object is not rotated, ...IF the object is rotated, it's the same as changing its transform.localPosition.x, I am obliged to change its localposition when the object is rotated, but I want to change its world position.
Say I have 20 rotated objects and I want to change the vertices all according to world position, there is no easy way to do that in unity, because I'm obliged to increase the vertex coordinates in their local rotation, and therefore local position.
Is there a way to solve the above issue? so that increasing vertex.x sends a vertex towards the right no matter the rotation of the mesh?
Answer by YM_Industries · Nov 22, 2012 at 08:51 AM
You can use transform.TransformDirection, transform.TransformPoint and the inverse functions of these to accomplish this. (This is basically just a summary of the comments above, posted here so the question will show up as answered.)
complete solution is-transform.TransformPoint prior to moving the vertices,and transform.InverseTransformPoint again prior to writing them back to the mesh
How did I manage to make 3 answers? I only meant to make one...
Answer by YM_Industries · Nov 22, 2012 at 05:38 AM
I'm not entirely sure I understand exactly what you want to do here, but these should point you in the right direction. Let me know if you need more help. You can use transform.TransformPoint() to transform a point from local space to world space. You can also use transform.InverseTransformPoint() to convert from world space to local space.
So your solution might look something like this:
Vector3 newVertex = new Vector3(transform.TransformPoint(vertex));
newVertex.x+=5;
newVertex = transform.InverseTransformPoint(newVertex);
Good luck!
hi thanks i didnt know about inverse transform point! at the moment I already use
var vertex = vtxArray[i];
vtxArray[i] = transform.TransformPoint(vtxArray[i]);
so it takes lots of tiles and changes them as if they were a continuous plane. however I started rotating some of the tiles, and the vertex changes now happen perpendicular to the way the tiles are facing, rather than happening relative to the way the world is facing. I want to bend the tiles of the floor up, and then the tiles of the adjoining walls up as well, but the adjoining walls bend in.
I could make 6 different cases for the 6 different rotations of the tiles, but I would prefer a more logical solution.
For example if I could keep the GameObject rotation at right angles, but to reset the perceived rotations setting at 0, 0, 0 in the Inspector, then the vertex calculations would all happen along the same rotation. for that I would have to somehow reset the GameObject, or recalculate the mesh.
the problem is you can calculate the world position of all the vertices, but vertex.x still the local rotation of the GameObject, so if the GameObject is rotated, then transform point becomes a bit ineffective for making vertex changes according to world space.
Still not entirely sure what you want, but do you want to effectively un-parent your vertex from your GameObject?
I think I have to learn how to use transform.TransformDirection it changes direction from local to world space.
Probably. I use transform.TransformDirection quite a lot in my game, and I only learned it 2 days ago. Just one of those things that's really useful.
thanks man! I'll have to read a lot about it, it's pretty hazy right now-I marked you up on another thread! I hope someone knows how to TransformDirection of a vertex axis movement!Cheers
Answer by YM_Industries · Nov 22, 2012 at 08:51 AM
You can use transform.TransformDirection, transform.TransformPoint and the inverse functions of these to accomplish this. (This is basically just a summary of the comments above, posted here so the question will show up as answered.)
the question isn't really answered though, because I need to move 3 individual vertex coordinates, and TransformDirection is used to calculate Vector3 directions, it's actually really complicated for a beginner to calculate vertex(x.y.z) to individually change up and down left and right according to world directions rather than local rotation. I have still no idea how to use the TransformDirection for vertices.
No problem if the question isn't answered, just mark it as answered once it is. transform.TransformDirection isn't meant to be used on vertices. Vertices should use transform.TransformPoint ins$$anonymous$$d.
lol! ok. so if you turn the object and increase vertex x it goes up ins$$anonymous$$d of right... maybe there is a way to make it go towards world x axis.
When you say towards the world x axis, do you just want the vertex to have its X value increase? In simple terms, what do you actually want to happen here?
in layman's terms, when I turn an object and increased its vertex.y coordinates, I don't want them to translate sideways, I want to translate upwards. Same as they would do if the object was not rotated.
so if I take 10 objects and rotate them all different, and increase some vertex.y coordinates of all of them, I want their vertices to all move upwards and not all upwards according to their local rotation.
Answer by drudiverse · Aug 22, 2015 at 11:33 PM
I am not totally convinced about this page...
The transform. transformDirection will tell you the vector orientation of the object, which is super difficult afterwards to use...
So transform transformpoint, fine gets you the world position and scale of vertices...
and afterwards transfor direction, you would have to use it to pivot every vertex around some point in space to find the position of every vertex including their world position and world rotation...
so you would have to use some kind of crazy rotate around to match the difference in between upwards and rotated object.
I am pretty sure of that from experience.
How to do it is sooo much coding and rotations. OMG. i don't know off hand how to do it and it cant be a trivial afternoon task for an average programmer.
Your answer
Follow this Question
Related Questions
Store initial rotation in JavaScript 2 Answers
Reset posiotion 1 Answer
How to reset rotation of object after AddTorque has been applied? 1 Answer
Camera position/rotation reset after 5 seconds of mouse inactivity 0 Answers
Help With Simple Rotation 4 Answers