mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 19:57:11 +02:00
make Blender keep a shared pointer to the model it's blending
This commit is contained in:
parent
bc0ea0e893
commit
9f0084dbb1
2 changed files with 11 additions and 12 deletions
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static int modelPointerTypeId = qRegisterMetaType<QPointer<Model> >();
|
static int nakedModelPointerTypeId = qRegisterMetaType<ModelPointer>();
|
||||||
static int weakNetworkGeometryPointerTypeId = qRegisterMetaType<QWeakPointer<NetworkGeometry> >();
|
static int weakNetworkGeometryPointerTypeId = qRegisterMetaType<QWeakPointer<NetworkGeometry> >();
|
||||||
static int vec3VectorTypeId = qRegisterMetaType<QVector<glm::vec3> >();
|
static int vec3VectorTypeId = qRegisterMetaType<QVector<glm::vec3> >();
|
||||||
float Model::FAKE_DIMENSION_PLACEHOLDER = -1.0f;
|
float Model::FAKE_DIMENSION_PLACEHOLDER = -1.0f;
|
||||||
|
@ -821,21 +821,21 @@ QStringList Model::getJointNames() const {
|
||||||
class Blender : public QRunnable {
|
class Blender : public QRunnable {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Blender(Model* model, int blendNumber, const QWeakPointer<NetworkGeometry>& geometry,
|
Blender(ModelPointer model, int blendNumber, const QWeakPointer<NetworkGeometry>& geometry,
|
||||||
const QVector<FBXMesh>& meshes, const QVector<float>& blendshapeCoefficients);
|
const QVector<FBXMesh>& meshes, const QVector<float>& blendshapeCoefficients);
|
||||||
|
|
||||||
virtual void run();
|
virtual void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QPointer<Model> _model;
|
ModelPointer _model;
|
||||||
int _blendNumber;
|
int _blendNumber;
|
||||||
QWeakPointer<NetworkGeometry> _geometry;
|
QWeakPointer<NetworkGeometry> _geometry;
|
||||||
QVector<FBXMesh> _meshes;
|
QVector<FBXMesh> _meshes;
|
||||||
QVector<float> _blendshapeCoefficients;
|
QVector<float> _blendshapeCoefficients;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blender::Blender(Model* model, int blendNumber, const QWeakPointer<NetworkGeometry>& geometry,
|
Blender::Blender(ModelPointer model, int blendNumber, const QWeakPointer<NetworkGeometry>& geometry,
|
||||||
const QVector<FBXMesh>& meshes, const QVector<float>& blendshapeCoefficients) :
|
const QVector<FBXMesh>& meshes, const QVector<float>& blendshapeCoefficients) :
|
||||||
_model(model),
|
_model(model),
|
||||||
_blendNumber(blendNumber),
|
_blendNumber(blendNumber),
|
||||||
|
@ -847,7 +847,7 @@ Blender::Blender(Model* model, int blendNumber, const QWeakPointer<NetworkGeomet
|
||||||
void Blender::run() {
|
void Blender::run() {
|
||||||
PROFILE_RANGE(__FUNCTION__);
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
QVector<glm::vec3> vertices, normals;
|
QVector<glm::vec3> vertices, normals;
|
||||||
if (!_model.isNull()) {
|
if (_model) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
foreach (const FBXMesh& mesh, _meshes) {
|
foreach (const FBXMesh& mesh, _meshes) {
|
||||||
if (mesh.blendshapes.isEmpty()) {
|
if (mesh.blendshapes.isEmpty()) {
|
||||||
|
@ -877,7 +877,7 @@ void Blender::run() {
|
||||||
}
|
}
|
||||||
// post the result to the geometry cache, which will dispatch to the model if still alive
|
// post the result to the geometry cache, which will dispatch to the model if still alive
|
||||||
QMetaObject::invokeMethod(DependencyManager::get<ModelBlender>().data(), "setBlendedVertices",
|
QMetaObject::invokeMethod(DependencyManager::get<ModelBlender>().data(), "setBlendedVertices",
|
||||||
Q_ARG(const QPointer<Model>&, _model), Q_ARG(int, _blendNumber),
|
Q_ARG(ModelPointer, _model), Q_ARG(int, _blendNumber),
|
||||||
Q_ARG(const QWeakPointer<NetworkGeometry>&, _geometry), Q_ARG(const QVector<glm::vec3>&, vertices),
|
Q_ARG(const QWeakPointer<NetworkGeometry>&, _geometry), Q_ARG(const QVector<glm::vec3>&, vertices),
|
||||||
Q_ARG(const QVector<glm::vec3>&, normals));
|
Q_ARG(const QVector<glm::vec3>&, normals));
|
||||||
}
|
}
|
||||||
|
@ -1088,7 +1088,7 @@ float Model::getLimbLength(int jointIndex) const {
|
||||||
bool Model::maybeStartBlender() {
|
bool Model::maybeStartBlender() {
|
||||||
const FBXGeometry& fbxGeometry = _geometry->getFBXGeometry();
|
const FBXGeometry& fbxGeometry = _geometry->getFBXGeometry();
|
||||||
if (fbxGeometry.hasBlendedMeshes()) {
|
if (fbxGeometry.hasBlendedMeshes()) {
|
||||||
QThreadPool::globalInstance()->start(new Blender(this, ++_blendNumber, _geometry,
|
QThreadPool::globalInstance()->start(new Blender(getThisPointer(), ++_blendNumber, _geometry,
|
||||||
fbxGeometry.meshes, _blendshapeCoefficients));
|
fbxGeometry.meshes, _blendshapeCoefficients));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1284,10 +1284,9 @@ void ModelBlender::noteRequiresBlend(ModelPointer model) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelBlender::setBlendedVertices(const QPointer<Model>& model, int blendNumber,
|
void ModelBlender::setBlendedVertices(ModelPointer model, int blendNumber,
|
||||||
const QWeakPointer<NetworkGeometry>& geometry, const QVector<glm::vec3>& vertices, const QVector<glm::vec3>& normals) {
|
const QWeakPointer<NetworkGeometry>& geometry, const QVector<glm::vec3>& vertices, const QVector<glm::vec3>& normals) {
|
||||||
|
if (model) {
|
||||||
if (!model.isNull()) {
|
|
||||||
model->setBlendedVertices(blendNumber, geometry, vertices, normals);
|
model->setBlendedVertices(blendNumber, geometry, vertices, normals);
|
||||||
}
|
}
|
||||||
_pendingBlenders--;
|
_pendingBlenders--;
|
||||||
|
|
|
@ -384,7 +384,7 @@ protected:
|
||||||
RigPointer _rig;
|
RigPointer _rig;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QPointer<Model>)
|
Q_DECLARE_METATYPE(ModelPointer)
|
||||||
Q_DECLARE_METATYPE(QWeakPointer<NetworkGeometry>)
|
Q_DECLARE_METATYPE(QWeakPointer<NetworkGeometry>)
|
||||||
|
|
||||||
/// Handle management of pending models that need blending
|
/// Handle management of pending models that need blending
|
||||||
|
@ -398,7 +398,7 @@ public:
|
||||||
void noteRequiresBlend(ModelPointer model);
|
void noteRequiresBlend(ModelPointer model);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setBlendedVertices(const QPointer<Model>& model, int blendNumber, const QWeakPointer<NetworkGeometry>& geometry,
|
void setBlendedVertices(ModelPointer model, int blendNumber, const QWeakPointer<NetworkGeometry>& geometry,
|
||||||
const QVector<glm::vec3>& vertices, const QVector<glm::vec3>& normals);
|
const QVector<glm::vec3>& vertices, const QVector<glm::vec3>& normals);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue