3 registered members (VoroneTZ, monk12, Quad),
829
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Has anyone suceeded using D3DXCreateMeshFVF with A8
#399700
04/18/12 17:35
04/18/12 17:35
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Im trying to manually create and use a mesh in A8 like I did back in the A7 days, but it just keeps producing invalid meshes.
So invalid are they that the engine generates a windows crash on exit.
So has anyone SUCESSFULLY gotten it to work in A8 yet?
Preferably with a small WORKING sample code to demo it?
Thanks guys...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Has anyone suceeded using D3DXCreateMeshFVF with A8
[Re: fogman]
#399746
04/19/12 06:26
04/19/12 06:26
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
That link is no good to me dude.
Its a compacted EXE, so there is mo way for me to get to the "meshes.c" file...
Can you just post the relevent piece of source-code? (just the function itself and any relevent global references)
Thanks dude.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Has anyone suceeded using D3DXCreateMeshFVF with A8
[Re: EvilSOB]
#399750
04/19/12 08:19
04/19/12 08:19
|
Joined: Oct 2004
Posts: 900 Lgh
rojart
User
|
User
Joined: Oct 2004
Posts: 900
Lgh
|
The reason of the problem is that A8 uses not the FVF definition, but a slightly different vertex declaration for the mesh. You must call D3DXCreateMesh, not D3DXCreateMeshFVF. here is my simple example how it works:
#include <default.c>
#include <ackphysx.h>
#include <d3d9.h>
#define PRAGMA_PATH "%EXE_DIR%\samples"
#define NVB 9 // Number of Vertices
#define NIB 42 // Number of Indexes
#define NAB 14 // Number of Attributes
LPD3DXMESH pMesh;
D3DVERTEX pvb[NVB];
short pib[NIB];
long pab[NAB];
ENTITY* ent;
function create_house(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[1].x = 8;pvb[1].y = 8;pvb[1].z = -8;
pvb[2].x = 8;pvb[2].y = 8;pvb[2].z = 8;
pvb[3].x = -8;pvb[3].y = 8;pvb[3].z = 8;
pvb[4].x = -8;pvb[4].y = -8;pvb[4].z = -8;
pvb[5].x = 8;pvb[5].y = -8;pvb[5].z = -8;
pvb[6].x = 8;pvb[6].y = -8;pvb[6].z = 8;
pvb[7].x = -8;pvb[7].y = -8;pvb[7].z = 8;
pvb[8].x = 0;pvb[8].y = 32;pvb[8].z = 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] = 1;
pib[ 6] = 7;pib[ 7] = 3;pib[ 8] = 4; pab[ 2] = 2;
pib[ 9] = 0;pib[10] = 4;pib[11] = 3; pab[ 3] = 3;
pib[12] = 4;pib[13] = 0;pib[14] = 5; pab[ 4] = 4;
pib[15] = 1;pib[16] = 5;pib[17] = 0; pab[ 5] = 5;
pib[18] = 5;pib[19] = 1;pib[20] = 6; pab[ 6] = 6;
pib[21] = 2;pib[22] = 6;pib[23] = 1; pab[ 7] = 7;
pib[24] = 7;pib[25] = 4;pib[26] = 6; pab[ 8] = 8;
pib[27] = 5;pib[28] = 6;pib[29] = 4; pab[ 9] = 9;
pib[30] = 3;pib[31] = 8;pib[32] = 0; pab[10] = 10;
pib[33] = 2;pib[34] = 8;pib[35] = 3; pab[11] = 11;
pib[36] = 1;pib[37] = 8;pib[38] = 2; pab[12] = 12;
pib[39] = 0;pib[40] = 8;pib[41] = 1; pab[13] = 13;
D3DXCreateMesh(num_triangles, num_vertices, D3DXMESH_MANAGED , pvertexdecl, pd3ddev, &pMesh);
D3DVERTEX *pnewvb; pMesh->LockVertexBuffer(0, (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();
D3DXComputeNormals(pMesh,0);
//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); //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 init_mesh() {
ent = ent_create(CUBE_MDL, vector(-100, 0, 0), NULL);
ent_clone(ent); set(ent, SHADOW|CAST);
create_house(ent);
wait_for(create_house);
c_setminmax(ent);
pXent_settype(ent,PH_RIGID,PH_CONVEX);
wait(1);
}
function spot1() {
set(me, SPOTLIGHT|CAST|LIGHT);
my.lightrange = 500;
vec_set(my.blue,vector(255,100,100));
while(1) {
my.pan += 3*time_step;
my.tilt = -60;
wait(1);
}
}
function spot2() {
set(me, SPOTLIGHT|CAST|LIGHT);
my.lightrange = 500;
vec_set(my.blue,vector(255,50,100));
while(1) {
my.pan -= 3*time_step;
my.tilt = -60;
wait(1);
}
}
function main() {
random_seed(0);
vec_set(sky_color,vector(76,51,25));
video_set(1024, 768, 32, 2);
fps_max = 60; sun_light = 0;
shadow_stencil = 1;
physX_open();
level_load("small.hmp");
vec_set(ambient_color,vector(40,40,40));
vec_set(camera.x,vector(-211,-77,50));
vec_set(camera.pan,vector(35,-19,0));
pXent_settype(level_ent,PH_STATIC,PH_POLY);
init_mesh(); wait_for(init_mesh);
int i; for(i=1;i<NAB+1;i++)
ent_setskin(ent, bmap_fill(bmap_createblack(32,32,24),vector(50+integer(random(255)),100+integer(random(255)),100+integer(random(255))),100),i);
ent.ambient = 50;
//printf("Total number of model skins = %d", (long)ent_status(ent, 8));
you = ent_create(CUBE_MDL,vector(0,0,200),spot1);
you = ent_create(CUBE_MDL,vector(100,0,200),spot2);
def_move();
while(1) {
pX_pick(); // pick and move the mesh with the cursor
wait(1);
}
}
function on_esc_event() {
pMesh = ent_getmesh(ent,0,0);
pMesh->Release();
ent_setmesh(ent,0,0,0);
sys_exit("");
}
|
|
|
Re: Has anyone suceeded using D3DXCreateMeshFVF with A8
[Re: fogman]
#399788
04/20/12 07:26
04/20/12 07:26
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Thanks Rojart, exactly what I needed. Thanks to everyone lse too. Here is what Ive come up with for MY needs, based on what Rojart posted. Works a treat!
//===================================================================================
//
#include <d3d9.h>
//
LPD3DXMESH Panel_Mesh;
//
void morph_to_3dpanel(ENTITY *entity)
{
D3DVERTEX vbuff[4]; memset(vbuff, 0, 0x04*ent_status(entity,22));
vbuff[0].x = 10; vbuff[0].y = 10; vbuff[1].x =-10; vbuff[1].y = 10;
vbuff[2].x =-10; vbuff[2].y =-10; vbuff[3].x = 10; vbuff[3].y =-10;
vbuff[0].u1 = 0; vbuff[0].v1 = 0; vbuff[1].u1 = 1; vbuff[1].v1 = 0;
vbuff[2].u1 = 1; vbuff[2].v1 = 1; vbuff[3].u1 = 0; vbuff[3].v1 = 1;
short ibuff[12] = { 0,1,2, 2,3,0, 2,1,0, 0,3,2 };
//--------------------------------------------------------------------------------
D3DXCreateMesh(0x04, 0x04, D3DXMESH_MANAGED , pvertexdecl, pd3ddev, &Panel_Mesh);
D3DVERTEX *vb; Panel_Mesh->LockVertexBuffer(0, (void**)&vb);
memcpy(vb, vbuff, 0x04*ent_status(entity,22));
Panel_Mesh->UnlockVertexBuffer();
short *ib; Panel_Mesh->LockIndexBuffer (0, (void**)&ib);
memcpy(ib, ibuff, 0x04*3*sizeof(short));
Panel_Mesh->UnlockIndexBuffer();
//--------------------------------------------------------------------------------
D3DXComputeNormals(Panel_Mesh,0);
ent_setmesh(entity, Panel_Mesh, 0, 0);
}
//
//===================================================================================
//
function exit_event()
{ you=NULL; while((you=ent_next(you)))
{ Panel_Mesh = ent_getmesh(you,0,0);
if(Panel_Mesh)
{ Panel_Mesh->Release(); ent_setmesh(you,0,0,0); } }
sys_exit(""); }
//
//-----------------------------------------------------------------------------------
//
void on_exit_startup() { wait(2); on_exit = exit_event; }
//
//===================================================================================
It generates a simple 2D, double-sided, uv_mapped square as a physical mesh. (and YES, the back-side is a mirror-image intentionally) Size is adjusted later on elsewhere by ent_setvertex'ing the 4 vertices... But Ive got a couple of questions too... (for anyone) This code is part of a 'plug-in' header file for my (old) 3d-Panels system. So I want it to be pretty self-contained, bullet-proof, and non-intrusive. 1> You will notice that I run through all the currently loaded entities and do a "Release" on them ALL. Is this a safe thing to do in a real application? Or should I ONLY 'Release' the ones Ive created? 2> Is the way tht I hook into the 'exit' event being dont in a 'bad' way? That is, if you had an existing application already 'somehow' hooking the on_exit events, would my way of hooking in 'break' yours in a difficult to find and/or fix way? 3> When performing an ent_remove on an entity carring my custom mesh, do I need to catch them and do a "Release" myself, or will the engine do it naturally? 4> I noticed in Rojart's code then he doea a 'wait_for(create_house)'... I cant see any need for this as the function contains no 'wait's. Is there a hidden need for the wait_for that Im not aware of? Thanks everyone for the hand...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|