Load spaeck file in initialize instead of initialiseGL

This commit is contained in:
Malin E
2022-08-02 14:05:39 +02:00
parent 39b8914917
commit 9c39874efc
2 changed files with 27 additions and 23 deletions

View File

@@ -262,22 +262,7 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary)
_selectedMeshes.onChange([this]() { selectionPropertyHasChanged(); });
addProperty(_selectedMeshes);
if (p.selectedMeshes.has_value()) {
const std::vector<std::string> options = _selectedMeshes.options();
std::set<std::string> selectedNames;
for (const std::string& s : *p.selectedMeshes) {
const auto it = std::find(options.begin(), options.end(), s);
if (it == options.end()) {
// The user has specified a mesh name that doesn't exist
LWARNING(fmt::format("Option '{}' not found in list of meshes", s));
}
else {
selectedNames.insert(s);
}
}
_selectedMeshes = selectedNames;
}
_assetSelectedMeshes = p.selectedMeshes.value_or(_assetSelectedMeshes);
}
void RenderableDUMeshes::fillSelectionProperty() {
@@ -318,6 +303,30 @@ bool RenderableDUMeshes::isReady() const {
(!_renderingMeshesMap.empty() || (!_labelset.entries.empty()));
}
void RenderableDUMeshes::initialize() {
bool success = loadData();
if (!success) {
throw ghoul::RuntimeError("Error loading data");
}
fillSelectionProperty();
const std::vector<std::string> options = _selectedMeshes.options();
std::set<std::string> selectedNames;
for (const std::string& s : _assetSelectedMeshes) {
const auto it = std::find(options.begin(), options.end(), s);
if (it == options.end()) {
// The user has specified a mesh name that doesn't exist
LWARNING(fmt::format("Option '{}' not found in list of meshes", s));
}
else {
selectedNames.insert(s);
}
}
_selectedMeshes = selectedNames;
}
void RenderableDUMeshes::initializeGL() {
_program = DigitalUniverseModule::ProgramObjectManager.request(
"RenderableDUMeshes",
@@ -332,11 +341,6 @@ void RenderableDUMeshes::initializeGL() {
ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames);
bool success = loadData();
if (!success) {
throw ghoul::RuntimeError("Error loading data");
}
createMeshes();
if (_hasLabel) {
@@ -690,8 +694,6 @@ bool RenderableDUMeshes::readSpeckFile() {
}
}
}
fillSelectionProperty();
setBoundingSphere(maxRadius);
return true;

View File

@@ -56,6 +56,7 @@ public:
explicit RenderableDUMeshes(const ghoul::Dictionary& dictionary);
~RenderableDUMeshes() override = default;
void initialize() override;
void initializeGL() override;
void deinitializeGL() override;
@@ -118,6 +119,7 @@ private:
bool _dataIsDirty = true;
bool _textColorIsDirty = true;
bool _hasLabel = false;
std::vector<std::string> _assetSelectedMeshes;
properties::Vec3Property _textColor;
properties::FloatProperty _textOpacity;