Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
2 registered members (Grant, AndrewAMD), 911 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[unpaid]Micro-tutorial of D3D mesh-generation #330404
06/27/10 12:54
06/27/10 12:54
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I give up... I just cant get it together... I hate directX!

Help!!

Can someone please write me a lite-c script to generate
a 4-vertex, 4-triangle, uv-mapped mesh using directx functions?
I just cant get it to go.
Please make the code as verbose as possible, no shortcuts please.
I just intend to teach myself from this, rather than use it in any project.

It is to run in lite-c with only lite-c.h and d3d9.h includes.
It also needs to use the standard D3DVERTEX as found in atypes.h.
Process that needs to be followed(unless flow is impossible):
1>open some entity from mdl-file
2>backup its existing mesh (eng_getmesh?)
3>create a new mesh with D3DXCreateMeshFVF
4>create new vertex buffer using CreateVertexBuffer (if not created by step#3
5>fill VB with a 4-pixel 100x100 'square'
6>create new face/triangle buffer using CreateIndexBuffer(?)(if not created by step#3
7>fill with 4 faces to make 'square' double sided
8>setup uvmapping so back side is mirror-image of front.
9>any other steps required before ent_setskin
10>ent_setmesh to the original entity.

Need more info? I hope not... But ask if you do.




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: [unpaid]Micro-tutorial of D3D mesh-generation [Re: EvilSOB] #330528
06/28/10 06:46
06/28/10 06:46
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
No takers?

C'mon you big bunch of 'girlie-men'. Give it a try.

If it just needs more clarifying, this is what Im trying to achieve.
But it dont display anything, but I dont even know if it is generating
a valid mesh or not. That why I wanted the above...
Code:
LPD3DXMESH *faked_mesh, *backup_mesh;

void	make_panelmesh_startup()
{	///////////////////////////////////////////////////////////////////////////////////////
	static short Ibuff[2] 	={ 0, 2 };
	static short Vbuff[112]	={ 0,16968,0,49736,0,0,0,32768,0,32768,0,49024,0,0,0,0,0,
										0,0,0,0,0,0,0,0,0,0,0,0,49736,0,16968,0,0,0,32768,0,
										32768,0,49024,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,49736,
										0,49736,0,0,0,32768,0,32768,0,16256,0,0,0,0,0,0,0,0,0,
										0,0,0,0,0,0,0,0,16968,0,16968,0,0,0,32768,0,32768,0,
										16256,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0					 };
	///////////////////////////////////////////////////////////////////////////////////////	
	LPDIRECT3DDEVICE9 pd3d_dev = pd3ddev;
	LPD3DXMESH		pMesh		 = NULL;	
	D3DVERTEX*		pVertBuff = NULL;
	byte*				pFaceBuff = NULL;
	DWORD				pVerts	 = 4;
	DWORD				pFaces	 = 4;
	///////////////////////////////////////////////////////////////////////////////////////	
	if(SUCCEEDED(D3DXCreateMeshFVF(pFaces,pVerts,D3DXMESH_MANAGED,D3DFVF_D3DVERTEX,pd3d_dev, &pMesh)))
	{	if(SUCCEEDED(pMesh->LockVertexBuffer(D3DLOCK_NO_DIRTY_UPDATE, &pVertBuff)))
		{	memcpy(pVertBuff, Vbuff, sizeof(D3DVERTEX)*pVerts);
			pMesh->UnlockVertexBuffer();								}
		if(SUCCEEDED(pMesh->LockIndexBuffer(D3DLOCK_NO_DIRTY_UPDATE, &pFaceBuff)))
		{	memcpy(pFaceBuff, Ibuff, pFaces);
			pMesh->UnlockIndexBuffer();	  }
	}
	faked_mesh = pMesh;
}


void	splice(ENTITY* ent)
{
	if(ent.skill1==0)	
	{	backup_mesh = ent_getmesh(ent,0,0);	ent_setmesh(ent,(void*)faked_mesh,0,0);	ent.skill1=1;	}
	else
	{	ent_setmesh(ent,backup_mesh,0,0);	backup_mesh = NULL;								ent.skill1=0;	}
}




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: [unpaid]Micro-tutorial of D3D mesh-generation [Re: EvilSOB] #330546
06/28/10 11:20
06/28/10 11:20
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
i will try somthing on monday but i cant promising anything you got lots of more experience in stuff like this

i realy though you needed to do somthing to update the new shaders ore somthing before it shows correctly?
not sure, i think it wont work ent_fixnormals(my,my.frame);

if you got the solution we can maby do some creasy stuff with it

anyway i think i cant do it but trying it is worth it


"empty"
Re: [unpaid]Micro-tutorial of D3D mesh-generation [Re: flits] #330574
06/28/10 15:01
06/28/10 15:01
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I'll get there, I just some short-term the support of a DirectX guru.
I really need this for my 3D-Panels system. (look in Lite-C Contributions)

FYI, ent_fixnormals no help Im afraid....

I fear Im missing something simple and fundamental.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: [unpaid]Micro-tutorial of D3D mesh-generation [Re: EvilSOB] #330903
06/30/10 18:25
06/30/10 18:25
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
i tried alot en i did create a cube

creating a skin doesnt work yet but oke

the only mistake i think that you made is the indexbuffer

its pretty hard to assing the right vertex to the poly's

Code:
#include <litec.h>
#include <default.c>
#include <d3d9.h>

var ent_test = NULL;

long num_tris = 13;
long num_verts = 8;

D3DVERTEX*		pVertBuff = NULL;
byte*				pFaceBuff = NULL;

LPD3DXMESH pNewMesh;

short IndexData[36] = {	3,2,1,3,1,0,
								4,5,6,4,6,7,
								2,6,5,1,2,5,
								3,4,7,3,0,4,
								0,1,4,5,4,1,
								2,3,6,7,6,3};

var i;

void test()
{
	ent_test = my;
	
	D3DXCreateMeshFVF(num_tris,num_verts,D3DXMESH_MANAGED,D3DFVF_D3DVERTEX,(LPDIRECT3DDEVICE9)pd3ddev,&pNewMesh);
	
	var fhandle = file_open_read ("test.txt");
	
	pNewMesh->LockVertexBuffer( 0, &pVertBuff);
	for(i=0;i<8;i++)
	{
		pVertBuff[i].x = file_var_read(fhandle);
		pVertBuff[i].y = file_var_read(fhandle);
		pVertBuff[i].z = file_var_read(fhandle);
		pVertBuff[i].nx = file_var_read(fhandle);
		pVertBuff[i].ny = file_var_read(fhandle);
		pVertBuff[i].nz = file_var_read(fhandle);
		pVertBuff[i].u1 = file_var_read(fhandle);
		pVertBuff[i].v1 = file_var_read(fhandle);
		pVertBuff[i].u2 = file_var_read(fhandle);
		pVertBuff[i].v2 = file_var_read(fhandle);
		pVertBuff[i].x3 = file_var_read(fhandle);
		pVertBuff[i].y3 = file_var_read(fhandle);
		pVertBuff[i].z3 = file_var_read(fhandle);
		pVertBuff[i].w3 = file_var_read(fhandle);
	}
	pNewMesh->UnlockVertexBuffer();
	file_close(fhandle);
	
	pNewMesh->LockIndexBuffer(0, &pFaceBuff);
	
	memcpy(pFaceBuff,IndexData, 36*sizeof(short));
	
	pNewMesh->UnlockIndexBuffer();
	
	
		
	wait(1);
	ent_setmesh(my,pNewMesh,0,0);
	c_setminmax(my);
	
	c_updatehull(my,1);
}

void quit()
{
	return;
	
	pMesh = ent_getmesh(ent_test,0,0);
	pMesh->Release();
	ent_setmesh(ent_test,NULL,0,0);
}

void main()
{	
	fps_max = 80;
	
	wait(1);
	
	level_load("");
	
	ent_create("blok.mdl",vector(255,0,0),test);
	
	on_exit = quit;
}




test.txt

Code:
-8 8 -8 -0.408 0.408 -0.816 0 0 0 0 0 0 0 0 8 8 -8 0.667 0.667 -0.333 0.801 0 0.801 0 0 0 0 0 8 8 8 0.408 0.408 0.816 0 0 0 0 0 0 0 0 -8 8 8 -0.667 0.667 0.333 0.801 0 0.801 0 0 0 0 0 -8 -8 -8 -0.667 -0.667 -0.333 0 0.795 0 0.795 0 0 0 0 8 -8 -8 0.408 -0.408 -0.816 0.801 0.795 0.801 0.795 0 0 0 0 8 -8 8 0.667 -0.667 0.333 0 0.795 0 0.795 0 0 0 0 -8 -8 8 -0.408 -0.408 0.816 0.801 0.795 0.801 0.795 0 0 0 0




Last edited by flits; 06/30/10 18:26.

"empty"
Re: [unpaid]Micro-tutorial of D3D mesh-generation [Re: flits] #331160
07/02/10 10:27
07/02/10 10:27
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
have you seen the D3D lessons in the included samples? most of what's in there will get what you need

Re: [unpaid]Micro-tutorial of D3D mesh-generation [Re: MrGuest] #331179
07/02/10 12:29
07/02/10 12:29
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Im back at last.... Thanks for the reply guys.

flits: Im taking a look at your code now.

MrGuest: Yeah, but they just confused me more than anything because
the code 'jumps around" so much between step, without being really clear about what each step is doing...


I will post results...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: [unpaid]Micro-tutorial of D3D mesh-generation [Re: EvilSOB] #331201
07/02/10 15:04
07/02/10 15:04
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Thanks muchly flits.

It helps and it doesnt help.

I can now see that it is ONLY a flaw in my data, not my coding.

But the data I was using was extracted from a real MDL file, so now
Ive got to figure out why...

Thanks dude.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: [unpaid]Micro-tutorial of D3D mesh-generation [Re: EvilSOB] #331208
07/02/10 16:26
07/02/10 16:26
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
i did extract it from a mdl also (execept index buffer)

didnt know where to start so i didt start with the vertex buffer

the hardes part was to get the index buffer working
index buffer connectes the polygons between the vertex
i read somewhere that you need to nubmer the clock wise ( i didnt understand this myself)

as far as i learnt from al of this is that the easest part is the positions of the vertex

you can find the rest in D3DVERTEX

typedef struct {
float x,y,z; // position in DirectX coordinates
float nx,ny,nz; // normal
float u1,v1; // first coordinate set, for textures
float u2,v2; // second coordinate set, for shadow maps
float x3,y3,z3,w3; // third coordinate set, for tangent vector and handedness
// float tu4,tv4; // 4th coordinate set (not yet implemented), for additional data
} D3DVERTEX;

already there in atypes.h


there is even more i learnt, after setting this up
vertex related stuff dont work (probaly fixable with vec_to_mesh)
setting ent_setskin gives strange results
the uper an down faces gives rare results
in D3DXCreateMeshFVF i need to add a extra face else i get strange results
creating a dummy instead of a mdl make's it crashe(dont know why)
the release dont work stil dont know why but in the manual there was somthing about that you need to realease it


last thing i thing i stoping playing with it for a while because its way to hot here and got lots of other projects but i learnt realy much (never used memcpy)


hope you got some nice results becuase i got some times realy strange objects


Last edited by flits; 07/02/10 16:26.

"empty"
Re: [unpaid]Micro-tutorial of D3D mesh-generation [Re: flits] #331283
07/03/10 05:59
07/03/10 05:59
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Finally got it figured out, and now working.
There were a couple of MAJOR flaws in my code, as stated below.

1> Storing the static vertex data as shorts. BAD!
This led to occaisional data corruption as 'chopping' up the long
data into shorts was killing some negative numbers (mostly -1).

2> Static index data: Stuffed!
My index data was based on data extracted from a real MDL.
BUT, I was only reading ONE BYTE per face, when I should have been
reading THREE SHORTS per face. DUH! Dunno how I managed that.

3> There may have been some othor minor issues, but I cant remember them.

So here is a working code that builds a 100x100x0 panel-shaped mesh, and stores
it into a global pointer. (cause you only need it once, and ent_clone duplicates)
(FYI texture mapping is working, front side is whole texture,
and the backside is a mirror imiage of it, so it is kindof see-through)

Code:
//this event needed to release all custom meshes to prevent on-exit-crashes
void exit_event()	{	me = NULL;	while(me=ent_next(me))	ent_setmesh(me,0,0,0);	}		


LPD3DXMESH *panel_mesh;

void	make_panelmesh_startup()
{	///////////////////////////////////////////////////////////////////////////////////////
	//	static hard-coded mesh		////
	static short Ibuff[12] 	={	0,2,1,0,3,2,3,1,2,3,0,1 };
	static byte Vbuff[224]	={ 0,128,95,56,0,0,200,66,47,0,200,66,0,0,128,191,0,0,0,128,28,
		10,15,53,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,95,
		56,0,0,200,194,47,0,200,66,0,0,128,63,0,0,0,128,28,10,15,181,0,0,0,0,0,0,128,63,0,0,0,
		0,0,0,128,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,95,184,0,0,200,194,47,0,200,194,0,
		0,128,191,0,0,0,128,28,10,15,53,0,0,128,63,0,0,128,63,0,0,128,63,0,0,128,63,0,0,0,0,0,
		0,0,0,0,0,0,0,0,0,0,0,0,128,95,184,0,0,200,66,47,0,200,194,0,0,128,63,0,0,0,128,28,10,
		15,181,0,0,128,63,0,0,0,0,0,0,128,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	};
	///////////////////////////////////////////////////////////////////////////////////////	
	LPDIRECT3DDEVICE9 pd3d_dev = pd3ddev;		LPD3DXMESH pMesh;
	D3DVERTEX* pVertBuff;							short* pFaceBuff;
	///////////////////////////////////////////////////////////////////////////////////////	
	if(SUCCEEDED(D3DXCreateMeshFVF(0x4,0x4,D3DXMESH_MANAGED,D3DFVF_D3DVERTEX,pd3d_dev, &pMesh)))
	{	if(SUCCEEDED(pMesh->LockVertexBuffer(0x0, &pVertBuff)))
		{	memcpy(pVertBuff, Vbuff, sizeof(D3DVERTEX)*0x4);
			pMesh->UnlockVertexBuffer();								}
		if(SUCCEEDED(pMesh->LockIndexBuffer(0x0, &pFaceBuff)))
		{	memcpy(pFaceBuff, Ibuff, (sizeof(short)*0x3)*0x4);
			pMesh->UnlockIndexBuffer();	  						}	}
	panel_mesh = pMesh;
}







"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1