0 registered members (),
677
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: Damocles]
#404092
07/02/12 11:19
07/02/12 11:19
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Im just passing through, cause I still dont have much time, but try this updated (but utterly untested) version of ent_merge. It SHOULD by-pass the collision_mode problem.
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
var old_coll_mode=collision_mode; collision_mode=1;
//--------------------------------------------------------------------------------------
// 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();
collision_mode=old_coll_mode; 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 { collision_mode=old_coll_mode; 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);
//--------------------------------------------------------------------------------------
collision_mode=old_coll_mode; return(targ);
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: Benni003]
#404115
07/02/12 17:11
07/02/12 17:11
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
You shouldnt get that if my original declaration for it is still included before my ent_merge function. Put this following above my function and it should be fine.
HRESULT WINAPI D3DXConcatenateMeshes
( LPD3DXMESH *ppMeshes,
UINT NumMeshes,
DWORD Options,
void* junk1,
void* junk2,
CONST D3DVERTEXELEMENT9 *pDecl,
LPDIRECT3DDEVICE9 pD3DDevice,
LPD3DXMESH *ppMeshOut
);
And also remember to have the "#include <d3d9.h>" at the top of you main script. Otherwise post the whole of your script and we will see what we can see...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: Benni003]
#444862
08/20/14 05:34
08/20/14 05:34
|
Joined: May 2008
Posts: 257
djfeeler
Member
|
Member
Joined: May 2008
Posts: 257
|
Hello !
Your code is very great ! I would like to know if we can remove an element that has been added ?
Thanks in advance !
Djfeeler
Last edited by djfeeler; 08/20/14 05:35.
|
|
|
Re: Merge 2 Meshes/Entities during game...
[Re: djfeeler]
#445849
09/27/14 10:25
09/27/14 10:25
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
your best option is to rather use the TUST library here is something i am busy with
///////////////////////////////
#include <acknex.h>
#include <default.c>
#define PRAGMA_PATH "tust"
///////////////////////////////
#include "tust.h"
//max units
#define population 21000/12
//step in units of unit_space
var unit_space=16;
typedef struct cluster_unit
{
VECTOR pos;
LPD3DXMESH mesh;
int uid;
}cluster_unit;
//build the model from the cluster models
void build_cluster_units(List* cluster,DynamicModel *model)
{
if(model!=NULL && cluster!=NULL)
{
memset(model,0,sizeof(DynamicModel));
ListItem *it = cluster->first;
for(it = cluster->first; it != NULL; it = it->next)
{
cluster_unit* mycluster=(cluster_unit*)it.data;
dmdl_add_mesh(model,mycluster.mesh,mycluster.pos);
}
list_end_iterate(it);
}
}
//add a unit to the cluster
//the cluster model must be re-build with build_cluster_units
void add_cluster_unit(List *cluster,ENTITY *ent,int uid)
{
cluster_unit *mycluster=malloc(sizeof(cluster_unit));
vec_set(mycluster.pos,ent.x);
mycluster.mesh=ent_getmesh(ent,0,0);
mycluster.uid=uid;
list_add(cluster,(cluster_unit*)mycluster);
sys_free(mycluster);
}
//remove a unit from the cluster
//the cluster model has to be re-build with build_cluster_units after
void remove_cluster_unit(List *cluster,int uid)
{
ListItem *it = cluster->first;
for(it = cluster->first; it != NULL; it = it->next)
{
cluster_unit* mycluster=(cluster_unit*)it.data;
if(mycluster.uid==uid)list_remove(cluster,it.data);
}
list_end_iterate(it);
}
function main()
{
max_entities =50000;
max_particles=50000;
vec_set(screen_size,vector(800,600,0));
vec_set(screen_color,vector(1,1,1)); // dark blue
vec_set(sky_color,vector(1,1,1)); // dark blue
video_window(NULL,NULL,0,"random generator");
level_load("");
random_seed(500);
while(total_frames<1)wait(1);
camera.x=-100;
//camera.z=1000;
//camera.tilt-=90;
def_debug();def_debug();def_move();
////////////////////////////////////////////////
//populate the cluster list with entity data
//position of placement
VECTOR pos;
vec_set(pos,nullvector);
int i;
DynamicModel *model =dmdl_create();
List *cluster=list_create();
for(i=0;i<population;i+=1)
{
ENTITY* cube=ent_create(CUBE_MDL,pos,NULL);
//store cluster_unit in the list
add_cluster_unit(cluster,cube,i);
//remove entity
ptr_remove(cube);
if(pos.x<unit_space * 50)pos.x+=unit_space;
else
{
pos.y+=unit_space;
pos.x=0;
}
}
////////////////////////////////////////////////
//merge and re-build cluster units into single model
build_cluster_units(cluster,model);
//create merged entity
ENTITY *cluster_ent=dmdl_create_instance(model,nullvector,NULL);
////////////////////////////////////////////////
//remove some units from cluster
for(i=0;i<100;i++) remove_cluster_unit(cluster,integer(random(population)) );
////////////////////////////////////////////////
//merge and re-build cluster units into single model
build_cluster_units(cluster,model);
//create merged entity
ENTITY *cluster_ent1=dmdl_create_instance(model,vector(0,-600,0),NULL);
////////////////////////////////////////////////
//remove dynamic model
sys_free(model);
//remove list
sys_free(cluster);
}
Last edited by Wjbender; 09/27/14 12:41.
Compulsive compiler
|
|
|
|