parent
5ec40943cf
commit
17a93ec524
|
@ -103,6 +103,7 @@ MainWindow::MainWindow() :
|
|||
connect(generateTangentsAction, SIGNAL(triggered()), this, SLOT(generateTangents()));
|
||||
connect(uniquifyVerticesAction, SIGNAL(triggered()), this, SLOT(uniquifyVertices()));
|
||||
connect(mergeMeshesAction, SIGNAL(triggered()), this, SLOT(mergeMeshes()));
|
||||
editMaterialAction->setShortcut(QKeySequence("Ctrl+E"));
|
||||
connect(editMaterialAction, SIGNAL(triggered()), this, SLOT(editMaterial()));
|
||||
}
|
||||
|
||||
|
@ -578,6 +579,11 @@ MainWindow::editMaterial()
|
|||
QVBoxLayout* layout = new QVBoxLayout;
|
||||
layout->addWidget(materialWidget);
|
||||
|
||||
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok,
|
||||
Qt::Horizontal, &dialog);
|
||||
layout->addWidget(buttonBox);
|
||||
connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
|
||||
|
||||
if (!m_modelView->selection().isEmpty())
|
||||
{
|
||||
QSetIterator<Mesh::PrimitiveGroup*> iter(m_modelView->selection());
|
||||
|
@ -589,9 +595,23 @@ MainWindow::editMaterial()
|
|||
}
|
||||
}
|
||||
|
||||
connect(materialWidget, SIGNAL(materialChanged(const cmod::Material&)), this, SLOT(changeCurrentMaterial(const cmod::Material&)));
|
||||
|
||||
dialog.setLayout(layout);
|
||||
dialog.resize(350, 250);
|
||||
|
||||
dialog.show();
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::changeCurrentMaterial(const Material& material)
|
||||
{
|
||||
if (!m_modelView->selection().isEmpty())
|
||||
{
|
||||
QSetIterator<Mesh::PrimitiveGroup*> iter(m_modelView->selection());
|
||||
Mesh::PrimitiveGroup* selectedGroup = iter.next();
|
||||
m_modelView->setMaterial(selectedGroup->materialIndex, material);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ public slots:
|
|||
void mergeMeshes();
|
||||
void editMaterial();
|
||||
|
||||
void changeCurrentMaterial(const cmod::Material&);
|
||||
|
||||
private:
|
||||
ModelViewWidget* m_modelView;
|
||||
QLabel* m_statusBarLabel;
|
||||
|
|
|
@ -26,6 +26,32 @@ static Material::Color fromQtColor(const QColor& color)
|
|||
return Material::Color(color.redF(), color.greenF(), color.blueF());
|
||||
}
|
||||
|
||||
// TODO: implement a copy constructor and assignment operator for materials
|
||||
static void copyMaterial(Material& dest, const Material& src)
|
||||
{
|
||||
dest.diffuse = src.diffuse;
|
||||
dest.specular = src.specular;
|
||||
dest.emissive = src.emissive;
|
||||
dest.opacity = src.opacity;
|
||||
dest.specularPower = src.specularPower;
|
||||
dest.blend = src.blend;
|
||||
|
||||
for (unsigned int i = 0; i < Material::TextureSemanticMax; ++i)
|
||||
{
|
||||
if (dest.maps[i])
|
||||
{
|
||||
delete dest.maps[i];
|
||||
dest.maps[i] = NULL;
|
||||
}
|
||||
|
||||
if (src.maps[i])
|
||||
{
|
||||
dest.maps[i] = new Material::DefaultTextureResource(src.maps[i]->source());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void setWidgetColor(QLabel* widget, const Material::Color& color)
|
||||
{
|
||||
widget->setPalette(QPalette(toQtColor(color)));
|
||||
|
@ -106,6 +132,8 @@ MaterialWidget::MaterialWidget(QWidget* parent) :
|
|||
connect(changeDiffuse, SIGNAL(clicked()), this, SLOT(editDiffuse()));
|
||||
connect(changeSpecular, SIGNAL(clicked()), this, SLOT(editSpecular()));
|
||||
connect(changeEmissive, SIGNAL(clicked()), this, SLOT(editEmissive()));
|
||||
connect(m_opacity, SIGNAL(returnPressed()), this, SLOT(changeMaterialParameters()));
|
||||
connect(m_specularPower, SIGNAL(returnPressed()), this, SLOT(changeMaterialParameters()));
|
||||
|
||||
setMaterial(Material());
|
||||
|
||||
|
@ -121,7 +149,7 @@ MaterialWidget::~MaterialWidget()
|
|||
void
|
||||
MaterialWidget::setMaterial(const Material& material)
|
||||
{
|
||||
m_material = material;
|
||||
copyMaterial(m_material, material);
|
||||
|
||||
setWidgetColor(m_diffuseColor, m_material.diffuse);
|
||||
setWidgetColor(m_specularColor, m_material.specular);
|
||||
|
@ -129,37 +157,51 @@ MaterialWidget::setMaterial(const Material& material)
|
|||
m_opacity->setText(QString::number(m_material.opacity));
|
||||
m_specularPower->setText(QString::number(m_material.specularPower));
|
||||
|
||||
emit materialChanged();
|
||||
if (m_material.maps[Material::DiffuseMap])
|
||||
m_baseTexture->setText(m_material.maps[Material::DiffuseMap]->source().c_str());
|
||||
else
|
||||
m_baseTexture->setText("");
|
||||
if (m_material.maps[Material::SpecularMap])
|
||||
m_specularMap->setText(m_material.maps[Material::SpecularMap]->source().c_str());
|
||||
else
|
||||
m_specularMap->setText("");
|
||||
if (m_material.maps[Material::EmissiveMap])
|
||||
m_emissiveMap->setText(m_material.maps[Material::EmissiveMap]->source().c_str());
|
||||
else
|
||||
m_emissiveMap->setText("");
|
||||
if (m_material.maps[Material::NormalMap])
|
||||
m_normalMap->setText(m_material.maps[Material::NormalMap]->source().c_str());
|
||||
else
|
||||
m_normalMap->setText("");
|
||||
|
||||
emit materialChanged(m_material);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MaterialWidget::editDiffuse()
|
||||
{
|
||||
QColor color = QColorDialog::getColor(toQtColor(m_material.diffuse), this);
|
||||
m_material.diffuse = fromQtColor(color);
|
||||
setWidgetColor(m_diffuseColor, m_material.diffuse);
|
||||
emit materialChanged();
|
||||
QColorDialog dialog(this);
|
||||
connect(&dialog, SIGNAL(currentColorChanged(QColor)), this, SLOT(setDiffuse(QColor)));
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MaterialWidget::editSpecular()
|
||||
{
|
||||
QColor color = QColorDialog::getColor(toQtColor(m_material.specular), this);
|
||||
m_material.specular = fromQtColor(color);
|
||||
setWidgetColor(m_specularColor, m_material.specular);
|
||||
emit materialChanged();
|
||||
QColorDialog dialog(this);
|
||||
connect(&dialog, SIGNAL(currentColorChanged(QColor)), this, SLOT(setSpecular(QColor)));
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MaterialWidget::editEmissive()
|
||||
{
|
||||
QColor color = QColorDialog::getColor(toQtColor(m_material.emissive), this);
|
||||
m_material.emissive = fromQtColor(color);
|
||||
setWidgetColor(m_emissiveColor, m_material.emissive);
|
||||
emit materialChanged();
|
||||
QColorDialog dialog(this);
|
||||
connect(&dialog, SIGNAL(currentColorChanged(QColor)), this, SLOT(setEmissive(QColor)));
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
|
||||
|
@ -185,3 +227,39 @@ void
|
|||
MaterialWidget::editNormalMap()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MaterialWidget::setDiffuse(const QColor& color)
|
||||
{
|
||||
m_material.diffuse = fromQtColor(color);
|
||||
setWidgetColor(m_diffuseColor, m_material.diffuse);
|
||||
emit materialChanged(m_material);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MaterialWidget::setSpecular(const QColor& color)
|
||||
{
|
||||
m_material.specular = fromQtColor(color);
|
||||
setWidgetColor(m_specularColor, m_material.specular);
|
||||
emit materialChanged(m_material);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MaterialWidget::setEmissive(const QColor& color)
|
||||
{
|
||||
m_material.emissive = fromQtColor(color);
|
||||
setWidgetColor(m_emissiveColor, m_material.emissive);
|
||||
emit materialChanged(m_material);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MaterialWidget::changeMaterialParameters()
|
||||
{
|
||||
m_material.opacity = m_opacity->text().toFloat();
|
||||
m_material.specularPower = m_specularPower->text().toFloat();
|
||||
emit materialChanged(m_material);
|
||||
}
|
||||
|
|
|
@ -38,9 +38,13 @@ public slots:
|
|||
void editSpecularMap();
|
||||
void editEmissiveMap();
|
||||
void editNormalMap();
|
||||
void setDiffuse(const QColor& color);
|
||||
void setSpecular(const QColor& color);
|
||||
void setEmissive(const QColor& color);
|
||||
void changeMaterialParameters();
|
||||
|
||||
signals:
|
||||
void materialChanged();
|
||||
void materialChanged(const cmod::Material&);
|
||||
|
||||
private:
|
||||
QLabel* m_diffuseColor;
|
||||
|
|
|
@ -290,6 +290,27 @@ ModelViewWidget::cameraTransform() const
|
|||
return t;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ModelViewWidget::setMaterial(unsigned int index, const cmod::Material& material)
|
||||
{
|
||||
if (!m_model || index >= m_model->getMaterialCount())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy material parameters
|
||||
// TODO: eliminate const cast when Model::setMaterial() is implemented
|
||||
Material* modelMaterial = const_cast<Material*>(m_model->getMaterial(index));
|
||||
modelMaterial->diffuse = material.diffuse;
|
||||
modelMaterial->specular = material.specular;
|
||||
modelMaterial->emissive = material.emissive;
|
||||
modelMaterial->opacity = material.opacity;
|
||||
modelMaterial->specularPower = material.specularPower;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void
|
||||
ModelViewWidget::initializeGL()
|
||||
{
|
||||
|
|
|
@ -62,6 +62,8 @@ public:
|
|||
|
||||
Eigen::Transform3d cameraTransform() const;
|
||||
|
||||
void setMaterial(unsigned int index, const cmod::Material& material);
|
||||
|
||||
protected:
|
||||
void initializeGL();
|
||||
void paintGL();
|
||||
|
|
Loading…
Reference in New Issue