Notifications
Clear all

[Closed] After add mod CollapseObject() stack? C++

Using the sdk sample to add a ResetXForm mod on an object, I’m having a hard time collapsing the stack


		INode *node = ip->GetSelNode(i);
		Matrix3 ntm, ptm, rtm(1), piv(1), tm;
 
		// Get Parent and Node TMs
		ntm = node->GetNodeTM(ip->GetTime());
		ptm = node->GetParentTM(ip->GetTime());
 
		// Compute the relative TM
		ntm = ntm * Inverse(ptm);
 
		// The reset TM only inherits position
		rtm.SetTrans(ntm.GetTrans());
 
		// Set the node TM to the reset TM 
		tm = rtm*ptm;
		node->SetNodeTM(ip->GetTime(), tm);
 
		// Compute the pivot TM
		piv.SetTrans(node->GetObjOffsetPos());
		PreRotateMatrix(piv,node->GetObjOffsetRot());
		ApplyScaling(piv,node->GetObjOffsetScale());
 
		// Reset the offset to 0
		node->SetObjOffsetPos(Point3(0,0,0));
		node->SetObjOffsetRot(IdentQuat());
		node->SetObjOffsetScale(ScaleValue(Point3(1,1,1)));
 
		// Take the position out of the matrix since
		// we don't reset position
		ntm.NoTrans();
 
		// Apply the offset to the TM
		ntm = piv * ntm;
 
		// Apply a derived object to the node's object
		Object *obj = node->GetObjectRef();
		IDerivedObject *Refobj = CreateDerivedObject(obj);
 
		// Create an XForm mod
		SimpleMod *mod = (SimpleMod*)ip->CreateInstance(OSM_CLASS_ID,Class_ID(CLUSTOSM_CLASS_ID,0));
 
		// Apply the transformation to the mod.
		SetXFormPacket pckt(ntm);
		mod->tmControl->SetValue(ip->GetTime(),&pckt);
 
		// Add the modifier to the derived object.
		ModContext* Xform = new ModContext(new Matrix3(1), NULL, NULL);
		Refobj->AddModifier(mod, Xform);
		node->SetObjectRef(Refobj);

		// collapse object stack
		obj->CollapseObject();
		Refobj->CollapseObject();

I did try CollapseObject for my object and the Object Reference. What did I miss?

3 Replies

from the samples, something you may be able to use

void TreeViewUtil::Collapse(INode *node)
 {
 	ICustAttribCollapseManager * iCM = ICustAttribCollapseManager::GetICustAttribCollapseManager();
 
 	Interface7 *ip= GetCOREInterface7();
 
 	Object *oldObj = node->GetObjectRef();
 	SClass_ID sc = oldObj->SuperClassID();
 
 	theHold.Begin();
 	if (theHold.Holding()) 
 	{
 		theHold.Put(new ObjManipulatorRestore);
 		theHold.Put(new CollapseRestore());
 		theHold.Put(new UpdateUIRestore());
 	}
 	//LAM : added following to handle extension objects 8/2/00
 	// NH 14 April 04: Added support for the maintaining CAs on stack collapse
 	// LAM - 7/22/05 - Collapse does not affect WSMs, So we shouldn't enumerate them....
 	bool ignoreBaseObjectCAs = false;
 	if(iCM && iCM->GetCustAttribSurviveCollapseState())
 	{
 		NotifyCollapseMaintainCustAttribEnumProc2 PreNCEP(true,node);
 		EnumGeomPipeline(&PreNCEP,oldObj);
 	}
 	else
 	{
 		NotifyCollapseEnumProc PreNCEP(true,node);
 		EnumGeomPipeline(&PreNCEP,oldObj);
 	}
 
 	ip->StopCreating();
 	ip->ClearPickMode();
 	
 	if (sc == GEN_DERIVOB_CLASS_ID)
 	{
 		// stack not empty, collapse stack 
 		ObjectState os = oldObj->Eval(ip->GetTime());			
 
 		HoldSuspend hs; 
 		//LAM : modified following to handle polymesh 7/21/00
 //		Object *obj = (Object*)os.obj->Clone();
 		Object *obj = os.obj->CollapseObject();
 		// Now get rid of superfulous objects 		
 		if(os.obj == obj)
 		{
 			// if we are cloning the base object, the clone will take care of the CAs
 			Object *theBaseObject = oldObj->FindBaseObject();
 			if (obj == theBaseObject)
 				ignoreBaseObjectCAs = true;
 
 			obj = (Object*)obj->Clone();
 		}
 		hs.Resume();
 
 		obj->SetSubSelState(0); // Reset the selection level to object level (in case it happens to have an edit mesh modifier
 		oldObj->SetAFlag(A_LOCK_TARGET);
 		node->SetObjectRef(obj);
 		ip->InvalidateObCache(node);
 		node->NotifyDependents(FOREVER, 0, REFMSG_SUBANIM_STRUCTURE_CHANGED);
 
 		//LAM : added following to handle extension objects 8/2/00
 		// Notify all mods and objs in the pipleine, that they have been collapsed
 		// NH 14 April 04: Added support for the maintaining CAs on stack collapse
 		if(iCM && iCM->GetCustAttribSurviveCollapseState())
 		{
 			NotifyCollapseMaintainCustAttribEnumProc2 PostNCEP(false,node,ignoreBaseObjectCAs,obj);
 			EnumGeomPipeline(&PostNCEP,oldObj);
 		}
 		else
 		{
 			NotifyCollapseEnumProc PostNCEP(false,node,obj);
 			EnumGeomPipeline(&PostNCEP,oldObj);
 		}
 
 		oldObj->ClearAFlag(A_LOCK_TARGET);
 		oldObj->MaybeAutoDelete();
 
 		if (theHold.Holding())
 		{
 			theHold.Put(new CollapseRestore (TRUE));
 			theHold.Put(new ObjManipulatorRestore (TRUE));
 		}
 		theHold.Accept(GetString(IDS_COLLAPSE));
 	}
 }

you can save yourself an awful lot of questions/time by using visual studios very excellent find in files feature (the binoculars on a folder icon on the main menu bar). Add the sdk samples folder as the search base and lookup the proper usage of most the stuff in the sdk.

This looks good,
I will get this to work with no questions my friend

Thanks