Beispiel #1
0
/**
* Sets an attribute bool in the material or a stage.
* @param stage The stage or -1 for the material.
* @param attribName The name of the attribute.
* @param value The value to set.
* @param addUndo Flag that specifies if the system should add an undo operation.
*/
void MaterialDoc::SetAttributeBool(int stage, const char* attribName, bool value, bool addUndo) {
	//Make sure we need to set the attribute
	bool orig  = GetAttributeBool(stage, attribName);
	if(orig != value) {

		idDict* dict;
		if(stage == -1) {
			dict = &editMaterial.materialData;
		} else {
			assert(stage >= 0 && stage < GetStageCount());
			dict = &editMaterial.stages[stage]->stageData;
		}

		if(addUndo) {
			//Create a new Modifier for this change so we can undo and redo later
			AttributeMaterialModifierBool* mod = new AttributeMaterialModifierBool(manager, name, stage, attribName, value, orig);
			manager->AddMaterialUndoModifier(mod);
		}

		dict->SetBool(attribName, value);

		manager->AttributeChanged(this, stage, attribName);
		OnMaterialChanged();
	}
}
Beispiel #2
0
/**
* Moves a stage from one location to another.
* @param from The original location of the stage.
* @param to The new location of the stage.
* @param addUndo Flag that specifies if the system should add an undo operation.
*/
void MaterialDoc::MoveStage(int from, int to, bool addUndo) {
	assert(from >= 0 && from < GetStageCount());
	assert(to >= 0 && to < GetStageCount());

	int origFrom = from;
	int origTo = to;

	if(from < to)
		to++;

	MEStage_t* pMove = editMaterial.stages[from];
	editMaterial.stages.Insert(pMove, to);

	if(from > to)
		from++;

	editMaterial.stages.RemoveIndex(from);

	manager->StageMoved(this, origFrom, origTo);

	if(addUndo) {
		StageMoveModifier *mod = new StageMoveModifier(manager, name, origFrom, origTo);
		manager->AddMaterialUndoModifier(mod);
	}

	OnMaterialChanged();
}
Beispiel #3
0
/**
* Specifies the enabled state of a single stage.
* @param stage The stage to change.
* @param enabled The enabled state.
*/
void MaterialDoc::EnableStage(int stage, bool enabled) {

	assert(stage >= 0 && stage < GetStageCount());
	editMaterial.stages[stage]->enabled = enabled;

	OnMaterialChanged();
}
Beispiel #4
0
/**
* Removes a stage from the material.
* @param stage The stage to remove.
* @param addUndo Flag that specifies if the system should add an undo operation.
*/
void MaterialDoc::RemoveStage(int stage, bool addUndo) {
	assert(stage >= 0 && stage < GetStageCount());

	if(addUndo) {
		//Add modifier to undo this operation
		StageDeleteModifier* mod = new StageDeleteModifier(manager, name, stage, editMaterial.stages[stage]->stageData);
		manager->AddMaterialUndoModifier(mod);
	}

	//delete the stage and remove it from the list
	delete editMaterial.stages[stage];
	editMaterial.stages.RemoveIndex(stage);

	manager->StageDeleted(this, stage);

	OnMaterialChanged();
}
Beispiel #5
0
/**
* Inserts a new stage to the material at a specified location.
* @param stage The location to insert the stage.
* @param stageType The type of the stage: normal or special.
* @param stageName The name of the stage.
* @param addUndo Flag that specifies if the system should add an undo operation.
*/
void MaterialDoc::InsertStage(int stage, int stageType, const char* stageName, bool addUndo) {
	MEStage_t* newStage = new MEStage_t();

	editMaterial.stages.Insert(newStage, stage);
	newStage->stageData.Set("name", stageName);
	newStage->stageData.SetInt("stagetype", stageType);
	newStage->enabled = true;

	if(addUndo) {
		StageInsertModifier* mod = new StageInsertModifier(manager, name, stage, stageType, stageName);
		manager->AddMaterialUndoModifier(mod);
	}

	manager->StageAdded(this, stage);

	OnMaterialChanged();
}
Beispiel #6
0
/**
* Sets the material name.
* @param materialName The new name of the material.
* @param addUndo Flag that specifies if the system should add an undo operation.
*/
void MaterialDoc::SetMaterialName(const char* materialName, bool addUndo) {
	idStr oldName = name;

	declManager->RenameDecl(DECL_MATERIAL, oldName, materialName); 
	name = renderMaterial->GetName();
	
	if(addUndo) {
		RenameMaterialModifier* mod = new RenameMaterialModifier(manager, name, oldName);
		manager->AddMaterialUndoModifier(mod);
	}

	manager->MaterialNameChanged(oldName, this);

	OnMaterialChanged();

	//Need to do an instant apply for material name changes
	ApplyMaterialChanges();
}
Beispiel #7
0
void IMaterial::AddTexture(ITexture* texture)
{
    MEDUSA_ASSERT_NOT_NULL(texture, "");
    MEDUSA_ASSERT_FALSE(mTextures.ContainsKey(texture->Unit()), "Duplicate add texture of same unit");
    MEDUSA_ASSERT_FALSE(mTextureSamplerDict.ContainsKey(texture->SamplerName()), "Duplicate add texture of same sampler name");

    texture->Retain();
    mTextures.Add(texture->Unit(), texture);
    mTextureSamplerDict.Add(texture->SamplerName(), texture);
    OnMaterialChanged(RenderableChangedFlags::BatchChanged);

    EnableBlend(texture->IsBlend());

    if (mFirstTexture == nullptr)
    {
        mFirstTexture = texture;
    }
}
Beispiel #8
0
/**
* Sets an attribute float in the material or a stage.
* @param stage The stage or -1 for the material.
* @param attribName The name of the attribute.
* @param value The value to set.
* @param addUndo Flag that specifies if the system should add an undo operation.
*/
void MaterialDoc::SetAttributeFloat(int stage, const char* attribName, float value, bool addUndo) {
	//Make sure we need to set the attribute
	float orig  = GetAttributeFloat(stage, attribName);
	if(orig != value) {

		idDict* dict;
		if(stage == -1) {
			dict = &editMaterial.materialData;
		} else {
			assert(stage >= 0 && stage < GetStageCount());
			dict = &editMaterial.stages[stage]->stageData;
		}

		dict->SetFloat(attribName, value);

		manager->AttributeChanged(this, stage, attribName);
		OnMaterialChanged();
	}
}
Beispiel #9
0
/**
* Deletes the material.
*/
void MaterialDoc::Delete() {
	deleted = true;

	OnMaterialChanged();
}
Beispiel #10
0
/**
* Called when the editor modifies the source of the material.
* @param text The new source text.
*/
void MaterialDoc::SourceModify(SourceModifyOwner* owner) {
	
	sourceModifyOwner = owner;
	sourceModify = true;
	OnMaterialChanged();
}