Add Model::setLightPosition.
+ Convert some std::strings to QStrings.
This commit is contained in:
parent
5984763d43
commit
6528e872e5
@ -485,13 +485,7 @@ void QtkScene::update()
|
||||
// Helper lambda to set the light position used by GLSL shaders on the model.
|
||||
// TODO: This could be a helper function on the Model class.
|
||||
auto setLightPosition = [](const std::string & lightName, Model * model) {
|
||||
if (auto light = MeshRenderer::getInstance(lightName.c_str()); light) {
|
||||
QVector3D position = light->getTransform().getTranslation();
|
||||
model->setUniform("uLight.position", position);
|
||||
} else {
|
||||
qDebug() << "[QtkScene] Failed to set light position: "
|
||||
<< lightName.c_str();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
QMatrix4x4 posMatrix;
|
||||
|
@ -56,8 +56,7 @@ void ToolBox::createPageProperties(const Object * object)
|
||||
ui->toolBox->setCurrentWidget(widget);
|
||||
|
||||
auto * layout = new QFormLayout;
|
||||
layout->addRow(new QLabel(tr("Name:")),
|
||||
new QLabel(object->getName().c_str()));
|
||||
layout->addRow(new QLabel(tr("Name:")), new QLabel(object->getName()));
|
||||
|
||||
layout->addRow(new QLabel(tr("Type:")),
|
||||
new QLabel(type == Object::Type::QTK_MESH ? "Mesh" : "Model"));
|
||||
|
@ -43,7 +43,7 @@ void Qtk::TreeView::updateView(const Qtk::Scene * scene)
|
||||
mSceneName = scene->getSceneName();
|
||||
auto objects = scene->getObjects();
|
||||
for (const auto & object : objects) {
|
||||
QStringList list(QStringList(QString(object->getName().c_str())));
|
||||
QStringList list(QStringList(QString(object->getName())));
|
||||
ui->treeWidget->insertTopLevelItem(0, new QTreeWidgetItem(list));
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ MeshRenderer::MeshRenderer(const char * name, const ShapeBase & shape) :
|
||||
|
||||
MeshRenderer::~MeshRenderer()
|
||||
{
|
||||
sInstances.remove(mName.c_str());
|
||||
sInstances.remove(mName);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
@ -56,6 +56,17 @@ void Model::flipTexture(const std::string & fileName, bool flipX, bool flipY)
|
||||
}
|
||||
}
|
||||
|
||||
void Model::setLightPosition(const QString & lightName, const char * uniform)
|
||||
{
|
||||
if (auto light = MeshRenderer::getInstance(lightName); light) {
|
||||
QVector3D position = light->getTransform().getTranslation();
|
||||
setUniform(uniform, position);
|
||||
} else {
|
||||
qDebug() << "[QtkScene] Failed to set " << mName
|
||||
<< "light position: " << lightName;
|
||||
}
|
||||
}
|
||||
|
||||
// Static function to access ModelManager for getting Models by name
|
||||
Model * Qtk::Model::getInstance(const char * name)
|
||||
{
|
||||
@ -102,7 +113,7 @@ void Model::loadModel(const std::string & path)
|
||||
sortModelMeshes();
|
||||
|
||||
// Object finished loading, insert it into ModelManager
|
||||
mManager.insert(getName().c_str(), this);
|
||||
mManager.insert(getName(), this);
|
||||
}
|
||||
|
||||
void Model::processNode(aiNode * node, const aiScene * scene)
|
||||
|
@ -63,7 +63,7 @@ namespace Qtk
|
||||
loadModel(mModelPath);
|
||||
}
|
||||
|
||||
inline ~Model() override { mManager.remove(getName().c_str()); }
|
||||
inline ~Model() override { mManager.remove(getName()); }
|
||||
|
||||
/*************************************************************************
|
||||
* Public Methods
|
||||
@ -113,6 +113,14 @@ namespace Qtk
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position of a light used in GLSL unfiroms.
|
||||
*
|
||||
* @param lightName Object name of the light
|
||||
*/
|
||||
void setLightPosition(const QString & lightName,
|
||||
const char * uniform = "uLight.position");
|
||||
|
||||
/*************************************************************************
|
||||
* Accessors
|
||||
************************************************************************/
|
||||
|
@ -100,7 +100,7 @@ namespace Qtk
|
||||
return mShape.mVertices;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline std::string getName() const { return mName; }
|
||||
[[nodiscard]] inline QString getName() const { return mName; }
|
||||
|
||||
[[nodiscard]] inline const Type & getType() const { return mType; }
|
||||
|
||||
@ -143,7 +143,7 @@ namespace Qtk
|
||||
* Setters
|
||||
************************************************************************/
|
||||
|
||||
virtual inline void setName(const std::string & name) { mName = name; }
|
||||
virtual inline void setName(const QString & name) { mName = name; }
|
||||
|
||||
virtual inline void setColors(const Colors & value)
|
||||
{
|
||||
@ -255,7 +255,7 @@ namespace Qtk
|
||||
Transform3D mTransform;
|
||||
Shape mShape;
|
||||
Texture mTexture;
|
||||
std::string mName;
|
||||
QString mName;
|
||||
bool mBound;
|
||||
Type mType = QTK_OBJECT;
|
||||
};
|
||||
|
@ -103,7 +103,7 @@ std::vector<Object *> Scene::getObjects() const
|
||||
Object * Scene::getObject(const QString & name) const
|
||||
{
|
||||
for (const auto & object : getObjects()) {
|
||||
if (object->getName() == name.toStdString()) {
|
||||
if (object->getName() == name) {
|
||||
return object;
|
||||
}
|
||||
}
|
||||
@ -121,6 +121,6 @@ void Scene::initSceneObjectName(Object * object)
|
||||
// If the object name exists make it unique.
|
||||
auto count = ++mObjectCount[object->getName()];
|
||||
if (count > 1) {
|
||||
object->setName(object->getName() + " (" + std::to_string(count) + ")");
|
||||
object->setName(object->getName() + " (" + QString::number(count) + ")");
|
||||
}
|
||||
}
|
||||
|
@ -120,9 +120,7 @@ namespace Qtk
|
||||
*/
|
||||
[[nodiscard]] uint64_t getObjectCount(const QString & name)
|
||||
{
|
||||
return mObjectCount.count(name.toStdString())
|
||||
? mObjectCount[name.toStdString()]
|
||||
: 0;
|
||||
return mObjectCount.count(name) ? mObjectCount[name] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -248,7 +246,7 @@ namespace Qtk
|
||||
/* MeshRenderers used simple geometry. */
|
||||
std::vector<MeshRenderer *> mMeshes {};
|
||||
/* Track count of objects with same initial name. */
|
||||
std::unordered_map<std::string, uint64_t> mObjectCount;
|
||||
std::unordered_map<QString, uint64_t> mObjectCount;
|
||||
};
|
||||
} // namespace Qtk
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user