Posted: 19th Apr 2021 23:32
oops!! we post at the same time !
Posted: 20th Apr 2021 1:07
ok i tried the save .x with these mods

+ Code Snippet
function saveMesh(id as integer,filename as string )
t as integer:mesh as integer:n as integer: s as integer:verts as integer:i as integer
x# as float:y# as float:z# as float:end$ as string:b$ as string:name as string
nx# as float:ny# as float:nz# as float:u# as float:v# as float


name = "raw:"+GetReadPath()+"media/"+filename
print("Creating : "+name)
//OpenToWrite ( 1, "raw:"+GetReadPath()+"media\20cajas.x", 0 )
OpenToWrite(1,name,0)
writeline( 1,"xof 0303txt 0032")
writeline(1,"")  `space
writeline(1,"#Save boxes to .x by Chafari ")
writeline(1,"#Made in AGK2 December 2018")
writeline(1,"")  `space
//for t= 1 to 370      `No hay tantos objetos, pero hacemos un rastreo largo por ver si el objeto existe
t=id
	n=0
	s=0
  if GetObjectExists(t)
		mesh = CreateMemblockFromObjectMesh(t,1)
		`number of vertex
		verts= GetMemblockInt( mesh, 0 )

		`VERTICES
		writeline(1,"Mesh {")
		writeline(1, str(verts) + ";")
		 for i= 0 to verts-1
			 x#=GetMeshMemblockVertexX(mesh,i)
			 y#=GetMeshMemblockVertexy(mesh,i)
			 z#=GetMeshMemblockVertexz(mesh,i)
			
			`vertex
			 if i < verts - 1 then end$ = ";," else end$ = ";;"
			 writeline( 1, str(x#, 6) + ";" + str(y#, 6) + ";" + str(z#, 6) + end$)
		 next i
		 
		`FACES 
		writeline(1,"12;") 
		for i= 0 to 18

			inc s
			if s=3
			   writeline(1,str(3)+";"+str(n+2)+","+str(n+1)+","+str(n)+";,")
				if i<16 then b$=";," else b$=";;"
			   writeline(1,str(3)+";"+str(n+3)+","+str(n+1)+","+str(n+2)+b$)
			   n=n+1
			   s=0
			   n=n+3
			endif
		next
		n=0 `reset n
		`----------------------------------------------------------------------------
		`NORMALES
		writeline(1,"MeshNormals {")
		writeline(1, str(verts) + ";")
		 for i= 0 to verts-1
			 nx#=GetMeshMemblockVertexNormalX(mesh,i)
			 ny#=GetMeshMemblockVertexNormaly(mesh,i)
			 nz#=GetMeshMemblockVertexNormalz(mesh,i)
			
			`Normals
			 if i < verts - 1 then end$ = ";," else end$ = ";;"
			 writeline( 1, str(nx#, 6) + ";" + str(ny#, 6) + ";" + str(nz#, 6) + end$)
		 next i
		 
		writeline(1,"12;") 
		for i= 0 to 18
			
			inc s
			if s=3
			   writeline(1,str(3)+";"+str(n+2)+","+str(n+1)+","+str(n)+";,")
			   if i<16 then b$=";," else b$=";;"
			   writeline(1,str(3)+";"+str(n+3)+","+str(n+1)+","+str(n+2)+b$)
			   n=n+1
			   s=0
			   n=n+3
			endif
		next
		writeline(1,"}")


		`COORDENADAS DE TEXTURA
		writeline(1,"MeshTextureCoords {")
		writeline(1, str(verts) + ";")
		 for i= 0 to verts-1
			 U#=GetMeshMemblockVertexU(mesh,i)
			 V#=GetMeshMemblockVertexV(mesh,i)
			`UV
			 if i < verts - 1 then end$ = ";," else end$ = ";;"
			 writeline( 1, str(U#, 6) + ";" + str(V#, 6) + end$)
		 next
		 
		writeline(1,"}")

		 writeline(1," MeshMaterialList { ")
		 writeline(1,"    1;")
		 writeline(1,"    1;")
		 writeline(1,"    0;;")
		 writeline(1,"    Material Material {")
		 writeline(1,"    0.640000; 0.640000; 0.640000; 1.000000;;")
		 writeline(1,"    96.078431;")
		 writeline(1,"    0.500000; 0.500000; 0.500000;;")
		 writeline(1,"    0.000000; 0.000000; 0.000000;;")
		 //writeline(1,"    TextureFilename {" + chr(34)+ str(t)+".png" + chr(34)+ ";}")  `different texture per limb...  1.png,  2.png  3.png   etc etc.
		            `to import all meshes (limbs) in AGK , as AGK will cosider all meshes with same texture as the same mesh (limb)
		 writeline(1,"    TextureFilename {" + chr(34)+"test.png" + chr(34)+ ";}")  `saving a texture for the whole object
		 writeline(1,"       }")
		 writeline(1,"    }")
		 writeline(1,"}")
		 writeline(1,"//------------------new mesh -------------------------")

		   DeleteMemblock(t)
   endif
// next
   CloseFile ( 1 )

endfunction


and get this with the (single plane) mesh im exporting
Posted: 20th Apr 2021 1:16
When ideal when i use the obj it exports and apply a texture it looks like

Ive attached the grid.obj if that helps

the tledit program allows for changing the vertices and the example here is if vertices havent been changed

ps the final .x is also allot larger than the final .obj which includes texturing (but the .obj creator does miss saving allot of data but does load straight into agk after)

and if your after fullscreen mode SetWindowSize(devWidth#,devHeight#,1) may be used where 1 sets full screen mode on
Posted: 20th Apr 2021 11:48
Hi there .
Ok ....let's go step by step . This is what I was talking about when I said that we have to know what are we going to export. When I use last script .rar I post avove I get lot of boxes in different position.?:- I know aswel that exporting to Obj perhaps could be easier but some other time is like a pain in the neck.
I made some test to your object .Obj and realised that most of them has wrong normals....that what I mean a pain on the neck . I corrected some of them| to compare results .
When we write .Obj we write vertex , vertex texture , vertex normals etc.

Then when we write the faces we do something like:
2/1/1 3/2/2 4/3/3


It can't be
1/1/1 2/2/2 3/3/3


when we create a script to export Obj we have to be careful with this

"


I made some test aswell with your objects bill.obj and stamplarge.obj . This was the resul with the correct and incorrect normals .



Posted: 20th Apr 2021 11:58
seems like it works but is the green a colour youve applied

the code that does it is the buildmodel function
which is really blinks save object code
Posted: 20th Apr 2021 12:01
I had to put a green light to see where the normals fail...even when all is white you can see the fifference ....bear with me !



Edit:

I'm back

Here is the result of the same example with no lights....it doesn't have the green texture either so that it does not interfere with the image . The correct is the left one the other looks too flat ...no shadows or wrong normals

Posted: 20th Apr 2021 12:10
theres 2 buildmodel functions both are different the tledit program has one that works for the mesh land
the other one should be pretty right most of the time but maybe not the normals


thats the normals they were excluded
Posted: 20th Apr 2021 12:15
I try to execute your programs tedit3 and tlEdit5 and I get errors as last updates only work in window 10 ....I'm still using windows Vista ....too old PC . But if I can be any useful, I could convert and correct your objects to .x or .Obj corrected
Posted: 20th Apr 2021 12:20
it may be the plugin that causes you issues dont know but they both use a menu plugin and its kinda weird to use
that would be great any help you can give

The makecar function code should have the normals when recreating the cars
the code for the mesh was cut short and used quads instead of tris
Posted: 20th Apr 2021 12:28
What program do you use to make your objects ?
Posted: 20th Apr 2021 12:30
the models i purchased are kenneys but i use blender
Posted: 20th Apr 2021 12:32
You could use Blender and export to .x and then if you prefer .Obj you could use any converter...This converters use to have good plug-in to export different formats

Edit.

You can instead use this Bengismo solution to correct normals .

+ Code Snippet
function fixobjectnormals(msblk as integer)


if getobjectexists(msblk)=1
if getmemblockexists(50)=1 then deletememblock(50)
CreateMemblockFromObjectMesh(50,msblk,1)
// Start by getting the relevant info
NumVertices = GetMemblockInt( 50, 0)
NumIndices = GetMemblockInt( 50, 4)
NumTriangles = NumIndices/3 
//NumAttributes = GetMemblockInt( msblk, 8) // number if attributes ( should be 3 for a heightmap)
//VertexSize = GetMemblockInt( msblk, 12) // Bytes per vertex (should be 32)
//VertexOffset = GetMemblockInt( msblk, 16 ) // (Normally 60)
IndicesOffset = GetMemblockInt( 50, 20 )

// How to generate surface normals the proper way
//1) Normal vectors must all be zero before start!!
//2) Iterate through the triangles and get the normal on each triangle then ADD that to each of the 3 vertices normal. Other triangles will add to these values if they share indices.
//3) Loop through all the vertices and normalize the normals

// Fill all the vertex normals with 0,0,0
for ind =0 to NumVertices-1
SetMeshMemblockVertexNormal(50, ind, 0 , 0 , 0)
next ind



// loop through all the triangles
Offset = IndicesOffset
for it = 0 to NumTriangles-1

// Get the indices 
inda = GetMemblockInt(50, Offset)
indb = GetMemblockInt(50, Offset+4)
indc = GetMemblockInt(50, Offset+8)

// Get the first vector (P2-P1)
Vx# = GetMeshMemblockVertexX(50,indb) - GetMeshMemblockVertexX(50,inda)
Vy# = GetMeshMemblockVertexY(50,indb) - GetMeshMemblockVertexY(50,inda)
Vz# = GetMeshMemblockVertexZ(50,indb) - GetMeshMemblockVertexZ(50,inda)

// Get the second vector (P3-P1)
Wx# = GetMeshMemblockVertexX(50,indc) - GetMeshMemblockVertexX(50,indb)
Wy# = GetMeshMemblockVertexY(50,indc) - GetMeshMemblockVertexY(50,indb)
Wz# = GetMeshMemblockVertexZ(50,indc) - GetMeshMemblockVertexZ(50,indb)

// Cross product them to get the normal
Nx#=(Vz#*Wy#)-(Vy#*Wz#)
Ny#=(Vx#*Wz#)-(Vz#*Wx#)
Nz#=(Vy#*Wx#)-(Vx#*Wy#)

// add the calculated normal to each of the vertices in this triangle
px# = GetMeshMemblockVertexNormalX(50, inda)
py# = GetMeshMemblockVertexNormalY(50, inda)
pz# = GetMeshMemblockVertexNormalZ(50, inda)
SetMeshMemblockVertexNormal(50, inda, px# + Nx#, py# + Ny#, pz# + Nz#)

px# = GetMeshMemblockVertexNormalX(50, indb)
py# = GetMeshMemblockVertexNormalY(50, indb)
pz# = GetMeshMemblockVertexNormalZ(50, indb)
SetMeshMemblockVertexNormal(50, indb, px# + Nx#, py# + Ny#, pz# + Nz#)

px# = GetMeshMemblockVertexNormalX(50, indc)
py# = GetMeshMemblockVertexNormalY(50, indc)
pz# = GetMeshMemblockVertexNormalZ(50, indc)
SetMeshMemblockVertexNormal(50, indc, px# + Nx#, py# + Ny#, pz# + Nz#)

// Move the offset to the next triangle
Offset = Offset + 12

next it

// Normalise all the vertex normals 
for ind =0 to NumVertices-1
// Get the normal
nx# = GetMeshMemblockVertexNormalX(50, ind)
ny# = GetMeshMemblockVertexNormalY(50, ind)
nz# = GetMeshMemblockVertexNormalZ(50, ind)

// normalise the normal
len# = sqrt((nx#*nx#) + (ny#*ny#) + (nz#*nz#))
nx# = nx#/len#
ny# = ny#/len#
nz# = nz#/len#

// Set the new normal
SetMeshMemblockVertexNormal( 50, ind, nx#, ny#, nz# )
next ind
SetObjectMeshFromMemblock(msblk,1,50)
deletememblock(50)
endif 
endfunction
Posted: 20th Apr 2021 12:34
yeh the prob is i like the way i can export both a track and scenery straight into the game and it works in agk
Posted: 20th Apr 2021 12:39
I know what you mean ! ....I use to do the same ....whe I just start making my Obj exporter I only use vertex a faces to see the mesh ....then I decided to add textures and so on . We post at the same time ...take a look to Bengismo solution to correct normals...you can correct your object on the fly even if they keep wrong normals
Posted: 20th Apr 2021 12:43
at this stage as you seemed to have the .x exporter working i thought that could be a save land option (tledit5)
but i may have jumped the gun
Posted: 20th Apr 2021 12:59
but i may have jumped the gun


Not exactly !... don't give up . Remember the body I made with boxes and moving vertex ? ....when you know where the vertex are ,and what vertex to move , you will be able to write correctly to .x . In Dbpro as commented above you could use any 3D object around the world and export it wihtout knowing nothing more then use and convert to .x. Why was that posible ? ...it was posible because in Dbpro we can split any object to triangles and joing then againg...so when writing to .x you just follow an order 0,1,2 0,1,2 0,1,2 it was like just exporting lot of triangles that at the end form the final object .

In Agk is more o less the same but we can't gess so easily the index data of every vertex....at least in my case . I will be around the forum for any help

Cheers.
Posted: 22nd Apr 2021 10:17
@chafari im wondering if you need the plugins installed in your agkcompiler/plugins directory to compile them altho to run the programs you just need the folder structure ive supplied
Posted: 22nd Apr 2021 12:38
Hi fubarpk ....no matter what i do i always get compilation error . I would really like to be able to help here in this project, but I don't know where the error is .

@chafari im wondering if you need the plugins installed in your agkcompiler/plugins directory to compile


If you know what plugins do I need , and you got them and If you could send them to me, it would be of great help .

These are the errors i get when i try to compile ....
Posted: 22nd Apr 2021 17:38
the plugins needed for tledit5 are in the plugin folder inside
the plugins needed for tedit3 are inside the plugin folder there

to compile for me they need to be in
c;\programfiles(x86)\steam\steamapps\common\app game kit 2\tier 1\compiler\plugins folder
in there respective folders

you may need to go into agk players settings/preferences

there are two plugins one called nuklear and the other called fileexplore
Posted: 22nd Apr 2021 19:35
Ok...I always forget about the dll's....I will test it in two hours when I get home



EDIT. No way !!
I have downloaded last version for clasic 2021.02.10 , instaled correctly ...first of all I made some test opening some of my old programs ...all seem to work correctly with my programs .....then I tried to execute tledit5.agk and this time it gave me the same erros....then I copy dll's fileExplore and Nuklear in tier1 compiler / plugins and this time it said

compilation faild
failed to open file "/plugins/Nuclear/Commands.txt "for reading bla bla
then I realize that inside agk2 /tier 1/compiler /plugins /ExamplePlugin there was a file that was exaltly "Commands.txt" then I copied and paste in both plugin folder "fileExplore" and "Nuklear" . This time when I execute the program I've got more then 10 lines of error ....I tried to delete every thing new in Agk2 compiler folders and when I try to execute any of my programs it says no found compiler I uninstall every thing and start again ....Now all mi programs run again but I'm the same point.....I can't execut tedit3 or tlEdit5. I fill myself like a stupid and I know that it must be me doing something wrong .