From c73757f740b5accc961723d2de6d741d0d68074c Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 3 Jun 2016 09:17:44 -0700 Subject: [PATCH] use many colors for collision hull rendering --- libraries/render-utils/src/Model.cpp | 50 ++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 8011b0c4c8..ded1184c24 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -35,7 +35,46 @@ int vec3VectorTypeId = qRegisterMetaType >(); float Model::FAKE_DIMENSION_PLACEHOLDER = -1.0f; #define HTTP_INVALID_COM "http://invalid.com" -model::MaterialPointer Model::_collisionHullMaterial; +const int NUM_COLLISION_HULL_COLORS = 24; +std::vector _collisionHullMaterials; + +void initCollisionHullMaterials() { + // generates bright colors in red, green, blue, yellow, magenta, and cyan spectrums + // (no browns, greys, or dark shades) + float component[NUM_COLLISION_HULL_COLORS] = { + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.2f, 0.4f, 0.6f, 0.8f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 0.8f, 0.6f, 0.4f, 0.2f + }; + _collisionHullMaterials.reserve(NUM_COLLISION_HULL_COLORS); + + // each component gets the same cuve + // but offset by a multiple of one third the full width + int numComponents = 3; + int sectionWidth = NUM_COLLISION_HULL_COLORS / numComponents; + int greenPhase = sectionWidth; + int bluePhase = 2 * sectionWidth; + + // we stride through the colors to scatter adjacent shades + // so they don't tend to group together for large models + for (int i = 0; i < sectionWidth; ++i) { + for (int j = 0; j < numComponents; ++j) { + model::MaterialPointer material; + material = std::make_shared(); + int index = j * sectionWidth + i; + float red = component[index]; + float green = component[(index + greenPhase) % NUM_COLLISION_HULL_COLORS]; + float blue = component[(index + bluePhase) % NUM_COLLISION_HULL_COLORS]; + material->setAlbedo(glm::vec3(red, green, blue)); + material->setMetallic(0.02f); + material->setRoughness(0.5f); + _collisionHullMaterials.push_back(material); + } + } +} Model::Model(RigPointer rig, QObject* parent) : QObject(parent), @@ -1217,13 +1256,10 @@ void Model::segregateMeshGroups() { int totalParts = mesh.parts.size(); for (int partIndex = 0; partIndex < totalParts; partIndex++) { if (showingCollisionHull) { - if (!_collisionHullMaterial) { - _collisionHullMaterial = std::make_shared(); - _collisionHullMaterial->setAlbedo(glm::vec3(1.0f, 0.5f, 0.0f)); - _collisionHullMaterial->setMetallic(0.02f); - _collisionHullMaterial->setRoughness(0.5f); + if (_collisionHullMaterials.empty()) { + initCollisionHullMaterials(); } - _collisionRenderItemsSet << std::make_shared(networkMesh, partIndex, _collisionHullMaterial, transform, offset); + _collisionRenderItemsSet << std::make_shared(networkMesh, partIndex, _collisionHullMaterials[partIndex % NUM_COLLISION_HULL_COLORS], transform, offset); } else { _modelMeshRenderItemsSet << std::make_shared(this, i, partIndex, shapeID, transform, offset); }