Jump to content
Developer Wiki and Function Reference Links ×

Working with materials in a plugin event enabled…


Paolo

Recommended Posts

I have an event-enabled plugin that manages materials.

I'd like to be notified when the material settings change. I see there is the function:

 

FUNCTION vsoStateMaterialChng(
				hObj                : HANDLE;
				VAR materialID      : INTEGER;
				VAR deleted         : BOOLEAN;
				VAR previousTexture : INTEGER): BOOLEAN;

I have placed it in the reset event, in the same manner as IsNewCustomObject(parmName) or vsoStateGetParamChng( parmHand, widgID, prmIndex, oldValue )

but I noticed that vsoStateMaterialChng get never called whenever I change materials or set the material checkbox on / off!

Is there a reason? How should be it used?

Link to comment

I'm in the same boat. I could never get vsoStateMaterialChng to work so I gave up.

 

I assume you are invoking (in kObjOnInitXProperties:) the Material check box and material list with  result := SetObjPropVS(kObjXPropSupportBuildingMaterialInOIP, TRUE );

 

Just a thought (possible workaround) - you could try creating an invisible "Material" parameter ie "__material".

 

In the kResetEventID: you could get the current Material settings (with GetObjMaterialName), compare with "__material" value, if different then material has changed and do somethng, then store current material settings to "__material" - if that makes sense.

 

I suspect maybe vsoStateMaterialChng may be invoked by a change to "__material" but who knows.

  • Like 1
Link to comment

@BillW

 

Quote

I assume you are invoking (in kObjOnInitXProperties:) the Material check box and material list with  result := SetObjPropVS(kObjXPropSupportBuildingMaterialInOIP, TRUE );

Yes, I have the material controls in the OIP, but I need some notification when the user changes it…

I'll give your suggestion a try, thank you.

Link to comment

@BillW

I got your suggestion, and applied it this way:
Added a (hidden) _Material parameter of type Static text

I already have a parameter Material of type Material

I declare in Vars materialChange : BOOLEAN;

 

in the prep event:

kObjOnWidgetPrep:
BEGIN
	
    …
	old_Material_Name := GetRField(parmHand, parmName, '_Material'); {parmHand and parmName are from GetCustomObjectInfo()}
	result := GetObjMaterialName(parmHand, new_Material_Name); {when the material checkbox is deselected, new_Material_Name = ''}
	
	{check if old and new differs.}
	materialChange := Not (old_Material_Name = new_Material_Name);

	{now set _Material to store the new_Material_Name}
	setRField(parmHand, parmName, '_Material', new_Material_Name);
    
    {at this point it's necessary to reset the plugin to get this working} 
    if materialChange then resetObject(parmHand);

    …
    
	vsoSetEventResult( -8 {kObjectEventHandled} );
END;

 

later, in the reset event I can get the updated material of the plugin via GetObjMaterialHandle(parmHand).

There is no way to do this through vsoStateGetParamChng() or the more specific vsoStateMaterialChng() that seems to not work at all…

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...