void mrShaderButtonHandler::OnCommand() {

	DbgAssert(m_dialogHWnd != NULL);

	// Add the filter
	IMtlBrowserFilter_Manager* filterManager = Get_IMtlBrowserFilter_Manager();
	if(filterManager != NULL) {
		filterManager->AddFilter(m_shaderFilter);
	}

	// Browse for a texmap
	BOOL newMat;
	BOOL cancel;
	MtlBase* mtlBase = GetCOREInterface()->DoMaterialBrowseDlg(m_dialogHWnd, (BROWSE_MAPSONLY | BROWSE_INCNONE), newMat, cancel);
	if(!cancel) {
		DbgAssert((mtlBase == NULL) || ((mtlBase->SuperClassID() == TEXMAP_CLASS_ID)));

		Texmap* texmap = static_cast<Texmap*>(mtlBase);
		SetShader(texmap);
	
		Update();
	}

	if(filterManager != NULL) {
		filterManager->RemoveFilter(m_shaderFilter);
	}
}
void CMaxMaterialCollection::OnScratchLibChanged()
{
#ifdef PERSIST_SCRATCH

	//figure out which materials were added or deleted and fire appropriate events.
	//this is currently pretty inefficient since we hav to walk the entire list of materials to 
	//figure out which ones to add or remove. Could improve this by adding better messagin from 
	//mpSceneLib

	if(s_PreventRecursion)
		return;
	s_PreventRecursion = true;

	int numLibMtls = mpScratchMtlLib->Count();
	//int numMtlsWrapped = mMtlMap.size();

	//adding material
	if(numLibMtls > mLastScratchMtlLibSize )
	{

		for(int i=0; i< numLibMtls; i++)
		{
			//get the max material to be wrapped
			MtlBase *pMtl = mpScratchMtlLib->operator[](i);
			assert(pMtl); //can this be empty?
			if(pMtl == NULL || pMtl->SuperClassID() != MATERIAL_CLASS_ID)
				continue;

			DWORD_PTR key = (DWORD_PTR) pMtl;

			if(mMtlMap.find(key)!= mMtlMap.end())
				continue;//found

			//Create the wrapper
			CComObject<CMaxMaterial> *pWrapperObject;
			HRESULT hr = CComObject<CMaxMaterial>::CreateInstance(&pWrapperObject);
			assert(SUCCEEDED(hr));
			if(!SUCCEEDED(hr))
			{
				s_PreventRecursion = false;
				return;
			}

			//Initalize the new wrapper
			pWrapperObject->setCollection(this);
			//TODO validate the downcast
			pWrapperObject->setMtl((Mtl *)pMtl);

		}
	}
	s_PreventRecursion = false;
	mLastScratchMtlLibSize = numLibMtls;
#endif
}
//stop gap method
//if the material editor becomes visible and teh material in it is not
//already wrapped we better add it. 
void CMaxMaterialCollection::OnMeditVisible()
{
	if(!m_suspendCount)
	{
		MtlBase *m = GetMtlEditInterface()->GetCurMtl();
		if(m->SuperClassID()!=MATERIAL_CLASS_ID)
			return;
		CComPtr<IMaxMaterial> pWrapper;
		FindItemKey((DWORD_PTR)(m), &pWrapper.p);
		if(!pWrapper)
		{
			MakeWrapperObject((Mtl*)m);
			FindItemKey((DWORD_PTR)(m), &pWrapper.p);
			if(pWrapper)
				AddPersistence(pWrapper);
		}
	}
}
Beispiel #4
0
void ViewportLoader::ActivateEffect(MtlBase * mtl, BOOL state)
{

	ICustAttribContainer* cc = mtl->GetCustAttribContainer();
	if(!cc)
		return;
	MtlBase * mb = (MtlBase *) cc->GetOwner();
	if(!mb)
		return;

	if(state && effect)
		mb->SetMtlFlag(MTL_HW_MAT_ENABLED);
	else
		mb->ClearMtlFlag(MTL_HW_MAT_ENABLED);
	
	GetCOREInterface()->ForceCompleteRedraw();

}
Beispiel #5
0
bool ViewportLoader::IsLoaderActiveInMedit()
{
	MtlBase* mtl = FindOwnerMaterial();

	if ( mtl && mtl->TestMtlFlag( MTL_BEING_EDITED ) )
	{
		ICustAttribContainer * cc = mtl->GetCustAttribContainer();
		if ( cc )
		{
			for( int i = 0; i < cc->GetNumCustAttribs(); i++ )
			{
				if ( this == cc->GetCustAttrib( i ) )
					return true;
			}
		}
	}

	return false;
}
Beispiel #6
0
bool mrShaderFilter::Include(MtlBase& mtlBase, DWORD flags) {

	// Validate using the class ID
	ClassDesc* classDesc = GetCOREInterface()->GetDllDir().ClassDir().FindClass(mtlBase.SuperClassID(), mtlBase.ClassID());
	DbgAssert(classDesc != NULL);
	if(classDesc != NULL) {
		return Include(*classDesc, flags);
	}
	else {
		return true;
	}
}
Beispiel #7
0
static INT_PTR CALLBACK DefaultDlgProc(
		HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
		case WM_INITDIALOG:
			theSCPUtil.Init(hWnd);
			break;

		case WM_DESTROY:
			theSCPUtil.Destroy(hWnd);
			break;

		case WM_COMMAND:
			switch (LOWORD(wParam)) {
				case IDC_CLOSE:
					theSCPUtil.iu->CloseUtility();
					break;

				case IDC_BTN1:
					{
					// Open a material browser to find the material to inspect
					Interface *ip = theSCPUtil.ip;

					BOOL newMat,cancel;
					MtlBase *mtlb = ip->DoMaterialBrowseDlg(hWnd,BROWSE_MATSONLY|BROWSE_INSTANCEONLY,newMat,cancel);


					if(!cancel&&mtlb)
					{
						// Check to see if this is one of ours
						if(mtlb->ClassID() == GAMEMTL_CLASSID)
						{

						Mtl *scp = (Mtl*)mtlb;

						// Get the number of pblock2s and references on the mtl
						int num_pblock2 = scp->NumParamBlocks();
						int num_refs = scp->NumRefs();

							// Get the custom parameters
							// We defined two custom parameters in our scripted plugin
							// called GM_Custom1 and GM_Custom2
							// When we walk through the retrieved paramblock2, we can
							// get access to the hardwired internal name and check that
							// against our own names, to see if its the parameter we want
							// This way, its position-independant : it doesn't matter
							// where the parameters ARE in the pblock2, we will find them.
							if(num_pblock2>0)
							{
								// Get the first paramblock2 (the only one in our scripted plugin)
								IParamBlock2 *pb2 = scp->GetParamBlock(0);
								// The the descriptor to 'decode'
								ParamBlockDesc2 *pdc = pb2->GetDesc();

								// Loop through all the defined parameters therein
								for(int i=0;i<pdc->count;i++)
								{
									// Get a ParamDef structure for the parameter
									ParamDef pD = pdc->paramdefs[i];
									

									// Now compare against our names
									// When we match against one we want, we get the 
									// ParamID from the ParamDef and pass it to GetValue of ParamBlock2
									// which will retrieve us the value
									if(stricmp(pD.int_name,"GM_Custom1")==0)
									{
										int itmp = pb2->GetInt(pD.ID,theSCPUtil.ip->GetTime());

										char s[255];
										sprintf(s,"%i",itmp);
										SetWindowText(GetDlgItem(hWnd,IDC_GM1),s);
									}

									if(stricmp(pD.int_name,"GM_Custom2")==0)
									{
										float ftmp = pb2->GetFloat(pD.ID,theSCPUtil.ip->GetTime());

										char s[255];
										sprintf(s,"%.1f%%",ftmp);
										SetWindowText(GetDlgItem(hWnd,IDC_GM2),s);
									}

								}

								// Mustn't forget to...
								pb2->ReleaseDesc();
							}


							// With a scripted plugin that overrides/extends an existing plugin,
							// the original "delegate" is kept as Reference 0.
							// If the scripted plugin is a brand new one, Ref 0 will be the first
							// paramblock2, and ref n will be paramblock2 n, if applicable.
							//
							// In this case, we get a poitner back to the original Standard Material
							// that we override, and get its Diffuse color
							Mtl *delegate = (Mtl*)scp->GetReference(0);
							theSCPUtil.cs->SetColor(delegate->GetDiffuse());

						}
						else
						{
							// The user chose something that wasn't a GameMtl class
							MessageBox(hWnd,"Chosen Material Is NOT a GAMEMTL!","Error",MB_OK);
						}
					}

					}
					break;
			}
			break;


		default:
			return FALSE;
	}
	return TRUE;
}
void CMaxMaterialCollection::OnSceneLibChanged()
{
	//figure out which materials were added or deleted and fire appropriate events.
	//this is currently pretty inefficient since we hav to walk the entire list of materials to 
	//figure out which ones to add or remove. Could improve this by adding better messagin from 
	//mpSceneLib

	if(s_PreventRecursion)
		return;
	s_PreventRecursion = true;

	int numLibMtls = mpSceneMtlLib->Count();
	//int numMtlsWrapped = mMtlMap.size();

	//adding material
	if(numLibMtls > mLastSceneMtlLibSize )
	{

		for(int i=0; i< numLibMtls; i++)
		{
			//get the max material to be wrapped
			MtlBase *pMtl = mpSceneMtlLib->operator[](i);
			//assert(pMtl); //can this be empty?
			//the assertion is no good because a makerefrestore may be setting the ref from
			//lib to material to null. The lib notifies us.
			if(pMtl == NULL || pMtl->SuperClassID() != MATERIAL_CLASS_ID)
				continue;

			//TODO validate the downcast
			HRESULT hr = MakeWrapperObject(static_cast<Mtl*>(pMtl));
			assert(SUCCEEDED(hr));
			if (!SUCCEEDED(hr))
			{
				s_PreventRecursion = false;
				return;
			}

		}
	}
	//removing material
	/*
	We no longer track removals other than to update our record of the new size (mLastSceneMtlLibSize)
	The idea is that we keep all of our wrappers alive unless explicitly destroyed. 
	We assume that all new materials will pass through the scenematerials lib via OkMtlForScene or some equivalent method.

	else if(numLibMtls < mLastSceneMtlLibSize )
	{
		ifxClxnType::iterator it=mMtlMap.begin();
		while(it!=mMtlMap.end())
		{
			Mtl *pMtlToCheck = (Mtl *) (*it).first;
			if(mpSceneMtlLib->FindMtl(pMtlToCheck) == -1)//no longer in scene
			{
				pMtlWrapper.Attach((*it).second);
#ifdef XXXRECYCLE_MATS
			//add the wrapper to our data structure
				mRecycledMtlMap.insert(*it);
				pMtlWrapper.p->AddRef();
#endif
				Fire_OnMaterialRemoved(this, pMtlWrapper);
				it = mMtlMap.erase(it);
				pMtlWrapper.Release();
			}
			else
				it++;
		}
	}
	*/
	//update our record of the size of sceneMtlLib
	mLastSceneMtlLibSize = numLibMtls;
	s_PreventRecursion = false;
/* TO DO implement an integrity checker
#ifndef NDEBUG
	else
		CheckIntegrity();
#endif
		*/
}