Merge pull request #14156 from sabrina-shanman/bug_dynamic-hulls

Fix "Good" collision not honoring mesh groups in OBJ files
This commit is contained in:
John Conklin II 2018-10-17 11:12:21 -07:00 committed by GitHub
commit eb088772d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 9 deletions

View file

@ -308,7 +308,7 @@ bool RenderableModelEntityItem::findDetailedParabolaIntersection(const glm::vec3
}
void RenderableModelEntityItem::getCollisionGeometryResource() {
QUrl hullURL(getCompoundShapeURL());
QUrl hullURL(getCollisionShapeURL());
QUrlQuery queryArgs(hullURL);
queryArgs.addQueryItem("collision-hull", "");
hullURL.setQuery(queryArgs);
@ -325,8 +325,9 @@ bool RenderableModelEntityItem::computeShapeFailedToLoad() {
void RenderableModelEntityItem::setShapeType(ShapeType type) {
ModelEntityItem::setShapeType(type);
if (getShapeType() == SHAPE_TYPE_COMPOUND) {
if (!_compoundShapeResource && !getCompoundShapeURL().isEmpty()) {
auto shapeType = getShapeType();
if (shapeType == SHAPE_TYPE_COMPOUND || shapeType == SHAPE_TYPE_SIMPLE_COMPOUND) {
if (!_compoundShapeResource && !getCollisionShapeURL().isEmpty()) {
getCollisionGeometryResource();
}
} else if (_compoundShapeResource && !getCompoundShapeURL().isEmpty()) {
@ -352,18 +353,21 @@ void RenderableModelEntityItem::setCompoundShapeURL(const QString& url) {
bool RenderableModelEntityItem::isReadyToComputeShape() const {
ShapeType type = getShapeType();
auto model = getModel();
if (type == SHAPE_TYPE_COMPOUND) {
if (!model || getCompoundShapeURL().isEmpty()) {
auto shapeType = getShapeType();
if (shapeType == SHAPE_TYPE_COMPOUND || shapeType == SHAPE_TYPE_SIMPLE_COMPOUND) {
auto shapeURL = getCollisionShapeURL();
if (!model || shapeURL.isEmpty()) {
return false;
}
if (model->getURL().isEmpty()) {
if (model->getURL().isEmpty() || !_dimensionsInitialized) {
// we need a render geometry with a scale to proceed, so give up.
return false;
}
if (model->isLoaded()) {
if (!getCompoundShapeURL().isEmpty() && !_compoundShapeResource) {
if (!shapeURL.isEmpty() && !_compoundShapeResource) {
const_cast<RenderableModelEntityItem*>(this)->getCollisionGeometryResource();
}
@ -518,7 +522,16 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
return;
}
auto& meshes = model->getGeometry()->getMeshes();
std::vector<std::shared_ptr<const graphics::Mesh>> meshes;
if (type == SHAPE_TYPE_SIMPLE_COMPOUND) {
auto& fbxMeshes = _compoundShapeResource->getFBXGeometry().meshes;
meshes.reserve(fbxMeshes.size());
for (auto& fbxMesh : fbxMeshes) {
meshes.push_back(fbxMesh._mesh);
}
} else {
meshes = model->getGeometry()->getMeshes();
}
int32_t numMeshes = (int32_t)(meshes.size());
const int MAX_ALLOWED_MESH_COUNT = 1000;
@ -752,7 +765,7 @@ bool RenderableModelEntityItem::shouldBePhysical() const {
auto model = getModel();
// If we have a model, make sure it hasn't failed to download.
// If it has, we'll report back that we shouldn't be physical so that physics aren't held waiting for us to be ready.
if (model && getShapeType() == SHAPE_TYPE_COMPOUND && model->didCollisionGeometryRequestFail()) {
if (model && (getShapeType() == SHAPE_TYPE_COMPOUND || getShapeType() == SHAPE_TYPE_SIMPLE_COMPOUND) && model->didCollisionGeometryRequestFail()) {
return false;
} else if (model && getShapeType() != SHAPE_TYPE_NONE && model->didVisualGeometryRequestFail()) {
return false;

View file

@ -554,6 +554,10 @@ QString ModelEntityItem::getCompoundShapeURL() const {
return _compoundShapeURL.get();
}
QString ModelEntityItem::getCollisionShapeURL() const {
return getShapeType() == SHAPE_TYPE_COMPOUND ? getCompoundShapeURL() : getModelURL();
}
void ModelEntityItem::setColor(const rgbColor& value) {
withWriteLock([&] {
memcpy(_color, value, sizeof(_color));

View file

@ -70,6 +70,9 @@ public:
static const QString DEFAULT_COMPOUND_SHAPE_URL;
QString getCompoundShapeURL() const;
// Returns the URL used for the collision shape
QString getCollisionShapeURL() const;
void setColor(const rgbColor& value);
void setColor(const xColor& value);