|
My screenshot describes my question clearly (better than words I think)
So, is it possible to have more control with the UV mapping and decide which portion of the texture to map on the Mesh (in a tiling style).
(comments are locked)
|
|
At this point are you familiar with the uv array? http://docs.unity3d.com/Documentation/ScriptReference/Mesh-uv.html which is just part of Mesh http://docs.unity3d.com/Documentation/ScriptReference/Mesh.html Based on what you have described: Just play with uv values of 0.0, 0.5 and 1.0. You'll soon get the idea! Your image just goes from 0 to 1 in each direction, it's that simple. Your quadrants are just the obvious. DRAW A DIAGRAM of your eight triangles and start setting the uvs. Enjoy! if you get big into vertices consider this fount of interesting information and downloads, etc etc http://answers.unity3d.com/questions/193695/in-unity-is-there-a-fast-way-to-find-nearby-triang.html Now here's a diagram:
large image: CLICK HERE TO SEE DIAGRAM PROPERLY So, say you want your ELEPHANT to appear in area D. The elephant obviously enough exists at the coords I have written here...
Your area D is two triangles (7 and 8). So .......... there are six verts (two triangles ... 2x3 = 6 !!) Just set the six verts to those values!! 0,,5 etc. It's that simple !!! OF COURSE as Owen points out, this "hello mesh" exercise only works if everything is completely regularly-spaced and so on. Enjoy! Helpful notes
Yeah, I'm sorry for the answer. The Unity team should make the comment versus answer thingie a little more obvious for new members :D I suppose that even for old members it's easy to make a mistake and use the comment box to comment normally. :) Fattie, you're right. I'm greatly interested in the 'Hello Mesh' learning process. I kind of understand your diagram very perfectly (theatrically) but programming-wise I'm still confused how things are connected together. On your example, you refer the uv array having a relationship with the triangle array. I thought the uv array was mainly having a relationship with the vertices array from the Mesh class. Besides, for what I want to accomplish I'm not intending to use a 3d software to build the models and textures. I need to build everything dynamically inside Unity. That's why I have to understand the Mesh stuff as perfectly as possible. I also googled keywords like "mesh programming" and I didn't find anything sadly. Is it possible for you to code a small demo (very simple to understand) using the script based on my image or your diagram? Thank you very much for all your support! I really appreciate it!
Aug 01 '12 at 08:28 AM
the_scholar
(comments are locked)
|
|
It would probably be easier to just use 4 planes, then 4 materials (one for each numeral,) which you swap in and out. Other approaches might squeeze out a little more speed, but I not much and you probably won't need it. Moving around UVs can easily stretch your texture, flip it, repeat ... . But to have a "non-continuous" texture, like the four 1's, all of the interior verts would need to have been previously split in the modelling program. That's just a basic concept in unwrapping. If you did that then you could code using You could also write a custom shader, which would work for a 4-vert plane. For example, To elaborate, the hard part of setting the UVs in code is you have to know how the verts were numbered during the export. It's possible the verts making the lower-left square are numbered 0,1,4 and 5; or 3,7,6 and 4; or anything else. The verts for the other 4 squares may not follow the same pattern, so you can't just reuse code with "vertNum+4". To find the numbers, you can print out the vert coords in Unity. Lots of verts have duplicate coords, so you have to guess which is part of which square. But, sure, once you get a 0-15 picture of how the plane verts are numbered, then you just need four lines that look like
Jul 31 '12 at 06:20 PM
Owen Reynolds
hmm .. export ... ? it's only 8 triangles, you just make 'em ! you know Owen, I believe he only meant it as a "hello Mesh" learning example all of what you say is true of course. unfortunately it appears to be the case of a disappearing new user, so another hour wasted
Jul 31 '12 at 07:15 PM
Fattie
xD Hello Mesh! brilliant!
Jul 31 '12 at 09:53 PM
Bunny83
(comments are locked)
|
|
So, I decided to make the mesh of my plane a bit simpler and made it only one cell rather than four cells. It seems to work great, only the numeral '2' tile of my image appears on my plane when I play-test Unity.
So, if I come back to my previous four-cells plane example, it would be impossible to have the same results without adding more vertices (splitting) as Owen instructed? The problem is the 5 inner vertices which are shared by two or four quads. You can only specify one texture coordinate per vertex, so it's not possible to set all four corners of all four tiles to different values. You have to split the vertices, so each tile have it's own 4 vertices. That means your 2x2 quad mesh which has 9 vertices would need 16 vertices. When you create the mesh procedurally, it's even much easier. Always four vertices in the array will make up one quad. The triangle array will contain blocks of 6 values which always refer to one four-vertices-block. I can post an example if you really want, but those two answers should be enough ;)
Aug 01 '12 at 10:22 AM
Bunny83
not that I'm aware of. For example, the Unity native cube is made of 24 verts, not 8 as it would at first seem. You have more flexibility with manipulating vert UVs, colours and tangents.
Aug 01 '12 at 10:31 AM
alucardj
No ;) You have 2 triangles per quad. One triangle needs 3 indices so one quad needs 6 indices. When you have 4 quads (2x2) you would need 4x4 vertices and 4x6 indices. So you need 16 vertices and 24 indices.
Aug 01 '12 at 11:02 AM
Bunny83
ThumbUp to everyone on this page from me =]
Aug 01 '12 at 01:06 PM
alucardj
If it makes things easier, you can safely think of quads/squares instead of triangles -- 4 verts/quad, total of 16, is just fine. The only time tris come into play is when making the tri array. "Quad" 4,5,9,10 becomes two tris 4,5,9 and 9,10,4 (which is an easy pattern.) Don't get too hung up on "everything is really tris." Everything is also in binary, but the computer just handles it. Graphics cards gladly take quads as input (a tri-list is the last resort out of 5 ways to list faces, but easy to understand.) The modellers I know prefer to use quads whenever they can. Also, suggest:
Aug 01 '12 at 02:12 PM
Owen Reynolds
(comments are locked)
|





and your point being?
@BeB_Wir3: Don't post such comments as an answer! Answers should answer the question.
I've converted your answer into a comment