Beispiel #1
0
GeometryResource::Pointer ModelCache::getGeometryResource(const QUrl& url, const GeometryMappingPair& mapping, const QUrl& textureBaseUrl) {
    bool combineParts = true;
    GeometryExtra geometryExtra = { mapping, textureBaseUrl, combineParts };
    GeometryResource::Pointer resource = getResource(url, QUrl(), &geometryExtra, std::hash<GeometryExtra>()(geometryExtra)).staticCast<GeometryResource>();
    if (resource) {
        if (resource->isLoaded() && resource->shouldSetTextures()) {
            resource->setTextures();
        }
    }
    return resource;
}
Beispiel #2
0
bool ZoneEntityItem::contains(const glm::vec3& point) const {
    GeometryResource::Pointer resource = _shapeResource;
    if (_shapeType == SHAPE_TYPE_COMPOUND && resource) {
        if (resource->isLoaded()) {
            const HFMModel& hfmModel = resource->getHFMModel();

            Extents meshExtents = hfmModel.getMeshExtents();
            glm::vec3 meshExtentsDiagonal = meshExtents.maximum - meshExtents.minimum;
            glm::vec3 offset = -meshExtents.minimum- (meshExtentsDiagonal * getRegistrationPoint());
            glm::vec3 scale(getScaledDimensions() / meshExtentsDiagonal);

            glm::mat4 hfmToEntityMatrix = glm::scale(scale) * glm::translate(offset);
            glm::mat4 entityToWorldMatrix = getTransform().getMatrix();
            glm::mat4 worldToHFMMatrix = glm::inverse(entityToWorldMatrix * hfmToEntityMatrix);

            return hfmModel.convexHullContains(glm::vec3(worldToHFMMatrix * glm::vec4(point, 1.0f)));
        }
    }
    return EntityItem::contains(point);
}