* remove unneeded Q_DECLARE_METATYPEs

* CR feedback
This commit is contained in:
humbletim 2018-02-26 19:07:55 -05:00
parent 767569bc40
commit d3bae87066
7 changed files with 25 additions and 28 deletions

View file

@ -95,11 +95,3 @@ namespace scriptable {
class ScriptableMeshPart;
using ScriptableMeshPartPointer = QPointer<ScriptableMeshPart>;
}
Q_DECLARE_METATYPE(glm::uint32)
Q_DECLARE_METATYPE(QVector<glm::uint32>)
Q_DECLARE_METATYPE(NestableType)
Q_DECLARE_METATYPE(scriptable::MeshPointer)
Q_DECLARE_METATYPE(scriptable::WeakMeshPointer)
Q_DECLARE_METATYPE(scriptable::ModelProviderPointer)

View file

@ -85,4 +85,8 @@ private:
};
Q_DECLARE_METATYPE(glm::uint32)
Q_DECLARE_METATYPE(QVector<glm::uint32>)
Q_DECLARE_METATYPE(NestableType)
#endif // hifi_GraphicsScriptingInterface_h

View file

@ -118,7 +118,7 @@ bool scriptable::ScriptableMesh::setVertexAttributes(glm::uint32 vertexIndex, co
return buffer_helpers::mesh::setVertexAttributes(getMeshPointer(), vertexIndex, attributes);
}
int scriptable::ScriptableMesh::_getSlotNumber(const QString& attributeName) const {
int scriptable::ScriptableMesh::getSlotNumber(const QString& attributeName) const {
if (auto mesh = getMeshPointer()) {
return buffer_helpers::ATTRIBUTES.value(attributeName, -1);
}
@ -142,9 +142,9 @@ QVariantMap scriptable::ScriptableMesh::getBufferFormats() const {
}
bool scriptable::ScriptableMesh::removeAttribute(const QString& attributeName) {
auto slot = isValid() ? _getSlotNumber(attributeName) : -1;
auto slot = isValid() ? getSlotNumber(attributeName) : -1;
if (slot < 0) {
return 0;
return false;
}
if (slot == gpu::Stream::POSITION) {
context()->throwError("cannot remove .position attribute");
@ -158,7 +158,7 @@ bool scriptable::ScriptableMesh::removeAttribute(const QString& attributeName) {
}
glm::uint32 scriptable::ScriptableMesh::addAttribute(const QString& attributeName, const QVariant& defaultValue) {
auto slot = isValid() ? _getSlotNumber(attributeName) : -1;
auto slot = isValid() ? getSlotNumber(attributeName) : -1;
if (slot < 0) {
return 0;
}
@ -187,7 +187,7 @@ glm::uint32 scriptable::ScriptableMesh::addAttribute(const QString& attributeNam
}
glm::uint32 scriptable::ScriptableMesh::fillAttribute(const QString& attributeName, const QVariant& value) {
auto slot = isValid() ? _getSlotNumber(attributeName) : -1;
auto slot = isValid() ? getSlotNumber(attributeName) : -1;
if (slot < 0) {
return 0;
}
@ -218,7 +218,7 @@ QVariantList scriptable::ScriptableMesh::queryVertexAttributes(QVariant selector
if (!isValidIndex(0, attributeName)) {
return result;
}
auto slotNum = _getSlotNumber(attributeName);
auto slotNum = getSlotNumber(attributeName);
const auto& bufferView = buffer_helpers::mesh::getBufferView(getMeshPointer(), static_cast<gpu::Stream::Slot>(slotNum));
glm::uint32 numElements = (glm::uint32)bufferView.getNumElements();
for (glm::uint32 i = 0; i < numElements; i++) {
@ -231,7 +231,7 @@ QVariant scriptable::ScriptableMesh::getVertexProperty(glm::uint32 vertexIndex,
if (!isValidIndex(vertexIndex, attributeName)) {
return QVariant();
}
auto slotNum = _getSlotNumber(attributeName);
auto slotNum = getSlotNumber(attributeName);
const auto& bufferView = buffer_helpers::mesh::getBufferView(getMeshPointer(), static_cast<gpu::Stream::Slot>(slotNum));
return buffer_helpers::getValue<QVariant>(bufferView, vertexIndex, qUtf8Printable(attributeName));
}
@ -240,7 +240,7 @@ bool scriptable::ScriptableMesh::setVertexProperty(glm::uint32 vertexIndex, cons
if (!isValidIndex(vertexIndex, attributeName)) {
return false;
}
auto slotNum = _getSlotNumber(attributeName);
auto slotNum = getSlotNumber(attributeName);
const auto& bufferView = buffer_helpers::mesh::getBufferView(getMeshPointer(), static_cast<gpu::Stream::Slot>(slotNum));
return buffer_helpers::setValue(bufferView, vertexIndex, value);
}
@ -331,7 +331,7 @@ bool scriptable::ScriptableMesh::isValidIndex(glm::uint32 vertexIndex, const QSt
return false;
}
if (!attributeName.isEmpty()) {
auto slotNum = _getSlotNumber(attributeName);
auto slotNum = getSlotNumber(attributeName);
if (slotNum < 0) {
if (context()) {
context()->throwError(QString("invalid attributeName=%1").arg(attributeName));

View file

@ -74,9 +74,8 @@ namespace scriptable {
QVector<scriptable::ScriptableMeshPartPointer> getMeshParts() const;
QVariantMap getMeshExtents() const;
// TODO: remove Q_INVOKABLE (curently exposed for debugging )
Q_INVOKABLE int _getSlotNumber(const QString& attributeName) const;
operator bool() const { return !weakMesh.expired(); }
int getSlotNumber(const QString& attributeName) const;
public slots:
const scriptable::ScriptableModelPointer getParentModel() const { return qobject_cast<scriptable::ScriptableModel*>(model); }

View file

@ -57,7 +57,7 @@ bool scriptable::ScriptableMeshPart::setVertexProperty(glm::uint32 vertexIndex,
if (!isValidIndex(vertexIndex, attributeName)) {
return false;
}
auto slotNum = parentMesh->_getSlotNumber(attributeName);
auto slotNum = parentMesh->getSlotNumber(attributeName);
const auto& bufferView = buffer_helpers::mesh::getBufferView(getMeshPointer(), static_cast<gpu::Stream::Slot>(slotNum));
return buffer_helpers::setValue(bufferView, vertexIndex, value);
}
@ -369,7 +369,7 @@ bool scriptable::ScriptableMeshPart::setIndices(const QVector<glm::uint32>& indi
return false;
}
glm::uint32 len = indices.size();
if (len != getNumVertices()) {
if (len != getNumIndices()) {
context()->throwError(QString("setIndices: currently new indicies must be assign 1:1 across old indicies (indicies.size()=%1, numIndices=%2)")
.arg(len).arg(getNumIndices()));
return false;

View file

@ -44,8 +44,6 @@ namespace scriptable {
scriptable::ScriptableModelPointer cloneModel(const QVariantMap& options = QVariantMap());
QString toString() const;
// QScriptEngine-specific wrappers
//glm::uint32 forEachMeshVertexAttribute(QScriptValue callback);
protected:
glm::uint32 getNumMeshes() { return meshes.size(); }
@ -54,5 +52,4 @@ namespace scriptable {
}
Q_DECLARE_METATYPE(scriptable::ScriptableModelPointer)
Q_DECLARE_METATYPE(scriptable::ScriptableModelBase)
Q_DECLARE_METATYPE(scriptable::ScriptableModelBasePointer)
Q_DECLARE_METATYPE(QVector<scriptable::ScriptableModelPointer>)

View file

@ -604,15 +604,20 @@ bool Model::replaceScriptableModelMeshPart(scriptable::ScriptableModelBasePointe
render::Transaction transaction;
const render::ScenePointer& scene = AbstractViewStateInterface::instance()->getMain3DScene();
meshIndex = meshIndex >= 0 ? meshIndex : 0;
partIndex = partIndex >= 0 ? partIndex : 0;
meshIndex = max(meshIndex, 0);
partIndex = max(partIndex, 0);
if (meshIndex >= meshes.size()) {
if (meshIndex >= (int)meshes.size()) {
qDebug() << meshIndex << "meshIndex >= newModel.meshes.size()" << meshes.size();
return false;
}
auto mesh = meshes[meshIndex].getMeshPointer();
if (partIndex >= (int)mesh->getNumParts()) {
qDebug() << partIndex << "partIndex >= mesh->getNumParts()" << mesh->getNumParts();
return false;
}
{
// update visual geometry
render::Transaction transaction;