add combineParts flag to getGeometryResource. append ?collsion-hull to urls that are used as compound collision hulls

This commit is contained in:
Seth Alves 2017-04-10 10:14:36 -07:00
parent d7dd2bce72
commit 554b23357c
4 changed files with 15 additions and 12 deletions

View file

@ -611,7 +611,7 @@ void RenderableModelEntityItem::setShapeType(ShapeType type) {
ModelEntityItem::setShapeType(type);
if (getShapeType() == SHAPE_TYPE_COMPOUND) {
if (!_compoundShapeResource && !getCompoundShapeURL().isEmpty()) {
_compoundShapeResource = DependencyManager::get<ModelCache>()->getGeometryResource(getCompoundShapeURL());
_compoundShapeResource = DependencyManager::get<ModelCache>()->getGeometryResource(getCompoundShapeURL(), false);
}
} else if (_compoundShapeResource && !getCompoundShapeURL().isEmpty()) {
// the compoundURL has been set but the shapeType does not agree
@ -621,7 +621,8 @@ void RenderableModelEntityItem::setShapeType(ShapeType type) {
void RenderableModelEntityItem::setCompoundShapeURL(const QString& url) {
auto currentCompoundShapeURL = getCompoundShapeURL();
ModelEntityItem::setCompoundShapeURL(url);
QString hullURL = url + "?collision-hull";
ModelEntityItem::setCompoundShapeURL(hullURL);
if (getCompoundShapeURL() != currentCompoundShapeURL || !_model) {
EntityTreePointer tree = getTree();
@ -629,7 +630,7 @@ void RenderableModelEntityItem::setCompoundShapeURL(const QString& url) {
QMetaObject::invokeMethod(tree.get(), "callLoader", Qt::QueuedConnection, Q_ARG(EntityItemID, getID()));
}
if (getShapeType() == SHAPE_TYPE_COMPOUND) {
_compoundShapeResource = DependencyManager::get<ModelCache>()->getGeometryResource(url);
_compoundShapeResource = DependencyManager::get<ModelCache>()->getGeometryResource(hullURL, false);
}
}
}
@ -661,7 +662,7 @@ bool RenderableModelEntityItem::isReadyToComputeShape() {
}
return true;
} else if (!getCompoundShapeURL().isEmpty()) {
_compoundShapeResource = DependencyManager::get<ModelCache>()->getGeometryResource(getCompoundShapeURL());
_compoundShapeResource = DependencyManager::get<ModelCache>()->getGeometryResource(getCompoundShapeURL(), false);
}
}

View file

@ -90,7 +90,7 @@ void GeometryMappingResource::downloadFinished(const QByteArray& data) {
}
auto modelCache = DependencyManager::get<ModelCache>();
GeometryExtra extra{ mapping, _textureBaseUrl, false }; // XXX
GeometryExtra extra{ mapping, _textureBaseUrl, false };
// Get the raw GeometryResource
_geometryResource = modelCache->getResource(url, QUrl(), &extra).staticCast<GeometryResource>();
@ -180,8 +180,7 @@ void GeometryReader::run() {
throw QString("empty geometry, possibly due to an unsupported FBX version");
}
} else if (_url.path().toLower().endsWith(".obj")) {
bool combineParts = false;
fbxGeometry.reset(OBJReader().readOBJ(_data, _mapping, combineParts, _url));
fbxGeometry.reset(OBJReader().readOBJ(_data, _mapping, _combineParts, _url));
} else {
throw QString("unsupported format");
}
@ -277,15 +276,16 @@ QSharedPointer<Resource> ModelCache::createResource(const QUrl& url, const QShar
const GeometryExtra* geometryExtra = static_cast<const GeometryExtra*>(extra);
auto mapping = geometryExtra ? geometryExtra->mapping : QVariantHash();
auto textureBaseUrl = geometryExtra ? geometryExtra->textureBaseUrl : QUrl();
bool combineParts = geometryExtra ? geometryExtra->combineParts : false;
bool combineParts = geometryExtra ? geometryExtra->combineParts : true;
resource = new GeometryDefinitionResource(url, mapping, textureBaseUrl, combineParts);
}
return QSharedPointer<Resource>(resource, &Resource::deleter);
}
GeometryResource::Pointer ModelCache::getGeometryResource(const QUrl& url, const QVariantHash& mapping, const QUrl& textureBaseUrl) {
GeometryExtra geometryExtra = { mapping, textureBaseUrl, false }; // XXX
GeometryResource::Pointer ModelCache::getGeometryResource(const QUrl& url, bool combineParts,
const QVariantHash& mapping, const QUrl& textureBaseUrl) {
GeometryExtra geometryExtra = { mapping, textureBaseUrl, combineParts };
GeometryResource::Pointer resource = getResource(url, QUrl(), &geometryExtra).staticCast<GeometryResource>();
if (resource) {
if (resource->isLoaded() && resource->shouldSetTextures()) {

View file

@ -136,7 +136,9 @@ class ModelCache : public ResourceCache, public Dependency {
public:
GeometryResource::Pointer getGeometryResource(const QUrl& url,
const QVariantHash& mapping = QVariantHash(), const QUrl& textureBaseUrl = QUrl());
bool combineParts,
const QVariantHash& mapping = QVariantHash(),
const QUrl& textureBaseUrl = QUrl());
protected:
friend class GeometryMappingResource;

View file

@ -811,7 +811,7 @@ void Model::setURL(const QUrl& url) {
invalidCalculatedMeshBoxes();
deleteGeometry();
auto resource = DependencyManager::get<ModelCache>()->getGeometryResource(url);
auto resource = DependencyManager::get<ModelCache>()->getGeometryResource(url, true);
resource->setLoadPriority(this, _loadingPriority);
_renderWatcher.setResource(resource);
onInvalidate();