Notifications
Clear all

[Closed] Sdk disable modifier

Could someone point Mr in the right direction here. I want to create a function which disables every modifier of an object based in a class name I pass to the function as an argument.


Modifier* FindPhysiqueModifier (INode* nodePtr)
{
  // Get object from node. Abort if no object.
  Object* ObjectPtr = nodePtr->GetObjectRef();
 
  if (!ObjectPtr) return NULL;
  // Is derived object ?
  while (ObjectPtr->SuperClassID() == GEN_DERIVOB_CLASS_ID && ObjectPtr)
  {
    // Yes -> Cast.
     IDerivedObject *DerivedObjectPtr = ( IDerivedObject *)(ObjectPtr);
 
    // Iterate over all entries of the modifier stack.
    int ModStackIndex = 0;
    while (ModStackIndex < DerivedObjectPtr->NumModifiers())
    {
      // Get current modifier.
      Modifier* ModifierPtr = DerivedObjectPtr->GetModifier(ModStackIndex);
 
      // Is this Physique ?
      if (ModifierPtr->ClassID() == Class_ID(PHYSIQUE_CLASS_ID_A, PHYSIQUE_CLASS_ID_B)) {
        // Yes -> Exit.
        return ModifierPtr;
      }
 
      // Next modifier stack entry.
      ModStackIndex++;
    }
    ObjectPtr = DerivedObjectPtr->GetObjRef();
  }
 
  // Not found.
  returnNULL;
}

3 Replies

Untested but should work

void DisableModifiersByClassName(INode* node, const MSTR& className)
{
    if (!node)
        return;

    auto object = node->GetObjectRef();

    while (object && object->SuperClassID() == DERIVOB_CLASS_ID) {
        auto derivedObject = static_cast<IDerivedObject*>(object);

        for (auto i = 0; i < derivedObject->NumModifiers(); ++i) {
            auto modifier = derivedObject->GetModifier(i);

            MSTR modifierClassName;
            modifier->GetClassName(modifierClassName);

            if (_wcsicmp(modifierClassName, className) == 0)
                modifier->DisableMod();
        }

        object = derivedObject->GetObjRef();
    }
}

1 Reply
(@jokermartini)
Joined: 11 months ago

Posts: 0

error: auto derivedObject = static_cast<IDerivedObject*>(object);

Invalid type conversion why is this?

Hi, I changed the code a little bit, so now it should work, its still untested, but if you have any issues, let me know ^^


void DisableModifiersByClassName(INode* node, MSTR className){
	if (node) {
		Object* obj = node->GetObjectRef();
		if (obj->SuperClassID() == DERIVOB_CLASS_ID) {
			IDerivedObject* D_obj = static_cast<IDerivedObject*>(obj);

			for (int i = 0; i < D_obj->NumModifiers(); i++) {
				Modifier* mod = D_obj->GetModifier(i);

				MSTR modClassName;
				mod->GetClassName(modClassName);

				if (_wcsicmp(modClassName, className) == 0)
					mod->DisableMod();
			}
		}
	}
}