Post by EightBitDragon on Feb 2, 2012 17:13:34 GMT -5
This is a small bit of code I created a while back for creating waterfalls, but I never utilized it. OzCrash had also created a scrolling texture effect, and from the looks of his video, is more refined. This code I've created is far less accurate because it scrolls the whole entire UV mapping. It is only useful for individual waterfall objects, rivers and other water effects, but its a start.
Very simply, if you would like to scroll the texture of your mesh in BlitzSonic, you could add a <scroll/> tag to the mesh parse, with x# and y# speed attributes. Then, in the mesh structure type, add a Scroll boolean (a true or false variable) and the x# and y# floats. When the mesh is loaded, if the <scroll/> tag is encountered, it saves the x# and y# to the mesh structure, and sets Scroll to True.
In the stage update, you would then loop through each mesh structure, and if 'Scroll' is True, execute the scrolling code on the mesh. Something like this:
Finally, you need the ScrollTex function. This is the code I came up with. It seems to work fine for simple applications, but remember that UV coords go from 0.0 to 1.0, which means the speed you set should be a very low number, or the scrolling will be REALLY fast.
The code should be self-explanatory.
Happy BlitzSonic modding!
Very simply, if you would like to scroll the texture of your mesh in BlitzSonic, you could add a <scroll/> tag to the mesh parse, with x# and y# speed attributes. Then, in the mesh structure type, add a Scroll boolean (a true or false variable) and the x# and y# floats. When the mesh is loaded, if the <scroll/> tag is encountered, it saves the x# and y# to the mesh structure, and sets Scroll to True.
Type MeshStructure
Field Entity
Field Scroll
Field x#, y#
End Type
In the stage update, you would then loop through each mesh structure, and if 'Scroll' is True, execute the scrolling code on the mesh. Something like this:
For m.MeshStructure = each MeshStructure
If m\Scroll = True then ScrollTex(m\Entity, m\x#, m\y#)
Next
Finally, you need the ScrollTex function. This is the code I came up with. It seems to work fine for simple applications, but remember that UV coords go from 0.0 to 1.0, which means the speed you set should be a very low number, or the scrolling will be REALLY fast.
The code should be self-explanatory.
Function ScrollTex(mesh, x#, y#)
; Loop through all the surfaces
For index = 1 To CountSurfaces(mesh)
surf = GetSurface(mesh, index)
; For each surface, count each vertex amd adjust it's position
For vertex = 0 To CountVertices(surf)-1
u# = VertexU#(surf,vertex) + x#
v# = VertexV#(surf,vertex) + y#
; Wrap the uv coords for safety. This may be redundant.
If x# > 0.0 Then
If u# < 0.0 Then u# = 1.0
EndIf
If x# < 0.0 Then
If u# > 1.0 Then u# = 0.0
EndIf
If y# > 0.0 Then
If v# < 0.0 Then v# = 1.0
EndIf
If y# < 0.0 Then
If v# > 1.0 Then v# = 0.0
EndIf
; Assign the new coords.
VertexTexCoords surf, vertex, u#, v#
; Go to next vertex
Next
; Go to next surface
Next
End Function
Happy BlitzSonic modding!