Use std::vector types in ShapeInfo

This commit is contained in:
sabrina-shanman 2019-11-01 18:01:41 -07:00
parent 921eed1ec1
commit da5f80c139
7 changed files with 53 additions and 60 deletions

View file

@ -387,7 +387,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
foreach (const HFMMesh& mesh, collisionGeometry.meshes) { foreach (const HFMMesh& mesh, collisionGeometry.meshes) {
// each meshPart is a convex hull // each meshPart is a convex hull
foreach (const HFMMeshPart &meshPart, mesh.parts) { foreach (const HFMMeshPart &meshPart, mesh.parts) {
pointCollection.push_back(QVector<glm::vec3>()); pointCollection.emplace_back();
ShapeInfo::PointList& pointsInPart = pointCollection[i]; ShapeInfo::PointList& pointsInPart = pointCollection[i];
// run through all the triangles and (uniquely) add each point to the hull // run through all the triangles and (uniquely) add each point to the hull
@ -400,14 +400,14 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
glm::vec3 p0 = mesh.vertices[meshPart.triangleIndices[j]]; glm::vec3 p0 = mesh.vertices[meshPart.triangleIndices[j]];
glm::vec3 p1 = mesh.vertices[meshPart.triangleIndices[j + 1]]; glm::vec3 p1 = mesh.vertices[meshPart.triangleIndices[j + 1]];
glm::vec3 p2 = mesh.vertices[meshPart.triangleIndices[j + 2]]; glm::vec3 p2 = mesh.vertices[meshPart.triangleIndices[j + 2]];
if (!pointsInPart.contains(p0)) { if (std::find(pointsInPart.cbegin(), pointsInPart.cend(), p0) == pointsInPart.cend()) {
pointsInPart << p0; pointsInPart.push_back(p0);
} }
if (!pointsInPart.contains(p1)) { if (std::find(pointsInPart.cbegin(), pointsInPart.cend(), p1) == pointsInPart.cend()) {
pointsInPart << p1; pointsInPart.push_back(p1);
} }
if (!pointsInPart.contains(p2)) { if (std::find(pointsInPart.cbegin(), pointsInPart.cend(), p2) == pointsInPart.cend()) {
pointsInPart << p2; pointsInPart.push_back(p2);
} }
} }
@ -422,17 +422,17 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
glm::vec3 p1 = mesh.vertices[meshPart.quadIndices[j + 1]]; glm::vec3 p1 = mesh.vertices[meshPart.quadIndices[j + 1]];
glm::vec3 p2 = mesh.vertices[meshPart.quadIndices[j + 2]]; glm::vec3 p2 = mesh.vertices[meshPart.quadIndices[j + 2]];
glm::vec3 p3 = mesh.vertices[meshPart.quadIndices[j + 3]]; glm::vec3 p3 = mesh.vertices[meshPart.quadIndices[j + 3]];
if (!pointsInPart.contains(p0)) { if (std::find(pointsInPart.cbegin(), pointsInPart.cend(), p0) == pointsInPart.cend()) {
pointsInPart << p0; pointsInPart.push_back(p0);
} }
if (!pointsInPart.contains(p1)) { if (std::find(pointsInPart.cbegin(), pointsInPart.cend(), p1) == pointsInPart.cend()) {
pointsInPart << p1; pointsInPart.push_back(p1);
} }
if (!pointsInPart.contains(p2)) { if (std::find(pointsInPart.cbegin(), pointsInPart.cend(), p2) == pointsInPart.cend()) {
pointsInPart << p2; pointsInPart.push_back(p2);
} }
if (!pointsInPart.contains(p3)) { if (std::find(pointsInPart.cbegin(), pointsInPart.cend(), p3) == pointsInPart.cend()) {
pointsInPart << p3; pointsInPart.push_back(p3);
} }
} }

View file

@ -1429,14 +1429,13 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorker() {
QtConcurrent::run([entity, voxelSurfaceStyle, voxelVolumeSize, mesh] { QtConcurrent::run([entity, voxelSurfaceStyle, voxelVolumeSize, mesh] {
auto polyVoxEntity = std::static_pointer_cast<RenderablePolyVoxEntityItem>(entity); auto polyVoxEntity = std::static_pointer_cast<RenderablePolyVoxEntityItem>(entity);
QVector<QVector<glm::vec3>> pointCollection; ShapeInfo::PointCollection pointCollection;
AABox box; AABox box;
glm::mat4 vtoM = std::static_pointer_cast<RenderablePolyVoxEntityItem>(entity)->voxelToLocalMatrix(); glm::mat4 vtoM = std::static_pointer_cast<RenderablePolyVoxEntityItem>(entity)->voxelToLocalMatrix();
if (voxelSurfaceStyle == PolyVoxEntityItem::SURFACE_MARCHING_CUBES || if (voxelSurfaceStyle == PolyVoxEntityItem::SURFACE_MARCHING_CUBES ||
voxelSurfaceStyle == PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES) { voxelSurfaceStyle == PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES) {
// pull each triangle in the mesh into a polyhedron which can be collided with // pull each triangle in the mesh into a polyhedron which can be collided with
unsigned int i = 0;
const gpu::BufferView& vertexBufferView = mesh->getVertexBuffer(); const gpu::BufferView& vertexBufferView = mesh->getVertexBuffer();
const gpu::BufferView& indexBufferView = mesh->getIndexBuffer(); const gpu::BufferView& indexBufferView = mesh->getIndexBuffer();
@ -1465,19 +1464,16 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorker() {
box += p2Model; box += p2Model;
box += p3Model; box += p3Model;
QVector<glm::vec3> pointsInPart; ShapeInfo::PointList pointsInPart;
pointsInPart << p0Model; pointsInPart.push_back(p0Model);
pointsInPart << p1Model; pointsInPart.push_back(p1Model);
pointsInPart << p2Model; pointsInPart.push_back(p2Model);
pointsInPart << p3Model; pointsInPart.push_back(p3Model);
// add next convex hull
QVector<glm::vec3> newMeshPoints; // add points to a new convex hull
pointCollection << newMeshPoints; pointCollection.push_back(pointsInPart);
// add points to the new convex hull
pointCollection[i++] << pointsInPart;
} }
} else { } else {
unsigned int i = 0;
polyVoxEntity->forEachVoxelValue(voxelVolumeSize, [&](const ivec3& v, uint8_t value) { polyVoxEntity->forEachVoxelValue(voxelVolumeSize, [&](const ivec3& v, uint8_t value) {
if (value > 0) { if (value > 0) {
const auto& x = v.x; const auto& x = v.x;
@ -1496,7 +1492,7 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorker() {
return; return;
} }
QVector<glm::vec3> pointsInPart; ShapeInfo::PointList pointsInPart;
float offL = -0.5f; float offL = -0.5f;
float offH = 0.5f; float offH = 0.5f;
@ -1523,20 +1519,17 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorker() {
box += p110; box += p110;
box += p111; box += p111;
pointsInPart << p000; pointsInPart.push_back(p000);
pointsInPart << p001; pointsInPart.push_back(p001);
pointsInPart << p010; pointsInPart.push_back(p010);
pointsInPart << p011; pointsInPart.push_back(p011);
pointsInPart << p100; pointsInPart.push_back(p100);
pointsInPart << p101; pointsInPart.push_back(p101);
pointsInPart << p110; pointsInPart.push_back(p110);
pointsInPart << p111; pointsInPart.push_back(p111);
// add next convex hull // add points to a new convex hull
QVector<glm::vec3> newMeshPoints; pointCollection.push_back(pointsInPart);
pointCollection << newMeshPoints;
// add points to the new convex hull
pointCollection[i++] << pointsInPart;
} }
}); });
} }
@ -1546,7 +1539,7 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorker() {
void RenderablePolyVoxEntityItem::setCollisionPoints(ShapeInfo::PointCollection pointCollection, AABox box) { void RenderablePolyVoxEntityItem::setCollisionPoints(ShapeInfo::PointCollection pointCollection, AABox box) {
// this catches the payload from computeShapeInfoWorker // this catches the payload from computeShapeInfoWorker
if (pointCollection.isEmpty()) { if (pointCollection.empty()) {
EntityItem::computeShapeInfo(_shapeInfo); EntityItem::computeShapeInfo(_shapeInfo);
withWriteLock([&] { withWriteLock([&] {
_shapeReady = true; _shapeReady = true;

View file

@ -217,7 +217,7 @@ btTriangleIndexVertexArray* createStaticMeshArray(const ShapeInfo& info) {
} }
const ShapeInfo::TriangleIndices& triangleIndices = info.getTriangleIndices(); const ShapeInfo::TriangleIndices& triangleIndices = info.getTriangleIndices();
int32_t numIndices = triangleIndices.size(); int32_t numIndices = (int32_t)triangleIndices.size();
if (numIndices < 3) { if (numIndices < 3) {
// not enough indices to make a single triangle // not enough indices to make a single triangle
return nullptr; return nullptr;
@ -237,7 +237,7 @@ btTriangleIndexVertexArray* createStaticMeshArray(const ShapeInfo& info) {
mesh.m_indexType = PHY_INTEGER; mesh.m_indexType = PHY_INTEGER;
mesh.m_triangleIndexStride = VERTICES_PER_TRIANGLE * sizeof(int32_t); mesh.m_triangleIndexStride = VERTICES_PER_TRIANGLE * sizeof(int32_t);
} }
mesh.m_numVertices = pointList.size(); mesh.m_numVertices = (int)pointList.size();
mesh.m_vertexBase = new unsigned char[VERTICES_PER_TRIANGLE * sizeof(btScalar) * (size_t)mesh.m_numVertices]; mesh.m_vertexBase = new unsigned char[VERTICES_PER_TRIANGLE * sizeof(btScalar) * (size_t)mesh.m_numVertices];
mesh.m_vertexStride = VERTICES_PER_TRIANGLE * sizeof(btScalar); mesh.m_vertexStride = VERTICES_PER_TRIANGLE * sizeof(btScalar);
mesh.m_vertexType = PHY_FLOAT; mesh.m_vertexType = PHY_FLOAT;
@ -362,7 +362,7 @@ const btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info)
const ShapeInfo::PointCollection& pointCollection = info.getPointCollection(); const ShapeInfo::PointCollection& pointCollection = info.getPointCollection();
uint32_t numSubShapes = info.getNumSubShapes(); uint32_t numSubShapes = info.getNumSubShapes();
if (numSubShapes == 1) { if (numSubShapes == 1) {
if (!pointCollection.isEmpty()) { if (!pointCollection.empty()) {
shape = createConvexHull(pointCollection[0]); shape = createConvexHull(pointCollection[0]);
} }
} else { } else {
@ -380,7 +380,7 @@ const btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info)
case SHAPE_TYPE_SIMPLE_COMPOUND: { case SHAPE_TYPE_SIMPLE_COMPOUND: {
const ShapeInfo::PointCollection& pointCollection = info.getPointCollection(); const ShapeInfo::PointCollection& pointCollection = info.getPointCollection();
const ShapeInfo::TriangleIndices& triangleIndices = info.getTriangleIndices(); const ShapeInfo::TriangleIndices& triangleIndices = info.getTriangleIndices();
uint32_t numIndices = triangleIndices.size(); uint32_t numIndices = (uint32_t)triangleIndices.size();
uint32_t numMeshes = info.getNumSubShapes(); uint32_t numMeshes = info.getNumSubShapes();
const uint32_t MIN_NUM_SIMPLE_COMPOUND_INDICES = 2; // END_OF_MESH_PART + END_OF_MESH const uint32_t MIN_NUM_SIMPLE_COMPOUND_INDICES = 2; // END_OF_MESH_PART + END_OF_MESH
if (numMeshes > 0 && numIndices > MIN_NUM_SIMPLE_COMPOUND_INDICES) { if (numMeshes > 0 && numIndices > MIN_NUM_SIMPLE_COMPOUND_INDICES) {

View file

@ -116,7 +116,7 @@ static const uint SHAPE_TANGENT_OFFSET = offsetof(GeometryCache::ShapeVertex, ta
std::map<std::pair<bool, bool>, gpu::PipelinePointer> GeometryCache::_webPipelines; std::map<std::pair<bool, bool>, gpu::PipelinePointer> GeometryCache::_webPipelines;
std::map<std::pair<bool, bool>, gpu::PipelinePointer> GeometryCache::_gridPipelines; std::map<std::pair<bool, bool>, gpu::PipelinePointer> GeometryCache::_gridPipelines;
void GeometryCache::computeSimpleHullPointListForShape(const int entityShape, const glm::vec3 &entityExtents, QVector<glm::vec3> &outPointList) { void GeometryCache::computeSimpleHullPointListForShape(const int entityShape, const glm::vec3 &entityExtents, ShapeInfo::PointList &outPointList) {
auto geometryCache = DependencyManager::get<GeometryCache>(); auto geometryCache = DependencyManager::get<GeometryCache>();
const GeometryCache::Shape geometryShape = GeometryCache::getShapeForEntityShape( entityShape ); const GeometryCache::Shape geometryShape = GeometryCache::getShapeForEntityShape( entityShape );

View file

@ -155,7 +155,7 @@ public:
static GeometryCache::Shape getShapeForEntityShape(int entityShapeEnum); static GeometryCache::Shape getShapeForEntityShape(int entityShapeEnum);
static QString stringFromShape(GeometryCache::Shape geoShape); static QString stringFromShape(GeometryCache::Shape geoShape);
static void computeSimpleHullPointListForShape(int entityShape, const glm::vec3 &entityExtents, QVector<glm::vec3> &outPointList); static void computeSimpleHullPointListForShape(int entityShape, const glm::vec3 &entityExtents, ShapeInfo::PointList &outPointList);
int allocateID() { return _nextID++; } int allocateID() { return _nextID++; }
void releaseID(int id); void releaseID(int id);

View file

@ -189,7 +189,7 @@ uint32_t ShapeInfo::getNumSubShapes() const {
return 0; return 0;
case SHAPE_TYPE_COMPOUND: case SHAPE_TYPE_COMPOUND:
case SHAPE_TYPE_SIMPLE_COMPOUND: case SHAPE_TYPE_SIMPLE_COMPOUND:
return _pointCollection.size(); return (uint32_t)_pointCollection.size();
case SHAPE_TYPE_MULTISPHERE: case SHAPE_TYPE_MULTISPHERE:
case SHAPE_TYPE_SIMPLE_HULL: case SHAPE_TYPE_SIMPLE_HULL:
case SHAPE_TYPE_STATIC_MESH: case SHAPE_TYPE_STATIC_MESH:
@ -200,10 +200,10 @@ uint32_t ShapeInfo::getNumSubShapes() const {
} }
} }
int ShapeInfo::getLargestSubshapePointCount() const { uint32_t ShapeInfo::getLargestSubshapePointCount() const {
int numPoints = 0; uint32_t numPoints = 0;
for (int i = 0; i < _pointCollection.size(); ++i) { for (uint32_t i = 0; i < (uint32_t)_pointCollection.size(); ++i) {
int n = _pointCollection[i].size(); uint32_t n = _pointCollection[i].size();
if (n > numPoints) { if (n > numPoints) {
numPoints = n; numPoints = n;
} }

View file

@ -12,7 +12,7 @@
#ifndef hifi_ShapeInfo_h #ifndef hifi_ShapeInfo_h
#define hifi_ShapeInfo_h #define hifi_ShapeInfo_h
#include <QVector> #include <vector>
#include <QString> #include <QString>
#include <QUrl> #include <QUrl>
#include <glm/glm.hpp> #include <glm/glm.hpp>
@ -53,11 +53,11 @@ class ShapeInfo {
public: public:
using PointList = QVector<glm::vec3>; using PointList = std::vector<glm::vec3>;
using PointCollection = QVector<PointList>; using PointCollection = std::vector<PointList>;
using TriangleIndices = QVector<int32_t>; using TriangleIndices = std::vector<int32_t>;
using SphereData = glm::vec4; using SphereData = glm::vec4;
using SphereCollection = QVector<SphereData>; using SphereCollection = std::vector<SphereData>;
static QString getNameForShapeType(ShapeType type); static QString getNameForShapeType(ShapeType type);
static ShapeType getShapeTypeForName(QString string); static ShapeType getShapeTypeForName(QString string);
@ -85,7 +85,7 @@ public:
TriangleIndices& getTriangleIndices() { return _triangleIndices; } TriangleIndices& getTriangleIndices() { return _triangleIndices; }
const TriangleIndices& getTriangleIndices() const { return _triangleIndices; } const TriangleIndices& getTriangleIndices() const { return _triangleIndices; }
int getLargestSubshapePointCount() const; uint32_t getLargestSubshapePointCount() const;
float computeVolume() const; float computeVolume() const;