Whoops, sorry forgot about that snippet. I know it works in DBC, and there should be no reason for it not to work in pro.
Here it is (not by me):
function make_matrix_x(mx#,mz#,tx,tz,textname$,file$)
Rem Create .X objects as alternatives to DB matrices
Rem
Rem - because, for a given degree of detailing( i.e. polygon count)
Rem DB runs faster with objects than matrices
rem
rem Use of objects will need a special "get height" function
rem I have creaetd programs based on this code to create a group of 25 terrain objects
rem with a total polygon count of over 200,000 polygons and successfully loaded them
rem into a DB "game". Worst case frame rate (all polygons in view) was 15 on a
rem 700MHz Athlon with Voodoo 3000 and 128Mb RAM.
rem
rem these objects normals are created to suit DB - if you load them into abything else,
rem they will probably look wierd !
rem
rem you may use this code without charge. Please credit me (Mick Trist) if you
rem pass it on in any way. No support/warranty is offered. I take no responsibility
rem for any loss, direct or consequential, which you may suffer as a result of using
rem this code
rem
rem Thanks are due to Kevin Picone of uwdesign for suggesting this approach in the
rem first place, and also for his help in debugging my first models.
rem
rem I would also like to thank Oblivion and BigDan256 for their help.
rem
rem when loading object, use "scale object n sf#*100,sf#*100,sf#*100"
xw#=mx#/tx : zw#=mz#/tz : rem tile dimensions
twidth#=mx#/(tx-1) : theight#=mz#/(tz-1) : rem texture map tile dimensions
sf#=mx#/50 : rem object scaling factor - to keep object within acceptable limits to DB
rem .bmp file for textures - should be 256*256 for best results
rem put your filename here
rem this bit is up to you - here I load an array of heights
dim norm#(tx,tz,3) : rem
dim lscape(tx+1,tz+1)
for a=1 to tx
for b=1 to tz
lscape(a,b)=get matrix height(1,a-1,b-1)*0.908
next b
next a
rem this is my height array - again you must create this
rem my model is called xt.x
if file exist(file$)=1 then delete file file$
open to write 1,file$
rem start "static" .x file output
write string 1,"xof 0302txt 0032"
write string 1,"Header {"
write string 1," 1;"
write string 1," 0;"
write string 1," 1;"
write string 1,"}"
write string 1,"Frame mesh1 {"
rem this transform is probably redundant
write string 1," FrameTransformMatrix {"
write string 1,"1.0,0.0,0.0,0.0,"
write string 1,"0.0,1.0,0.0,0.0,"
write string 1,"0.0,0.0,1.0,0.0,"
write string 1,"0.0,0.0,0.0,1.0;;"
write string 1,"}"
write string 1,"Mesh mesh1 {"
points=(tx)*(tz)
l$=str$(points)+";"
write string 1,l$
rem output vertex coordinates for our matrix
for z=0 to tz-1
for x=0 to tx-1
th#=lscape(x+1,z+1)/sf#
rem we multiply by 0.999 to ensure that the value is formatted as a real number
l$=str$(0.999*x*xw#/sf#)+";"+str$(th#*0.999)+";"+str$(0.999*z*zw#/sf#)+";"
if x=tx-1 and z=tz-1 then l$=l$+";" else l$=l$+","
write string 1,l$
next x
next z
l$=""
write string 1,l$
faces=(tx-1)*(tz-1)*2
l$=str$(faces)+";"
rem output the face coordinates for each triangle
write string 1,l$
for z=0 to tz-2
for x=0 to tx-2
l$="3;"+str$(x+tx*z)+","+str$(x+tx*(z+1))+","+str$(x+tx*(z+1)+1)+";,"
write string 1,l$
l$="3;"+str$(x+1+tx*z)+","+str$(x+tx*z)+","+str$(x+tx*(z+1)+1)+";"
if x=tx-2 and z=tz-2 then l$=l$+";" else l$=l$+","
write string 1,l$
next x
next z
l$=""
write string 1,l$
write string 1,"MeshMaterialList {"
write string 1,"1;"
l$=str$(faces)+";"
write string 1,l$
l$="0,"
for f=1 to faces-1
write string 1,l$
next f
write string 1,"0;;"
rem I don't understand much about this bit - I've copied data from models made in Bryce
rem - seems to work OK
write string 1,"Material {"
write string 1,"0.75;0.75;1.0;1.0;;"
write string 1,"8.0;"
write string 1,"0.75;0.75;0.75;;"
write string 1,"0.23;0.23;0.23;;"
write string 1,"TextureFilename {"
write string 1,chr$(34)+ textname$ + chr$(34)+";" : rem put your texture name here
write string 1,"}"
write string 1,"}"
write string 1,"}"
write string 1,"MeshNormals {"
l$=str$(0)+";"
write string 1,l$
rem create_terrain_normals - this seems to work well for matrices and .x models
gosub smooth_matrix
rem write out normals
for z=0 to tz-1
for x=0 to tx-1
l$=str$(norm#(x,z,0))+";"+str$(norm#(x,z,1))+";"+str$(norm#(x,z,2))+";"
if x=tx-1 and z=tz-1 then l$=l$+";" else l$=l$+","
write string 1,l$
next x
next z
l$=str$(faces)+";"
rem output normal coordinates
write string 1,l$
for z=0 to tz-2
for x=0 to tx-2
l$="3;"+str$(x+tx*z)+","+str$(x+tx*(z+1))+","+str$(x+1+tx*z)+";,"
write string 1,l$
l$="3;"+str$(x+1+tx*z)+","+str$(x+tx*(z+1))+","+str$(x+tx*(z+1)+1)+";"
if x=tx-2 and z=tz-2 then l$=l$+";" else l$=l$+","
write string 1,l$
next x
next z
write string 1,"}"
write string 1,"MeshTextureCoords {"
l$=str$(points)+";"
write string 1,l$
rem output simple texture mapping - using 100% of texture area
for z=0 to tz-1
for x=0 to tx-1
tcx#=(x-1)*twidth#/mx# : tcz#=(z-1)*theight#/mz#
l$=str$(tcx#)+";"+str$(tcz#)+";"
if x=tx-1 and z=tz-1 then l$=l$+";"
write string 1,l$
next x
next z
write string 1,"}"
write string 1,"}"
write string 1,"}"
close file 1
exitfunction
rem We're done!
smooth_matrix:
rfact#=2.5*xw#
for z=0 to tx-1
for x=0 to tz-1
rem Get matrix heights
h8#=lscape(x,z+1)
h4#=lscape(x+1,z)
h#=lscape(x,z)
h2#=lscape(x+1,z+1)
rem Calculate projected angle X using heights
x1#=(x-1)*rfact# : y1#=h#
x2#=(x+0)*rfact# : y2#=h4#
dx#=x2#-x1#
dy#=y2#-y1#
ax#=atanfull(dx#,dy#)
ax#=wrapvalue(90-ax#)
rem Calculate projected angle Z using heights
z1#=(z-1)*rfact# : y1#=h2#
z2#=(z+0)*rfact# : y2#=h8#
dz#=z2#-z1#
dy#=y2#-y1#
az#=atanfull(dz#,dy#)
az#=wrapvalue(90-az#)
rem Make normal from projected angle
nx#=sin(ax#)
ny#=cos(ax#)
nz#=sin(az#)
rem Setting matrix normal for smoothness
rem this algorithm seems to suit DB, but not other engines !!
norm#(x,z,0)=nx# : norm#(x,z,1)=ny#/15 : norm#(x,z,2)=nz#
next x
next z
return
endfunction
Yo quiero ser anarquia