- Home /
creating a mesh and generating it's specific uvs
Hi guys. I'll try and be concise. I'm trying to take a a piece of an image and make it into a 3d plane, and I don't know much about generating uvs in unity.
I'm building a gui in 3d using planes, textures, and raycast selection
we're getting ready for localization and language changes
I'd like to take all of the text in my hud and put it in a single texture, so i can make an english version, a french version, etc just by swapping out images.
to create the actually 3d hud components, I want to make an editor class where as i can open up the image with all of the text on it, drag select an area to select some text, and have unity create a plane with the uvs mapped to that location.
I have already created an editor tool to build a plane, from an image, with the same aspect ratio of that image, so I know a bit about editor extending.
I'm really curious here about if it's possible to
- display an image in the editor and read mouse clicks to get co-ordinates on that texture
- take that data, create a plane, turn that data into uv mapping co-ordinates for the plane, and scale the plane so that the aspect ratio of the plane matches the aspect ratio of the uv co-ordinates.
Basically the intention here would be to take a section of an image and turn it into a 3d plane.
Any advice would be delightful. Thanks guys!
Yeah, it shouldn't be a big deal if you have some basic knowledge and i think you have from what i've read above ;) I don't have much time at the moment (need some sleep ;)) but i'll go for it tomorrow. Just a little hint: GUI.DrawTexture works also in editor windows
Answer by hypnoslave · Jan 29, 2011 at 10:38 PM
I GOT IT!
in the OnGUI function of your editor:
- create a new orthographic camera with a texture plane right in front of it.
- call Handles.DrawCamera to create a render window on the editor gui.
- create a ray using HandleUtility.GUIPointToWorldRay
- using physics.raycast on mouse click to check for collision on the plane
- read the texture coordinates of the raycast collisions with RaycastHit.textureCoord
then instantiate a plane and set it's uvs to match the coordinates from the clicks that you made.
voila!
very nice, I just did almost the same :D. First i tried to use DrawTexture, but it's not very flexible. In the scene you can use the whole awesomeness of Unity. I like playing around with the editor. You can even create your own modelling program (or window ;)). I want the Unity editor to be my operation system, that would be nice :P I think you can accept your own answer. great job.
Answer by DaveA · Jan 29, 2011 at 06:10 AM
I would look into this: http://unity3d.com/support/documentation/ScriptReference/ExecuteInEditMode.html
You might be able then to raycast to that texture and read out the coords from the raycast hit texture coordinate