45 if (!simulationHandler)
47 for (
const auto& material : materials)
48 simulationHandler->bind(material.second);
53 if (!simulationHandler)
55 for (
const auto& material : materials)
56 simulationHandler->unbind(material.second);
60 : _name(fs::path(path).stem())
74 , _loaderProperties(loaderProperties)
80 , _model(std::move(model))
82 _model->updateBounds();
89 , _model(std::move(model))
91 _model->updateBounds();
99 , _model(std::move(model))
101 _model->updateBounds();
122 if (newRotationCenter ==
Vector3d(0))
133 _instances.push_back(instance);
134 _instances.rbegin()->setInstanceID(_nextInstanceID++);
136 _model->markInstancesDirty();
141 auto i = std::remove_if(_instances.begin(), _instances.end(),
142 [
id](
const auto& instance) { return id == instance.getInstanceID(); });
143 if (i == _instances.end())
146 _instances.erase(i, _instances.end());
149 _model->markInstancesDirty();
157 _model->markInstancesDirty();
162 auto i = std::find_if(_instances.begin(), _instances.end(),
163 [
id](
const auto& instance) { return id == instance.getInstanceID(); });
164 return i == _instances.end() ? nullptr : &(*i);
173 _bounds.
merge(_model->getBounds());
177 if (!instance.getVisible())
186 auto newModelDesc = std::make_shared<ModelDescriptor>(std::move(model),
getPath());
188 *newModelDesc =
static_cast<const ModelParams&
>(*this);
190 newModelDesc->_bounds = _bounds;
191 newModelDesc->_metadata = _metadata;
192 newModelDesc->_model->copyFrom(
getModel());
193 newModelDesc->_instances = _instances;
194 newModelDesc->_properties = _properties;
195 newModelDesc->_model->buildBoundingBox();
201 : _animationParameters(animationParameters)
202 , _volumeParameters(volumeParameters)
203 , _geometryParameters(geometryParameters)
204 , _fieldParameters(fieldParameters)
223 return _geometries->_spheres[materialId].size() - 1;
229 _geometries->_cylinders[materialId].push_back(cylinder);
230 return _geometries->_cylinders[materialId].size() - 1;
242 if (streamline.position.size() < 2)
243 throw std::runtime_error(
244 "Number of vertices is less than two which is minimum needed for a "
247 if (streamline.position.size() != streamline.color.size())
248 throw std::runtime_error(
"Number of vertices and colors do not match.");
250 if (streamline.position.size() != streamline.radius.size())
251 throw std::runtime_error(
"Number of vertices and radii do not match.");
253 auto& streamlinesData =
_geometries->_streamlines[materialId];
255 const size_t startIndex = streamlinesData.vertex.size();
256 const size_t endIndex = startIndex + streamline.position.size() - 1;
258 for (
size_t index = startIndex; index < endIndex; ++index)
259 streamlinesData.indices.push_back(index);
261 for (
size_t i = 0; i < streamline.position.size(); i++)
262 streamlinesData.vertex.push_back(
Vector4f(streamline.position[i], streamline.radius[i]));
264 for (
const auto& color : streamline.color)
265 streamlinesData.vertexColor.push_back(color);
273 throw std::runtime_error(
274 "Number of vertices is less than two which is minimum needed for a "
278 throw std::runtime_error(
"Number of vertices and indices do not match.");
281 throw std::runtime_error(
"Number of vertices and normals do not match.");
284 throw std::runtime_error(
"Number of vertices and tangents do not match.");
292 const uint64_t geomIdx =
_geometries->_sdf.geometries.size();
293 _geometries->_sdf.geometryIndices[materialId].push_back(geomIdx);
294 _geometries->_sdf.neighbours.push_back(neighbourIndices);
302 _geometries->_sdf.neighbours[geometryIdx] = neighbourIndices;
320 auto iter =
_geometries->_volumes.find(materialId);
338 material.second->setSpecularColor(
Vector3f(0.f));
339 material.second->setOpacity(1.f);
340 material.second->setReflectionIndex(0.f);
341 material.second->setEmission(0.f);
347 const float a = float(index) / float(
_materials.size() - 1);
348 material.second->setDiffuseColor(
Vector3f(a * a, std::sqrt(a), 1.f - a));
352 material.second->setDiffuseColor(
Vector3f(0.5f +
float(std::rand() % 127) / 255.f,
353 0.5f +
float(std::rand() % 127) / 255.f,
354 0.5f +
float(std::rand() % 127) / 255.f));
357 material.second->setDiffuseColor(
358 Vector3f(
float(rand() % 255) / 255.f,
float(rand() % 255) / 255.f,
float(rand() % 255) / 255.f));
363 material.second->setOpacity(
float(std::rand() % 100) / 100.f);
364 material.second->setRefractionIndex(1.2f);
365 material.second->setSpecularColor(
Vector3f(1.f));
366 material.second->setSpecularExponent(10.f);
370 material.second->setEmission(std::rand() % 20);
374 material.second->setReflectionIndex(
float(std::rand() % 100) / 100.f);
375 material.second->setSpecularColor(
Vector3f(1.f));
376 material.second->setSpecularExponent(10.f);
380 material.second->setReflectionIndex(
float(std::rand() % 100) / 100.f);
381 material.second->setOpacity(
float(std::rand() % 100) / 100.f);
382 material.second->setRefractionIndex(1.2f);
383 material.second->setSpecularColor(
Vector3f(1.f));
384 material.second->setSpecularExponent(10.f);
388 material.second->setReflectionIndex(
float(std::rand() % 100) / 100.f);
389 material.second->setSpecularColor(
Vector3f(1.f));
390 material.second->setSpecularExponent(10.f);
391 material.second->setGlossiness(
float(std::rand() % 100) / 100.f);
395 material.second->setOpacity(
float(std::rand() % 100) / 100.f);
396 material.second->setRefractionIndex(1.2f);
397 material.second->setSpecularColor(
Vector3f(1.f));
398 material.second->setSpecularExponent(10.f);
399 material.second->setGlossiness(
float(std::rand() % 100) / 100.f);
404 float value = float(std::rand() % 255) / 255.f;
405 material.second->setDiffuseColor(
Vector3f(value, value, value));
408 material.second->commit();
418 uint64_t nbSpheres = 0;
419 uint64_t nbCylinders = 0;
420 uint64_t nbCones = 0;
421 uint64_t nbMeshes =
_geometries->_triangleMeshes.size();
423 nbSpheres += spheres.second.size();
424 for (
const auto& cylinders :
_geometries->_cylinders)
425 nbCylinders += cylinders.second.size();
427 nbCones += cones.second.size();
429 CORE_INFO(
"Spheres: " << nbSpheres <<
", Cylinders: " << nbCylinders <<
", Cones: " << nbCones
430 <<
", Meshes: " << nbMeshes <<
", Memory: " <<
_sizeInBytes <<
" bytes ("
439 CORE_THROW(
"Material " + std::to_string(materialId) +
" is not registered in the model");
448 for (
const auto& cylinders :
_geometries->_cylinders)
452 for (
const auto& triangleMesh :
_geometries->_triangleMeshes)
454 const auto& mesh = triangleMesh.second;
461 for (
const auto& streamline :
_geometries->_streamlines)
463 _sizeInBytes += streamline.second.indices.size() *
sizeof(int32_t);
470 for (
const auto& sdfIndices :
_geometries->_sdf.geometryIndices)
471 _sizeInBytes += sdfIndices.second.size() *
sizeof(uint64_t);
472 for (
const auto& sdfNeighbours :
_geometries->_sdf.neighbours)
489 *newMaterial = *material.second;
515 if (spheres.first != BOUNDINGBOX_MATERIAL_ID)
516 for (
const auto&
sphere : spheres.second)
526 for (
const auto& cylinders :
_geometries->_cylinders)
527 if (cylinders.first != BOUNDINGBOX_MATERIAL_ID)
528 for (
const auto& cylinder : cylinders.second)
530 _geometries->_cylindersBounds.merge(cylinder.center);
539 if (cones.first != BOUNDINGBOX_MATERIAL_ID)
540 for (
const auto& cone : cones.second)
550 for (
const auto& mesh :
_geometries->_triangleMeshes)
551 if (mesh.first != BOUNDINGBOX_MATERIAL_ID)
552 for (
const auto& vertex : mesh.second.vertices)
559 for (
const auto& streamline :
_geometries->_streamlines)
560 for (
size_t index = 0; index < streamline.second.vertex.size(); ++index)
562 const auto& pos =
Vector3f(streamline.second.vertex[index]);
563 const float radius = streamline.second.vertex[index][3];
564 const auto radiusVec =
Vector3f(radius, radius, radius);
565 _geometries->_streamlinesBounds.merge(pos + radiusVec);
566 _geometries->_streamlinesBounds.merge(pos - radiusVec);
573 for (
const auto& geom :
_geometries->_sdf.geometries)
588 for (
const auto& curve : curves.second)
589 for (
const auto& vertex : curve.vertices)
597 _geometries->_fieldsBounds.merge(field.second->getBounds());
628 material->setName(name);
644 size_t volumeSizeInBytes = 0;
646 volumeSizeInBytes +=
volume.second->getSizeInBytes();
703 material.second->setDiffuseColor(colormap[i]);
704 material.second->setSpecularColor(colormap[i]);
void setIsReadyCallback(const IsReadyCallback &callback)
uint32_t getFrame() const
void removeIsReadyCallback()
bool hasIsReadyCallback() const
void _updateValue(T &member, const T &newValue, const bool triggerCallback=true)
void merge(const Box< T > &aabb)
The ModelDescriptor struct defines the metadata attached to a model.Model descriptor are exposed via ...
void removeInstance(const size_t id)
ModelDescriptor()=default
const Model & getModel() const
ModelDescriptor & operator=(ModelDescriptor &&rhs)=default
const ModelInstances & getInstances() const
void addInstance(const ModelInstance &instance)
ModelInstance * getInstance(const size_t id)
ModelDescriptorPtr clone(ModelPtr model) const
A class representing an instance of a 3D model.
PLATFORM_API bool getBoundingBox() const
Get the value of _boundingBox.
PLATFORM_API bool getVisible() const
Get the value of _visible.
Transformation _transformation
PLATFORM_API const Transformation & getTransformation() const
Get the value of _transformation.
The ModelParams class represents the parameters needed for initializing a model instance.
PLATFORM_API ModelParams()=default
PLATFORM_API const std::string & getPath() const
getPath gets the path of the model
PLATFORM_API const std::string & getName() const
getName gets the name of the model
The abstract Model class holds the geometry attached to an asset of the scene (mesh,...
virtual PLATFORM_API ~Model()
Virtual destructor for Model class.
PLATFORM_API void removeVolume(const size_t materialId)
Remove a volume from the model.
PLATFORM_API void copyFrom(const Model &rhs)
Copies the model data from another model.
std::set< BVHFlag > _bvhFlags
PLATFORM_API bool empty() const
TransferFunction _transferFunction
AbstractSimulationHandlerPtr _simulationHandler
virtual PLATFORM_API MaterialPtr createMaterialImpl(const PropertyMap &properties={})=0
PLATFORM_API void addVolume(const size_t materialId, VolumePtr)
Add a volume to the model.
PLATFORM_API void updateBounds()
Updates the bounds of the geometries.
void _markGeometriesClean()
PLATFORM_API AbstractSimulationHandlerPtr getSimulationHandler() const
Returns the simulation handler.
bool _areGeometriesDirty() const
PLATFORM_API void updateSDFGeometryNeighbours(size_t geometryIdx, const uint64_ts &neighbourIndices)
Update the list of neighbours for an SDF geometry.
bool _triangleMeshesDirty
PLATFORM_API bool commitSimulationData()
Function to commit simulation data.
PLATFORM_API uint64_t addSphere(const size_t materialId, const Sphere &sphere)
Adds a sphere to the model.
PLATFORM_API uint64_t addSDFGeometry(const size_t materialId, const SDFGeometry &geom, const uint64_ts &neighbourIndices)
Adds an SDFGeometry to the scene.
PLATFORM_API uint64_t addCylinder(const size_t materialId, const Cylinder &cylinder)
Adds a cylinder to the model.
PLATFORM_API MaterialPtr createMaterial(const size_t materialId, const std::string &name, const PropertyMap &properties={})
Factory method to create an engine-specific material.
void _updateSizeInBytes()
std::shared_ptr< Geometries > _geometries
virtual void _commitSimulationDataImpl(const float *frameData, const size_t frameSize)=0
PLATFORM_API Model(AnimationParameters &animationParameters, VolumeParameters &volumeParameters, GeometryParameters &geometryParameters, FieldParameters &fieldParameters)
Constructor for Model class.
PLATFORM_API void addField(const size_t materialId, FieldPtr)
Add a field to the model.
PLATFORM_API uint64_t addCone(const size_t materialId, const Cone &cone)
Adds a cone to the model.
AnimationParameters & _animationParameters
PLATFORM_API void applyDefaultColormap()
Applies a default color map (rainbow) to the model.
PLATFORM_API void addCurve(const size_t materialId, const Curve &curve)
Adds a curve to the model.
PLATFORM_API void logInformation()
Logs information about the model, like the number of primitives, and the associated memory footprint.
PLATFORM_API void setSimulationHandler(AbstractSimulationHandlerPtr handler)
Sets the simulation handler.
PLATFORM_API bool commitTransferFunction()
Function to commit transfer function.
PLATFORM_API bool isDirty() const
PLATFORM_API void addStreamline(const size_t materialId, const Streamline &streamline)
Adds a streamline to the model.
PLATFORM_API MaterialPtr getMaterial(const size_t materialId) const
Returns a pointer to a specific material.
PLATFORM_API size_t getSizeInBytes() const
Returns the size in bytes of all geometries.
virtual void _commitTransferFunctionImpl(const Vector3fs &colors, const floats &opacities, const Vector2d valueRange)=0
PLATFORM_API void setMaterialsColorMap(const MaterialsColorMap colorMap)
Sets the materials handled by the model, and available to the geometry.
const ColorMap & getColorMap() const
const Vector2d & getValuesRange() const
floats calculateInterpolatedOpacities() const
std::map< std::string, std::string > ModelMetadata
std::shared_ptr< Volume > VolumePtr
std::map< size_t, MaterialPtr > MaterialMap
glm::vec< 3, uint32_t > Vector3ui
std::shared_ptr< AbstractSimulationHandler > AbstractSimulationHandlerPtr
glm::vec< 3, double > Vector3d
Boxd getSDFBoundingBox(const SDFGeometry &geom)
Vector3fs getRainbowColormap(const uint32_t colormapSize)
Get the Rainbow Colormap.
std::shared_ptr< ModelDescriptor > ModelDescriptorPtr
std::shared_ptr< Field > FieldPtr
std::vector< Cone > Cones
std::unique_ptr< Model > ModelPtr
std::shared_ptr< Material > MaterialPtr
Boxd transformBox(const Boxd &box, const Transformation &transformation)