Models' Texture Movement

Blitz3D Forums/Blitz3D Programming/Models' Texture Movement

ClayPigeon(Posted 2010) [#1]
OK, I have a really simple problem. In my game, I have several places in my world where there are rivers. I have all the rivers as separate model children called 'river' in my world model. What I want know how to do is create a UV map on the rivers so that if I go into B3D and EntityTexture a water texture to the 'river' child only, I can then PositionTexture the water over 1 to the right or something each frame and the texture will appear to flow all over the river without any strange artifacts. Thanks!


stayne(Posted 2010) [#2]
You need to use a program that can do UV mapping. I use Ultimate Unwrap Pro, works great.


ClayPigeon(Posted 2010) [#3]
@stayne: I have the tools to do UV mapping. What I'm asking is how would I make the map correct so that it flows in the directions I want it to. Oh, I forgot to say, I'm using DeleD to make my worlds.


Ross C(Posted 2010) [#4]
You need to map it, so all the triangles run flat, straight down the texture. That way, you can easily scroll the texture. Only problem you will have is UV distortion. I'm not really sure how to properly fix that...


Kryzon(Posted 2010) [#5]
I don't know how mapping in DeleD is done, but here's how I would do it [in 3DS]:

Create a quad "strip" (the river or stream). Make it the shape you want, and weld the vertices to the rest of the level.

Then I'd go through all 4 vertices of each quad of this river strip mesh, manually editing the UVs of each vertex in order to make that quad map perfectly the texture, regardless of it's 3D shape. If you go try mapping each quad with a customized planar gizmo, it won't hold the same results - unfortunately, you really have to go manually with this (unless you can script a gizmo for this, somehow).

Here's a visual description:


The numbers are the UVs each vertex should have. Consider this data as the following format: "U,V".
What you're looking for here is making each adjacent edge continue the texture in a seamless way.

Only problem you will have is UV distortion. I'm not really sure how to properly fix that...

I don't think it's fixable in any way, since you're trying to apply a square\rectangular texture to a shape with a different ratio.
But what I believe will help is making each quad with a width and length ratio closer to the texture's, and making the river mesh more straight, without too strong curves (if that doesn't conflict with your level design, of course). You can have curved rivers, really, it's just a matter of balance and where you set your tolerance to stretching and skeweing.


ClayPigeon(Posted 2010) [#6]
Thanks! I was hoping it would be that easy. Now, there's something I've been wondering. I know how you can grab model children from a model with FindChild and assign a variable to it to reference it. Is there some way to do something like that to grab individual textures or materials from a model? If so, I could use that to just texture the river in DeleD, then grab it in B3D and move it as opposed to applying it in B3D and moving it.


Kryzon(Posted 2010) [#7]
Well, I don't think you should texture that river at all; just keep it with the polygons really.
That way there won't be any leftover brushes from your mesh, leaking your memory (since Finding a brush or a texture gives you a copy of said material, instead of giving you the original).
But I get what you said; it would indeed be awesome if we could just extract the currently applied texture and use that, instead.

You can find the river(s)\waterfall(s) entities with GetChild() too, which in turn would make your level design more modular with name prefixes and such. Then you'd use PaintEntity to paint each of these elements with a Brush that has that tileable water texture:
For Index = 1 To CountChildren(MESH_Level1)
       
       child = GetChild(MESH_Level1,Index)

       If Left(EntityName(child),6) = "RIVER_" Then
              PaintEntity(child,FLOW_RiverBrush)
       End If

Next


That brush you would create with the Brush commands, giving it a special name and the appropriate texture.

(I recommend you give intelligent prefixes to level elements, variables and so on 'cause that'll make things much easier and organized, of course. Not to mention it will ease the addition of further content to your game engine, which is one of the top priorities you should have when building it).


Ross C(Posted 2010) [#8]
Expanding slightly on Kryzon's idea. What i do in my editor, is have the properties for the river, in it's EntityName. For instance:

EntityName "<name>River <TextureScrollX>0.1"

And run through each entity, extracting these properties, and storing each entity in a seperate type object. That way you can set lots of different entity properties in the editor, and build code to make these things happen when the code runs.


Kryzon(Posted 2010) [#9]
That's a good idea, Ross (although I go the lazy way and set it directly from the modelling application).

Do you know if there's a size limit regarding the entity name's string? (in case of elements with a lot of tags and properties).


Ross C(Posted 2010) [#10]
I've always wondered that myself. But i doubt i will run into it. I'm mearly creating say:

<Name>Platform_2 <Trigger>Key_Space <TriggerDistance>10 <TriggerTransform>Move <TriggerMode>PingPong <TriggerSpeed>2

Evrytime you get within 10 units of a platform, pressing space triggers a ping pong motion of the platform. You can have things follow waypoints etc etc. Unfortunetly, i'll never finish my editor, because i keep adding stuff :(


ClayPigeon(Posted 2010) [#11]
(I recommend you give intelligent prefixes to level elements, variables and so on 'cause that'll make things much easier and organized, of course. Not to mention it will ease the addition of further content to your game engine, which is one of the top priorities you should have when building it).


When I assign vars to something, I usually put the name followed by its type. (eg. RockEntity, WallType, StepSound)

This sounds like it will work. All I need to know is if I configure the UV coordinates without a texture, then texture it in B3D, will it retain the UV coordinates when I texture it?


ClayPigeon(Posted 2010) [#12]
OK. I tried it. Everything seems to be working fine -- Except my UV mapping skills:



That Ultimate Unwrap seems you have to pay for it, so I used the NashaUV that comes with DeleD CE and that's what it gave me..


Ross C(Posted 2010) [#13]
UV's are stored in the vertices of a mesh. They don't know anything about the texture, not even it's size.


Kryzon(Posted 2010) [#14]
That was an awesome idea putting arrows in your texture. Nicely thought.

Yeah, it's just a matter of correcting the UVs to make it work right (please show a screenshot of it later on, with the definitive texture etc!).


ClayPigeon(Posted 2010) [#15]
Sorry, it was totally my fault. I selected the faulty faces and rotated their coordinates. Here is the result:



Here is a download link to the source code I made for the river. (ZIP contains all files including the arrow texture)

http://host-a.net/ClayPigeon/RiverTest.zip

P.S.: The UV program I'm using doesn't support grid snapping, and it's visual so I can't just enter the UV coords - I have to drag them to the correct corners. Does anyone know of a UV mapping program that supports .b3d files? (preferably free?)


Kryzon(Posted 2010) [#16]
Are you sure you can't manually type in the UVs?

I tried taking a look at the NashaUV interface:



If you look at the top-left corner, there are two text boxes for "U" and "V", I guess there's where you could manually type the UVs for each quad of the river mesh (which in the end would make all quads overlay eachother, all of them occuping the whole UV space).


Ross C(Posted 2010) [#17]
That would be idea, as you'd get a potential seamless texturing, if you have a seamless texture that is.


ClayPigeon(Posted 2010) [#18]
Well I was hoping I wouldn't have to do that.. I mean, what if I have a river that extends really far with a lot of polygons? Also, that screenshot you have there is not actually quite what I got when I opened NashaUV. The quads were all clumped in an odd way into the same square. I guess it will just have to be trial and error. Thanks!