EntityScriptingInterface::getMeshes support for Model entities

This commit is contained in:
Seth Alves 2017-07-19 08:59:09 -07:00
parent 044b8fc19a
commit a8698c2fbc
6 changed files with 48 additions and 2 deletions

View file

@ -1282,3 +1282,10 @@ void RenderableModelEntityItem::mapJoints(const QStringList& modelJointNames) {
}
}
}
bool RenderableModelEntityItem::getMeshes(MeshProxyList& result) {
if (!_model || !_model->isLoaded()) {
return false;
}
return _model->getMeshes(result);
}

View file

@ -116,6 +116,8 @@ public:
return _animation;
}
bool getMeshes(MeshProxyList& result) override;
private:
QVariantMap parseTexturesToMap(QString textures);
void remapTextures();

View file

@ -137,7 +137,7 @@ Box Mesh::evalPartsBound(int partStart, int partEnd) const {
model::MeshPointer Mesh::map(std::function<glm::vec3(glm::vec3)> vertexFunc,
std::function<glm::vec3(glm::vec3)> normalFunc,
std::function<uint32_t(uint32_t)> indexFunc) {
std::function<uint32_t(uint32_t)> indexFunc) const {
// vertex data
const gpu::BufferView& vertexBufferView = getVertexBuffer();
gpu::BufferView::Index numVertices = (gpu::BufferView::Index)getNumVertices();

View file

@ -124,7 +124,7 @@ public:
// create a copy of this mesh after passing its vertices, normals, and indexes though the provided functions
MeshPointer map(std::function<glm::vec3(glm::vec3)> vertexFunc,
std::function<glm::vec3(glm::vec3)> normalFunc,
std::function<uint32_t(uint32_t)> indexFunc);
std::function<uint32_t(uint32_t)> indexFunc) const;
void forEach(std::function<void(glm::vec3)> vertexFunc,
std::function<void(glm::vec3)> normalFunc,

View file

@ -24,6 +24,7 @@
#include <PerfStat.h>
#include <ViewFrustum.h>
#include <GLMHelpers.h>
#include <model-networking/SimpleMeshProxy.h>
#include "AbstractViewStateInterface.h"
#include "MeshPartPayload.h"
@ -462,6 +463,40 @@ bool Model::convexHullContains(glm::vec3 point) {
return false;
}
bool Model::getMeshes(MeshProxyList& result) {
const Geometry::Pointer& renderGeometry = getGeometry();
const Geometry::GeometryMeshes& meshes = renderGeometry->getMeshes();
if (!isLoaded()) {
return false;
}
Transform offset;
offset.setScale(_scale);
// not set -- far to the right
// offset.postTranslate(_offset); // far to right
// offset.postTranslate(-_offset); // a bit to left
glm::mat4 offsetMat = offset.getMatrix();
for (std::shared_ptr<const model::Mesh> mesh : meshes) {
if (!mesh) {
continue;
}
MeshProxy* meshProxy = new SimpleMeshProxy(
mesh->map([=](glm::vec3 position) {
const glm::vec3 DEFAULT_ENTITY_REGISTRATION_POINT = glm::vec3(0.5f, 0.5f, 0.5f);
glm::vec3 regis = _registrationPoint - DEFAULT_ENTITY_REGISTRATION_POINT;
return glm::vec3(offsetMat * glm::vec4(position + _offset, 1.0f)) + regis; // very close
},
[=](glm::vec3 normal){ return glm::normalize(glm::vec3(offsetMat * glm::vec4(normal, 0.0f))); },
[&](uint32_t index){ return index; }));
result << meshProxy;
}
return true;
}
void Model::calculateTriangleSets() {
PROFILE_RANGE(render, __FUNCTION__);

View file

@ -257,6 +257,8 @@ public:
int getResourceDownloadAttempts() { return _renderWatcher.getResourceDownloadAttempts(); }
int getResourceDownloadAttemptsRemaining() { return _renderWatcher.getResourceDownloadAttemptsRemaining(); }
bool getMeshes(MeshProxyList& result);
public slots:
void loadURLFinished(bool success);