VR-Engage  2.3
Loading...
Searching...
No Matches
surfaceToVxMaterialMapper.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2024 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file surfaceToVxMaterialMapper.h
7//! \brief Provides mapping functionality between VR-Forces terrain surface types and Vortex physics materials
8//! \ingroup vreVrfVortex
9
10#pragma once
11
12#include "vreVrfVortex/export.h"
13
14#include <string>
15#include <vector>
16
17#include <geometry/surface.h>
18
19namespace Vx
20{
21class VxMaterial;
22class VxMaterialTable;
23} // namespace Vx
24
25namespace makVre
26{
27//! \brief Structure that holds information about a Vortex surface material mapping
28//!
29//! Stores the Vortex material associated with a terrain surface type as well as
30//! various flags that control how the surface is handled in the physics simulation.
32{
33 //! \brief Default constructor
34 //!
35 //! Initializes a surface info with no material and all flags set to false.
37 : material(nullptr)
38 , isFiltered(false)
40 , isUsingDefault(false)
41 {
42 }
43
44 Vx::VxMaterial* material; //!< Pointer to the Vortex material
45 bool isFiltered; //!< Flag indicating if this surface should be filtered out in triangle generation
46 bool shouldUseRoughnessMap; //!< Flag indicating if roughness mapping should be used for this surface
47 bool isUsingDefault; //!< Flag indicating if this surface is using the default material
48 std::string surfaceTypeString; //!< String representation of the surface type
49 std::string surfaceTypeMapping; //!< The material mapping string from configuration
50};
51
52//! \brief Value snapshot of a terrain surface-to-Vortex-material mapping.
53//!
54//! Captures the configured mapping rule and the resolved material for a terrain
55//! surface category. The material pointer is non-owning and remains valid only
56//! while the mapper's Vortex material table remains valid.
58{
59 std::string category; //!< Surface category, such as soil or roughness.
60 std::string surfaceType; //!< VR-Forces surface type within the category.
61 std::string configuredMapping; //!< Mapping rule configured in vortexConfig.lua.
62 const Vx::VxMaterial* material = nullptr; //!< Non-owning resolved material, or nullptr when no material applies.
63 bool isFiltered = false; //!< Whether triangles for the surface type are filtered.
64 bool usesRoughnessMapping = false; //!< Whether material selection depends on roughness.
65 bool usesDefaultMaterial = false; //!< Whether the configured default material is used.
66};
67
68//! \brief Class for mapping VR-Forces terrain surface types to Vortex physics materials
69//!
70//! This class provides the functionality to translate between VR-Forces terrain surface types
71//! (soil, water, cultural features, etc.) and Vortex physics materials. It maintains lookup
72//! tables for different surface type categories and provides methods to retrieve the appropriate
73//! Vortex material for a given surface.
75{
76public:
77 //! \brief Default constructor
78 //!
79 //! Initializes an empty material mapper with no default material.
81
82 //! \brief Destructor
83 //!
84 //! Cleans up all allocated surface info objects in the mapping tables.
86
87 //! \brief Initialize the material mapper with a Vortex material table
88 //!
89 //! Sets up the mapping between VR-Forces surface types and Vortex materials
90 //! based on configuration settings in vortexConfig.lua. This includes setting
91 //! up the default material, material mapping tables, and filter lists.
92 //!
93 //! Reinitializing discards all prior resolved mappings. Passing nullptr leaves
94 //! the mapper uninitialized.
95 //!
96 //! \param materialTable Non-owning material table containing available materials,
97 //! or nullptr to clear the mapper.
98 virtual void init(const Vx::VxMaterialTable* materialTable);
99
100 //! \brief Get the Vortex material for a specific terrain surface
101 //!
102 //! Determines the appropriate Vortex material based on the surface type.
103 //! For water surfaces, it uses the body of water type mapping.
104 //! For cultural features, it uses the cultural feature type mapping.
105 //! For ground or flimsy surfaces, it uses the soil type mapping.
106 //! Otherwise, it uses the roughness soil type mapping.
107 //!
108 //! \param surf The terrain surface to get the material for
109 //! \return A non-owning pointer to the resolved Vortex material, or nullptr
110 //! when the mapper is not initialized or no mapping applies.
111 Vx::VxMaterial* getVortexMaterial(const DtSurface& surf);
112
113 //! \brief Get the default Vortex material
114 //!
115 //! Returns the default material that is used when a specific mapping
116 //! is not found or when explicitly configured to use the default.
117 //!
118 //! \return A non-owning pointer to the configured default material, or nullptr
119 //! when the mapper is not initialized.
120 Vx::VxMaterial* getDefaultVortexMaterial();
121
122 //! \brief Checks whether the material mappings were initialized successfully
123 //! \return true when a default material and configured mappings are available;
124 //! otherwise, false.
125 bool isInitialized() const;
126
127 //! \brief Returns snapshots of all configured terrain surface-to-material mappings.
128 //!
129 //! Each snapshot contains the source category and surface type, the
130 //! configuration rule, the resolved material, and relevant mapping flags.
131 //!
132 //! \return Value copies of the current mappings. Each material pointer is
133 //! non-owning and is valid only while the mapper's material table is valid.
134 virtual std::vector<VortexSurfaceMaterialMapping> materialMappings() const;
135
136 //! \brief Check if a surface should be filtered out
137 //!
138 //! Determines if a given surface should be excluded from triangle generation
139 //! based on configuration settings.
140 //!
141 //! \param surf The terrain surface to check
142 //! \return True if the surface should be filtered out, false otherwise
143 bool isFiltered(const DtSurface& surf);
144
145 //! \brief Get the surface info for a specific terrain surface
146 //!
147 //! Retrieves the VortexSurfaceInfo object containing material and flags
148 //! for the given terrain surface. The appropriate info is selected based on
149 //! the surface type (water, cultural feature, ground, or roughness).
150 //!
151 //! \param surf The terrain surface to get the info for
152 //! \return A non-owning pointer to the corresponding mapping, or nullptr when
153 //! the mapper is not initialized or the surface type is unsupported.
154 VortexSurfaceInfo* getSurfaceInfo(const DtSurface& surf) const;
155
156protected:
157 //! \brief Clears all resolved material mappings
158 //!
159 //! Releases mapping records and resets the default material and initialization state.
161
162 Vx::VxMaterial* myDefaultMaterial; //!< Non-owning fallback material for unmapped surfaces.
163 bool myInitialized; //!< Whether initialization resolved a valid default material.
164
165 std::vector<VortexSurfaceInfo*> mySoilTypeToMaterialMap; //!< Mapping from soil types to Vortex materials
166 std::vector<VortexSurfaceInfo*>
167 myBodyOfWaterTypeToMaterialMap; //!< Mapping from body of water types to Vortex materials
168 std::vector<VortexSurfaceInfo*>
169 myCulturalFeatureTypeToMaterialMap; //!< Mapping from cultural feature types to Vortex materials
170 std::vector<VortexSurfaceInfo*>
171 myRoughnessSoilTypeToMaterialMap; //!< Mapping from roughness soil types to Vortex materials
172};
173} // namespace makVre
std::vector< VortexSurfaceInfo * > mySoilTypeToMaterialMap
Mapping from soil types to Vortex materials.
Definition surfaceToVxMaterialMapper.h:165
virtual void init(const Vx::VxMaterialTable *materialTable)
Initialize the material mapper with a Vortex material table.
virtual std::vector< VortexSurfaceMaterialMapping > materialMappings() const
Returns snapshots of all configured terrain surface-to-material mappings.
std::vector< VortexSurfaceInfo * > myCulturalFeatureTypeToMaterialMap
Mapping from cultural feature types to Vortex materials.
Definition surfaceToVxMaterialMapper.h:169
std::vector< VortexSurfaceInfo * > myRoughnessSoilTypeToMaterialMap
Mapping from roughness soil types to Vortex materials.
Definition surfaceToVxMaterialMapper.h:171
bool isInitialized() const
Checks whether the material mappings were initialized successfully.
bool isFiltered(const DtSurface &surf)
Check if a surface should be filtered out.
virtual ~DtSurfaceToVxMaterialMapper()
Destructor.
Vx::VxMaterial * getDefaultVortexMaterial()
Get the default Vortex material.
Vx::VxMaterial * myDefaultMaterial
Non-owning fallback material for unmapped surfaces.
Definition surfaceToVxMaterialMapper.h:162
VortexSurfaceInfo * getSurfaceInfo(const DtSurface &surf) const
Get the surface info for a specific terrain surface.
bool myInitialized
Whether initialization resolved a valid default material.
Definition surfaceToVxMaterialMapper.h:163
std::vector< VortexSurfaceInfo * > myBodyOfWaterTypeToMaterialMap
Mapping from body of water types to Vortex materials.
Definition surfaceToVxMaterialMapper.h:167
void clearMappings()
Clears all resolved material mappings.
DtSurfaceToVxMaterialMapper()
Default constructor.
Vx::VxMaterial * getVortexMaterial(const DtSurface &surf)
Get the Vortex material for a specific terrain surface.
Export macros for the VR-Forces Vortex extension library.
#define VREVRFVORTEX_DLL
Export macro for non-Windows platforms.
Definition export.h:30
Wheel articulated part IDs used in the system.
Definition surfaceToVxMaterialMapper.h:20
!
Definition glsVreMessageUtil.h:50
Structure that holds information about a Vortex surface material mapping.
Definition surfaceToVxMaterialMapper.h:32
bool isFiltered
Flag indicating if this surface should be filtered out in triangle generation.
Definition surfaceToVxMaterialMapper.h:45
VortexSurfaceInfo()
Default constructor.
Definition surfaceToVxMaterialMapper.h:36
Vx::VxMaterial * material
Pointer to the Vortex material.
Definition surfaceToVxMaterialMapper.h:44
std::string surfaceTypeString
String representation of the surface type.
Definition surfaceToVxMaterialMapper.h:48
bool isUsingDefault
Flag indicating if this surface is using the default material.
Definition surfaceToVxMaterialMapper.h:47
std::string surfaceTypeMapping
The material mapping string from configuration.
Definition surfaceToVxMaterialMapper.h:49
bool shouldUseRoughnessMap
Flag indicating if roughness mapping should be used for this surface.
Definition surfaceToVxMaterialMapper.h:46
Value snapshot of a terrain surface-to-Vortex-material mapping.
Definition surfaceToVxMaterialMapper.h:58
bool usesRoughnessMapping
Whether material selection depends on roughness.
Definition surfaceToVxMaterialMapper.h:64
std::string configuredMapping
Mapping rule configured in vortexConfig.lua.
Definition surfaceToVxMaterialMapper.h:61
std::string category
Surface category, such as soil or roughness.
Definition surfaceToVxMaterialMapper.h:59
bool isFiltered
Whether triangles for the surface type are filtered.
Definition surfaceToVxMaterialMapper.h:63
const Vx::VxMaterial * material
Non-owning resolved material, or nullptr when no material applies.
Definition surfaceToVxMaterialMapper.h:62
bool usesDefaultMaterial
Whether the configured default material is used.
Definition surfaceToVxMaterialMapper.h:65
std::string surfaceType
VR-Forces surface type within the category.
Definition surfaceToVxMaterialMapper.h:60