History

isolate calls to the QtScript libraries to an interface we control

Heather Anderson committed 5 years ago

Commit 1e018db1 parent 713b29e260 files · +6904 −5064Browse files

Showing the changes to libraries/script-engine/src/ModelScriptingInterface.cpp (1 of 260 files). Show all

Unified · Split

libraries/script-engine/src/ModelScriptingInterface.cpp+24−24
@@ -10,20 +10,20 @@ · 9 unmodified lines
10//10//
11 11
12#include "ModelScriptingInterface.h"12#include "ModelScriptingInterface.h"
13#include <QtScript/QScriptEngine>
14#include <QtScript/QScriptValueIterator>
15#include <QtScript/QScriptValue>
16#include <model-networking/SimpleMeshProxy.h>13#include <model-networking/SimpleMeshProxy.h>
17#include "ScriptEngine.h"14#include "ScriptEngine.h"
15#include "ScriptEngineCast.h"
18#include "ScriptEngineLogging.h"16#include "ScriptEngineLogging.h"
17#include "ScriptManager.h"
18#include "ScriptValueUtils.h"
19#include "OBJWriter.h"19#include "OBJWriter.h"
20 20
21ModelScriptingInterface::ModelScriptingInterface(QObject* parent) : QObject(parent) {21ModelScriptingInterface::ModelScriptingInterface(QObject* parent) : QObject(parent) {
22 _modelScriptEngine = qobject_cast<QScriptEngine*>(parent);22 _modelScriptEngine = qobject_cast<ScriptManager*>(parent)->engine();
23 23
24 qScriptRegisterSequenceMetaType<QList<MeshProxy*>>(_modelScriptEngine);24 scriptRegisterSequenceMetaType<QList<MeshProxy*>>(_modelScriptEngine.get());
25 qScriptRegisterMetaType(_modelScriptEngine, meshFaceToScriptValue, meshFaceFromScriptValue);25 scriptRegisterMetaType(_modelScriptEngine.get(), meshFaceToScriptValue, meshFaceFromScriptValue);
26 qScriptRegisterMetaType(_modelScriptEngine, qVectorMeshFaceToScriptValue, qVectorMeshFaceFromScriptValue);26 scriptRegisterMetaType(_modelScriptEngine.get(), qVectorMeshFaceToScriptValue, qVectorMeshFaceFromScriptValue);
27}27}
28 28
29QString ModelScriptingInterface::meshToOBJ(MeshProxyList in) {29QString ModelScriptingInterface::meshToOBJ(MeshProxyList in) {
@@ -35,7 +35,7 @@ QString ModelScriptingInterface::meshToOBJ(MeshProxyList in) { · 5 unmodified lines
35 return writeOBJToString(meshes);35 return writeOBJToString(meshes);
36}36}
37 37
38QScriptValue ModelScriptingInterface::appendMeshes(MeshProxyList in) {38ScriptValuePointer ModelScriptingInterface::appendMeshes(MeshProxyList in) {
39 // figure out the size of the resulting mesh39 // figure out the size of the resulting mesh
40 size_t totalVertexCount { 0 };40 size_t totalVertexCount { 0 };
41 size_t totalColorCount { 0 };41 size_t totalColorCount { 0 };
@@ -140,16 +140,16 @@ QScriptValue ModelScriptingInterface::appendMeshes(MeshProxyList in) { · 98 unmodified lines
140 140
141 141
142 MeshProxy* resultProxy = new SimpleMeshProxy(result);142 MeshProxy* resultProxy = new SimpleMeshProxy(result);
143 return meshToScriptValue(_modelScriptEngine, resultProxy);143 return meshToScriptValue(_modelScriptEngine.get(), resultProxy);
144}144}
145 145
146QScriptValue ModelScriptingInterface::transformMesh(glm::mat4 transform, MeshProxy* meshProxy) {146ScriptValuePointer ModelScriptingInterface::transformMesh(glm::mat4 transform, MeshProxy* meshProxy) {
147 if (!meshProxy) {147 if (!meshProxy) {
148 return QScriptValue(false);148 return ScriptValuePointer(false);
149 }149 }
150 MeshPointer mesh = meshProxy->getMeshPointer();150 MeshPointer mesh = meshProxy->getMeshPointer();
151 if (!mesh) {151 if (!mesh) {
152 return QScriptValue(false);152 return ScriptValuePointer(false);
153 }153 }
154 154
155 const auto inverseTransposeTransform = glm::inverse(glm::transpose(transform));155 const auto inverseTransposeTransform = glm::inverse(glm::transpose(transform));
@@ -158,45 +158,45 @@ QScriptValue ModelScriptingInterface::transformMesh(glm::mat4 transform, MeshPro · 2 unmodified lines
158 [&](glm::vec3 normal){ return glm::vec3(inverseTransposeTransform * glm::vec4(normal, 0.0f)); },158 [&](glm::vec3 normal){ return glm::vec3(inverseTransposeTransform * glm::vec4(normal, 0.0f)); },
159 [&](uint32_t index){ return index; });159 [&](uint32_t index){ return index; });
160 MeshProxy* resultProxy = new SimpleMeshProxy(result);160 MeshProxy* resultProxy = new SimpleMeshProxy(result);
161 return meshToScriptValue(_modelScriptEngine, resultProxy);161 return meshToScriptValue(_modelScriptEngine.get(), resultProxy);
162}162}
163 163
164QScriptValue ModelScriptingInterface::getVertexCount(MeshProxy* meshProxy) {164ScriptValuePointer ModelScriptingInterface::getVertexCount(MeshProxy* meshProxy) {
165 if (!meshProxy) {165 if (!meshProxy) {
166 return QScriptValue(false);166 return ScriptValuePointer(false);
167 }167 }
168 MeshPointer mesh = meshProxy->getMeshPointer();168 MeshPointer mesh = meshProxy->getMeshPointer();
169 if (!mesh) {169 if (!mesh) {
170 return QScriptValue(false);170 return ScriptValuePointer(false);
171 }171 }
172 172
173 gpu::BufferView::Index numVertices = (gpu::BufferView::Index)mesh->getNumVertices();173 gpu::BufferView::Index numVertices = (gpu::BufferView::Index)mesh->getNumVertices();
174 174
175 return numVertices;175 return _modelScriptEngine->newValue(numVertices);
176}176}
177 177
178QScriptValue ModelScriptingInterface::getVertex(MeshProxy* meshProxy, int vertexIndex) {178ScriptValuePointer ModelScriptingInterface::getVertex(MeshProxy* meshProxy, int vertexIndex) {
179 if (!meshProxy) {179 if (!meshProxy) {
180 return QScriptValue(false);180 return ScriptValuePointer(false);
181 }181 }
182 MeshPointer mesh = meshProxy->getMeshPointer();182 MeshPointer mesh = meshProxy->getMeshPointer();
183 if (!mesh) {183 if (!mesh) {
184 return QScriptValue(false);184 return ScriptValuePointer(false);
185 }185 }
186 186
187 const gpu::BufferView& vertexBufferView = mesh->getVertexBuffer();187 const gpu::BufferView& vertexBufferView = mesh->getVertexBuffer();
188 gpu::BufferView::Index numVertices = (gpu::BufferView::Index)mesh->getNumVertices();188 gpu::BufferView::Index numVertices = (gpu::BufferView::Index)mesh->getNumVertices();
189 189
190 if (vertexIndex < 0 || vertexIndex >= numVertices) {190 if (vertexIndex < 0 || vertexIndex >= numVertices) {
191 return QScriptValue(false);191 return ScriptValuePointer(false);
192 }192 }
193 193
194 glm::vec3 pos = vertexBufferView.get<glm::vec3>(vertexIndex);194 glm::vec3 pos = vertexBufferView.get<glm::vec3>(vertexIndex);
195 return vec3ToScriptValue(_modelScriptEngine, pos);195 return vec3ToScriptValue(_modelScriptEngine.get(), pos);
196}196}
197 197
198 198
199QScriptValue ModelScriptingInterface::newMesh(const QVector<glm::vec3>& vertices,199ScriptValuePointer ModelScriptingInterface::newMesh(const QVector<glm::vec3>& vertices,
200 const QVector<glm::vec3>& normals,200 const QVector<glm::vec3>& normals,
201 const QVector<MeshFace>& faces) {201 const QVector<MeshFace>& faces) {
202 graphics::MeshPointer mesh(std::make_shared<graphics::Mesh>());202 graphics::MeshPointer mesh(std::make_shared<graphics::Mesh>());
@@ -247,5 +247,5 @@ QScriptValue ModelScriptingInterface::newMesh(const QVector<glm::vec3>& vertices · 44 unmodified lines
247 247
248 248
249 MeshProxy* meshProxy = new SimpleMeshProxy(mesh);249 MeshProxy* meshProxy = new SimpleMeshProxy(mesh);
250 return meshToScriptValue(_modelScriptEngine, meshProxy);250 return meshToScriptValue(_modelScriptEngine.get(), meshProxy);
251}251}