mirror of
https://github.com/lubosz/overte.git
synced 2025-05-28 00:51:33 +02:00
Fix not being able to use both QVector<unsigned int> and QVector<glm::uint32> in scripting
This commit is contained in:
parent
27cf080ad6
commit
0bd00c3554
5 changed files with 21 additions and 22 deletions
|
@ -59,8 +59,8 @@ glm::uint32 scriptable::ScriptableMesh::getNumVertices() const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<unsigned int> scriptable::ScriptableMesh::findNearbyVertexIndices(const glm::vec3& origin, float epsilon) const {
|
QVector<glm::uint32> scriptable::ScriptableMesh::findNearbyVertexIndices(const glm::vec3& origin, float epsilon) const {
|
||||||
QVector<unsigned int> result;
|
QVector<glm::uint32> result;
|
||||||
if (!isValid()) {
|
if (!isValid()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -74,14 +74,14 @@ QVector<unsigned int> scriptable::ScriptableMesh::findNearbyVertexIndices(const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<unsigned int> scriptable::ScriptableMesh::getIndices() const {
|
QVector<glm::uint32> scriptable::ScriptableMesh::getIndices() const {
|
||||||
if (auto mesh = getMeshPointer()) {
|
if (auto mesh = getMeshPointer()) {
|
||||||
#ifdef SCRIPTABLE_MESH_DEBUG
|
#ifdef SCRIPTABLE_MESH_DEBUG
|
||||||
qCDebug(graphics_scripting, "getIndices mesh %p", mesh.get());
|
qCDebug(graphics_scripting, "getIndices mesh %p", mesh.get());
|
||||||
#endif
|
#endif
|
||||||
return buffer_helpers::bufferToVector<glm::uint32>(mesh->getIndexBuffer());
|
return buffer_helpers::bufferToVector<glm::uint32>(mesh->getIndexBuffer());
|
||||||
}
|
}
|
||||||
return QVector<unsigned int>();
|
return QVector<glm::uint32>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -83,9 +83,8 @@ namespace scriptable {
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
const scriptable::ScriptableModelPointer getParentModel() const { return qobject_cast<scriptable::ScriptableModel*>(model); }
|
const scriptable::ScriptableModelPointer getParentModel() const { return qobject_cast<scriptable::ScriptableModel*>(model); }
|
||||||
// Functions exposed to scripts need to use QVector<unsigned int> instead of QVector<glm::uint32> as a workaround to QScriptEngine meta types
|
QVector<glm::uint32> getIndices() const;
|
||||||
QVector<unsigned int> getIndices() const;
|
QVector<glm::uint32> findNearbyVertexIndices(const glm::vec3& origin, float epsilon = 1e-6) const;
|
||||||
QVector<unsigned int> findNearbyVertexIndices(const glm::vec3& origin, float epsilon = 1e-6) const;
|
|
||||||
|
|
||||||
glm::uint32 addAttribute(const QString& attributeName, const QVariant& defaultValue = QVariant());
|
glm::uint32 addAttribute(const QString& attributeName, const QVariant& defaultValue = QVariant());
|
||||||
glm::uint32 fillAttribute(const QString& attributeName, const QVariant& value);
|
glm::uint32 fillAttribute(const QString& attributeName, const QVariant& value);
|
||||||
|
|
|
@ -244,8 +244,8 @@ glm::uint32 scriptable::ScriptableMeshPart::fillAttribute(const QString& attribu
|
||||||
return isValid() ? parentMesh->fillAttribute(attributeName, value) : 0;
|
return isValid() ? parentMesh->fillAttribute(attributeName, value) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<unsigned int> scriptable::ScriptableMeshPart::findNearbyPartVertexIndices(const glm::vec3& origin, float epsilon) const {
|
QVector<glm::uint32> scriptable::ScriptableMeshPart::findNearbyPartVertexIndices(const glm::vec3& origin, float epsilon) const {
|
||||||
QSet<unsigned int> result;
|
QSet<glm::uint32> result;
|
||||||
if (!isValid()) {
|
if (!isValid()) {
|
||||||
return result.toList().toVector();
|
return result.toList().toVector();
|
||||||
}
|
}
|
||||||
|
@ -328,14 +328,14 @@ scriptable::ScriptableMeshPart::ScriptableMeshPart(scriptable::ScriptableMeshPoi
|
||||||
setObjectName(QString("%1.part[%2]").arg(parentMesh ? parentMesh->objectName() : "").arg(partIndex));
|
setObjectName(QString("%1.part[%2]").arg(parentMesh ? parentMesh->objectName() : "").arg(partIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<unsigned int> scriptable::ScriptableMeshPart::getIndices() const {
|
QVector<glm::uint32> scriptable::ScriptableMeshPart::getIndices() const {
|
||||||
if (auto mesh = getMeshPointer()) {
|
if (auto mesh = getMeshPointer()) {
|
||||||
#ifdef SCRIPTABLE_MESH_DEBUG
|
#ifdef SCRIPTABLE_MESH_DEBUG
|
||||||
qCDebug(graphics_scripting, "getIndices mesh %p", mesh.get());
|
qCDebug(graphics_scripting, "getIndices mesh %p", mesh.get());
|
||||||
#endif
|
#endif
|
||||||
return buffer_helpers::bufferToVector<glm::uint32>(mesh->getIndexBuffer());
|
return buffer_helpers::bufferToVector<glm::uint32>(mesh->getIndexBuffer());
|
||||||
}
|
}
|
||||||
return QVector<unsigned int>();
|
return QVector<glm::uint32>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool scriptable::ScriptableMeshPart::setFirstVertexIndex( glm::uint32 vertexIndex) {
|
bool scriptable::ScriptableMeshPart::setFirstVertexIndex( glm::uint32 vertexIndex) {
|
||||||
|
@ -365,11 +365,11 @@ bool scriptable::ScriptableMeshPart::setLastVertexIndex( glm::uint32 vertexIndex
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool scriptable::ScriptableMeshPart::setIndices(const QVector<unsigned int>& indices) {
|
bool scriptable::ScriptableMeshPart::setIndices(const QVector<glm::uint32>& indices) {
|
||||||
if (!isValid()) {
|
if (!isValid()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
unsigned int len = indices.size();
|
glm::uint32 len = indices.size();
|
||||||
if (len != getNumIndices()) {
|
if (len != getNumIndices()) {
|
||||||
context()->throwError(QString("setIndices: currently new indicies must be assign 1:1 across old indicies (indicies.size()=%1, numIndices=%2)")
|
context()->throwError(QString("setIndices: currently new indicies must be assign 1:1 across old indicies (indicies.size()=%1, numIndices=%2)")
|
||||||
.arg(len).arg(getNumIndices()));
|
.arg(len).arg(getNumIndices()));
|
||||||
|
@ -379,14 +379,14 @@ bool scriptable::ScriptableMeshPart::setIndices(const QVector<unsigned int>& ind
|
||||||
auto indexBuffer = mesh->getIndexBuffer();
|
auto indexBuffer = mesh->getIndexBuffer();
|
||||||
|
|
||||||
// first loop to validate all indices are valid
|
// first loop to validate all indices are valid
|
||||||
for (unsigned int i = 0; i < len; i++) {
|
for (glm::uint32 i = 0; i < len; i++) {
|
||||||
if (!isValidIndex(indices.at(i))) {
|
if (!isValidIndex(indices.at(i))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const auto first = getFirstVertexIndex();
|
const auto first = getFirstVertexIndex();
|
||||||
// now actually apply them
|
// now actually apply them
|
||||||
for (unsigned int i = 0; i < len; i++) {
|
for (glm::uint32 i = 0; i < len; i++) {
|
||||||
buffer_helpers::setValue(indexBuffer, first + i, indices.at(i));
|
buffer_helpers::setValue(indexBuffer, first + i, indices.at(i));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -431,7 +431,7 @@ glm::uint32 scriptable::ScriptableMeshPart::getTopologyLength() const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<unsigned int> scriptable::ScriptableMeshPart::getFace(unsigned int faceIndex) const {
|
QVector<glm::uint32> scriptable::ScriptableMeshPart::getFace(glm::uint32 faceIndex) const {
|
||||||
switch (getTopology()) {
|
switch (getTopology()) {
|
||||||
case graphics::Mesh::Topology::POINTS:
|
case graphics::Mesh::Topology::POINTS:
|
||||||
case graphics::Mesh::Topology::LINES:
|
case graphics::Mesh::Topology::LINES:
|
||||||
|
@ -440,7 +440,7 @@ QVector<unsigned int> scriptable::ScriptableMeshPart::getFace(unsigned int faceI
|
||||||
if (faceIndex < getNumFaces()) {
|
if (faceIndex < getNumFaces()) {
|
||||||
return getIndices().mid(faceIndex * getTopologyLength(), getTopologyLength());
|
return getIndices().mid(faceIndex * getTopologyLength(), getTopologyLength());
|
||||||
}
|
}
|
||||||
default: return QVector<unsigned int>();
|
default: return QVector<glm::uint32>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,10 +55,9 @@ namespace scriptable {
|
||||||
bool isValid() const { auto mesh = getMeshPointer(); return mesh && partIndex < mesh->getNumParts(); }
|
bool isValid() const { auto mesh = getMeshPointer(); return mesh && partIndex < mesh->getNumParts(); }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// Functions exposed to scripts need to use QVector<unsigned int> instead of QVector<glm::uint32> as a workaround to QScriptEngine meta types
|
QVector<glm::uint32> getIndices() const;
|
||||||
QVector<unsigned int> getIndices() const;
|
bool setIndices(const QVector<glm::uint32>& indices);
|
||||||
bool setIndices(const QVector<unsigned int>& indices);
|
QVector<glm::uint32> findNearbyPartVertexIndices(const glm::vec3& origin, float epsilon = 1e-6) const;
|
||||||
QVector<unsigned int> findNearbyPartVertexIndices(const glm::vec3& origin, float epsilon = 1e-6) const;
|
|
||||||
QVariantList queryVertexAttributes(QVariant selector) const;
|
QVariantList queryVertexAttributes(QVariant selector) const;
|
||||||
QVariantMap getVertexAttributes(glm::uint32 vertexIndex) const;
|
QVariantMap getVertexAttributes(glm::uint32 vertexIndex) const;
|
||||||
bool setVertexAttributes(glm::uint32 vertexIndex, const QVariantMap& attributeValues);
|
bool setVertexAttributes(glm::uint32 vertexIndex, const QVariantMap& attributeValues);
|
||||||
|
@ -66,7 +65,7 @@ namespace scriptable {
|
||||||
QVariant getVertexProperty(glm::uint32 vertexIndex, const QString& attributeName) const;
|
QVariant getVertexProperty(glm::uint32 vertexIndex, const QString& attributeName) const;
|
||||||
bool setVertexProperty(glm::uint32 vertexIndex, const QString& attributeName, const QVariant& attributeValues);
|
bool setVertexProperty(glm::uint32 vertexIndex, const QString& attributeName, const QVariant& attributeValues);
|
||||||
|
|
||||||
QVector<unsigned int> getFace(glm::uint32 faceIndex) const;
|
QVector<glm::uint32> getFace(glm::uint32 faceIndex) const;
|
||||||
|
|
||||||
QVariantMap scaleToFit(float unitScale);
|
QVariantMap scaleToFit(float unitScale);
|
||||||
QVariantMap translate(const glm::vec3& translation);
|
QVariantMap translate(const glm::vec3& translation);
|
||||||
|
|
|
@ -35,6 +35,7 @@ int vec4MetaTypeId = qRegisterMetaType<glm::vec4>();
|
||||||
int qVectorVec3MetaTypeId = qRegisterMetaType<QVector<glm::vec3>>();
|
int qVectorVec3MetaTypeId = qRegisterMetaType<QVector<glm::vec3>>();
|
||||||
int qVectorQuatMetaTypeId = qRegisterMetaType<QVector<glm::quat>>();
|
int qVectorQuatMetaTypeId = qRegisterMetaType<QVector<glm::quat>>();
|
||||||
int qVectorBoolMetaTypeId = qRegisterMetaType<QVector<bool>>();
|
int qVectorBoolMetaTypeId = qRegisterMetaType<QVector<bool>>();
|
||||||
|
int qVectorGLMUint32MetaTypeId = qRegisterMetaType<QVector<unsigned int>>("QVector<glm::uint32>");
|
||||||
int quatMetaTypeId = qRegisterMetaType<glm::quat>();
|
int quatMetaTypeId = qRegisterMetaType<glm::quat>();
|
||||||
int pickRayMetaTypeId = qRegisterMetaType<PickRay>();
|
int pickRayMetaTypeId = qRegisterMetaType<PickRay>();
|
||||||
int collisionMetaTypeId = qRegisterMetaType<Collision>();
|
int collisionMetaTypeId = qRegisterMetaType<Collision>();
|
||||||
|
|
Loading…
Reference in a new issue