mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
started to hook up geometry downloader to ShapeInfo
This commit is contained in:
parent
844085b514
commit
1c73f50dbc
11 changed files with 169 additions and 96 deletions
|
@ -411,3 +411,7 @@ QString ModelEntityItem::getAnimationSettings() const {
|
|||
QString jsonByteString(jsonByteArray);
|
||||
return jsonByteString;
|
||||
}
|
||||
|
||||
void ModelEntityItem::computeShapeInfo(ShapeInfo& info) const {
|
||||
info.setParams(getShapeType(), 0.5f * getDimensions(), NULL, _collisionModelURL);
|
||||
}
|
||||
|
|
|
@ -48,11 +48,14 @@ public:
|
|||
virtual bool needsToCallUpdate() const;
|
||||
virtual void debugDump() const;
|
||||
|
||||
virtual void computeShapeInfo(ShapeInfo& info) const;
|
||||
|
||||
void updateShapeType(ShapeType type);
|
||||
virtual ShapeType getShapeType() const {
|
||||
// return _shapeType;
|
||||
// XXX make hull an option in editentity.js
|
||||
if (_collisionModelURL != "") {
|
||||
return SHAPE_TYPE_HULL;
|
||||
return SHAPE_TYPE_CONVEX_HULL;
|
||||
} else {
|
||||
return _shapeType;
|
||||
}
|
||||
|
|
|
@ -23,14 +23,14 @@
|
|||
|
||||
#if defined(NSIGHT_FOUND)
|
||||
#include "nvToolsExt.h"
|
||||
class ProfileRange {
|
||||
public:
|
||||
ProfileRange(const char *name) {
|
||||
nvtxRangePush(name);
|
||||
}
|
||||
~ProfileRange() {
|
||||
nvtxRangePop();
|
||||
}
|
||||
class ProfileRange {
|
||||
public:
|
||||
ProfileRange(const char *name) {
|
||||
nvtxRangePush(name);
|
||||
}
|
||||
~ProfileRange() {
|
||||
nvtxRangePop();
|
||||
}
|
||||
};
|
||||
|
||||
#define PROFILE_RANGE(name) ProfileRange profileRangeThis(name);
|
||||
|
@ -110,17 +110,17 @@ public:
|
|||
// For now, instead of calling the raw glCall, use the equivalent call on the batch so the call is beeing recorded
|
||||
// THe implementation of these functions is in GLBackend.cpp
|
||||
|
||||
void _glEnable(GLenum cap);
|
||||
void _glDisable(GLenum cap);
|
||||
|
||||
void _glEnable(GLenum cap);
|
||||
void _glDisable(GLenum cap);
|
||||
|
||||
void _glEnableClientState(GLenum array);
|
||||
void _glDisableClientState(GLenum array);
|
||||
|
||||
void _glCullFace(GLenum mode);
|
||||
void _glAlphaFunc(GLenum func, GLclampf ref);
|
||||
|
||||
void _glDepthFunc(GLenum func);
|
||||
void _glDepthMask(GLboolean flag);
|
||||
void _glDepthFunc(GLenum func);
|
||||
void _glDepthMask(GLboolean flag);
|
||||
void _glDepthRange(GLclampd zNear, GLclampd zFar);
|
||||
|
||||
void _glBindBuffer(GLenum target, GLuint buffer);
|
||||
|
@ -134,14 +134,14 @@ public:
|
|||
void _glUniform1f(GLint location, GLfloat v0);
|
||||
void _glUniform2f(GLint location, GLfloat v0, GLfloat v1);
|
||||
void _glUniform4fv(GLint location, GLsizei count, const GLfloat* value);
|
||||
void _glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
void _glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
|
||||
void _glDrawArrays(GLenum mode, GLint first, GLsizei count);
|
||||
void _glDrawArrays(GLenum mode, GLint first, GLsizei count);
|
||||
void _glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
|
||||
|
||||
void _glColorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer);
|
||||
void _glNormalPointer(GLenum type, GLsizei stride, const void *pointer);
|
||||
void _glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer);
|
||||
|
||||
void _glColorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer);
|
||||
void _glNormalPointer(GLenum type, GLsizei stride, const void *pointer);
|
||||
void _glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer);
|
||||
void _glVertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer);
|
||||
|
||||
void _glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
|
||||
|
@ -170,44 +170,44 @@ public:
|
|||
// TODO: As long as we have gl calls explicitely issued from interface
|
||||
// code, we need to be able to record and batch these calls. THe long
|
||||
// term strategy is to get rid of any GL calls in favor of the HIFI GPU API
|
||||
COMMAND_glEnable,
|
||||
COMMAND_glDisable,
|
||||
|
||||
COMMAND_glEnableClientState,
|
||||
COMMAND_glDisableClientState,
|
||||
|
||||
COMMAND_glCullFace,
|
||||
COMMAND_glAlphaFunc,
|
||||
|
||||
COMMAND_glDepthFunc,
|
||||
COMMAND_glDepthMask,
|
||||
COMMAND_glDepthRange,
|
||||
|
||||
COMMAND_glBindBuffer,
|
||||
|
||||
COMMAND_glBindTexture,
|
||||
COMMAND_glActiveTexture,
|
||||
|
||||
COMMAND_glDrawBuffers,
|
||||
|
||||
COMMAND_glUseProgram,
|
||||
COMMAND_glUniform1f,
|
||||
COMMAND_glUniform2f,
|
||||
COMMAND_glUniform4fv,
|
||||
COMMAND_glUniformMatrix4fv,
|
||||
|
||||
COMMAND_glDrawArrays,
|
||||
COMMAND_glDrawRangeElements,
|
||||
|
||||
COMMAND_glColorPointer,
|
||||
COMMAND_glNormalPointer,
|
||||
COMMAND_glTexCoordPointer,
|
||||
COMMAND_glVertexPointer,
|
||||
|
||||
COMMAND_glVertexAttribPointer,
|
||||
COMMAND_glEnableVertexAttribArray,
|
||||
COMMAND_glDisableVertexAttribArray,
|
||||
|
||||
COMMAND_glEnable,
|
||||
COMMAND_glDisable,
|
||||
|
||||
COMMAND_glEnableClientState,
|
||||
COMMAND_glDisableClientState,
|
||||
|
||||
COMMAND_glCullFace,
|
||||
COMMAND_glAlphaFunc,
|
||||
|
||||
COMMAND_glDepthFunc,
|
||||
COMMAND_glDepthMask,
|
||||
COMMAND_glDepthRange,
|
||||
|
||||
COMMAND_glBindBuffer,
|
||||
|
||||
COMMAND_glBindTexture,
|
||||
COMMAND_glActiveTexture,
|
||||
|
||||
COMMAND_glDrawBuffers,
|
||||
|
||||
COMMAND_glUseProgram,
|
||||
COMMAND_glUniform1f,
|
||||
COMMAND_glUniform2f,
|
||||
COMMAND_glUniform4fv,
|
||||
COMMAND_glUniformMatrix4fv,
|
||||
|
||||
COMMAND_glDrawArrays,
|
||||
COMMAND_glDrawRangeElements,
|
||||
|
||||
COMMAND_glColorPointer,
|
||||
COMMAND_glNormalPointer,
|
||||
COMMAND_glTexCoordPointer,
|
||||
COMMAND_glVertexPointer,
|
||||
|
||||
COMMAND_glVertexAttribPointer,
|
||||
COMMAND_glEnableVertexAttribArray,
|
||||
COMMAND_glDisableVertexAttribArray,
|
||||
|
||||
COMMAND_glColor4f,
|
||||
|
||||
NUM_COMMANDS,
|
||||
|
|
|
@ -26,8 +26,8 @@ int ShapeInfoUtil::toBulletShapeType(int shapeInfoType) {
|
|||
case SHAPE_TYPE_CAPSULE_Y:
|
||||
bulletShapeType = CAPSULE_SHAPE_PROXYTYPE;
|
||||
break;
|
||||
case SHAPE_TYPE_HULL:
|
||||
bulletShapeType = HULL_SHAPE_PROXYTYPE;
|
||||
case SHAPE_TYPE_CONVEX_HULL:
|
||||
bulletShapeType = CONVEX_HULL_SHAPE_PROXYTYPE;
|
||||
break;
|
||||
}
|
||||
return bulletShapeType;
|
||||
|
@ -45,8 +45,8 @@ int ShapeInfoUtil::fromBulletShapeType(int bulletShapeType) {
|
|||
case CAPSULE_SHAPE_PROXYTYPE:
|
||||
shapeInfoType = SHAPE_TYPE_CAPSULE_Y;
|
||||
break;
|
||||
case HULL_SHAPE_PROXYTYPE:
|
||||
shapeInfoType = SHAPE_TYPE_HULL;
|
||||
case CONVEX_HULL_SHAPE_PROXYTYPE:
|
||||
shapeInfoType = SHAPE_TYPE_CONVEX_HULL;
|
||||
break;
|
||||
}
|
||||
return shapeInfoType;
|
||||
|
@ -66,8 +66,16 @@ void ShapeInfoUtil::collectInfoFromShape(const btCollisionShape* shape, ShapeInf
|
|||
info.setSphere(sphereShape->getRadius());
|
||||
break;
|
||||
}
|
||||
case SHAPE_TYPE_HULL: {
|
||||
XXX;
|
||||
case SHAPE_TYPE_CONVEX_HULL: {
|
||||
const btConvexHullShape* convexHullShape = static_cast<const btConvexHullShape*>(shape);
|
||||
const int numPoints = convexHullShape->getNumPoints();
|
||||
const btVector3* btPoints = convexHullShape->getUnscaledPoints();
|
||||
QVector<glm::vec3> points;
|
||||
for (int i = 0; i < numPoints; i++) {
|
||||
glm::vec3 point(btPoints->getX(), btPoints->getY(), btPoints->getZ());
|
||||
points << point;
|
||||
}
|
||||
info.setConvexHull(points);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -99,8 +107,13 @@ btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
|
|||
shape = new btCapsuleShape(radius, height);
|
||||
break;
|
||||
}
|
||||
case SHAPE_TYPE_HULL: {
|
||||
XXX;
|
||||
case SHAPE_TYPE_CONVEX_HULL: {
|
||||
shape = new btConvexHullShape();
|
||||
QVector<glm::vec3> points = info.getPoints();
|
||||
foreach (glm::vec3 point, points) {
|
||||
btVector3 btPoint(point[0], point[1], point[2]);
|
||||
static_cast<btConvexHullShape*>(shape)->addPoint(btPoint);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
#include <glm/gtx/norm.hpp>
|
||||
|
||||
#include "ShapeInfoUtil.h"
|
||||
#include "ShapeManager.h"
|
||||
#include "ShapeInfoUtil.h"
|
||||
|
||||
ShapeManager::ShapeManager() {
|
||||
}
|
||||
|
@ -53,9 +53,8 @@ btCollisionShape* ShapeManager::getShape(const ShapeInfo& info) {
|
|||
return shape;
|
||||
}
|
||||
|
||||
bool ShapeManager::releaseShape(const ShapeInfo& info) {
|
||||
DoubleHashKey key = info.getHash();
|
||||
ShapeReference* shapeRef = _shapeMap.find(key);
|
||||
|
||||
void ShapeManager::dereferenceShapeReferece(ShapeReference* shapeRef, DoubleHashKey key) {
|
||||
if (shapeRef) {
|
||||
if (shapeRef->_refCount > 0) {
|
||||
shapeRef->_refCount--;
|
||||
|
@ -66,7 +65,7 @@ bool ShapeManager::releaseShape(const ShapeInfo& info) {
|
|||
collectGarbage();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
} else {
|
||||
// attempt to remove shape that has no refs
|
||||
assert(false);
|
||||
|
@ -75,13 +74,32 @@ bool ShapeManager::releaseShape(const ShapeInfo& info) {
|
|||
// attempt to remove unmanaged shape
|
||||
assert(false);
|
||||
}
|
||||
return false;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
bool ShapeManager::releaseShape(const btCollisionShape* shape) {
|
||||
ShapeInfo info;
|
||||
ShapeInfoUtil::collectInfoFromShape(shape, info);
|
||||
return releaseShape(info);
|
||||
|
||||
void ShapeManager::releaseShape(const ShapeInfo& info) {
|
||||
DoubleHashKey key = info.getHash();
|
||||
ShapeReference* shapeRef = _shapeMap.find(key);
|
||||
dereferenceShapeReferece(shapeRef, key);
|
||||
}
|
||||
|
||||
void ShapeManager::releaseShape(const btCollisionShape* shape) {
|
||||
// XXX make a table for this
|
||||
int numShapes = _shapeMap.size();
|
||||
for (int i = 0; i < numShapes; ++i) {
|
||||
ShapeReference* shapeRef = _shapeMap.getAtIndex(i);
|
||||
if (shapeRef->_shape == shape) {
|
||||
// XXX how can I find the key?
|
||||
// dereferenceShapeReferece(shapeRef);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ShapeInfo info;
|
||||
// ShapeInfoUtil::collectInfoFromShape(shape, info);
|
||||
// releaseShape(info);
|
||||
}
|
||||
|
||||
void ShapeManager::collectGarbage() {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "DoubleHashKey.h"
|
||||
|
||||
|
||||
class ShapeManager {
|
||||
public:
|
||||
|
||||
|
@ -28,9 +29,9 @@ public:
|
|||
/// \return pointer to shape
|
||||
btCollisionShape* getShape(const ShapeInfo& info);
|
||||
|
||||
/// \return true if shape was found and released
|
||||
bool releaseShape(const ShapeInfo& info);
|
||||
bool releaseShape(const btCollisionShape* shape);
|
||||
/// find and release a shape
|
||||
void releaseShape(const ShapeInfo& info);
|
||||
void releaseShape(const btCollisionShape* shape);
|
||||
|
||||
/// delete shapes that have zero references
|
||||
void collectGarbage();
|
||||
|
@ -46,6 +47,8 @@ private:
|
|||
ShapeReference() : _refCount(0), _shape(NULL) {}
|
||||
};
|
||||
|
||||
void dereferenceShapeReferece(ShapeReference* shapeRef, DoubleHashKey key);
|
||||
|
||||
btHashMap<DoubleHashKey, ShapeReference> _shapeMap;
|
||||
btAlignedObjectArray<DoubleHashKey> _pendingGarbage;
|
||||
};
|
||||
|
|
|
@ -1019,6 +1019,10 @@ void Model::setURL(const QUrl& url, const QUrl& fallback, bool retainCurrent, bo
|
|||
}
|
||||
|
||||
void Model::setCollisionModelURL(const QUrl& url, const QUrl& fallback, bool delayLoad) {
|
||||
if (_collisionUrl == url) {
|
||||
return;
|
||||
}
|
||||
_collisionUrl = url;
|
||||
_collisionGeometry = DependencyManager::get<GeometryCache>()->getGeometry(url, fallback, delayLoad);
|
||||
}
|
||||
|
||||
|
|
|
@ -290,11 +290,14 @@ private:
|
|||
float _lodDistance;
|
||||
float _lodHysteresis;
|
||||
float _nextLODHysteresis;
|
||||
|
||||
QSharedPointer<NetworkGeometry> _collisionGeometry;
|
||||
|
||||
float _pupilDilation;
|
||||
QVector<float> _blendshapeCoefficients;
|
||||
|
||||
QUrl _url;
|
||||
QUrl _collisionUrl;
|
||||
|
||||
gpu::Buffers _blendedVertexBuffers;
|
||||
std::vector<Transform> _transforms;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "SharedUtil.h" // for MILLIMETERS_PER_METER
|
||||
|
||||
#include "ShapeInfo.h"
|
||||
#include "GeometryCache.h"
|
||||
|
||||
void ShapeInfo::clear() {
|
||||
_type = SHAPE_TYPE_NONE;
|
||||
|
@ -22,7 +23,7 @@ void ShapeInfo::clear() {
|
|||
_externalData = NULL;
|
||||
}
|
||||
|
||||
void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QVector<glm::vec3>* data) {
|
||||
void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QVector<glm::vec3>* data, QString url) {
|
||||
_type = type;
|
||||
switch(type) {
|
||||
case SHAPE_TYPE_NONE:
|
||||
|
@ -37,12 +38,31 @@ void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QVector<
|
|||
_halfExtents = glm::vec3(radius);
|
||||
break;
|
||||
}
|
||||
case SHAPE_TYPE_CONVEX_HULL:
|
||||
_url = QUrl(url);
|
||||
// start download of model which contains collision hulls
|
||||
_type = SHAPE_TYPE_NONE; // until download is done
|
||||
|
||||
QSharedPointer<NetworkGeometry> networkGeometry =
|
||||
DependencyManager::get<GeometryCache>()->getGeometry (_url, QUrl(), false);
|
||||
|
||||
connect(networkGeometry, loaded, this, collisionGeometryLoaded);
|
||||
|
||||
break;
|
||||
default:
|
||||
_halfExtents = halfExtents;
|
||||
break;
|
||||
}
|
||||
_externalData = data;
|
||||
}
|
||||
|
||||
|
||||
void ShapeInfo::collisionGeometryLoaded() {
|
||||
_type = SHAPE_TYPE_CONVEX_HULL;
|
||||
// xxx copy points over;
|
||||
}
|
||||
|
||||
|
||||
void ShapeInfo::setBox(const glm::vec3& halfExtents) {
|
||||
_type = SHAPE_TYPE_BOX;
|
||||
_halfExtents = halfExtents;
|
||||
|
@ -61,9 +81,9 @@ void ShapeInfo::setEllipsoid(const glm::vec3& halfExtents) {
|
|||
_doubleHashKey.clear();
|
||||
}
|
||||
|
||||
void ShapeInfo::setHull(QString url) {
|
||||
_type = SHAPE_TYPE_HULL;
|
||||
_url = url;
|
||||
void ShapeInfo::setConvexHull(QVector<glm::vec3>& points) {
|
||||
_type = SHAPE_TYPE_CONVEX_HULL;
|
||||
_points = points;
|
||||
}
|
||||
|
||||
void ShapeInfo::setCapsuleY(float radius, float halfHeight) {
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#define hifi_ShapeInfo_h
|
||||
|
||||
#include <QVector>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "DoubleHashKey.h"
|
||||
|
@ -22,7 +24,7 @@ enum ShapeType {
|
|||
SHAPE_TYPE_BOX,
|
||||
SHAPE_TYPE_SPHERE,
|
||||
SHAPE_TYPE_ELLIPSOID,
|
||||
SHAPE_TYPE_HULL,
|
||||
SHAPE_TYPE_CONVEX_HULL,
|
||||
SHAPE_TYPE_PLANE,
|
||||
SHAPE_TYPE_COMPOUND,
|
||||
SHAPE_TYPE_CAPSULE_X,
|
||||
|
@ -33,15 +35,17 @@ enum ShapeType {
|
|||
SHAPE_TYPE_CYLINDER_Z
|
||||
};
|
||||
|
||||
class ShapeInfo {
|
||||
class ShapeInfo : QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void clear();
|
||||
|
||||
void setParams(ShapeType type, const glm::vec3& halfExtents, QVector<glm::vec3>* data = NULL);
|
||||
void setParams(ShapeType type, const glm::vec3& halfExtents, QVector<glm::vec3>* data = NULL, QString url="");
|
||||
void setBox(const glm::vec3& halfExtents);
|
||||
void setSphere(float radius);
|
||||
void setEllipsoid(const glm::vec3& halfExtents);
|
||||
void setHull(QString collisionModelURL);
|
||||
void setConvexHull(QVector<glm::vec3>& points);
|
||||
void setCapsuleY(float radius, float halfHeight);
|
||||
|
||||
const int getType() const { return _type; }
|
||||
|
@ -51,18 +55,24 @@ public:
|
|||
void setData(const QVector<glm::vec3>* data) { _externalData = data; }
|
||||
const QVector<glm::vec3>* getData() const { return _externalData; }
|
||||
|
||||
QString& getURL() { return _url; }
|
||||
QVector<glm::vec3> getPoints() const { return _points; }
|
||||
|
||||
float computeVolume() const;
|
||||
|
||||
const DoubleHashKey& getHash() const;
|
||||
|
||||
|
||||
private slots:
|
||||
void collisionGeometryLoaded();
|
||||
|
||||
|
||||
protected:
|
||||
ShapeType _type = SHAPE_TYPE_NONE;
|
||||
glm::vec3 _halfExtents = glm::vec3(0.0f);
|
||||
DoubleHashKey _doubleHashKey;
|
||||
const QVector<glm::vec3>* _externalData = NULL;
|
||||
QString _url;
|
||||
QVector<glm::vec3> _points; // points for convex collision hull
|
||||
QUrl _url; // url for model of convex collision hull
|
||||
};
|
||||
|
||||
#endif // hifi_ShapeInfo_h
|
||||
|
|
|
@ -57,15 +57,10 @@ void ShapeManagerTests::testShapeAccounting() {
|
|||
}
|
||||
|
||||
// release all references
|
||||
bool released = shapeManager.releaseShape(info);
|
||||
numReferences--;
|
||||
while (numReferences > 0) {
|
||||
released = shapeManager.releaseShape(info) && released;
|
||||
shapeManager.releaseShape(info);
|
||||
numReferences--;
|
||||
}
|
||||
if (!released) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected shape released" << std::endl;
|
||||
}
|
||||
|
||||
// verify shape still exists (not yet garbage collected)
|
||||
if (shapeManager.getNumShapes() != 1) {
|
||||
|
@ -99,7 +94,7 @@ void ShapeManagerTests::testShapeAccounting() {
|
|||
}
|
||||
|
||||
// release reference and verify that it is collected as garbage
|
||||
released = shapeManager.releaseShape(info);
|
||||
shapeManager.releaseShape(info);
|
||||
shapeManager.collectGarbage();
|
||||
if (shapeManager.getNumShapes() != 0) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected zero shapes after release" << std::endl;
|
||||
|
|
Loading…
Reference in a new issue