1 registered members (AndrewAMD),
684
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
OP
Newbie
|
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:
#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: FBL]
#359666
02/18/11 22:09
02/18/11 22:09
|
Joined: Dec 2010
Posts: 16 Brazil, Limeira, SP
Andre_Fernando
OP
Newbie
|
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]
#359682
02/19/11 01:38
02/19/11 01:38
|
Joined: Oct 2004
Posts: 900 Lgh
rojart
User
|
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.
|
|
|
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
OP
Newbie
|
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:
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
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
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
}
|
|
|
|