Unregister cloth

Posted By: 3run

Unregister cloth - 04/05/20 19:20

Hey!

Does anyone know, how to unregister and remove cloth? Manual suggests to use pXent_settype to unregister it, but after using it, you still can't remove the cloth (Error E1514 in physX_open). There is this 'pXent_reset_cloth' in header, it freezes the whole project! But it kinda seems to work (since I can remove cloth without any problems), it also makes all rigid bodies (which are registered at the time you call this function) stuck in the air!

Greets!
Posted By: rojart

Re: Unregister cloth - 04/30/20 19:06

Hey!
Have you tried the pXent_settype( myCloth, 0, 0 ); or ;ent_remove(ENTITY*); ?
Posted By: 3run

Re: Unregister cloth - 04/30/20 19:40

Originally Posted by rojart
Have you tried the pXent_settype( myCloth, 0, 0 ); or ;ent_remove(ENTITY*); ?
Hey rojart! Yes, I have tried both... But they didn't work. When I try to unregister the cloth and ptr_remove it, in acknex it's not visible (as if it was removed), but in PVD I can still see it's there... When I throw a ball to it I get E1513 crash in physX_open. But if I call pXent_reset_cloth at the end, it kinda works... but again, the whole thing freezes and rigid bodies created at that time are stopped in the air (as if they unregistered) and I can't see them in PVD and after a while I get E1513 in physX_ent_remove.
Code
#include <default.c>
#include <ackphysX.h>
#include <mtlFX.c>

PANEL* pInfo = NULL;
FONT* fA20b = "Arial#20b";

function fBallinit()
{
	set(my,SHADOW|CAST);
	pXent_settype(my,PH_RIGID,PH_SPHERE);
	pXent_setmass(my,6);
	pXent_setelasticity(my,100);
	pXent_addvelcentral(my,vec_rotate(vector(1000,0,400),camera.pan));
	pXent_addtorquelocal(my,vector(100,5,0));
	wait(-30);
	ent_remove(me);
}

function on_space_event()
{
	ent_create ("basket_ball.mdl", camera.x, fBallinit);
}


function main()
{	
	shadow_stencil = 2;
	fps_max = 60;

	level_load("");	
	physX_open();
	vec_set(sky_color,COLOR_BLUE);
	vec_set(sun_angle.pan,vector(300,60,5000));
	vec_set(camera.x,vector(-1200,100,500));
	vec_set(camera.pan,vector(0,-10,0));

	// generate ground plane
	ENTITY *ground = ent_createterrain(NULL,vector(0,0,0),16,16,1000);
	bmap_fill(bmap_for_entity(ground,0),COLOR_GREEN,100);
	pXent_settype(NULL,PH_STATIC,PH_PLANE);
	
	// generate flag pole	
	ENTITY *pole = ent_create(CUBE_MDL,vector(0,0,40*8),NULL);
	vec_set(pole.scale_x,vector(0.5,0.5,40));
	vec_set(pole.pan,vector(0,0,0));
	vec_set(pole.blue,COLOR_WHITE);
	set(pole,SHADOW|CAST);
	pXent_settype(pole,PH_STATIC,PH_BOX);

	// generate flag
	ENTITY *cloth = ent_create("clothflag.mdl",NULL,NULL);
	vec_set(cloth.pan,vector(0,0,0));
	cloth.material = mtl_twosided_alpha;
	cloth.ambient = 50;
	set(cloth,SHADOW|CAST);
	set(cloth.material,PASS_SOLID); // required for shadow
	
	// attach flag to pole
	c_setminmax(pole);
	c_setminmax(cloth);
	vec_set(cloth.x,vector(
	pole.x,
	pole.y+(cloth.max_y-cloth.min_y)/2,
	pole.z+pole.max_z-(cloth.max_z-cloth.min_z)/2));
	
	// setup flag cloth	
	var cloth_options[40];
	memcpy(cloth_options,CLOTH_DEFAULT,40*sizeof(var));
	vec_set(cloth_options[25],vector(-10,20,0));  // external acceleration
	vec_set(cloth_options[28],vector(5,10,5));  // random wind acceleration
	cloth_options[9] = 4; // Tear Factor
	cloth_options[37] |= NX_CLF_GRAVITY|NX_CLF_BENDING|NX_CLF_COLLISION_TWOWAY|NX_CLF_SELFCOLLISION|NX_CLF_TEARABLE|NX_CLF_BENDING_ORTHO;
	
	pXent_cloth(cloth,pole,NX_CLOTH_ATTACHMENT_TWOWAY,0,0,cloth_options);
	
	var counter = 5;
	while(counter > 0)
	{
		counter -= time_frame / 16;
		DEBUG_VAR(counter, 0);
		wait(1);
	}
	
	pXent_settype( cloth, 0, 0 );
	ptr_remove(cloth);
	pXent_reset_cloth();
}

Posted By: rojart

Re: Unregister cloth - 04/30/20 21:01

Ok, thanks for the problem, I will try to solve this problem, but it may take a while.

ps
Do you already know PhysX 4.x and PhysX 5.0?
Posted By: 3run

Re: Unregister cloth - 04/30/20 21:17

Nope, I didn't know that there are newer versions above 3.x (didn't really follow their development/updates).
I would be happy to have even 3.x working in acknex (not even talking about new 4.x or 5.x) grin
But unfortunately, I guess this never going to happen.
© 2024 lite-C Forums