mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 20:58:38 +02:00
added EntityScriptingInterface::getEntityLocalTransform. try harder to make sure polyvox mesh is ready before giving it to javascript
This commit is contained in:
parent
c45d4660e5
commit
98cae8d152
5 changed files with 43 additions and 13 deletions
|
@ -1312,7 +1312,7 @@ void RenderablePolyVoxEntityItem::setMesh(model::MeshPointer mesh) {
|
||||||
}
|
}
|
||||||
_mesh = mesh;
|
_mesh = mesh;
|
||||||
_meshDirty = true;
|
_meshDirty = true;
|
||||||
_meshInitialized = true;
|
_meshReady = true;
|
||||||
neighborsNeedUpdate = _neighborsNeedUpdate;
|
neighborsNeedUpdate = _neighborsNeedUpdate;
|
||||||
_neighborsNeedUpdate = false;
|
_neighborsNeedUpdate = false;
|
||||||
});
|
});
|
||||||
|
@ -1324,7 +1324,7 @@ void RenderablePolyVoxEntityItem::setMesh(model::MeshPointer mesh) {
|
||||||
void RenderablePolyVoxEntityItem::computeShapeInfoWorker() {
|
void RenderablePolyVoxEntityItem::computeShapeInfoWorker() {
|
||||||
// this creates a collision-shape for the physics engine. The shape comes from
|
// this creates a collision-shape for the physics engine. The shape comes from
|
||||||
// _volData for cubic extractors and from _mesh for marching-cube extractors
|
// _volData for cubic extractors and from _mesh for marching-cube extractors
|
||||||
if (!_meshInitialized) {
|
if (!_meshReady) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1601,15 +1601,22 @@ bool RenderablePolyVoxEntityItem::getMeshAsScriptValue(QScriptEngine *engine, QS
|
||||||
MeshProxy* meshProxy = nullptr;
|
MeshProxy* meshProxy = nullptr;
|
||||||
glm::mat4 transform = voxelToLocalMatrix();
|
glm::mat4 transform = voxelToLocalMatrix();
|
||||||
withReadLock([&] {
|
withReadLock([&] {
|
||||||
if (_meshInitialized) {
|
gpu::BufferView::Index numVertices = (gpu::BufferView::Index)_mesh->getNumVertices();
|
||||||
|
if (!_meshReady) {
|
||||||
|
// we aren't ready to return a mesh. the caller will have to try again later.
|
||||||
|
success = false;
|
||||||
|
} else if (numVertices == 0) {
|
||||||
|
// we are ready, but there are no triangles in the mesh.
|
||||||
|
success = true;
|
||||||
|
} else {
|
||||||
success = true;
|
success = true;
|
||||||
// the mesh will be in voxel-space. transform it into object-space
|
// the mesh will be in voxel-space. transform it into object-space
|
||||||
meshProxy = new MeshProxy(
|
meshProxy = new MeshProxy(
|
||||||
_mesh->map([=](glm::vec3 position){ return glm::vec3(transform * glm::vec4(position, 1.0f)); },
|
_mesh->map([=](glm::vec3 position){ return glm::vec3(transform * glm::vec4(position, 1.0f)); },
|
||||||
[=](glm::vec3 normal){ return glm::vec3(transform * glm::vec4(normal, 0.0f)); },
|
[=](glm::vec3 normal){ return glm::vec3(transform * glm::vec4(normal, 0.0f)); },
|
||||||
[](uint32_t index){ return index; }));
|
[&](uint32_t index){ return index; }));
|
||||||
|
result = meshToScriptValue(engine, meshProxy);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
result = meshToScriptValue(engine, meshProxy);
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ public:
|
||||||
uint8_t getVoxelInternal(int x, int y, int z) const;
|
uint8_t getVoxelInternal(int x, int y, int z) const;
|
||||||
bool setVoxelInternal(int x, int y, int z, uint8_t toValue);
|
bool setVoxelInternal(int x, int y, int z, uint8_t toValue);
|
||||||
|
|
||||||
void setVolDataDirty() { withWriteLock([&] { _volDataDirty = true; }); }
|
void setVolDataDirty() { withWriteLock([&] { _volDataDirty = true; _meshReady = false; }); }
|
||||||
|
|
||||||
// Transparent polyvox didn't seem to be working so disable for now
|
// Transparent polyvox didn't seem to be working so disable for now
|
||||||
bool isTransparent() override { return false; }
|
bool isTransparent() override { return false; }
|
||||||
|
@ -157,7 +157,7 @@ private:
|
||||||
model::MeshPointer _mesh;
|
model::MeshPointer _mesh;
|
||||||
gpu::Stream::FormatPointer _vertexFormat;
|
gpu::Stream::FormatPointer _vertexFormat;
|
||||||
bool _meshDirty { true }; // does collision-shape need to be recomputed?
|
bool _meshDirty { true }; // does collision-shape need to be recomputed?
|
||||||
bool _meshInitialized { false };
|
bool _meshReady { false };
|
||||||
|
|
||||||
NetworkTexturePointer _xTexture;
|
NetworkTexturePointer _xTexture;
|
||||||
NetworkTexturePointer _yTexture;
|
NetworkTexturePointer _yTexture;
|
||||||
|
|
|
@ -934,11 +934,7 @@ void EntityScriptingInterface::voxelsToMesh(QUuid entityID, QScriptValue callbac
|
||||||
QScriptValue mesh { false };
|
QScriptValue mesh { false };
|
||||||
|
|
||||||
polyVoxWorker(entityID, [&](PolyVoxEntityItem& polyVoxEntity) mutable {
|
polyVoxWorker(entityID, [&](PolyVoxEntityItem& polyVoxEntity) mutable {
|
||||||
if (polyVoxEntity.getOnCount() == 0) {
|
success = polyVoxEntity.getMeshAsScriptValue(callback.engine(), mesh);
|
||||||
success = true;
|
|
||||||
} else {
|
|
||||||
success = polyVoxEntity.getMeshAsScriptValue(callback.engine(), mesh);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1578,3 +1574,20 @@ glm::mat4 EntityScriptingInterface::getEntityTransform(const QUuid& entityID) {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::mat4 EntityScriptingInterface::getEntityLocalTransform(const QUuid& entityID) {
|
||||||
|
glm::mat4 result;
|
||||||
|
if (_entityTree) {
|
||||||
|
_entityTree->withReadLock([&] {
|
||||||
|
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(EntityItemID(entityID));
|
||||||
|
if (entity) {
|
||||||
|
glm::mat4 translation = glm::translate(entity->getLocalPosition());
|
||||||
|
glm::mat4 rotation = glm::mat4_cast(entity->getLocalOrientation());
|
||||||
|
glm::mat4 registration = glm::translate(ENTITY_ITEM_DEFAULT_REGISTRATION_POINT -
|
||||||
|
entity->getRegistrationPoint());
|
||||||
|
result = translation * rotation * registration;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
@ -304,6 +304,16 @@ public slots:
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE glm::mat4 getEntityTransform(const QUuid& entityID);
|
Q_INVOKABLE glm::mat4 getEntityTransform(const QUuid& entityID);
|
||||||
|
|
||||||
|
|
||||||
|
/**jsdoc
|
||||||
|
* Returns object to world transform, excluding scale
|
||||||
|
*
|
||||||
|
* @function Entities.getEntityLocalTransform
|
||||||
|
* @param {EntityID} entityID The ID of the entity whose local transform is to be returned
|
||||||
|
* @return {Mat4} Entity's object to parent transform, excluding scale
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE glm::mat4 getEntityLocalTransform(const QUuid& entityID);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void collisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
void collisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
||||||
|
|
||||||
|
|
|
@ -228,7 +228,7 @@ void Mesh::forEach(std::function<void(glm::vec3)> vertexFunc,
|
||||||
|
|
||||||
// normal data
|
// normal data
|
||||||
const gpu::BufferView& normalsBufferView = getAttributeBuffer(attributeTypeNormal);
|
const gpu::BufferView& normalsBufferView = getAttributeBuffer(attributeTypeNormal);
|
||||||
gpu::BufferView::Index numNormals = (gpu::BufferView::Index) normalsBufferView.getNumElements();
|
gpu::BufferView::Index numNormals = (gpu::BufferView::Index)normalsBufferView.getNumElements();
|
||||||
for (gpu::BufferView::Index i = 0; i < numNormals; i ++) {
|
for (gpu::BufferView::Index i = 0; i < numNormals; i ++) {
|
||||||
normalFunc(normalsBufferView.get<glm::vec3>(i));
|
normalFunc(normalsBufferView.get<glm::vec3>(i));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue