Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 681 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Print Thread
Rate Thread
Page 5 of 5 1 2 3 4 5
Re: Merge 2 Meshes/Entities during game... [Re: Benni003] #404091
07/02/12 11:10
07/02/12 11:10
Joined: Jan 2003
Posts: 4,305
Damocles Offline
Expert
Damocles  Offline
Expert

Joined: Jan 2003
Posts: 4,305
"entities are created ... without a collision model"

8.05 When set to 0 after level loading, all subsequent entities are created with PASSABLE flag and without a collision model. They are created faster and consume less memory this way, but can't be used as colliders or obstacles. When setting collision_mode to nonzero and resetting PASSABLE, the entity's collision model is created afterwards in the next frame cycle. The entities can then perform normal collision detection.


Maybe some nullpointer while merging since the collision model is not created.


Can you try it with ent_morph too.
Maybe it causes the same crash.

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 Offline
Expert
EvilSOB  Offline
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.
Click to reveal..
Code:
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: EvilSOB] #404093
07/02/12 11:29
07/02/12 11:29
Joined: Aug 2008
Posts: 394
Germany
Benni003 Offline OP
Senior Member
Benni003  Offline OP
Senior Member

Joined: Aug 2008
Posts: 394
Germany
hm, it say's D3DXConcatenateMeshes - undeclared identifer

Re: Merge 2 Meshes/Entities during game... [Re: Benni003] #404114
07/02/12 17:06
07/02/12 17:06
Joined: May 2010
Posts: 117
Germany , Dortmund
B
Bone Offline
Member
Bone  Offline
Member
B

Joined: May 2010
Posts: 117
Germany , Dortmund
Take the code from page 4 and replace the ent_merge function with the ent_merge function above

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 Offline
Expert
EvilSOB  Offline
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.
Click to reveal..
Code:
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: EvilSOB] #404116
07/02/12 17:21
07/02/12 17:21
Joined: Aug 2008
Posts: 394
Germany
Benni003 Offline OP
Senior Member
Benni003  Offline OP
Senior Member

Joined: Aug 2008
Posts: 394
Germany
Thanks, now it's working. And I know, d3d9.h was included wink

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
D
djfeeler Offline
Member
djfeeler  Offline
Member
D

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
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
your best option is to rather use the TUST library

here is something i am busy with

Code:
///////////////////////////////
#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
Page 5 of 5 1 2 3 4 5

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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