Lol, what you don't see is light I am having issues getting basic flat normals sorted out.
DBP code
set vector3 1,p2x#-p1x#,p2y#-p1y#,p2z#-p1z#
set vector3 2,p3x#-p1x#,p3y#-p1y#,p3z#-p1z#
cross product vector3 3,1,2
normalize vector3 4,3
nx#=x vector3(4)
ny#=y vector3(4)
nz#=z vector3(4)
what I have in AppGameKit so far...but not getting desirable results, and I have set the normalize flag on/off in the "normals" attribute, also tried different order of vertices in the subtraction code :/
`calculate the facet normal
SetVector3(vA,tgt3x#-tgt1x#,tgt3x#-tgt1y#,tgt3z#-tgt1z#)
SetVector3(vB,tgt2x#-tgt1x#,tgt2y#-tgt1y#,tgt2z#-tgt1z#)
GetVector3Cross(vcC,vA,vB)
fnx#=GetVector3X(vcC)
fny#=GetVector3Y(vcC)
fnz#=GetVector3Z(vcC)
length# = GetVector3Length(vcC)
nx#=fnx#/length#
ny#=fny#/length#
nz#=fnz#/length#
(vcC exists due to vC already in use)
Only really posting this just in case someone spots something obvious
Edit: Well I did said obvious...the order was wrong and notably on that first setvector3 line I have actually mistakenly put tgt3x# instead of tgt3y# in the middle parameter!!!!!!
So the full code thus far includes the unneeded indices(so far), facet normals and some height based vertex colours in a basic manner
// Project: test1
// Created: 2020-11-13
// show all errors
SetErrorMode(2)
x#=GetMaxDeviceWidth()
y#=GetmaxDeviceHeight()
SetScreenResolution(x#,y#)
// set window properties
SetWindowTitle( "make tri-list 338 functions" )
SetWindowSize( x#, y#, 0 ,0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
SetWindowPosition(0,0)
`MaximizeWindow()
// set display properties
SetVirtualResolution( x#, y# ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetPrintSize(24)
dim heightcolours[3,4] as integer
heightcolours[1,4]=50
heightcolours[1,1]=255 : heightcolours[1,2]=255 : heightcolours[1,3]=0
heightcolours[2,4]=150
heightcolours[2,1]=0 : heightcolours[2,2]=255 : heightcolours[2,3]=0
heightcolours[3,1]=183 : heightcolours[3,2]=170 : heightcolours[3,3]=125
objid=1
shaderid=1
imageid=1
membid=1
hmapid=2
hmapmemid=2
tgttricount=5000
vA=CreateVector3()
vB=CreateVector3()
vcC=CreateVector3()
vD=CreateVector3()
vE=CreateVector3()
vF=CreateVector3()
`LoadShader(shaderid,"Terrain.vs","Terrain.ps") `this shader for piece of mind memblock mesh change won't wipe the shader like i experienced with dbp
SetGenerateMipmaps(1)
`LoadImage(imageid,"detail.png")
SetGenerateMipmaps(0)
LoadImage(hmapid,"51.png")
CreateMemblockFromImage(hmapmemid,hmapid)
SetCameraPosition(1,0,50,0)
offsetstart=maketrilist338(objid,membid,tgttricount) `create 5k triangle object
layout338(membid,offsetstart,10.5) `lay the mesh out in tiled formation
heights338(membid,hmapmemid,0,0,0.1,offsetstart) `add heights from an image
facet338(membid,offsetstart,vA,vB,vcC,vD,vE,vF)
CreateObjectFromMeshMemblock(objID,membid)
`SetObjectImage(objid,imageid,0)
`SetObjectShader(objid,shaderid) `apply shader before mesh change for the aforementioned piece of mind "proof"
`SetObjectMeshFromMemblock(objid,1,membid) `now the change
SetCameraRotation(1,25,45,0)
SetCameraPosition(1,-50,120,-50)
addvirtualjoystick(1,128/2,y#-(128/2),128)
SetClearColor(128,128,189)
ClearScreen()
SetAmbientColor(0x60, 0x60, 0x60) // Brght ambient = soft shadows
SetSunColor(0x80, 0x80, 0x80)
SetShadowMappingMode( 3 ) // SHadows
SetShadowSmoothing( 1 ) // Random sampling
SetShadowMapSize( 2048, 2048 ) // Shadow map size
SetShadowRange(-1) // Use a short range for better shadows
SetShadowBias( 0.0012 )
setsunactive(1)
SetSkyBoxSunVisible(1)
SetSkyBoxVisible(1)
SetSunDirection(0.5,-1,2.5)
SetObjectLightMode(objid,1)
SetObjectCastShadow(objid, 1)
SetObjectReceiveShadow(objid, 1)
do
if ( GetRawKeyState( 27 ) ) then end
// control the camera
if ( GetRawKeyState( 87 ) ) then MoveCameraLocalZ( 1, 2.5 ) `w
if ( GetRawKeyState( 83 ) ) then MoveCameraLocalZ( 1, -2.5 ) `s
if ( GetRawKeyState( 65 ) ) then MoveCameraLocalX( 1, -2.5 ) `a
if ( GetRawKeyState( 68 ) ) then MoveCameraLocalX( 1, 2.5 ) `d
if ( GetRawKeyState( 81 ) ) then MoveCameraLocalY( 1, -0.5 ) `q
if ( GetRawKeyState( 69 ) ) then MoveCameraLocalY( 1, 0.5 ) `e
if ( GetVirtualJoystickx(1) > 0 ) then MoveCameraLocalx( 1, 0.5 )
if ( GetVirtualJoystickx(1) <0 ) then MoveCameraLocalx( 1, -0.5 )
if ( GetVirtualJoystickY(1) > 0 ) then MoveCameraLocalZ( 1, -0.5 )
if ( GetVirtualJoystickY(1) <0 ) then MoveCameraLocalZ( 1, 0.5 )
if ( GetPointerPressed() )
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
pressed = 1
endif
if ( GetPointerState() = 1 )
fDiffX# = (GetPointerX() - startx#)/4.0
fDiffY# = (GetPointerY() - starty#)/4.0
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endif
Print( ScreenFPS() )
print( "polycount : "+str(GetPolygonsDrawn()))
`print(str(x#)+" x "+str(y#))
`print( "offsetaddyfromfunction " + str(offsetstart))
Sync()
loop
function addindices338(mblkID as integer)
ind=GetMemblockInt(mblkID,4)
offs=GetMemblockInt(mblkID,20)
for t=0 to ind-1
SetMemblockInt(mblkID,offs+(4*t),t)
next t
endfunction
function maketrilist338(objectID as integer,memblockID as integer,tricount as integer)
attribA$="position"
attribB$="normal"
attribC$="uv"
attribD$="color"
`attribE$="indices"
`stringsizes****add2gether=32 ***noteposition should be 8 not 12 but prev existing test objects all had 12( 1 i loaded from dbp memblock mesh, rest where agk built in make primitive commands
aa=12
bb=8
cc=4
dd=8
`ee=8
`componentcount
attribA=3
attribB=3
attribC=2
attribD=4
`attribE=1
`datatypebyteflags
bytflgA=0
bytflgB=0
bytflgC=0
bytflgD=1
`bytflgE=0
numverts=tricount*3
indices=numverts
attribs=4 `****multiply b y 4 byte flags and put with results from "add2gether" notes
vertsz=36
offsetV=(attribs*4)+aa+bb+cc+dd+24
offsetO=offsetV+(numverts*vertsz)
normalize=0
mbsz=(numverts*vertsz)+offsetV+(indices*4)
CreateMemblock(memblockID,mbsz)
setmemblockint(memblockID,0,numverts)
SetMemblockInt(memblockID,4,indices)
SetMemblockInt(memblockID,8,attribs)
SetMemblockInt(memblockID,12,vertsz)
SetMemblockInt(memblockID,16,offsetV)
SetMemblockInt(memblockID,20,offsetO)
`position
`****add2gether this offset and prev highlighted remarks so 24+16+32=72 which is offsetV
attriboffsetA=24
`datatype
SetMemblockByte(memblockID,attriboffsetA,bytflgA)
`componentcount
SetMemblockByte(memblockID,attriboffsetA+1,attribA)
`normalflag
SetMemblockByte(memblockID,attriboffsetA+2,normalize)
`stringsize
SetMemblockByte(memblockID,attriboffsetA+3,aa)
`string
SetMemblockString(memblockID,attriboffsetA+4,attribA$)
`normals
attriboffsetB=attriboffsetA+4+aa
`datatype
SetMemblockByte(memblockID,attriboffsetB,bytflgB)
`componentcount
SetMemblockByte(memblockID,attriboffsetB+1,attribB)
`normalflag
SetMemblockByte(memblockID,attriboffsetB+2,0)
`stringsize
SetMemblockByte(memblockID,attriboffsetB+3,bb)
`string
SetMemblockString(memblockID,attriboffsetB+4,attribB$)
`uvs
attriboffsetC=attriboffsetB+4+bb
`datatype
SetMemblockByte(memblockID,attriboffsetC,bytflgC)
`componentcount
SetMemblockByte(memblockID,attriboffsetC+1,attribC)
`normalflag
SetMemblockByte(memblockID,attriboffsetC+2,normalize)
`stringsize
SetMemblockByte(memblockID,attriboffsetC+3,cc)
`string
SetMemblockString(memblockID,attriboffsetC+4,attribC$)
`color
attriboffsetD=attriboffsetC+4+cc
`datatype
SetMemblockByte(memblockID,attriboffsetD,bytflgD)
`componentcount
SetMemblockByte(memblockID,attriboffsetD+1,attribD)
`normalflag
SetMemblockByte(memblockID,attriboffsetD+2,1)
`stringsize
SetMemblockByte(memblockID,attriboffsetD+3,dd)
`string
SetMemblockString(memblockID,attriboffsetD+4,attribD$)
addindices338(memblockID)
`CreateObjectFromMeshMemblock(objectID,memblockID)
endfunction offsetV
function layout338(memblocknum as integer,offsetstart as integer,tilesize# as float)
`TILE LAYOUT **(dbp)**
`points 1 through 4 are height points ; p1, p2, p3, p4
`other characters show layout of triangles, Tri1 on left, Tri2 on right
`ROTATION of vertices(v1,v2,v3) are CW SO v1=p1,v2=p3,v3=p4 FOR Tri1 AND v1=p1,v2=p4,v3=p2 FOR Tri2
`3///4
`///|/
`//|//
`/|///
`1///2
`UV coord layout
`v1p1=0u;1v
`v2p3=0u;0v
`v3p4=1u;0v
`TILE LAYOUT **(agk)**
`points 1 through 4 are height points ; p1, p2, p3, p4
`other characters show layout of triangles, Tri1 on left, Tri2 on right
`ROTATION of vertices(v1,v2,v3) are CCW SO*********** v1=p4,v2=p3,v3=p1 FOR Tri1 AND v1=p2,v2=p4,v3=p1 FOR Tri2
`3///4
`///|/
`//|//
`/|///
`1///2
`UV coord layout
`v1p4=1u;0v
`v2p3=0u;0v
`v3p1=0u;1v
`variables
vc=GetMemblockInt(memblocknum,0) `vertcount
pc=vc/3 `polycount
ttltls=pc/2 `tilecount
clmsnrows=sqrt(ttltls) `columns/rows tile count
vsz=GetMemblockInt(memblocknum,12) `vertsize in bytes
tloffsz=6*vsz `tile offset size
tilenum=0
`cycle
for xd=1 to clmsnrows
for zd=1 to clmsnrows
`outer dimensions
btm#=(xd-1)*tilesize#
lft#=(zd-1)*tilesize#
top#=xd*tilesize#
rgt#=zd*tilesize#
`starting offset for this tile
thisoffsetstart=offsetstart+(tloffsz*tilenum)
`tri1
`v1p1(top right)
`position x then y then z
SetMemblockFloat(memblocknum,thisoffsetstart,rgt#)
SetMemblockFloat(memblocknum,thisoffsetstart+4,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+8,top#)
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+12,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+16,1.0)
SetMemblockFloat(memblocknum,thisoffsetstart+20,0.0)
`uv
SetMemblockFloat(memblocknum,thisoffsetstart+24,1.0)
SetMemblockFloat(memblocknum,thisoffsetstart+28,0.0)
`diffuse
SetMemblockbyte(memblocknum,thisoffsetstart+32,255)
SetMemblockbyte(memblocknum,thisoffsetstart+32+1,0)
SetMemblockbyte(memblocknum,thisoffsetstart+32+2,0)
SetMemblockbyte(memblocknum,thisoffsetstart+32+3,255)
`v2p3(top left)
`position x then y then z
SetMemblockFloat(memblocknum,thisoffsetstart+vsz,lft#)
SetMemblockFloat(memblocknum,thisoffsetstart+vsz+4,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+vsz+8,top#)
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+vsz+12,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+vsz+16,1.0)
SetMemblockFloat(memblocknum,thisoffsetstart+vsz+20,0.0)
`uv
SetMemblockFloat(memblocknum,thisoffsetstart+vsz+24,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+vsz+28,0.0)
`diffuse
SetMemblockByte(memblocknum,thisoffsetstart+vsz+32,0)
SetMemblockByte(memblocknum,thisoffsetstart+vsz+32+1,255)
SetMemblockByte(memblocknum,thisoffsetstart+vsz+32+2,0)
SetMemblockByte(memblocknum,thisoffsetstart+vsz+32+3,255)
`v3p4(bottom left)
`position x then y then z
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2),lft#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+4,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+8,btm#)
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+12,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+16,1.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+20,0.0)
`uv
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+24,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+28,1.0)
`diffuse
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*2)+32,0)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*2)+32+1,0)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*2)+32+2,255)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*2)+32+3,255)
`tri2
`v1p1(bottom right)
`position x then y then z
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3),rgt#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+4,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+8,btm#)
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+12,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+16,1.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+20,0.0)
`uv
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+24,1.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+28,1.0)
`diffuse
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*3)+32,255)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*3)+32+1,255)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*3)+32+2,255)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*3)+32+3,255)
`v2p4(top right)
`position x then y then z
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4),rgt#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+4,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+8,top#)
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+12,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+16,1.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+20,0.0)
`uv
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+24,1.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+28,0.0)
`diffuse
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*4)+32,255)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*4)+32+1,255)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*4)+32+2,255)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*4)+32+3,255)
`v3p2(bottom left)
`position x then y then z
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5),lft#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+4,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+8,btm#)
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+12,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+16,1.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+20,0.0)
`uv
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+24,0.0)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+28,1.0)
`diffuse
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*5)+32,255)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*5)+32+1,255)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*5)+32+2,255)
SetMemblockByte(memblocknum,thisoffsetstart+(vsz*5)+32+3,255)
`do last so can start at 0 - maintains a counter of tiles processed
tilenum=tilenum+1
next zd
next xd
endfunction
function heights338(objmeshmemid as integer,hgtmemid as integer,xstart as integer,ystart as integer,hgtscale# as float,offsetpos)
`"SIZE" PARAMETER *** note that the hmap will not be an image but a membock eventually so this objects hmap must be considered as section from a larger hmap which is why xstart and ystart are part of the function - also the larger memblock hmap can be rectangular, only the mesh must be square
`calculate the max number of point heights from vertexcount detailed in memblock
`ie sqrt(((verts/3)/2))+1 extra row ; ie 5k tri layout is verts/3=5k , 5000/2=2500 , sqrt(2500)=50 , 50+1=51 point heights in both x znd z directions
`get dimensions of hmap
`check if maxpointheights in x and z direction from start points exceed the limits of the hmap
`if they do leave them at 0.0 when they go beyond the memblock hmap limits
vc=GetMemblockInt(objmeshmemid,0)
pc=vc/3 `polycount
ttltls=pc/2 `tilecount
clmsnrows=sqrt(ttltls) `columns/rows tile count
vsz=GetMemblockInt(objmeshmemid,12) `vertsize in bytes
tloffsz=6*vsz `tile offset size
tilenum=0
pnthghtlim=clmsnrows+1
pnthghtx=GetMemblockInt(hgtmemid,0)
pnthghty=GetMemblockInt(hgtmemid,4)
failx=0
faily=0
pxlX=0
pxly=0
hgtposx=0
hgtposy=0
shift=1
`this is for aforementioned size parameter test
if xstart+pnthghtlim>pnthghtx then failx=(xstart+pnthghtlim)-pnthghtx
if ystart+pnthghtlim>pnthghty then faily=(ystart+pnthghtlim)-pnthghty
`cycle
for xd=1 to clmsnrows
hgtposy=ystart+(pnthghtlim-pxly)
pxly=pxly+1
shift=shift-1
for zd=1 to clmsnrows
pxlX=pxlX+1
if pxlX>clmsnrows then pxlX=1 `change 0 to 1 for no seams but bad hieght matches
hgtposx=xstart+pxlX+shift
memposBtmLft=(hgtposy*clmsnrows)+hgtposx
header=12
memposTopLft=memposBtmLft-pnthghtlim `change pnthghtlim to clmsnrows for no seams but bad hieght matches
memposTopRgt=memposBtmLft-pnthghtlim+1 `change pnthghtlim to clmsnrows for no seams but bad hieght matches
memposBtmRgt=memposBtmLft+1
memposBtmLft=(memposBtmLft*4)-4+header `+(51*4)
memposBtmRgt=(memposBtmRgt*4)-4+header `+(51*4)
memposTopLft=(memposTopLft*4)-4+header
memposTopRgt=(memposTopRgt*4)-4+header
hA=GetMemblockByte(hgtmemid,memposTopLft)
hB=GetMemblockByte(hgtmemid,memposTopRgt)
hC=GetMemblockByte(hgtmemid,memposBtmLft)
hD=GetMemblockByte(hgtmemid,memposBtmRgt)
tl#=hgtscale#*hA
tr#=hgtscale#*hB
bl#=hgtscale#*hC
br#=hgtscale#*hD
`starting offset for this tile
thisoffsetstart=offsetpos+(tloffsz*tilenum)
`tri1
`v1p1(top right)
`position x then y then z
SetMemblockFloat(objmeshmemid,thisoffsetstart+4,tr#)
`diffuse
if hB=<heightcolours[1,4]
r=heightcolours[1,1]
g=heightcolours[1,2]
b=heightcolours[1,3]
else
if hB<heightcolours[2,4] and hB>heightcolours[1,4]
r=heightcolours[2,1]
g=heightcolours[2,2]
b=heightcolours[2,3]
else
if hb=>heightcolours[2,4]
r=heightcolours[3,1]
g=heightcolours[3,2]
b=heightcolours[3,3]
endif
endif
endif
SetMemblockbyte(objmeshmemid,thisoffsetstart+32,r)
SetMemblockbyte(objmeshmemid,thisoffsetstart+32+1,g)
SetMemblockbyte(objmeshmemid,thisoffsetstart+32+2,b)
SetMemblockbyte(objmeshmemid,thisoffsetstart+32+3,255)
`v2p3(top left)
`position x then y then z
SetMemblockFloat(objmeshmemid,thisoffsetstart+vsz+4,tl#)
if hA=<heightcolours[1,4]
r=heightcolours[1,1]
g=heightcolours[1,2]
b=heightcolours[1,3]
else
if hA<heightcolours[2,4] and hA>heightcolours[1,4]
r=heightcolours[2,1]
g=heightcolours[2,2]
b=heightcolours[2,3]
else
if hA=>heightcolours[2,4]
r=heightcolours[3,1]
g=heightcolours[3,2]
b=heightcolours[3,3]
endif
endif
endif
`diffuse
SetMemblockByte(objmeshmemid,thisoffsetstart+vsz+32,r)
SetMemblockByte(objmeshmemid,thisoffsetstart+vsz+32+1,g)
SetMemblockByte(objmeshmemid,thisoffsetstart+vsz+32+2,b)
SetMemblockByte(objmeshmemid,thisoffsetstart+vsz+32+3,255)
`v3p4(btm left)
`position x then y then z
SetMemblockFloat(objmeshmemid,thisoffsetstart+(vsz*2)+4,bl#)
if hC=<heightcolours[1,4]
r=heightcolours[1,1]
g=heightcolours[1,2]
b=heightcolours[1,3]
else
if hC<heightcolours[2,4] and hC>heightcolours[1,4]
r=heightcolours[2,1]
g=heightcolours[2,2]
b=heightcolours[2,3]
else
if hC=>heightcolours[2,4]
r=heightcolours[3,1]
g=heightcolours[3,2]
b=heightcolours[3,3]
endif
endif
endif
`diffuse
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*2)+32,r)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*2)+32+1,g)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*2)+32+2,b)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*2)+32+3,255)
`tri2
`v1p1(bottom rgt)
`position x then y then z
SetMemblockFloat(objmeshmemid,thisoffsetstart+(vsz*3)+4,br#)
if hD=<heightcolours[1,4]
r=heightcolours[1,1]
g=heightcolours[1,2]
b=heightcolours[1,3]
else
if hD<heightcolours[2,4] and hD>heightcolours[1,4]
r=heightcolours[2,1]
g=heightcolours[2,2]
b=heightcolours[2,3]
else
if hD=>heightcolours[2,4]
r=heightcolours[3,1]
g=heightcolours[3,2]
b=heightcolours[3,3]
endif
endif
endif
`diffuse
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*3)+32,r)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*3)+32+1,g)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*3)+32+2,b)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*3)+32+3,255)
`v2p4(top right)
`position x then y then z
SetMemblockFloat(objmeshmemid,thisoffsetstart+(vsz*4)+4,tr#)
if hB=<heightcolours[1,4]
r=heightcolours[1,1]
g=heightcolours[1,2]
b=heightcolours[1,3]
else
if hB<heightcolours[2,4] and hB>heightcolours[1,4]
r=heightcolours[2,1]
g=heightcolours[2,2]
b=heightcolours[2,3]
else
if hb=>heightcolours[2,4]
r=heightcolours[3,1]
g=heightcolours[3,2]
b=heightcolours[3,3]
endif
endif
endif
`diffuse
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*4)+32,r)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*4)+32+1,g)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*4)+32+2,b)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*4)+32+3,255)
`v3p2(bottom left)
`position x then y then z
SetMemblockFloat(objmeshmemid,thisoffsetstart+(vsz*5)+4,bl#)
if hC=<heightcolours[1,4]
r=heightcolours[1,1]
g=heightcolours[1,2]
b=heightcolours[1,3]
else
if hC<heightcolours[2,4] and hC>heightcolours[1,4]
r=heightcolours[2,1]
g=heightcolours[2,2]
b=heightcolours[2,3]
else
if hC=>heightcolours[2,4]
r=heightcolours[3,1]
g=heightcolours[3,2]
b=heightcolours[3,3]
endif
endif
endif
`diffuse
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*5)+32,r)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*5)+32+1,g)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*5)+32+2,b)
SetMemblockByte(objmeshmemid,thisoffsetstart+(vsz*5)+32+3,255)
`do last so can start at 0 - maintains a counter of tiles processed
tilenum=tilenum+1
`to slow down for debugging
`sync()
`sleep(1)
next zd
next xd
endfunction
function facet338(memblocknum as integer,offsetstart as integer,vA,vB,vcC,vD,vE,vF)
`variables
vc=GetMemblockInt(memblocknum,0) `vertcount
pc=vc/3 `polycount
ttltls=pc/2 `tilecount
clmsnrows=sqrt(ttltls) `columns/rows tile count
vsz=GetMemblockInt(memblocknum,12) `vertsize in bytes
tloffsz=6*vsz `tile offset size
tilenum=0
`cycle
for xd=1 to clmsnrows
for zd=1 to clmsnrows
`starting offset for this tile
thisoffsetstart=offsetstart+(tloffsz*tilenum)
`tri1
`v1p1(top right)
`position x then y then z
tgt1x#=GetMemblockFloat(memblocknum,thisoffsetstart)
tgt1y#=GetMemblockFloat(memblocknum,thisoffsetstart+4)
tgt1z#=GetMemblockFloat(memblocknum,thisoffsetstart+8)
`v2p3(top left)
`position x then y then z
tgt2x#=GetMemblockFloat(memblocknum,thisoffsetstart+vsz)
tgt2y#=GetMemblockFloat(memblocknum,thisoffsetstart+vsz+4)
tgt2z#=GetMemblockFloat(memblocknum,thisoffsetstart+vsz+8)
`v3p4(bottom left)
`position x then y then z
tgt3x#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2))
tgt3y#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+4)
tgt3z#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+8)
`calculate the facet normal
SetVector3(vB,tgt1x#-tgt2x#,tgt1y#-tgt2y#,tgt1z#-tgt2z#)
SetVector3(vA,tgt3x#-tgt2x#,tgt3y#-tgt2y#,tgt3z#-tgt2z#)
GetVector3Cross(vcC,vA,vB)
fnx#=GetVector3X(vcC)
fny#=GetVector3Y(vcC)
fnz#=GetVector3Z(vcC)
length# = GetVector3Length(vcC)
nx#=fnx#/length#
ny#=fny#/length#
nz#=fnz#/length#
`write the norms
`v1p1(top right)
`position x then y then z
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+12,nx#)
SetMemblockFloat(memblocknum,thisoffsetstart+16,ny#)
SetMemblockFloat(memblocknum,thisoffsetstart+20,nz#)
`v2p3(top left)
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+vsz+12,nx#)
SetMemblockFloat(memblocknum,thisoffsetstart+vsz+16,ny#)
SetMemblockFloat(memblocknum,thisoffsetstart+vsz+20,nz#)
`v3p4(bottom left)
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+12,nx#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+16,ny#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*2)+20,nz#)
`tri2
`v1p1(bottom right)
`position x then y then z
tgt1x#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3))
tgt1y#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+4)
tgt1z#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+8)
`v2p4(top right)
`position x then y then z
tgt2x#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4))
tgt2y#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+4)
tgt2z#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+8)
`v3p2(bottom left)
`position x then y then z
tgt3x#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5))
tgt3y#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+4)
tgt3z#=GetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+8)
`calculate the facet normal
SetVector3(vE,tgt1x#-tgt2x#,tgt1y#-tgt2y#,tgt1z#-tgt2z#)
SetVector3(vD,tgt3x#-tgt2x#,tgt3y#-tgt2y#,tgt3z#-tgt2z#)
GetVector3Cross(vF,vD,vE)
fnx#=GetVector3X(vF)
fny#=GetVector3Y(vF)
fnz#=GetVector3Z(vF)
length# = GetVector3Length(vF)
nx#=fnx#/length#
ny#=fny#/length#
nz#=fnz#/length#
`write the norms
`v1p1(bottom right)
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+12,nx#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+16,ny#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*3)+20,nz#)
`v2p4(top right)
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+12,nx#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+16,ny#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*4)+20,nz#)
`v3p2(bottom left)
`NORM xyz
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+12,nx#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+16,ny#)
SetMemblockFloat(memblocknum,thisoffsetstart+(vsz*5)+20,nz#)
`do last so can start at 0 - maintains a counter of tiles processed
tilenum=tilenum+1
next zd
next xd
endfunction
function smooth338()
endfunction
function uvtanbinorms()
endfunction
Win 7 Pro 64 bit SP1, AMD A4-5300 APU 3.4GHz, 8GB DDR3, NVidia GeForce GTX 750 1GB GDDR5, ASUS A55BM-E