Atomic Destruction Group - RFront Help

RFRONT - motion editor for DarkBasic

(C) Dmitriy Korabelnikov 2004

This help is incomplete (as editor itself) but full functional. Analyzing some information about 3D I thought about what hell we have with 2D images in the end of 80s. (We still have it) Remember Microsoft Basic (gwbasic, Quick Basic) with many stupid "graphics modes" such as SCREEN 1, SCREEN 2,... Most of them were CGA and EGA modes, but who cares now. No double buffering, no way to save and load pictures, no sprites, nothing. 2D programmers were so cool that time, and 2D qwest games were so interesting. Now there are many standard formats of 2D images and many ways and libraries to load them. I just imagine: what if our "super cool and modern" days of 3D is the same CGA era, but in 3D? Maybe .X format of 3D files is a kind of lame raw .BMP format, only in 3D? And so, I understood all 3D.

Warning: The proposed DBA source code works only in DarkBasic Classic 1.13 (with memblock and DLL support) DarkBasic Pro has other internal format of mesh and I found some bugs in CHANGE MESH command of DBPro (for instance texture disappears after CHANGE MESH) Please test the latest versions of DBPro compiler. But anyway, X files created by RFront can be loaded to DBPro.

1] Select a model to animate using mouse. Do not select *_m1.x ... *_m4.x files. This files are output files and can not be edited once again. Press Enter or F5 to load model.

2] Now you can see something like this. You can rotate camera around model using Del, End. Three transparent blue planes can be moved using arrow keys and PgUp, PgDn. They can be used to find coordinates in 3D. First 3 values from the left side are coordinates of planes intersection.

3] Press F7 to enter preset mode. Now you can adjust skeleton. Click on green cubes and move them using buttons 1-6. If you are not sure, that cube is at the good place, simply rotate camera using Del, End.

4] Now you must have something like this.

5] Using Up and Down keys move horisontal plane slightly under hands and mark position using F2. Now move horisontal plane slightly above hands and mark position using F3. Save final skeleton by F1. Go back to animation mode by F7.

6] Now click on any rotating point of model. For example, on shoulder. Rotate using 1-6 keys.

7] Now click on other rotating point of model. Make any form you want. Don't screw too much. If you are mistaken, reload model by F5.

8] Suppose, you complete a desired pose. Now you can save this pose in one of 4 slots by F1-F4. For example for this model jenny.x resulting files can be jenny_m1.x, jenny_m2.x, jenny_m3.x, jenny_m4.x
Warning! There is no prompt to overwrite file. Rename and backup files using Total Commander. Now you can edit new pose by F5 or load another model by F6.

9] See example twoants.dba for some info how to use poses for animation. First of all, you must include next functions to your code:

Universal loader (See _system.dba). The main purpose of this loader is to make a runtime message WHAT IN THE HELL IS A NAME of "file not found". You can disable file check if you create program in "make final mode" using check variable.
function ld(fi$,n,m$)
f$=rootdir$(0)+fi$
check=(m$>"a")
t$=lower$(m$)
if check
if file exist(f$)=0 then ink 255,0:print f$;" - no file":sync:wait key:end
endif
if t$="i" then load image f$,n
if t$="m" then load music f$,n
if t$="s" then load sound f$,n
if t$="b" then load bitmap f$,n
if t$="x" then load object f$,n
if t$="e" then load mesh f$,n:
endfunction

Make a smooth animation from poses. This function use linear interpolation, so do not try to rotate hand to 90 degrees. Use more (not 2) poses for complex animation. (see _flip.dba)
` Make an animation mesh set from pose
` from_start,from_end - starting mesh, ending mesh numbers(source)
` new_start - first animation set mesh number (destination)
` parts - number of frames (number of destination meshes)
` Memblocks 1-3 are used for operations
function makeanim(from_start,from_end,new_start,parts)
make memblock from mesh 1,from_start
make memblock from mesh 2,from_start
make memblock from mesh 3,from_end
vert=memblock dword(1,0)
pvert=memblock dword(1,4)
norm=memblock dword(1,8)
pnorm=memblock dword(1,12)
m=new_start
for n=1 to parts
copy memblock 2,1,0,0,get memblock size(2)
p=pvert
for i=1 to vert*3
d#=(memblock float(3,p)-memblock float(2,p))/parts
write memblock float 1,p,memblock float(2,p)+(n*d#):p=p+4
next i
p=pnorm
for i=1 to norm*3
d#=(memblock float(3,p)-memblock float(2,p))/parts
write memblock float 1,p,memblock float(2,p)+(n*d#):p=p+4
next i
make mesh from memblock m,1:inc m
next n
delete memblock 1
delete memblock 2
delete memblock 3
endfunction

Now how it looks in main code.
antmod0.x antmod1.x antmod2.x
Program start (data loading and animation set creating)
#include "_system.dba"
#include "_flip.dba"
sync on
` You must declare this to use ld function (program data directory)
dim rootdir$(0):rootdir$(0)="antsdata/"
` ...
` Lode model texture
ld("ant.bmp",1,"i")
` Load poses, say, as meshes 100,101,102
ld("antmod0.x",100,"e")
ld("antmod1.x",101,"e")
ld("antmod2.x",102,"e")
` Create atimation set as meshes 1 - 16
makeanim(100,101,1,8)
makeanim(101,102,9,8)
` Make animated models
` Now we have two textured cubes of size 1
` They are not looking as running ants yet.
for i=1 to 2
make object cube i,1
` This string is nessssary for some models to move them face forward
rotate object i,0,180,0:fix object pivot i
texture object i,1
next i

Now the key: main loop
do
` ...
` Here we use the same animation for models 1 and 2
` In good program code must be more complex.
` More code examples coming soon.
` Tick is used to make a reasonable 25 FPS animation 
` (remember SYNC RATE 50 at program start)
tick=(tick+1)&0
if tick=0
` Each cycle we change variable fr from 1 to 16 and back from 16 to 1
` (remember we created meshes 1-16 at start)
` (Flip-flop animation)
if fr=1 then dfr=1
if fr=16 then dfr=-1
fr=fr+dfr
` Here we change mesh of animated objects
change mesh 1,0,fr
change mesh 2,0,fr
endif
`...
sync
loop

More source code. The very important part of RFront is a function xsave, which saves meshes in binary .X format. (There is a SAVE MESH command in DarkBasicPro but this function works even better). Look at source in _xsave.dba

More help in progress (I think). Later!

Hosted by uCoz