Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, TipmyPip, VoroneTZ, Quad, 1 invisible), 688 guests, and 11 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: How to create 3D mesh? [Re: rojart] #359114
02/15/11 18:41
02/15/11 18:41
Joined: Dec 2010
Posts: 16
Brazil, Limeira, SP
Andre_Fernando Offline OP
Newbie
Andre_Fernando  Offline OP
Newbie

Joined: Dec 2010
Posts: 16
Brazil, Limeira, SP
Thank you very much, it helped me a lot!

Re: How to create 3D mesh? [Re: Andre_Fernando] #359548
02/18/11 14:53
02/18/11 14:53
Joined: Dec 2010
Posts: 16
Brazil, Limeira, SP
Andre_Fernando Offline OP
Newbie
Andre_Fernando  Offline OP
Newbie

Joined: Dec 2010
Posts: 16
Brazil, Limeira, SP
I learned how the process of creation of the 3D mesh, but I have another question, how do I apply texture the triangles in different faces in uv mapping? I tried to apply but they are all merged. Below is an example of what I need:



I used this code:

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

#define NVB 8  // Vertices
#define NIB 34 // Indexes
#define NAB 12 // Attributes

LPD3DXMESH pMesh;
D3DVERTEX pvb[NVB];
short pib[NIB];
long  pab[NAB];

ENTITY* ent;

MATERIAL* m2sided ={effect="technique TS{pass p0{CullMode=1;}}";}

void export_obj(ENTITY *entity, var scale);

function recreate_mesh(ENTITY *entity)
{	
	//printf("Total number of mesh vertices = %d", (long)ent_status(entity, 1));
	
	int num_triangles = NAB;
	int num_vertices  = NVB;
	
	// Vertices

	pvb[0].x = -8;pvb[0].y =  8;pvb[0].z = -8;	pvb[0].u1 = 0;pvb[0].v1 = 1;
	pvb[1].x =  8;pvb[1].y =  8;pvb[1].z = -8;	pvb[1].u1 = 1;pvb[1].v1 = 1;
	pvb[2].x =  8;pvb[2].y =  8;pvb[2].z =  8;	pvb[2].u1 = 0;pvb[2].v1 = 1;
	pvb[3].x = -8;pvb[3].y =  8;pvb[3].z =  8;	pvb[3].u1 = 1;pvb[3].v1 = 1;
	pvb[4].x = -8;pvb[4].y = -8;pvb[4].z = -8;	pvb[4].u1 = 0;pvb[4].v1 = 0;
	pvb[5].x =  8;pvb[5].y = -8;pvb[5].z = -8;	pvb[5].u1 = 1;pvb[5].v1 = 0;
	pvb[6].x =  8;pvb[6].y = -8;pvb[6].z =  8;	pvb[6].u1 = 0;pvb[6].v1 = 0;
	pvb[7].x = -8;pvb[7].y = -8;pvb[7].z =  8;	pvb[7].u1 = 1;pvb[7].v1 = 0;
	
	// Triangles / Attributes
	
	pib[ 0] = 6;pib[ 1] = 2;pib[ 2] = 7; pab[ 0] = 0;
	pib[ 3] = 3;pib[ 4] = 7;pib[ 5] = 2; pab[ 1] = 0;
	pib[ 6] = 7;pib[ 7] = 3;pib[ 8] = 4; pab[ 2] = 0;
	pib[ 9] = 0;pib[10] = 4;pib[11] = 3; pab[ 3] = 0;
	pib[12] = 4;pib[13] = 0;pib[14] = 5; pab[ 4] = 0;
	pib[15] = 1;pib[16] = 5;pib[17] = 0; pab[ 5] = 0;
	pib[18] = 5;pib[19] = 1;pib[20] = 6; pab[ 6] = 0;
	pib[21] = 2;pib[22] = 6;pib[23] = 1; pab[ 7] = 0;
	pib[24] = 7;pib[25] = 4;pib[26] = 6; pab[ 8] = 0;
	pib[27] = 5;pib[28] = 6;pib[29] = 4; pab[ 9] = 0;
	pib[30] = 3;pib[31] = 0;pib[32] = 2; pab[10] = 0;
	pib[33] = 1;pib[34] = 2;pib[35] = 0; pab[11] = 0;
	
	D3DXCreateMesh(num_triangles, num_vertices, D3DXMESH_MANAGED , pvertexdecl, pd3ddev, &pMesh);

	D3DVERTEX *pnewvb;  pMesh->LockVertexBuffer(1, (void**)&pnewvb);
	short *pnewib;  pMesh->LockIndexBuffer(0, (void**)&pnewib);
	long *pnewab;  pMesh->LockAttributeBuffer(0, &pnewab);
	
	memcpy(pnewvb, pvb, num_vertices*ent_status(entity,22));
	memcpy(pnewib, pib, num_triangles*3*sizeof(short));
	memcpy(pnewab, pab, num_triangles*sizeof(long));
	
	
	pMesh->UnlockVertexBuffer();
	pMesh->UnlockIndexBuffer();
	pMesh->UnlockAttributeBuffer();
	
	//int entBuffer = ent_buffers(entity,0,0,&pnewvb,&pnewib,&pnewab);
	//printf("Number of triangles of the mesh = %i", entBuffer);
	
	ent_setmesh(entity, pMesh, 0, 0);
//	export_obj(entity,2);
	//printf("ent_setmesh(entity, pMesh, 0, 0);");
	
	//int entBuffer = ent_buffers(entity,0,0,&pnewvb,&pnewib,&pnewab);
	//printf("Number of triangles of the mesh = %i", entBuffer);

	//printf("Total number of mesh vertices = %d", (long)ent_status(entity, 1));
}

function create_mesh()
{
	ent = ent_create(CUBE_MDL, 0, 0);
	ent_setskin(ent, bmap_create("texture.bmp"), 1);
	set(ent, LIGHT);
	ent.material = m2sided;
	
	//printf("Total number of model skins = %d", (long)ent_status(ent, 8));
	
	ent_clone(ent);
	recreate_mesh(ent);
	wait(2);
//	wait_for(recreate_mesh);
	ent_getvertex(ent,NULL,ent_status(ent,0));
	c_setminmax(ent);
	//printf("Total number of model skins = %d", (long)ent_status(ent, 8));
}

function main()
{
	vec_set(sky_color,COLOR_BLACK);
	level_load("");
	vec_set(camera.x,vector(-50,0,0));
	
	create_mesh();
	wait_for(create_mesh);
	//printf("Total number of mesh vertices = %d", (long)ent_status(ent, 1));
	
	while(1){
		ent.pan +=2*mickey.x*time_step;
		ent.tilt +=2*mickey.y*time_step;
		wait(1);
	}
}

function on_esc_event()
{ 
	pMesh = ent_getmesh(ent,0,0);
	pMesh->Release();
	ent_setmesh(ent,NULL,0,0);wait(1);
	sys_exit("");
}



I used this texture:



Someone can tell me?
Thanks

Re: How to create 3D mesh? [Re: Andre_Fernando] #359561
02/18/11 15:40
02/18/11 15:40
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
pvb[x].u1 = 0;pvb[x].v1 = 1

Here you have to set the UV mapping. 0/0 is the top left pixel of the skin, 1/1 the bottom right pixel of the skin. With the current setup you always use the full skin.

So you might want to choose one side of the cube to be at 0.1/0.1..0.4/0.4, the next side 0.6/0.1..0.9/0.4 the third side 0.1/0.6..0.4/0.9

You may need to use more vertices to get a proper UV map.

Re: How to create 3D mesh? [Re: FBL] #359666
02/18/11 22:09
02/18/11 22:09
Joined: Dec 2010
Posts: 16
Brazil, Limeira, SP
Andre_Fernando Offline OP
Newbie
Andre_Fernando  Offline OP
Newbie

Joined: Dec 2010
Posts: 16
Brazil, Limeira, SP
I don't understand, how do I associate more vertices in the mesh in UV?
I wanted each individual face of the cube were to UV.

Last edited by Andre_Fernando; 02/19/11 00:08.
Re: How to create 3D mesh? [Re: Andre_Fernando] #359681
02/19/11 01:19
02/19/11 01:19
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
You need more vertices in total. Each vertex has UV coordinates. So if a vertex is shared by two faces, but each faces needs different UVs for this vertex, you need to split this vertex into two vertices with the same position (xyz), but different u1/v1.
This way each face can have its own coordinates.

Re: How to create 3D mesh? [Re: Andre_Fernando] #359682
02/19/11 01:38
02/19/11 01:38
Joined: Oct 2004
Posts: 900
Lgh
rojart Offline
User
rojart  Offline
User

Joined: Oct 2004
Posts: 900
Lgh
@Andre_Fernando Firstly, you should understand how the uv mapping works, like here.



What you show us, is just the maximum uv coordinate from 0 to 1, therefore they is merged.


Regards, Robert

Quote
Everything should be made as simple as possible, but not one bit simpler.
by Albert Einstein

PhysX Preview of Cloth, Fluid and Soft Body

A8.47.1P
Re: How to create 3D mesh? [Re: Andre_Fernando] #367896
04/19/11 21:12
04/19/11 21:12
Joined: Dec 2010
Posts: 16
Brazil, Limeira, SP
Andre_Fernando Offline OP
Newbie
Andre_Fernando  Offline OP
Newbie

Joined: Dec 2010
Posts: 16
Brazil, Limeira, SP
Sorry about the delay in responding, because I was studying the matter. Ok, now I know the process of creating a 3D mesh and how work the UV Mapping in the mesh. Thank you!

What I am now in doubt is the command "mouse_pos3d". I did many attempts but could not. I searched the forum but did not find anything like what I needed. Below a picture of animation frames of what needed:



I wanted to create a mesh from a region of a scene, where the 3D positions are relative to mouse, and an axle is fixed in the grid. The code below is almost what I want:


Code:
function shoot_with_mouse() 
{  
  VECTOR to;
  vec_set(to,mouse_dir3d);
  vec_scale(to,1000); // set a range
  vec_add(to,mouse_pos3d);
  c_trace(mouse_pos3d,to,ACTIVATE_SHOOT);
}



Can anyone help me?

Thanks

Re: How to create 3D mesh? [Re: Andre_Fernando] #368031
04/20/11 20:43
04/20/11 20:43
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Code:
function shoot_with_mouse() 
{  
  VECTOR to;
  vec_set(to,mouse_dir3d);
  vec_scale(to,1000); // set a range
  vec_add(to,mouse_pos3d);
  c_trace(mouse_pos3d,to,ACTIVATE_SHOOT);
  vec_set(to,mouse_dir3d);
  vec_scale(to,result); // set the range to the result of the trace
  vec_add(to,mouse_pos3d);//'to' contains now the position on the grid
}



Re: How to create 3D mesh? [Re: Pappenheimer] #370007
05/10/11 13:43
05/10/11 13:43
Joined: Dec 2010
Posts: 16
Brazil, Limeira, SP
Andre_Fernando Offline OP
Newbie
Andre_Fernando  Offline OP
Newbie

Joined: Dec 2010
Posts: 16
Brazil, Limeira, SP
Hello. When I create the 3D mesh in the scene with DirectX, the mesh is not diffuse and not speculate too. I tryed change anything in the D3DXCreateMesh but not work. I can change the Ambient and Emissive, but Diffuse and Specular I can not change. Why is it happens? Is There any line of code that's missing?

Thanks!

Re: How to create 3D mesh? [Re: Andre_Fernando] #370309
05/12/11 11:48
05/12/11 11:48
Joined: Oct 2004
Posts: 900
Lgh
rojart Offline
User
rojart  Offline
User

Joined: Oct 2004
Posts: 900
Lgh
Have you tried to use Surface normals?

Face and Vertex Normal Vectors (Direct3D 9)

Simply add D3DXComputeNormals(pMesh,0); but prior ent_setmesh(entity, pMesh, 0, 0); was executed.


Regards, Robert

Quote
Everything should be made as simple as possible, but not one bit simpler.
by Albert Einstein

PhysX Preview of Cloth, Fluid and Soft Body

A8.47.1P
Page 2 of 3 1 2 3

Moderated by  HeelX, Spirit 

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