@chafari The download link in the forum also has a .rar just for you to try :p
Hopefully it works as it seems that the zip file is fine on my end.
Nice Animation BTW!
Ok here is the example i was gunna make for you guys....hopefully some of it makes sence....cheers
Rem Project: testanims
Rem Created: Saturday, January 14, 2012
Rem ***** Main Source File ****
`note this example uses a global array for storing image data
`loadimagetodata("texture.bmp","test",1,1,25,25)
`end
`These data statements can be copied to your darkbasic application
`Coded by SoftMotion(c)2012 as freeware!
`[memblock size]
global anim
anim=0
global direction
direction=0
global vertcnt
autocam off
sync on
sync rate 60
data 2512
data 25,0,0,0,25,0,0,0,32,0
data 0,0,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 70,70,70,255,70,70,70,255,70,70
data 70,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,70,70,70,255,70,70,70,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,70,70,70,255
data 255,255,255,255,255,255,255,255,255,255
data 255,255,70,70,70,255,0,242,255,255
data 0,242,255,255,0,242,255,255,70,70
data 70,255,255,255,255,255,255,255,255,255
data 70,70,70,255,70,70,70,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,70,70,70,255
data 255,255,255,255,255,255,255,255,255,255
data 255,255,70,70,70,255,0,242,255,255
data 0,242,255,255,0,242,255,255,70,70
data 70,255,255,255,255,255,255,255,255,255
data 70,70,70,255,70,70,70,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,70,70,70,255
data 255,255,255,255,255,255,255,255,255,255
data 255,255,70,70,70,255,0,242,255,255
data 0,242,255,255,0,242,255,255,70,70
data 70,255,255,255,255,255,255,255,255,255
data 70,70,70,255,70,70,70,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,70,70,70,255
data 255,255,255,255,255,255,255,255,70,70
data 70,255,70,70,70,255,0,242,255,255
data 0,242,255,255,0,242,255,255,70,70
data 70,255,70,70,70,255,255,255,255,255
data 70,70,70,255,70,70,70,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,70,70,70,255
data 255,255,255,255,255,255,255,255,70,70
data 70,255,70,70,70,255,0,242,255,255
data 0,242,255,255,0,242,255,255,70,70
data 70,255,70,70,70,255,255,255,255,255
data 70,70,70,255,70,70,70,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 70,70,70,255,70,70,70,255,70,70
data 70,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,70,70,70,255,70,70,70,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 70,70,70,255,70,70,70,255,70,70
data 70,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,70,70,70,255,70,70,70,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,0,0,0
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,0,0,0,0,0,0,0,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,0,0,0
data 0,0,0,0,0,0,0,0,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,0,0,0
data 0,0,0,0,0,0,0,0,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,0,0,0
data 0,0,0,0,0,0,0,0,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,0,0,0
data 0,0,0,0,0,0,0,0,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255,0,242,255,255,0,242,255,255
data 0,242,255,255,0,242,255,255,0,242
data 255,255
`[End data statements]
makeimagefromdata(1,1,1)
make object box 1,100,100,100
texture object 1,1
`create vertex animation
lock vertexdata for limb 1,0
vertcnt=get vertexdata vertex count()
indexcnt=get vertexdata index count()
global dim animationverts#(vertcnt,30,2)
`make dumby box
make object box 2,1,1,1
hide object 2
`create animation
`frame 0
for vrc=0 to vertcnt-1 step 1
pt1#=get vertexdata position x(vrc)
pt2#=get vertexdata position y(vrc)
pt3#=get vertexdata position z(vrc)
`far#=distance#(0,0,0,pt1,pt2,pt3)
`position object 2,0,0,0
`point object 2,pt1#,pt2#,pt3#
`if get vertexdata position y(vrc)<0 then yrotate object 2,wrapvalue(object angle y(2)+(aa*5))
`if get vertexdata position y(vrc)>0 then yrotate object 2,wrapvalue(object angle y(2)-(aa*5))
`move object 2,far#
animationverts#(vrc,0,0)=pt1#
animationverts#(vrc,0,1)=pt2#
animationverts#(vrc,0,2)=pt3#
next vrc
`rotate first set
for aa=1 to 10 step 1
for vrc=0 to vertcnt-1 step 1
pt1#=get vertexdata position x(vrc)
pt2#=get vertexdata position y(vrc)
pt3#=get vertexdata position z(vrc)
far#=distance#(0,pt2#,0,pt1#,pt2#,pt3#)
position object 2,0,pt2#,0
point object 2,pt1#,pt2#,pt3#
if get vertexdata position y(vrc)<0 then rotate object 2,0,wrapvalue(object angle y(2)-(aa*2)),0
if get vertexdata position y(vrc)>0 then rotate object 2,0,wrapvalue(object angle y(2)+(aa*2)),0
move object 2,far#
animationverts#(vrc,aa,0)=object position x(2)
animationverts#(vrc,aa,1)=object position y(2)
animationverts#(vrc,aa,2)=object position z(2)
next vrc
next aa
`rotate second set
for aa=1 to 10 step 1
for vrc=0 to vertcnt-1 step 1
pt1#=get vertexdata position x(vrc)
pt2#=get vertexdata position y(vrc)
pt3#=get vertexdata position z(vrc)
far#=distance#(0,pt2#,0,pt1#,pt2#,pt3#)
position object 2,0,pt2#,0
point object 2,pt1#,pt2#,pt3#
if get vertexdata position y(vrc)<0 then rotate object 2,0,wrapvalue(object angle y(2)-20+(aa*2)),0
if get vertexdata position y(vrc)>0 then rotate object 2,0,wrapvalue(object angle y(2)+20-(aa*2)),0
move object 2,far#
animationverts#(vrc,aa+10,0)=object position x(2)
animationverts#(vrc,aa+10,1)=object position y(2)
animationverts#(vrc,aa+10,2)=object position z(2)
next vrc
next aa
`rotate third set
for aa=1 to 10 step 1
for vrc=0 to vertcnt-1 step 1
pt1#=get vertexdata position x(vrc)
pt2#=get vertexdata position y(vrc)
pt3#=get vertexdata position z(vrc)
far#=distance#(0,pt2#,0,pt1#,pt2#,pt3#)
position object 2,0,pt2#,0
point object 2,pt1#,pt2#,pt3#
if get vertexdata position y(vrc)<0 then rotate object 2,0,wrapvalue(object angle y(2)+(aa*2)),0
if get vertexdata position y(vrc)>0 then rotate object 2,0,wrapvalue(object angle y(2)-(aa*2)),0
move object 2,far#
animationverts#(vrc,aa+20,0)=object position x(2)
animationverts#(vrc,aa+20,1)=object position y(2)
animationverts#(vrc,aa+20,2)=object position z(2)
next vrc
next aa
unlock vertexdata
delete object 2
position camera 0,0,-500
point camera 0,0,0
speed=50
time=timer()
do
yrotate object 1,wrapvalue(object angle y(1)+.5)
xrotate object 1,wrapvalue(object angle x(1)+.5)
zrotate object 1,wrapvalue(object angle z(1)+.5)
if time+speed<timer() then time=timer():updateanimation()
position camera 0,0,-500
point camera 0,0,0
texture object 1,1:show object 1
set cursor 1,1:print "animation sequence="+str$(anim)+ " speed ms="+str$(speed)
set cursor 1,20:print "press spacekey to save object as dbo with animation and texture"
if spacekey()=1 then goto nextsection
sync
loop
nextsection:
`create 2 memblocks
`
if memblock exist(1)=1 then delete memblock 1
if memblock exist(2)=1 then delete memblock 2
if memblock exist(3)=1 then delete memblock 3
make memblock from image 1,1
make memblock from array 2,animationverts#(0)
length1=get memblock size(1)
length2=get memblock size(2)
make memblock 3,length1+length2+16
`save image first
`a dword = 8 bytes
pointer=0
write memblock dword 3,pointer,length1
pointer=pointer+8
`write memblock data
for t=0 to length1-1 step 1
write memblock byte 3,pointer,memblock byte(1,t)
pointer=pointer+1
next t
`write animation to same memblock
write memblock dword 3,pointer,length2
pointer=pointer+8
`write memblock data 2
for t=0 to length2-1 step 1
write memblock byte 3,pointer,memblock byte(2,t)
pointer=pointer+1
next t
`done
`now lets save the dbo file
add memblock to object 3,1
if file exist("test.dbo")=1 then delete file "test.dbo"
`reset frame to 0
resetanimation()
sync
save object "test.dbo",1
`ok done
`lets delete the scene
if object exist(1)=1 then delete object 1
if image exist(1)=1 then delete image 1
load object "test.dbo",1
`now lets extract the memblock
if memblock exist(1)=1 then delete memblock 1
get memblock from object 1,1
`now lets split the memblock into 2 (texture data first)
pointer=0
length1=memblock dword(1,0)
pointer=pointer+8
if memblock exist(2)=1 then delete memblock 2
make memblock 2,length1
for t=0 to length1-1 step 1
write memblock byte 2,t,memblock byte(1,pointer)
pointer=pointer+1
next t
`lets extract memblock 2 (animation)
length2=memblock dword(1,pointer)
pointer=pointer+8
if memblock exist(3)=1 then delete memblock 3
make memblock 3,length2
for t=0 to length2-1 step 1
write memblock byte 3,t,memblock byte(1,pointer)
pointer=pointer+1
next t
`now lets work with the 2 memblocks
make array from memblock animationverts#(0),3
make image from memblock 1,2
texture object 1,1
position camera 0,0,-500
point camera 0,0,0
speed=50
time=timer()
sleep 500
do
yrotate object 1,wrapvalue(object angle y(1)+.5)
xrotate object 1,wrapvalue(object angle x(1)+.5)
zrotate object 1,wrapvalue(object angle z(1)+.5)
if time+speed<timer() then time=timer():updateanimation()
position camera 0,0,-500
point camera 0,0,0
texture object 1,1:show object 1
set cursor 1,1:print "loaded the memblocks from dbo and now playing!"
set cursor 1,20:print "press spacekey to make our own 3d format using memblocks"
if spacekey()=1 then goto nextsection2
sync
loop
nextsection2:
`ok so that worked...
`now lets make a memblock from that dbo file we made and name it
`something else and add extra data
open to read 1,"test.dbo"
if memblock exist(4)=1 then delete memblock 4
make memblock from file 4,1
close file 1
if file exist("myownformat.cc")=1 then delete file "myownformat.cc"
open to write 1,"myownformat.cc"
write string 1,"This is my own cool format"
write string 1,"My character stats health |100 speed |50 attacklevel |5"
write string 1,"here is the dbo file next"
write memblock 1,4
close file 1
`ok we are done and the file should be made
`now lets load our new format in :p
sleep 500
if object exist(1)=1 then delete object 1
if memblock exist(1)=1 then delete memblock 1
if memblock exist(2)=1 then delete memblock 2
if memblock exist(3)=1 then delete memblock 3
if memblock exist(4)=1 then delete memblock 4
if image exist(1)=1 then delete image 1
open to read 1,"myownformat.cc"
read string 1,dumby$
read string 1,pullstats$
speed1=findvalue1#(pullstats$,"speed"," |")
health1=findvalue1#(pullstats$,"health"," |")
attack1=findvalue1#(pullstats$,"attacklevel"," |")
read string 1,dumby$
`ok now the dbo file
read memblock 1,1
close file 1
`now lets make a temp dbo file
`load it
`then delete it as if it was never there
if file exist("hide.dbo")=1 then delete file "hide.dbo"
open to write 1,"hide.dbo"
make file from memblock 1,1
close file 1
if object exist(1)=1 then delete object 1
load object "hide.dbo",1
delete file "hide.dbo"
`deleted hidden file just created
`ok done
`lets extract the memblocks
if image exist(1)=1 then delete image 1
if memblock exist(1)=1 then delete memblock 1
get memblock from object 1,1
`now lets split the memblock into 2 (texture data first)
pointer=0
length1=memblock dword(1,0)
pointer=pointer+8
if memblock exist(2)=1 then delete memblock 2
make memblock 2,length1
for t=0 to length1-1 step 1
write memblock byte 2,t,memblock byte(1,pointer)
pointer=pointer+1
next t
`lets extract memblock 2 (animation)
length2=memblock dword(1,pointer)
pointer=pointer+8
if memblock exist(3)=1 then delete memblock 3
make memblock 3,length2
for t=0 to length2-1 step 1
write memblock byte 3,t,memblock byte(1,pointer)
pointer=pointer+1
next t
`now lets work with the 2 memblocks
make array from memblock animationverts#(0),3
make image from memblock 1,2
texture object 1,1
position camera 0,0,-500
point camera 0,0,0
speed=50
time=timer()
sleep 500
do
yrotate object 1,wrapvalue(object angle y(1)+.5)
xrotate object 1,wrapvalue(object angle x(1)+.5)
zrotate object 1,wrapvalue(object angle z(1)+.5)
if time+speed<timer() then time=timer():updateanimation()
position camera 0,0,-500
point camera 0,0,0
texture object 1,1:show object 1
set cursor 1,1:print "loaded the memblocks from dbo and now playing from own format!"
set cursor 1,20:print "press spacekey to exit"
set cursor 1,50:print "extra data loaded from own format:Health="+str$(health1)+" attack lvl="+str$(attack1)+" speed="+str$(speed1)
if spacekey()=1 then end
sync
loop
function updateanimation()
if direction=0 then anim=anim+1
if direction=1 then anim=anim-1
if anim=<-1 then anim=1:direction=0
if anim=>31 then anim=29:direction=1
lock vertexdata for limb 1,0
vertcnt=get vertexdata vertex count()
for vrc=0 to vertcnt-1 step 1
set vertexdata position vrc,animationverts#(vrc,anim,0),animationverts#(vrc,anim,1),animationverts#(vrc,anim,2)
next vrc
unlock vertexdata
endfunction
function resetanimation()
lock vertexdata for limb 1,0
vertcnt=get vertexdata vertex count()
for vrc=0 to vertcnt-1 step 1
set vertexdata position vrc,animationverts#(vrc,0,0),animationverts#(vrc,0,1),animationverts#(vrc,0,2)
next vrc
unlock vertexdata
endfunction
function makeimagefromdata(pointer,imageID,memblockID)
restore
if pointer<>1
for r=1 to pointer-1 step 1
read dumby
next r
endif
read mblocksize
`message "memb size"+str$(mblocksize)
if memblock exist(memblockID)=1 then delete memblock memblockid
make memblock memblockID,mblocksize
for td=1 to mblocksize step 1
read gg
write memblock byte memblockID,td-1,gg
next td
if image exist(imageID)=1 then delete image imageID
make image from memblock imageID,memblockID
endfunction
function loadimagetodata(sourcefilename$,savefilename$,memblockID,imageID,sizex,sizey)
`written by SoftMotion(c)2012
`Freeware
pointx=0
pointy=0
file_to_resize$=sourcefilename$
if file exist(file_to_resize$)=0 then exitfunction
if image exist(imageID)=1 then delete image imageID
if memblock exist(memblockID)=1 then delete memblock memblockID
local dim image(sizex,sizey)
for x=0 to sizex
for y=0 to sizey
image(x,y)=0
next y
next x
load image file_to_resize$,imageID,1
make memblock from image memblockID,imageID
delete image imageID
size=GET MEMBLOCK SIZE(memblockID)
pos=0
Width#=memblock DWORD(memblockID,0):height#=memblock DWORD(memblockID,4):depth=memblock dword(memblockID,8)
pos=12
if depth=32 then cnt=4
if depth=24 then cnt=3
if depth=16 then cnt=2
if depth=8 then cnt=1
counter=12
desiredwidth#=sizex
desiredheight#=sizey
scx#=desiredwidth#/width#
scy#=desiredheight#/height#
sx#=0
sy#=0
for y1=0 to height#-1 step 1
sy#=sy#+scy#
for x1=0 to width#-1 step 1
sx#=sx#+scx#
for ty=0 to scy# step 1:for tx=0 to scx# step 1:
a1=int(sx#-tx)
b1=int(sy#-ty)
if a1<0 then a1=0
if a1>desiredwidth#-1 then a1=desiredwidth#-1
if b1<0 then b1=0
if b1>desiredheight#-1 then b1=desiredheight#-1
image(a1,b1)=memblock DWORD(memblockID,counter):
next tx:next ty
counter=counter+cnt
next x1
sx#=0
next y1
if memblock exist(memblockID)=1 then delete memblock memblockID
drawresx=sizex
drawresy=sizey
length=int(drawresx*drawresy*4)+12
make memblock memblockID,length
write memblock DWORD memblockID,0,drawresx:write memblock DWORD memblockID,4,drawresy:write memblock dword memblockID,8,32
pos=12
counter=12
cnt=4
for y1=0 to drawresy-1 step 1
aty=aty+1
for x1=0 to drawresx-1 step 1
atx=atx+1
color_a=image(x1,y1)
write memblock dword memblockID,counter,color_a
counter=counter+cnt
next x1
atx=0
next y1
`write to file
if file exist(savefilename$+".txt")=1 then delete file savefilename$+".txt"
open to write 1,savefilename$+".txt"
write string 1,"`These data statements can be copied to your darkbasic application"
write string 1,"`Coded by SoftMotion(c)2012 as freeware!"
write string 1,"`[memblock size]"
write string 1,""
write string 1,"data "+str$(length)
dim populate(10)
popcnt=1
for y=0 to length-1 step 1
populate(popcnt)=memblock byte(memblockID,y)
popcnt=popcnt+1
if popcnt=>11 then write string 1,"data "+str$(populate(1))+","+str$(populate(2))+","+str$(populate(3))+","+str$(populate(4))+","+str$(populate(5))+","+str$(populate(6))+","+str$(populate(7))+","+str$(populate(8))+","+str$(populate(9))+","+str$(populate(10)):popcnt=1
next y
popcnt=popcnt-1
if popcnt=1 then write string 1,"data "+str$(populate(1))
if popcnt=2 then write string 1,"data "+str$(populate(1))+","+str$(populate(2))
if popcnt=3 then write string 1,"data "+str$(populate(1))+","+str$(populate(2))+","+str$(populate(3))
if popcnt=4 then write string 1,"data "+str$(populate(1))+","+str$(populate(2))+","+str$(populate(3))+","+str$(populate(4))
if popcnt=5 then write string 1,"data "+str$(populate(1))+","+str$(populate(2))+","+str$(populate(3))+","+str$(populate(4))+","+str$(populate(5))
if popcnt=6 then write string 1,"data "+str$(populate(1))+","+str$(populate(2))+","+str$(populate(3))+","+str$(populate(4))+","+str$(populate(5))+","+str$(populate(6))
if popcnt=7 then write string 1,"data "+str$(populate(1))+","+str$(populate(2))+","+str$(populate(3))+","+str$(populate(4))+","+str$(populate(5))+","+str$(populate(6))+","+str$(populate(7))
if popcnt=8 then write string 1,"data "+str$(populate(1))+","+str$(populate(2))+","+str$(populate(3))+","+str$(populate(4))+","+str$(populate(5))+","+str$(populate(6))+","+str$(populate(7))+","+str$(populate(8))
if popcnt=9 then write string 1,"data "+str$(populate(1))+","+str$(populate(2))+","+str$(populate(3))+","+str$(populate(4))+","+str$(populate(5))+","+str$(populate(6))+","+str$(populate(7))+","+str$(populate(8))+","+str$(populate(9))
write string 1,"`[End data statements]"
close file 1
endfunction
function distance#(px#,py#,pz#,tpx#,tpy#,tpz#)
vecx# = px# - tpx#
vecy# = py# - tpy#
vecz# = pz# - tpz#
vecx# = vecx#*vecx#
vecy# = vecy#*vecy#
vecz# = vecz#*vecz#
dist# = sqrt(vecx#+vecy#+vecz#)
endfunction dist#
function findvalue1#(cm$,cm2$,tok$)
a$=first token$(cm$,tok$)
if a$=cm2$ then goto processtoken1
repeat
a$=next token$(tok$)
if a$=cm2$ then goto processtoken1
until a$=""
processtoken1:
val$=next token$(tok$)
val#=val(val$)
endfunction val#
function findvalue2#(cm$,cm2$,tok$)
a$=first token$(cm$,tok$)
if a$=cm2$ then goto processtoken2
repeat
a$=next token$(tok$)
if a$=cm2$ then goto processtoken2
until a$=""
processtoken2:
dumby$=next token$(tok$)
val$=next token$(tok$)
val#=val(val$)
endfunction val#
function findvalue3#(cm$,cm2$,tok$)
a$=first token$(cm$,tok$)
if a$=cm2$ then goto processtoken3
repeat
a$=next token$(tok$)
if a$=cm2$ then goto processtoken3
until a$=""
processtoken3:
for f=1 to 2 step 1
dumby$=next token$(tok$)
next f
val$=next token$(tok$)
val#=val(val$)
endfunction val#
some of the code was only used to create the data statements...
(do not need any media but i suggest you put in in a folder)
the code does this:
-reconstructs a texture from data statements
-creats a vertex animation
-stores both animation and texture into a dbo file
-constructs a new file format to hide the dbo extension and add extra data
-thats it
Hopefuly it helps to understand the memblock usage a tad better...