added everything

This commit is contained in:
Metario
2017-04-17 06:17:10 -06:00
commit 9c6ff74f19
6121 changed files with 1625704 additions and 0 deletions

View File

@ -0,0 +1,183 @@
/*==============================================================================
file: mrShaderButtonHandler.h
author: Daniel Levesque
created: 23 April 2003
description:
Implementation of a DADMgr which handles shader buttons outside of the
material editor.
modified:
<EFBFBD> 2003 Autodesk
==============================================================================*/
#include "mrShaderButtonHandler.h"
#include <mentalray\imrShader.h>
//==============================================================================
// class ShaderButtonDADMgr
//==============================================================================
mrShaderButtonHandler::mrShaderButtonHandler(unsigned int applyTypes, int ctrlID)
: m_shaderFilter(applyTypes, TYPE_MAX_TYPE, true),
m_ctrlID(ctrlID),
m_dialogHWnd(NULL)
{
}
mrShaderButtonHandler::~mrShaderButtonHandler() {
}
void mrShaderButtonHandler::Enable(bool enable) {
DbgAssert(m_dialogHWnd != NULL);
HWND ctrlHWnd = GetDlgItem(m_dialogHWnd, m_ctrlID);
ICustButton* custButton = GetICustButton(ctrlHWnd);
if(custButton != NULL) {
custButton->Enable(enable);
ReleaseICustButton(custButton);
}
else {
DbgAssert(false);
}
}
void mrShaderButtonHandler::OnInitDialog(HWND hDialog) {
m_dialogHWnd = hDialog;
DbgAssert(m_dialogHWnd != NULL);
HWND ctrlHWnd = GetDlgItem(m_dialogHWnd, m_ctrlID);
ICustButton* custButton = GetICustButton(ctrlHWnd);
if(custButton != NULL) {
custButton->SetDADMgr(this);
ReleaseICustButton(custButton);
}
else {
DbgAssert(false);
}
Update();
}
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 mrShaderButtonHandler::OnClose() {
DbgAssert(m_dialogHWnd != NULL);
m_dialogHWnd = NULL;
}
void mrShaderButtonHandler::Update() {
DbgAssert(m_dialogHWnd != NULL);
HWND ctrlHWnd = GetDlgItem(m_dialogHWnd, m_ctrlID);
ICustButton* custButton = GetICustButton(ctrlHWnd);
if(custButton != NULL) {
TSTR text;
Texmap* shader = GetShader();
if(shader != NULL)
text = shader->GetFullName();
else
text = GetNoneString();
custButton->SetText(text.data());
ReleaseICustButton(custButton);
}
else {
DbgAssert(false);
}
}
SClass_ID mrShaderButtonHandler::GetDragType(HWND hwnd, POINT p) {
return TEXMAP_CLASS_ID;
}
ReferenceTarget* mrShaderButtonHandler::GetInstance(HWND hwnd, POINT p, SClass_ID type) {
if(type == TEXMAP_CLASS_ID) {
Texmap* shader = GetShader();
return shader;
}
else {
return NULL;
}
}
BOOL mrShaderButtonHandler::OkToDrop(ReferenceTarget *dropThis, HWND hfrom, HWND hto, POINT p, SClass_ID type, BOOL isNew) {
if(type == TEXMAP_CLASS_ID) {
Texmap* texmap = static_cast<Texmap*>(dropThis);
if(texmap == NULL) {
return TRUE;
}
else {
return m_shaderFilter.Include(*texmap, 0);
}
}
return FALSE;
}
int mrShaderButtonHandler::SlotOwner() {
return OWNER_SCENE;
}
void mrShaderButtonHandler::Drop(ReferenceTarget *dropThis, HWND hwnd, POINT p, SClass_ID type) {
DbgAssert(OkToDrop(dropThis, NULL, hwnd, p, type, FALSE));
if((dropThis == NULL) || (dropThis->SuperClassID() == TEXMAP_CLASS_ID)) {
Texmap* texmap = static_cast<Texmap*>(dropThis);
SetShader(texmap);
Update();
}
}
BOOL mrShaderButtonHandler::AutoTooltip() {
return TRUE;
}

View File

@ -0,0 +1,89 @@
/*==============================================================================
file: mrShaderButtonHandler.h
author: Daniel Levesque
created: 23 April 2003
description:
Implementation of a DADMgr which handles shader buttons outside of the
material editor.
modified:
<EFBFBD> 2003 Autodesk
==============================================================================*/
#ifndef _MRSHADERBUTTONHANDLER_H_
#define _MRSHADERBUTTONHANDLER_H_
#include <windows.h>
#include <max.h>
#include <mentalray\shared_src\mrShaderFilter.h>
class imrShader;
//==============================================================================
// class mrShaderButtonHandler
//
// Base class for shader DAD managers.
//
// Users need only derive from this class and implement the pure virtual
// methods. The DialogProc should call the OnInitDialog(), OnCommand(), and OnClose()
// methods.
//==============================================================================
class mrShaderButtonHandler : public DADMgr {
public:
// Initialize with accepted apply types
mrShaderButtonHandler(
unsigned int applyTypes, // Accepted apply types, a combination of imrShaderClassDesc::ApplyFlags
int ctrlID // ID of the button control. Must be an ICustButton control.
);
virtual ~mrShaderButtonHandler();
void OnInitDialog(HWND hDialog); // To be called on WM_INITDIALOG
void OnCommand(); // To be called on WM_COMMAND for this button.
void OnClose(); // To be called on WM_CLOSE
// Updates the text on the button
void Update();
void Enable(bool enable);
// -- from DADMgr
virtual SClass_ID GetDragType(HWND hwnd, POINT p);
virtual ReferenceTarget *GetInstance(HWND hwnd, POINT p, SClass_ID type);
virtual BOOL OkToDrop(ReferenceTarget *dropThis, HWND hfrom, HWND hto, POINT p, SClass_ID type, BOOL isNew = FALSE);
virtual int SlotOwner();
virtual void Drop(ReferenceTarget *dropThis, HWND hwnd, POINT p, SClass_ID type);
virtual BOOL AutoTooltip();
protected:
virtual void SetShader(Texmap* shader) = 0;
virtual Texmap* GetShader() = 0;
// Loads a localized string for "None" (Shows up on the button when no shader is assigned)
virtual const TCHAR* GetNoneString() = 0;
private:
// The shader filter used to validate the shaders
mrShaderFilter m_shaderFilter;
int m_ctrlID;
HWND m_dialogHWnd;
};
#endif

View File

@ -0,0 +1,284 @@
/*==============================================================================
file: mrShaderFilter.cpp
author: Daniel Levesque
created: 21feb2003
description:
The filter for the material/map browser, which also doubles as a PBValidator.
modified:
<EFBFBD> 2003 Autodesk
==============================================================================*/
#include "mrShaderFilter.h"
#include <mentalray\imrShaderClassDesc.h>
#include <mentalray\imrPreferences.h>
#include <mentalray\imrShaderTranslation.h>
//==============================================================================
// class mrShaderFilter
//==============================================================================
mrShaderFilter::mrShaderFilter(
unsigned int applyTypes, // Accepted apply types, a combination of imrShaderClassDesc::ApplyFlags
ParamType2 paramType, // Accepted return types. Pass TYPE_MAX_TYPE to accept all types.
bool acceptStructs // Should shaders returning structures be accepted? (the structure has to contain a member with a valid type)
)
: m_enabled(true),
m_applyTypes(applyTypes),
m_paramType(paramType),
m_acceptStructs(acceptStructs)
{
}
mrShaderFilter::~mrShaderFilter() {
}
const TCHAR* mrShaderFilter::FilterName() {
return _T("mental ray: Shader Filter");
}
bool mrShaderFilter::Enabled() {
return m_enabled;
}
void mrShaderFilter::Enable(bool enable) {
m_enabled = enable;
}
void mrShaderFilter::Registered() {
// do nothing
}
void mrShaderFilter::Unregistered() {
// do nothing
}
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;
}
}
bool mrShaderFilter::Include(ClassDesc& classDesc, DWORD flags) {
// [dl | 20may2003] Disregard the 'mr extensions active' flag.
/*
// If this is a mental ray shader, then never include it if the mental ray
// custom attributes are not active.
imrShaderClassDesc* shaderClassDesc = Get_mrShaderClassDesc(&classDesc);
imrShaderTranslation_ClassInfo* customClassInfo = Get_imrShaderTranslation_ClassInfo(classDesc);
if((shaderClassDesc != NULL) || (customClassInfo != NULL)) {
imrPreferences* prefs = GetMRPreferences();
if((prefs != NULL) && !prefs->GetMRExtensionsActive()) {
return false;
}
}
*/
return (ValidateApplyType(classDesc) && ValidateReturnType(classDesc));
}
BOOL mrShaderFilter::Validate(PB2Value& v) {
ReferenceTarget* refTarg = v.r;
if((refTarg != NULL) && IsMtlBase(refTarg)) {
MtlBase* mtlBase = static_cast<MtlBase*>(refTarg);
return Include(*mtlBase, 0);
}
else {
// Null values are acceptable
return TRUE;
}
}
BOOL mrShaderFilter::Validate(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex) {
return Validate(v);
}
BaseInterface* mrShaderFilter::GetInterface(Interface_ID id) {
if(id == MRSHADERFILTER_INTERFACEID) {
return this;
}
else if(id == IMTLBROWSERFILTER_INTERFACEID) {
return static_cast<IMtlBrowserFilter*>(this);
}
else {
return PBValidator::GetInterface(id);
}
}
bool mrShaderFilter::ValidateApplyType(ClassDesc& classDesc) {
SClass_ID superClassID = classDesc.SuperClassID();
if(superClassID == MATERIAL_CLASS_ID) {
// Validate if materials are accepted
return ((m_applyTypes & imrShaderClassDesc::kApplyFlag_MtlPhen) != 0);
}
else if(superClassID == TEXMAP_CLASS_ID) {
// First, query for a possible custom apply type
imrShaderTranslation_ClassInfo* customClassInfo = Get_imrShaderTranslation_ClassInfo(classDesc);
if(customClassInfo != NULL) {
unsigned int customApplyType = customClassInfo->GetApplyTypes();
return ((customApplyType & m_applyTypes) != 0);
}
else {
imrShaderClassDesc* shaderClassDesc = Get_mrShaderClassDesc(&classDesc);
if(shaderClassDesc == NULL) {
// Not a mr shader. Validate if texture shaders are accepted.
return ((m_applyTypes & imrShaderClassDesc::kApplyFlag_Texture) != 0);
}
else {
// Depends on the apply type of the shader
unsigned int shaderApplyTypes = shaderClassDesc->GetApplyTypes();
return ((shaderApplyTypes & m_applyTypes) != 0);
}
}
}
else {
// Shouldn't occur
DbgAssert(false);
return false;
}
}
bool mrShaderFilter::ValidateReturnType(ClassDesc& classDesc) {
SClass_ID superClassID = classDesc.SuperClassID();
if(superClassID == MATERIAL_CLASS_ID) {
// Validate if we want a TYPE_MTL return type
//return ValidType(TYPE_MTL);
// Do not validate types for materials. Only use the apply type for validatoin.
return true;
}
else if(superClassID == TEXMAP_CLASS_ID) {
imrShaderClassDesc* shaderClassDesc = Get_mrShaderClassDesc(&classDesc);
if(shaderClassDesc == NULL) {
// Assume that the texture returns a color
return ValidType(static_cast<ParamType2>(TYPE_RGBA));
}
else {
// Go through the results structure
ParamBlockDesc2* pbDesc = shaderClassDesc->GetResultPBDesc();
if((pbDesc != NULL) && ValidateReturnType(*pbDesc)) {
return true;
}
// Go through the sub-structures, is allowed
if(m_acceptStructs) {
Tab<ParamBlockDesc2*>& resultDescs = shaderClassDesc->GetResultPBDescs();
int count = resultDescs.Count();
for(int i = 0; i < count; ++i) {
ParamBlockDesc2* pbDesc = resultDescs[i];
if((pbDesc != NULL) && ValidateReturnType(*pbDesc)) {
return true;
}
}
}
return false;
}
}
else {
// Shouldn't occur
DbgAssert(false);
return false;
}
}
bool mrShaderFilter::ValidType(ParamType2 type) {
switch(m_paramType) {
case TYPE_MAX_TYPE:
return true;
// Casts to more complex types are acceptable
#ifndef MAX51_MENTALRAY // TYPE_FRGBA and TYPE_POINT4 don't exist in 5.1
case TYPE_RGBA:
case TYPE_FRGBA:
return ((type == TYPE_RGBA) || (type == TYPE_FRGBA));
#else
case TYPE_RGBA:
return (type == TYPE_RGBA);
#endif
#ifndef MAX51_MENTALRAY // TYPE_FRGBA and TYPE_POINT4 don't exist in 5.1
case TYPE_POINT3:
case TYPE_POINT4:
return ((type == TYPE_RGBA)
|| (type == TYPE_FRGBA)
|| (type == TYPE_POINT3)
|| (type == TYPE_POINT4));
case TYPE_FLOAT:
return ((type == TYPE_RGBA)
|| (type == TYPE_FRGBA)
|| (type == TYPE_POINT3)
|| (type == TYPE_FLOAT));
#else
case TYPE_POINT3:
return ((type == TYPE_RGBA)
|| (type == TYPE_POINT3));
case TYPE_FLOAT:
return ((type == TYPE_RGBA)
|| (type == TYPE_POINT3)
|| (type == TYPE_FLOAT));
#endif
default:
return (type == m_paramType);
}
}
bool mrShaderFilter::ValidateReturnType(ParamBlockDesc2& pbDesc) {
// Go through all the parameters of the block
int count = pbDesc.Count();
for(int i = 0; i < count; ++i) {
ParamDef& paramDef = pbDesc.GetParamDef(pbDesc.IndextoID(i));
if(ValidType(paramDef.type))
return true;
}
return false;
}
void mrShaderFilter::DeleteThis() {
delete this;
}

View File

@ -0,0 +1,98 @@
/*==============================================================================
file: mrShaderFilter.h
author: Daniel Levesque
created: 21feb2003
description:
The filter for the material/map browser, which also doubles as a PBValidator.
modified:
<EFBFBD> 2003 Autodesk
==============================================================================*/
#ifndef _MRSHADERFILTER_H_
#define _MRSHADERFILTER_H_
#include <max.h>
#include <iparamb2.h>
#include <IMtlBrowserFilter.h>
#define MRSHADERFILTER_INTERFACEID Interface_ID(0x36ad69a6, 0x17db66d1)
//==============================================================================
// class mrShaderFilter
//
// Used to filter out unwanted shaders from the mtl/map browser. Also used as
// a PBValidtor.
//==============================================================================
class mrShaderFilter : public IMtlBrowserFilter, public PBValidator {
public:
mrShaderFilter(
unsigned int applyTypes, // Accepted apply types, a combination of imrShaderClassDesc::ApplyFlags
ParamType2 paramType, // Accepted return types. Pass TYPE_MAX_TYPE to accept all types.
bool acceptStructs // Should shaders returning structures be accepted? (the structure has to contain a member with a valid type)
);
virtual ~mrShaderFilter();
// Returns whether the given parameter type is accepted
bool ValidType(ParamType2 type);
// -- from IMtlBrowserFilter
virtual const TCHAR* FilterName();
virtual bool Enabled();
virtual void Enable(bool enable);
virtual void Registered();
virtual void Unregistered();
virtual bool Include(MtlBase& mtlBase, DWORD flags);
virtual bool Include(ClassDesc& classDesc, DWORD flags);
// -- from PBValidator
virtual BOOL Validate(PB2Value& v);
virtual BOOL Validate(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex);
virtual void DeleteThis();
// -- from InterfaceServer
virtual BaseInterface* GetInterface(Interface_ID id);
private:
// Returns whether the apply type of the given class is valid
bool ValidateApplyType(ClassDesc& classDesc);
// Returns whether the return type of the given class is valid
bool ValidateReturnType(ClassDesc& classDesc);
// Validates the return type based on a parameter block
bool ValidateReturnType(ParamBlockDesc2& pbDesc);
// -- Data Members --
// Is this filter enabled?
bool m_enabled;
// Accept shaders returning structs?
bool m_acceptStructs;
// The accepted apply types
unsigned int m_applyTypes;
// The accepted return param types
ParamType2 m_paramType;
};
inline mrShaderFilter* Get_mrShaderFilter(InterfaceServer* iserver) {
if(iserver == NULL)
return NULL;
else
return static_cast<mrShaderFilter*>(iserver->GetInterface(MRSHADERFILTER_INTERFACEID));
}
#endif