General Question mesh handles/UNIT

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
So rather then define the animation using the mesh index number I want to use a mesh handle. The reason is the mesh index changes.
compiles fines but I get a CTD when I run it


h:
Code:
    MESHHANDLE meshhg_Vessel, meshhg_VC, meshhg_sm[1];

    UINT meshi_Vessel, meshi_sm[1];

cpp:
Code:
ORION2NEW::ORION2NEW (OBJHANDLE hObj, int fmodel)
: VESSEL2 (hObj, fmodel)


{
    mode = 0;
    
    fairing = 0;
    ofs = _V(0, 0, 0);
    string[0] = 0;

    tex_rcs = oapiRegisterExhaustTexture("exhaust_crcs");
    tex_main = oapiRegisterExhaustTexture("exhaust_crcs");

    cmMesh = oapiLoadMeshGlobal("Orion-MPCV\\orion-CM");
    meshi_sm[0] = AddMesh(meshhg_sm[1] = oapiLoadMeshGlobal("Orion-MPCV\\orion606-SM"));
...

Code:
void ORION2NEW::DefineAnimations(void)

{
    anim_HGA = CreateAnimation(0.0);
    static UINT HGAGrp[4] = { GRP_HGA1, GRP_HGA2, GRP_HGA3, GRP_HGA4 };
    static MGROUP_ROTATE HGA(meshi_sm[0], HGAGrp, 4, _V(0, 1.948546, .2253037), _V(1, 0, 0), (float)(90 * RAD));
    AddAnimationComponent(anim_HGA, 0, 1, &HGA);

Code:
case 10:
        AddMesh(coverMesh, &ofs);
        AddMesh(meshhg_sm[1]);
    //    AddMesh(solar0Mesh, &ofs);
        AddMesh(lasMesh, &ofs);
        if (fairing) {
            AddMesh(fair1Mesh, &ofs);
            AddMesh(fair2Mesh, &ofs);
            AddMesh(fair3Mesh, &ofs);
        }
        break;
 

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,666
Reaction score
100
Points
78
I don't know the reason of the CTD, but why do you use vessel2? you can use vesssel 3 or 4
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
That what the original Orion was written. Converted to vessel 3. Still CTd. Trying to run debugger get errors.

---------- Post added 09-23-16 at 05:03 AM ---------- Previous post was 09-22-16 at 08:12 PM ----------

Not sure what is wrong.
it all works until I set the animation mesh number. Then CTD and debugger will not load file from orbiter

h
Code:
	MESHHANDLE meshhg_Vessel, meshhg_VC;

	UINT meshi_sm;

cpp:
Code:
ORION2NEW::ORION2NEW(OBJHANDLE hObj, int fmodel)
: VESSEL3(hObj, fmodel)
{
	mode = 0;
	
	fairing = 0;
	ofs = _V(0, 0, 0);
	string[0] = 0;

	tex_rcs = oapiRegisterExhaustTexture("exhaust_crcs");
	tex_main = oapiRegisterExhaustTexture("exhaust_crcs");

	cmMesh = oapiLoadMeshGlobal("Orion-MPCV\\orion-CM");
	//meshhg_Vessel =  oapiLoadMeshGlobal("Orion-MPCV\\orion606-SM"));
	meshi_sm = AddMesh(meshhg_Vessel = oapiLoadMeshGlobal("Orion-MPCV\\orion606-SM"));

So if I do this:
Code:
anim_HGA = CreateAnimation(0.0);
	static UINT HGAGrp[4] = { GRP_HGA1, GRP_HGA2, GRP_HGA3, GRP_HGA4 };
	static MGROUP_ROTATE HGA(meshi_sm, HGAGrp, 4, _V(0, 1.948546, .2253037), _V(1, 0, 0), (float)(90 * RAD));
	AddAnimationComponent(anim_HGA, 0, 1, &HGA);
a CTD and debugger issues.
but this works fine:
Code:
anim_HGA = CreateAnimation(0.0);
	static UINT HGAGrp[4] = { GRP_HGA1, GRP_HGA2, GRP_HGA3, GRP_HGA4 };
	static MGROUP_ROTATE HGA(5, HGAGrp, 4, _V(0, 1.948546, .2253037), _V(1, 0, 0), (float)(90 * RAD));
	AddAnimationComponent(anim_HGA, 0, 1, &HGA);
 

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,666
Reaction score
100
Points
78
I'm not sure you can do
Code:
meshi_sm=AddMesh(meshhg_Vessel = oapiLoadMeshGlobal...
Instead of breaking this in two:
Code:
meshhg_Vessel = oapiLoadMeshGlobal...
meshi_sm=AddMesh (meshhg_Vessel...
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
Did this:
Code:
	meshhg_Vessel = oapiLoadMeshGlobal("Orion-MPCV\\orion606-SM");
	meshi_sm = AddMesh(meshhg_Vessel);

still ctd if I replace the "5" with the meshi_sm.

So in the scenario it is in mode 0
Code:
	switch (mode) {
	case 0:
		AddMesh(coverMesh, &ofs);
		AddMesh(meshhg_Vessel);
	//	AddMesh(solar0Mesh, &ofs);
		break;


---------- Post added at 09:16 AM ---------- Previous post was at 07:00 AM ----------

So I am trying a different approach.
I am adding all the meshes and then setting the visibility according to the mode/case.

But now no meshes are seen:(

In the load scenario it looks at the mode. which in this case is 0. Then it goes to setCofig0 which then goes to reload meshes.

Code:
ORION2NEW::ORION2NEW(OBJHANDLE hObj, int fmodel)
: VESSEL3(hObj, fmodel)
{
	mode = 0;
	
	fairing = 0;
	ofs = _V(0, 0, 0);
	string[0] = 0;

	tex_rcs = oapiRegisterExhaustTexture("exhaust_crcs");
	tex_main = oapiRegisterExhaustTexture("exhaust_crcs");


	fair1h = fair2h = fair3h = fairLh = 0L;

	SetConfig0_Ready();
	mfds_left.ngroup = 0;
	mfds_right.ngroup = 1;
	mfds_co.ngroup = 3; //
	huds.ngroup = 2;
	huds.size = 0.25;
	// add meshes then set visibility
	astroMeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion-astro"));// mesh0
	SetMeshVisibilityMode(astroMeshUINT, MESHVIS_NEVER);

	cmMeshUINT = AddMesh(oapiLoadMeshGlobal("Orion - MPCV\\orion - CM"));// mesh1
	SetMeshVisibilityMode(cmMeshUINT, MESHVIS_NEVER);

	smMeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion606-SM"));// mesh2
	SetMeshVisibilityMode(smMeshUINT, MESHVIS_NEVER);

	cockpitMeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion-cockpit"));// mesh3
	SetMeshVisibilityMode(cockpitMeshUINT, MESHVIS_NEVER);

	panelMeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion-panel"));// mesh4
	SetMeshVisibilityMode(panelMeshUINT, MESHVIS_NEVER);

	coverMeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion-cover"));// mesh5
	SetMeshVisibilityMode(coverMeshUINT, MESHVIS_NEVER);

	hatchMeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion-hatch"));// mesh6
	SetMeshVisibilityMode(hatchMeshUINT, MESHVIS_NEVER);

	drogueMeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion-drogue"));// mesh7
	SetMeshVisibilityMode(drogueMeshUINT, MESHVIS_NEVER);

	chuteMeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion-chute"));// mesh8
	SetMeshVisibilityMode(chuteMeshUINT, MESHVIS_NEVER);

	fair1MeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion-fair1"));// mesh9
	SetMeshVisibilityMode(fair1MeshUINT, MESHVIS_NEVER);

	fair2MeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion-fair2"));// mesh10
	SetMeshVisibilityMode(fair2MeshUINT, MESHVIS_NEVER);

	fair3MeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion-fair3"));// mesh11
	SetMeshVisibilityMode(fair3MeshUINT, MESHVIS_NEVER);

	lasMeshMeshUINT = AddMesh(oapiLoadMeshGlobal("Orion-MPCV\\orion-las"));// mesh12
	SetMeshVisibilityMode(lasMeshMeshUINT, MESHVIS_NEVER);

Code:
void ORION2NEW::ReloadMeshes(void)
{
//	UINT meshidx;
	double dz;		// z-offset for various configs

	ClearMeshes(TRUE);

	switch (mode) {
	case 0:
	case 1:	dz = 0;	break;
	case 2:
	case 3:
	case 4:
	case 5:
	case 6:	dz = -2.06;	break;	// capsule config
	case 10:
	case 11: dz = 0;	break;
	case 12: dz = -2;	break;
	}

	ofs = _V(0, 0, 0 + dz);
	ofs_camera = _V(-0.41, 1.6, 2.2 + dz);	// left hand seat, eye-point of docking window
	ofs_hud = _V(0, 1.6, 2.5 + dz);

	ofs_astro[0] = _V(0.41, 1.1, 2.3 + dz);    // location of crew members
	/*	ofs_astro[1] =  _V( 0.42, 1.1, 1.4+dz);
	ofs_astro[2] =  _V( 1.26, 1.1, 1.4+dz);
	ofs_astro[3] =  _V(-1.26, 1.1, 1.4+dz);
	ofs_ummu =  _V(3,0,2.5+2*dz);
	*/

	//	ofs_ares =  _V(0,0,36.7);			// z = 36.2, d = -1.3
	//	ofs_1 =		_V(0,0,-16);
	//	ofs_2 =		_V(0,0, 20);

	SetCameraOffset(ofs_camera);
	SetMeshVisibilityMode(astroMeshUINT, MESHVIS_EXTERNAL | MESHVIS_VC);
	SetMeshVisibilityMode(cmMeshUINT, MESHVIS_EXTERNAL | MESHVIS_VC);
	SetMeshVisibilityMode(cockpitMeshUINT, MESHVIS_EXTERNAL | MESHVIS_VC);

	//SetMeshVisibilityMode(AddMesh(astroMesh, &ofs_astro[0]), MESHVIS_EXTERNAL | MESHVIS_VC);
	//SetMeshVisibilityMode(AddMesh(cmMesh, &ofs), MESHVIS_EXTERNAL | MESHVIS_VC);
	//SetMeshVisibilityMode(astroMesh), MESHVIS_EXTERNAL | MESHVIS_VC);

	//	SetMeshVisibilityMode (AddMesh (cockpitMesh, &ofs), MESHVIS_EXTERNAL | MESHVIS_VC);

	//meshidx = AddMesh(panelMesh, &ofs);
	SetMeshVisibilityMode(panelMeshUINT, MESHVIS_EXTERNAL | MESHVIS_VC);

	//mfds_left.nmesh = meshidx;
	//mfds_right.nmesh = meshidx;
	//mfds_co.nmesh = meshidx;  //
	//	oapiVCRegisterMFD (MFD_LEFT, &mfds_left);
	//	oapiVCRegisterMFD (MFD_RIGHT,&mfds_right);

//	huds.nmesh = meshidx;
//	huds.hudcnt = ofs_hud;
	//oapiVCRegisterHUD(&huds); // register changes in HUD parameters

//	SetMeshVisibilityMode(AddMesh(hatchMesh, &ofs), MESHVIS_VC | MESHVIS_EXTERNAL);
	SetMeshVisibilityMode(hatchMeshUINT, MESHVIS_EXTERNAL | MESHVIS_VC);
	switch (mode) {
	case 0:
	//	AddMesh(coverMesh, &ofs);
		SetMeshVisibilityMode(coverMeshUINT, MESHVIS_EXTERNAL | MESHVIS_VC);
		SetMeshVisibilityMode(smMeshUINT, MESHVIS_EXTERNAL | MESHVIS_VC);

		//AddMesh(meshhg_Vessel);
	//	AddMesh(solar0Mesh, &ofs);
		break;

Code:
void ORION2NEW::clbkLoadStateEx (FILEHANDLE scn, void *status)
{
	char *line;
	int value;
	while (oapiReadScenario_nextline (scn, line)) 
	{
		

		if (!_strnicmp(line, "JOINT1", 6)) {
			sscanf(line + 6, "%lf", &JOINT1_proc);
		}

		if (!_strnicmp(line, "JOINT2", 6)) {
			sscanf(line + 6, "%lf", &JOINT2_proc);
		}
		
		if (!_strnicmp(line, "JOINT7", 6)) {
			sscanf(line + 6, "%lf", &ARM3_proc);
		}
		if (!_strnicmp(line, "HGA", 3)) {
			sscanf(line + 3, "%d%lf", &HGA_status, &HGA_proc);
		}

		// call this method to let PayloadManager to load its internal parameters
		
			if (!_strnicmp(line, "MODE", 4)) {
				sscanf_s(line + 4, "%d", &value);
				mode = (int)value;
			}
			if (!_strnicmp(line, "FAIRING", 7)) {
				fairing = 1;
			}
			if (!_strnicmp(line, "WATER", 5)) {
				water = 1;
			}

		

		switch (mode) {
		case 0:
			SetConfig0_Ready();
			break;

Code:
	void ORION2NEW::SetConfig0_Ready(void)
	{
		SetSize(6);
		SetEmptyMass(CM_DRYMASS + CM_FUEL + SM_DRYMASS);
		SetPMI(_V(2.3, 2.3, 2));

		SetCW(0.5, 0.5, 1, 1);
		SetCrossSections(_V(35, 35, 24));
		SetRotDrag(_V(0.5, 0.5, 0.3));

		SetCOG_elev(2.5);

		SetPitchMomentScale(1e-4);
		SetBankMomentScale(1e-4);

		SetDockParams(_V(0, 0, 4.1), _V(0, 0, 1), _V(0, 1, 0));

		SetThrusters1_Orbit();
		mode = 0;
		ReloadMeshes();
	}
 
Last edited:

fred18

Addon Developer
Addon Developer
Donator
Joined
Feb 2, 2012
Messages
1,666
Reaction score
100
Points
78
I think that's the ClearMeshes call. You load all the meshes and set them as invisible, ok. But if you Clear all the Meshes then you unload all of them, so even if afterwards you try to change their visibility you don't have them anymore and you can't see anything
 
Top