there is an error in the code as i usually do with all of it ... i'll break it down for you
firstly using the actual function
hError = FlipSkin(1,0,0)
if hError > 0 then gosub _check_error
_check_error:
print Error$(hError)
print "waiting for keystroke to resume..."
hError = 0
wait for key
return
now i've change this to be simpler to use, the first number is the model and the second is the skin|texture.
The last is now a new value, which i'm dubbing as Flip Angle...
if its 0 then it flips the U (horizontal) Coords, if its 1 then it flips the V (vertical) Coords ... and if its 2 then it flips both
Also added a small gosub incase there is an error.
I'd suggest doing as i oftenly do and make a compiled Error Array, like
Error$(1) = "Media Not Found"
Error$(2) = "Memory Block Unavailable"
(these are the only 2 you'll really need for now)
this section makes sure the object is available to use ->
function FlipSkin(model,skin,flip)
memblock = 1
if file object exist(model) = 1
`<< Code Goes Here >>
else
hError = 1
endif
endfunction hError
you'll notice the endfunction has a
'hError' value, this is to make sure that what is returned will let us understand where and error occurred which DB isn't programmed to check for.
now you want to add in the << Code Goes Here >> spot
while memblock exist(memblock) = 0
inc memblock
if memblock > 32
hError = 2
exit
endif
endwhile
this simply automatically checks for the next available memoryblock position, a useful snippet if you get into the habit of releasing memoryblocks once you've finished with them
now right after this we put this
if memblock exists(memblock) = 1
`<< Code Goes Here >>
endif
might seem silly really but is really just somewhere to put you code neatly and just double checking that the block you want to use is actually there, but as it should be this is the reason for no 'Else' for the error logging.
yay... now we can finally get into the nitty gritty of the actual code
make mesh from object model,model
delete object model
make memblock from mesh model,memblock
delete mesh model
first we add this code ... basically the aim here is to take the specified model and throw it into a memblock for use. It is far easier to populate a memory block by having DarkBasic itself mess about with the actual populating with a from a mesh rather than doing it manually.
As currently DarkBasic only has a Mesh -> Memblock command this is why we convert first.
Notice that after changing format each time firstly to mesh then to memblock i'm deleting the old values... what i'm actually doing is freeing up the values so we can use them again once we're done with the editing.
It also helps with the actual memory being used, but most programmers don't think about that kinda thing for some reason.
Now as DarkBasic only supports a single set of UV coordinates PER Vertex the next thing to do is find out how many of the little buggers are in the model
Mesh Memblock Setup
be sure to check that out for more info on Mesh Memblocks...
vCount = memblock dword(memblock,0)
fCount = memblock dword(memblock,16)
vOfsLni = memblock dword(memblock,28)
Pos = 32 + (vCount*12) + (vCount*12) + (fCount*14)
if Pos = vOfsLni then bGood = 1
i'm not sure however the Calculated LNI Offset SHOULD be identical to the one in the dword position 28.
However sometimes there are discrepencies.
now we'll actually start flipping the UV points
if flip = 0
for index = 0 to vCount - 1
fCoord# = memblock float(memblock,pos)
fWrite# = 1.0 - fCoord#
write memblock float memblock,pos,fWrite#
inc pos,8
next index
endif
if flip = 1
pos = pos + 4
for index = 0 to vCount - 1
fCoord# = memblock float(memblock,pos)
fWrite# = 1.0 - fCoord#
write memblock float memblock,pos,fWrite#
inc pos,8
next index
endif
if flip = 2
for index = 0 to vCount - 1
fCoord# = memblock float(memblock,pos)
fWrite# = 1.0 - fCoord#
write memblock float memblock,pos,fWrite#
inc pos,4
fCoord# = memblock float(memblock,pos)
fWrite# = 1.0 - fCoord#
write memblock float memblock,pos,fWrite#
inc pos,4
next index
endif
now fCoord# is the 0.0 -> 1.0 floating point taken from the model, the fWrite# is the flipped floating point.
the pos = the memblocks byte position... you add 4 each time because a float is 4bytes.
hopefully this has now made everything a bit clearer and more importantly without some obvious flaws
now we use a 1.0 value and then subtract the original value because to produce a flip of the original you always use the Maximum Value - Current Value
and there is your flipped value
Anata aru kowagaru no watashi! ![](http://members.lycos.co.uk/timesaga/ssj2.gif)