how to animate a tile in a mesh?

Blitz3D Forums/Blitz3D Beginners Area/how to animate a tile in a mesh?

(Sorry :)

For the grass crossplane bit, it is simply an X shaped wall mesh, double sided with a texture on it. For testing, just use a cube for now.
Unfortunately, the following is out of my head and i am not on a windows machine at the moment, so cannot test it for you, but it should work, (may need a syntax correction or two :)

It would be loaded with something like:
;set color+alpha+mipmap on any texture with grass in name (must be 32bit PNG or TGA!)
texturefilter ("grass",1+2+8)   

;load the textured X mesh
global sourcegrass=loadmesh("mygrass.png")   

;enable backfaces so both sides of all 4 triangles of the crossplane are visible from both sides.
entityfx (sourcegrass, 16)  



Then using an array or custom type to store the data something like:
(assuming you use custom types rather than an array)

type Tgrass
    field handle%
    field X#
    field Y#
    field Z#
end type
(arrays are faster tho but not as 'pretty' :)


You obviously need to fill the above structure with some virtual 'grass' objects (each one will be a desired location). This structure could be filled in many ways, for example;
- by simply hard-coding them(yuck!),
- placement maps (a hidden image with different colors for different things)
- using a placement script from a level or terrain editor,
- by 'intelligent' mesh analysis of the terrain itself (ie. record pos. of 'random verticies that have the vertexcolor green').

Either way, object creation would be done by:
g.Tgrass=new Tgrass
   g\handle=0   ;(no need for a value here yet, this will store the copy's pointer or 'handle')
   g\x = 342    ;<--example coords
   g\y = 32
   g\z = 100



Then in your main loop add the dynamic placement code. I have used a reference pivot here for simplicity but using maths (*may*) be faster :/

Something like this in the main loop:
;create our reference object
refpoint=createpivot()

;iterate through all "grass" objects
for g.Tgrass = each Tgrass;
    
    ;position reference at position stored in the object "g" of type Tgrass 
    positionentity refpoint(g\x, g\y, g\z)

    ;work out how far away from camera the position of the reference is
    if entitydistance(camera,refpoint) < visiblerange then
         ;if it doesn't already exist make an "instance" and position it 
         if not g\handle then 
             g\handle=copyentity(sourcegrass)
             positionentity (g\handle, g\x, g\y, g\z)
         endif
    else
         ; if not in range and an instance exists then delete it, freeing precious resources!.
         if g\handle then
               freeentity g\handle : 
               g\handle=0  ;<---important, freeentity does not delete the pointer's value
         endif
    endif

next

;delete the refpoint (important!)
freeentity refpoint : refpoint = 0


Hope this helps and works ok, as i say, i cant test it for you im afraid. However the 'theory' is there to give you some ideas.

ps: This same kind of system can be used for pretty much anything, monsters, items, buildings etc..