1 registered members (AndrewAMD),
1,248
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: EvilSOB]
#402338
06/02/12 19:14
06/02/12 19:14
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Thanks for your input, EvilSOB! It works with the following modification with my testmodel, a SimplySid.mdl from otter, but it throws an error message, when I try it with the dozer.mdl of Wjbender.
for (iterate=0;iterate<vertices_source1;iterate++)
{
temp1.x=source1.x+vbuffer_source1[iterate].x*source1.scale_x;
temp1.y=source1.y+vbuffer_source1[iterate].y*source1.scale_z;
temp1.z=source1.z+vbuffer_source1[iterate].z*source1.scale_y;
// ========= START of EvilSOB's suggestion ===============
VECTOR new_norm;
new_norm.x = vbuffer_source1[iterate].nx;
new_norm.y = vbuffer_source1[iterate].ny;
new_norm.z = vbuffer_source1[iterate].nz;
vec_rotate(new_norm, source1.pan);
// vec_normalize(new_norm, 1); //maybe?!?
//
merged_vbuffer[iterate].nx = new_norm.x;
merged_vbuffer[iterate].ny = new_norm.z;
merged_vbuffer[iterate].nz = new_norm.y;
// ========= END of EvilSOB's suggestion ===============
VECTOR final;
final.x=temp1.x;
final.y=temp1.z;
final.z=temp1.y;
vec_rotate(final.x,source1.pan);
merged_vbuffer[iterate].x=final.x;
merged_vbuffer[iterate].y=final.z;
merged_vbuffer[iterate].z=final.y;
// merged_vbuffer[iterate].nx=vbuffer_source1[iterate].nx;
// merged_vbuffer[iterate].nz=vbuffer_source1[iterate].ny;
// merged_vbuffer[iterate].ny=vbuffer_source1[iterate].nz;
merged_vbuffer[iterate].u1=vbuffer_source1[iterate].u1;
merged_vbuffer[iterate].v1=vbuffer_source1[iterate].v1;
merged_vbuffer[iterate].u2=vbuffer_source1[iterate].u2;
merged_vbuffer[iterate].v2=vbuffer_source1[iterate].v2;
}
offsetv+=vertices_source1;
for (iterate=0;iterate<vertices_source2;iterate++)
{
temp1.x=source2.x+vbuffer_source2[iterate].x*source2.scale_x;
temp1.y=source2.y+vbuffer_source2[iterate].y*source2.scale_z;
temp1.z=source2.z+vbuffer_source2[iterate].z*source2.scale_y;
// ========= START of EvilSOB's suggestion ===============
VECTOR new_norm;
new_norm.x = vbuffer_source2[iterate+offsetv].nx;
new_norm.y = vbuffer_source2[iterate+offsetv].ny;
new_norm.z = vbuffer_source2[iterate+offsetv].nz;
vec_rotate(new_norm, source2.pan);
// vec_normalize(new_norm, 1); //maybe?!?
//
merged_vbuffer[iterate+offsetv].nx = new_norm.x;
merged_vbuffer[iterate+offsetv].ny = new_norm.z;
merged_vbuffer[iterate+offsetv].nz = new_norm.y;
// ========= END of EvilSOB's suggestion ===============
VECTOR final;
final.x=temp1.x;
final.y=temp1.z;
final.z=temp1.y;
vec_rotate(final.x,source2.pan);
merged_vbuffer[iterate+offsetv].x=final.x;
merged_vbuffer[iterate+offsetv].y=final.z;
merged_vbuffer[iterate+offsetv].z=final.y;
// merged_vbuffer[iterate+offsetv].nx=vbuffer_source2[iterate].nx;
// merged_vbuffer[iterate+offsetv].nz=vbuffer_source2[iterate].ny;
// merged_vbuffer[iterate+offsetv].ny=vbuffer_source2[iterate].nz;
merged_vbuffer[iterate+offsetv].u1=vbuffer_source2[iterate].u1;
merged_vbuffer[iterate+offsetv].v1=vbuffer_source2[iterate].v1;
merged_vbuffer[iterate+offsetv].u2=vbuffer_source2[iterate].u2;
merged_vbuffer[iterate+offsetv].v2=vbuffer_source2[iterate].v2;
}
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: Pappenheimer]
#402352
06/03/12 00:06
06/03/12 00:06
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I havent tested anything, but I suspect it is the source2 vertex loop. Such a simple fault, maybe even a typo...
Find the lines :
new_norm.x = vbuffer_source2[iterate+offsetv].nx;
new_norm.y = vbuffer_source2[iterate+offsetv].ny;
new_norm.z = vbuffer_source2[iterate+offsetv].nz;
and replace them with ::
new_norm.x = vbuffer_source2[iterate].nx;
new_norm.y = vbuffer_source2[iterate].ny;
new_norm.z = vbuffer_source2[iterate].nz;
And that will fix the crashes at least...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: Pappenheimer]
#402429
06/04/12 22:02
06/04/12 22:02
|
Joined: Aug 2008
Posts: 394 Germany
Benni003
OP
Senior Member
|
OP
Senior Member
Joined: Aug 2008
Posts: 394
Germany
|
It looks really interesting. Good work guys!
But if I want to merge the already merged Entity with an other, then it's not right working.
Last edited by Benni003; 06/04/12 22:02.
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: Benni003]
#402451
06/05/12 13:18
06/05/12 13:18
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I couldnt help myself... I had to give it a try, I'm up to my eyeballs in directx anyway... So you are back Benni! Cool, this IS your thread after all, and we've started to drift off-track without you! All we've done here is more of an entity 'splice' rather than a merge, I suppose. OK then, try this one... Its a stand-alone demo script of the ent_merge function Ive just completed today. Just load the script in SED, save, and run. Look at the code itself afterwards. Its just a timed demo, no interactions except camera zoom and angles. It starts showing you the 'brick' entity it will build a wall from. This is lightly tinted via the LIGHT flag so you can tell which one it is. After a second, it will move to its next location with a bit of randomness applied to its rotation and scales. BUT ... BEFORE it moves, the script will run my "ent_merge" function, thereby taking a 'copy' of the brick at that location and merging it into the "wall" entity. Let it continue and it will create a wall of nine blocks before the cluster-beeps indicate that the demo is complete... Have fun and let me know what you think, and CERTAINLY let me know if it doesnt work in certain situations! I havent tested it with that many models. !! IMPORTANT !! This function is CURRENTLY only able to store ONE skin. ie: the FIRST one it sees! All consecutive merged models will use their own original UV's with that first skin as the texture. Fixing this is a major task that requires more research and I dont really have the time to spare right know... And listening to Benni, it may not even be necessary for HIS needs, anyway.... Enough of my PRATTLE ... it on with the show!
#include <acknex.h>
#include <default.c>
#include <d3d9.h>
//
#define PRAGMA_PATH "%EXE_DIR%\projects\shadertest"
//
//
//=========================================================================================
//=========================================================================================
//
// this declaration has been OMITTED from D3D9.H or some reason... but I need it...
//
HRESULT WINAPI D3DXConcatenateMeshes
( LPD3DXMESH *ppMeshes,
UINT NumMeshes,
DWORD Options,
void* junk1,
void* junk2,
CONST D3DVERTEXELEMENT9 *pDecl,
LPDIRECT3DDEVICE9 pD3DDevice,
LPD3DXMESH *ppMeshOut
);
//
//-----------------------------------------------------------------------------------------
//
ENTITY* ent_merge(ENTITY* targ, ENTITY* src)
{ // verify that pointer parameters are valid... otherwise abort.
if(targ==NULL) { return(NULL); } //invalid TARGET entity pointer
if(src ==NULL) { return(NULL); } //invalid SOURCE entity pointer
//--------------------------------------------------------------------------------------
// initialize TARGET entity to a brand new 'empty' mesh
LPD3DXMESH meshes[3]; (meshes[0])=(meshes[1])=(meshes[2])=NULL;
short *tbuff; D3DVERTEX *vbuff;
if(targ==src)
{ D3DXCreateMesh(0x01,0x03,D3DXMESH_MANAGED,pvertexdecl,pd3ddev,&meshes[1]);
(meshes[1])->LockIndexBuffer (0, (void**)&tbuff);
tbuff[0]=0; tbuff[1]=1; tbuff[2]=2; (meshes[1])->UnlockIndexBuffer();
if((meshes[1])!=NULL) if(((meshes[0])=ent_getmesh(targ,0,0)))
{ ent_setmesh(targ,(meshes[1]),0,0); //(meshes[0])->Release();
return(targ); } }
//--------------------------------------------------------------------------------------
// merge supplied meshes into a new single mesh, and re-assign/release accordingly
meshes[0]=ent_getmesh(targ,0,0); meshes[1]=ent_getmesh(src,0,0);
D3DXConcatenateMeshes(meshes,0x2,D3DXMESH_MANAGED,0,0,pvertexdecl,pd3ddev,&meshes[2]);
int t,v, vert_off=ent_status(targ,1), vert_end=vert_off+ent_status(src,1);
//if((meshes[0])!=NULL) { (meshes[0])->Release(); }
if((meshes[2])!=NULL) { ent_setmesh(targ,(meshes[2]),0,0); }
else { return(NULL); }
if(!ent_status(targ,8)) { ent_setskin(targ,ent_getskin(src,1),1); } //if need skin
//--------------------------------------------------------------------------------------
// transform merged-in vertices
VECTOR tmpV; D3DVERTEX* vb; long* ab; ent_buffers(targ, 0,0, &vb, 0,&ab);
for(v=vert_off; v<vert_end; v++)
{ vb[v].nx = vb[v].ny = vb[v].nz = 0;
vec_mul(vec_set(tmpV, vector(vb[v].x,vb[v].z,vb[v].y)), src.scale_x);
vec_sub(vec_add(vec_rotate(tmpV, src.pan), src.x), targ.x);
vb[v].x=tmpV.x; vb[v].y=tmpV.z; vb[v].z=tmpV.y; }
for(t=0; t<ent_status(targ,4); t++) { ab[t] = NULL; }
//--------------------------------------------------------------------------------------
// re-calculate all normals
DWORD* p_adjacency = sys_malloc(ent_status(targ,4)*3*sizeof(DWORD));
(meshes[2])->GenerateAdjacency(0.001, p_adjacency);
D3DXComputeNormals((meshes[2]), p_adjacency); sys_free(p_adjacency);
(meshes[2])->OptimizeInplace(0x03000000, p_adjacency, NULL, NULL, NULL);
//--------------------------------------------------------------------------------------
return(targ);
}
//
//=========================================================================================
//=========================================================================================
//
//
//
//
void ent_randomize(ENTITY* ent) //give entity a (limited) random angle and scale
{ vec_set(ent.pan, vector(random(50)-25, random(50)-25, random(50)-25));
vec_set(ent.scale_x, vector(random(1)+0.5, random(1)+0.5, random(1)+0.5)); }
//
//-----------------------------------------------------------------------------------------
//
//
//
function main()
{
video_switch(10,32,0); level_load(""); wait(5); diag("\n\n\n");
vec_set(camera.x,vector(-750,0,10)); fps_min=fps_max=60;
def_move(); def_debug(); def_debug();
//--------------------------------------------------------------------------------------
//
// create an entity to 'assimilate' additional entities into itself
ENTITY* wall = ent_create(CUBE_MDL, nullvector, NULL); ent_clone(wall);
//
ent_merge(wall, wall); //initialize WALL entity to an 'empty' mesh
//
// create 'another brick in the wall' and color it differently so it stands out
ENTITY* brick = ent_create("box.mdl", nullvector, NULL);
vec_set(brick.blue, vector(50,50,50)); set(brick, LIGHT);
wait(-1); beep();
//
//
//
// merge the brick into the wall, and then move it to the next location, and pause
ent_merge(wall, brick); brick.z += 200; ent_randomize(brick);
wait(-1); beep();
//
// merge the brick into the wall, and then move it to the next location, and pause
ent_merge(wall, brick); brick.y += 200; ent_randomize(brick);
wait(-1); beep();
//
// merge the brick into the wall, and then move it to the next location, and pause
ent_merge(wall, brick); brick.z -= 200; ent_randomize(brick);
wait(-1); beep();
//
// merge the brick into the wall, and then move it to the next location, and pause
ent_merge(wall, brick); brick.z -= 200; ent_randomize(brick);
wait(-1); beep();
//
// merge the brick into the wall, and then move it to the next location, and pause
ent_merge(wall, brick); brick.y -= 200; ent_randomize(brick);
wait(-1); beep();
//
// merge the brick into the wall, and then move it to the next location, and pause
ent_merge(wall, brick); brick.y -= 200; ent_randomize(brick);
wait(-1); beep();
//
// merge the brick into the wall, and then move it to the next location, and pause
ent_merge(wall, brick); brick.z += 200; ent_randomize(brick);
wait(-1); beep();
//
// merge the brick into the wall, and then move it to the next location, and pause
ent_merge(wall, brick); brick.z += 200; ent_randomize(brick);
wait(-1); beep();
//
// merge the brick into the wall, and then remove the brick cause we are all finished
ent_merge(wall, brick); ent_remove(brick);
beep(); beep(); beep(); beep();
//
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: EvilSOB]
#402453
06/05/12 14:01
06/05/12 14:01
|
Joined: Aug 2008
Posts: 394 Germany
Benni003
OP
Senior Member
|
OP
Senior Member
Joined: Aug 2008
Posts: 394
Germany
|
Hey EvilSOB, thank you for your informations. Your code is very useful for me and I think also for many other people here! I will tell you, if something is wrong. Thank you a lot.
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: Pappenheimer]
#402475
06/06/12 05:45
06/06/12 05:45
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Benni :: No probs dude. If I find more time, I will try improving it.
Pappenheimer :: Did I try 'different' models? Yes and No. Yes - I tried others, but No - cause they all FAILED, as I expected.
This function is still a VERY limited work-in-progress. I was just posting where I had gotten to when I ran out of time. Im busy doing some HEAVY work with Esper and only did this code to have a break from his, to clear my mental buffers...
Other models just wont work AT THIS TIME, because this process cannot handle multiple skins. Only the first one it ever sees. I have not yet figured out how directx/acknex stores the 'which skin' information in the attribute table.
I know how directx is SUPPOSED to store it, but it doesnt seem to translate correctly when I do the ent_setmesh() stage, and if I try updating this information AFTER the ent_setmesh(), everything except skin1 is invisible... And I havent the time to research this at the moment Im afraid...
So, because it can only handle one skin, that why I only botherd trying with the same model time after time. Cause they all have the same skin that way, and so the process works in its limited fashion. And this limited fashion SOUNDED like it was all Benni needed, and its HIS thread...
So, I left it at that. IF I get time later, I will come back to this and improve upon what it can do, but I dont know when that will be...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: EvilSOB]
#402524
06/06/12 15:52
06/06/12 15:52
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
EvilSOB, everything is fine. Thank you for your snippet and explanations! I didn't want to force you to do anything, I just thought to give feedback, because you wrote "and CERTAINLY let me know if it doesnt work in certain situations!" BTW, the one skin only thing is no problem to me.
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: Pappenheimer]
#404074
07/02/12 08:16
07/02/12 08:16
|
Joined: Aug 2008
Posts: 394 Germany
Benni003
OP
Senior Member
|
OP
Senior Member
Joined: Aug 2008
Posts: 394
Germany
|
Hello, I have a Problem with the code. I want to Merge more then one Entity, so I do like this: Everything is good working:
function main()
{
level_load("");
wait(2);
wait(1);
demo_init();
ENTITY* ent1=ent_create("p.mdl",nullvector,0);
ENTITY* ent2=ent_create("p.mdl",vector(120,0,0),0);
ENTITY* merged=merge_ent(ent1,ent2);
merged.z+=200;//set this to zero, if you wanna see whether the result is identical in angle, scale and position
int i;
for(i=0;i<100;i++)
{
merged=merge_ent(merged,ent2);
wait(1);
}
}
But if I paste collision_mode=0; after the first wait, it crashes in merge ent:
function main()
{
level_load("");
wait(2);
collision_mode=0;
wait(1);
demo_init();
ENTITY* ent1=ent_create("p.mdl",nullvector,0);
ENTITY* ent2=ent_create("p.mdl",vector(120,0,0),0);
ENTITY* merged=merge_ent(ent1,ent2);
merged.z+=200;//set this to zero, if you wanna see whether the result is identical in angle, scale and position
int i;
for(i=0;i<100;i++)
{
merged=merge_ent(merged,ent2);
wait(1);
}
}
Does anyone know where the Problem is? Without collision_mode=0; it's good working. But I need to set it to 0.
Last edited by Benni003; 07/02/12 08:18.
|
|
|
|