Search Unity

Apply image to Flat Disc not working

Discussion in 'Scripting' started by Halo212, Feb 18, 2010.

  1. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    Hi,

    I am trying to apply a image / texture to a flat disc - (Sphere with Z axis=0)
    It only shows part of the image?

    I have tried making the image smaller and the disc larger but nothing works.
    All I want to do is see the whole image on the flat disc but only can see a small portion. Do I need to scale the image or use UV mapping?

    Any help greatly appreciated. :idea:
     
  2. RobbieDingo

    RobbieDingo

    Joined:
    Jun 2, 2008
    Posts:
    484
    you need to sort that out in your 3d modelling application. UV Map the texture to fit correctly there and Unity will comply...
     
  3. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    Many Thanks,

    I gather I can create a Disc shape in Blender3D, then apply my image so that it looks correct and then ask blender to create a UV Map, then export the whole object into unity. Would that be the correct way to do the UV Mapping?
     
  4. RobbieDingo

    RobbieDingo

    Joined:
    Jun 2, 2008
    Posts:
    484
    Hi, I'm not a Blender user, but that sounds right to me - give it a go!
     
  5. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    I have just downloaded Blender3D and must say that it looks rather complicated to msay the least, and i have no idea where to start.

    I am very new to 3D modelling, and am struggling with it.

    What program do you use?
    How would you do it in your program?
     
  6. RobbieDingo

    RobbieDingo

    Joined:
    Jun 2, 2008
    Posts:
    484
    Well, I don't do loads of 3d modelling myself, but I can usually manage to get what I need from my copy of Carrara Pro.

    Tell you what, if this is all you need and you want to give me the specifics, I'll knock something up for you if you like?

    Does it have to be a squashed sphere (is that really what you want)? or are you after a very short cylinder (so you have a flat top)?

    Another alternative for you could be to use just a small plain (a square) with a texture on it that has a circle (with transparent surrounding)?

    just a thought.

    R.
     
  7. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    Thanks thats really kind of you and would be really useful.

    Your absolutely right, I believe I do need a flat Cylinder and not a squshed sphere, as the visible part needs to be flat. Its just a flat circle really.

    What do you require from me in order to correctly position the image on the flat cylinder?

    P.S. If I did create a flat square with the texture applied and placed a transparent circle ontop of it, would I be able to "Fix" the underlying part of the image onto the circle in order to be able to rotate the transparent circle with the underlying part of the image still attached?
     
  8. RobbieDingo

    RobbieDingo

    Joined:
    Jun 2, 2008
    Posts:
    484
    OK, here's your Disc, hit 'Download' below for the object and a test texture.

    You can see in the screenshot here how it has been made, make sure you use one of the Transparent Materials, and ya, it's double sided...

    Best of luck...

    EDIT: To UT Community, please scroll down a few posts to get a better version of this very simple object - we found out this one is not quite square...
     

    Attached Files:

  9. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    Hi Dingo,

    Thats really really good. Very Much appreciated!

    I've just come in from a curry and tried it and it looks great.
    I gather I can create a texture sized 256 x 256 and apply it in the same fasion?

    I have some of my images that will be used, so will try with them too.
    Many Thanks.


    All the Best,
    Halo
     
  10. RobbieDingo

    RobbieDingo

    Joined:
    Jun 2, 2008
    Posts:
    484
    what ever texture you apply can be any permitted size and will fit in the centre, you can offset in the material settings if you need to...
     
  11. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    Thanks Dingo,

    I just tried with my test image, and it looks great.

    The only thing is I have applied a rotation script to it, but it doesnt rotate.
    I dragged the DiscObject into the scene view and applied the texture, but no movement appears.

    I have parented the DiscObject to a new Ga
    meObject, should I just drag it into scene view or do I need to Parent it? Or make it a rigidbody?

    You mentioned the offset setting, I gather this will enable an image to be moved left/right/up/down over the discobject to show a different part? For example if I placed an image onto the discobject and only wanted to show the bottom left corner, would that work through the offset setting?

    Can the transparent shader option be used on Iphone? As I may be us
    ing Iphone with this but would still like to keep the transparency.

    Once again, thanks for the great help on this one.
     
  12. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    I've just managed to get the disc to rotate, however it bobs up and down while rotating. Just wondering whether this is a problem with my object orientation not being perfectly correct?
     
  13. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    If you are only rotating around one axis, as long as the model origin is central, it shouldn't *bob*. Did you mention parenting the model to another GameObject, maybe the has caused it. Without seeing your rotation code and your editor setup it's hard to tell.

    Have you aligned your object in the parent ok? do you even need to join it to another object?
     
  14. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    You are right, I dont need to parent it. I have unparented it, but still get some bobbing effects. I have the scale all at the same value, I probably need to make sure that it is exactly facing the camera.

    Is there any simple way of aligning objects so that their rotation transform is correctly facing the camera?

    I have been using the rotate option in Unity editor but cant seem to get it 100% correct.
     
  15. RobbieDingo

    RobbieDingo

    Joined:
    Jun 2, 2008
    Posts:
    484
    you could make the object as a child of the camera, then it's rotation and position will be relative to the camera, change the values as needed, then un-child it.
     
  16. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    Hi RobbieDingo,


    I'm getting on really well with the UV mapped disc. The only thing I cant figure out is that when rotating it, the disc appears to roll up and down slightly during a full rotation. I was hoping that maybe I just hadn't aligned it properly but have attached it to the main camera as a child object and changed it's position to equal the main camera, but it still bobs up and down a little while rotating.

    Could it be because it is based on a cylinder? Or maybe my alignment is still wrong.

    I have x,y and z all set to scale at 100.

    Any suggestions?
     
  17. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    I gather the DiscObject is a perfect Circle? Just a thought.
     
  18. RobbieDingo

    RobbieDingo

    Joined:
    Jun 2, 2008
    Posts:
    484
    Hi, I suspect that the problem is that the circle (ie. the image on the texture) is not 100% in the centre of the object texture.

    Make your own texture, an exact square (eg. 256 x 256 px) and make sure that the circle you draw on the texture is in the exact centre - then test that?
     
  19. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    Hi,

    I have a blank transparent background sized at 256x256 in photoshop, then pasted the circular picture into the centre of the transparent background, then saved and tried again.

    I beleive that photoshop automatically centres it when you paste into a new window, and have tried counting the little squares on either side, which appear to be the same.

    No joy unfortunately !

    If you place the texture on the DiscObject it appears correct, but when rotating it will move up then down a little. Almost like a squashed circle would appear if roatating. I placed it just underneith a line drawn in the background, and when it rotates you can see it move up over the line then down then finish back in central position.

    It's a strange problem, any other thoughts?



    P.S. just for reference, does the texture always have to be circular on a transparent background to work, or could I use a rectangular / square texture?
     
  20. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    I have just found out that when copying using the eliptical tool it may create a non-perfect circle, so I Have to hold shift down while in Photoshop to create a Perfect Circle Copy of the image, just wondering whether there is a similar option in your modelling program? and whether the DiscObject was created Eliptical instead of a Perfect Circle?

    Anychance you can double check, just in case?
     
  21. RobbieDingo

    RobbieDingo

    Joined:
    Jun 2, 2008
    Posts:
    484
    Well it could be that the object I gave you was not correctly centered I guess.

    Try the one attached below. I just checked this one with the following code:-

    Code (csharp):
    1.  
    2. function Update() {
    3.     transform.Rotate (0, 100 * Time.deltaTime, 0.0);
    4. }
    5.  
    ... and it spins perfectly.
     

    Attached Files:

  22. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    Well done Robbie,

    Thanks very much, that works brilliantly, it must of been off center I suppose.
    I would love to know how you do the UV Mapping on an object like that, I have read a few different articles/tuts/texts about UV wrapping/mapping but am slowly learning it as Modelling is not one of my strong points. I have been given a few instructions on how to do it in Blender (I Really don't understand Blender), and have heard of different softwares to use for this kind of thing.

    I am planning on downloading a trial version of Carrara for any future modelling needs + Learning, would you say it is a good modelling app for this sort of thing?

    Any chance you can give me a very rough idea of how I would go about creating a UV Map like the one you have created for me in Carrara? As I cant seem to find that many tuts on doing discs and simple objects, but always some form of complicated model. I am really interested in learning some of the modelling techniques for use in Unity but just feel I need a starting point to get me going.


    Once again, many thanks for all your help on this one, I really appreciate it!
    :D

    Best Regards,
    Halo
     
  23. RobbieDingo

    RobbieDingo

    Joined:
    Jun 2, 2008
    Posts:
    484
    I think a lot of people here would not be using CarraraPro, I only use it because it something I learnt quite a while ago, its fairly cheep, and I still have a copy of it.

    Probably most people here would be using 3DStudioMax or Maya (if they are high end users), or Blender.

    Ive not used a lot of other 3d packages, but Blender in its current format is a nightmare (IMO). Carrara is quite friendly for those people just wanting to do simple stuff...

    UV Mapping simple objects is very straight forward in most packages - in Cararra you enter the UVMapping area, which shows a flat version of your mesh (as if it has been unfolded) over your texture atlas, then move the mesh sections around to fit the texture.

    As with all these things, you have to just roll your sleeves up and dive in - I personally find its best to set myself target of something I want to achieve, and work towards that as an outcome, rather than just open a package and play with it to see what it can do.

    For most people with at least some prior knowledge of 3d - I would expect it to take no more than 1 evening to work out how to UV map in Carrara. (But don't quote me!).

    Best of luck... What are you actually trying to do anyways?
     
  24. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    Excellent advice, I really do feel like diving in and getting to grips with the basics then expanding slowly.

    I have looked at a few different packages, Zbrush, softimage etc. I guess the best way would be to try them all and find out which one suits the best. I am looking for something that is really user friendly though.

    I really just want to learn the modelling practises that will be useful for Unity.
    I suppose my main aim would be at the moment to achieve the UV Mapping and mainly to be able to create a mesh that will allow moving parts when it is textured. I.E. User inputs custom image, this then gets applied to my mesh as 1 texture but allowing a part of the mesh to rotate or move independantly with whatever part of the texture may be over it. I gather that is possible to do?

    I was hoping that if I could create a mesh with moveable parts then I would be able to do the movement etc in Unity all from the 1 mesh and 1 texture.

    I have always had an interest in 3d modelling, but never really knew where to start.
     
  25. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    Hi Robbie,

    Thanks for your help with this problem, it going well now, only I tried it today on a texture with a circle in the middle and it appears to still be slightly off center - but only by a very small ammount.

    Is there any chance you can double check that the DiscObject is indeed perfectly centered? As my project requires absolute center rotation to work properly.

    Or do you think I may have made a mistake with my object alignment when using the unity rotation selector, as I align the rotation by dragging the inside rotation line.

    Best Regards,
    Halo
     
  26. RobbieDingo

    RobbieDingo

    Joined:
    Jun 2, 2008
    Posts:
    484
    Hi, like I said before, I tested it my end and it spins perfectly, you can check if the problem is your texture or elsewhere by switchIng for the texture I gave you right? There's nothing wrong with the object I gave you.

    You might be able to use the texture offsets to correct any errors you are seeing perhaps?

    I don't really understand your comment about the "inside rotation line" ? Best to type the rotation into the text fields any way...
     
  27. Halo212

    Halo212

    Joined:
    Feb 17, 2010
    Posts:
    60
    Thanks for your reply.

    Your absolutely correct, I have made a Basic mistake with my drawn texture and it turns out that it was drawn off-centered in the graphics program (Doh), hence why it only became noticeable today but appeared fine yesterday when I used a different texture.

    You will be pleased to know that I have found a great 3D modelling app that appears very user friendly. Cheetah3D, Love it to bits, hopefully with much practise I will be able to do some form of modelling for use in Unity.

    I will start doing the rotations using the text field as it seems to easy to make a rotational mistake when using the Unity Rotate Object Transform by hand, Thanks for the advice and all your help with the UV Mapping!

    Kind Regards,
    Halo

    :D