API Documentation
Loading...
Searching...
No Matches
Material.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: Material
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33
34#include <NDEVR/DesignObject.h>
35#include <NDEVR/Table.h>
36#include <NDEVR/Pointer.h>
37#include <NDEVR/BaseValues.h>
38#include <NDEVR/VectorFunctions.h>
39namespace NDEVR
40{
41 class DesignParameterAccumulator;
42 class Model;
43 /**--------------------------------------------------------------------------------------------------
44 \brief Container responsible for storing and setting the appearance of a Model or Geometry within
45 the NDEVR API 3D environment. Models may have 3 materials but Materials can be shared across
46 any number of Models within a Scene.
47 \warning Access to these members and data should be made in a thread-safe manner using DesignObjectLookup
48 read and write locks.
49 **/
51 {
52 public:
54 {
55 e_flat // Flat shading. Shading is done on per - face base, diffuse only.Also known as 'faceted shading'.
56 , e_gouraud // Simple Gouraud shading.
57 , e_phong // Phong - Shading - .
58 , e_phong_blinn // Phong - Blinn - Shading.
59 , e_toon // Shading per pixel. Also known as 'comic' shader.
60 , e_oren_nayar // Shading per pixel. Extension to standard Lambertian shading, taking the roughness of the material into account
61 , e_minnaert // Shading per pixel. Extension to standard Lambertian shading, taking the "darkness" of the material into account
62 , e_cook_torrance // Special shader for metallic surfaces.
63 , e_no_shading // No shading at all. Constant light influence of 1.0.
64 , e_fresnel // Fresnel shading.
65 , e_pbr
66 , e_ibl
67 , e_water
68 , e_background_gradiant
69 , e_skybox
70 , e_number_of_shading_models
71 };
72
73 enum UVMode
74 {
75 e_none
76 , e_solid_color
77 , e_color_channel
78 , e_scaled_channel
79 , e_color_by_model
80 , e_background
82 , e_background_contrast_plus_solid
83 , e_image
84 , e_color_by_layer
85 , e_highlight
86 };
87
89 {
90 e_no_linework
91 , e_global_linework
92 , e_modelspace_linework
93 };
94
96 {
97 e_tile_tex_undefined
98 , e_tile_texture_wrap // A texture coordinate u|v is translated to u%1|v%1
99 , e_tile_texture_clamp//Texture coordinates outside [0...1] are clamped to the nearest valid value.
100 , e_tile_texture_decal // If the texture coordinates for a pixel are outside [0...1] the texture is not applied to that pixel
101 , e_tile_texture_mirror//A texture coordinate u|v becomes u%1|v%1 if (u-(u%1))%2 is zero and 1-(u%1)|1-(v%1) otherwise
102 };
104 {
105 e_tex_coord_undefined
106 , e_use_mat_coordinates
107 , e_project_sphere
108 , e_project_cylinder
109 , e_project_box
110 , e_project_plane
111 };
112 //Possible properties for a Material. Use with Material::setMaterialProperty
114 {
115 e_two_sided
116 , e_shading_model
117 , e_opacity
118 , e_bump_scale
119 , e_shininess
120 , e_reflectivity
121 , e_wireframe
123 , e_pixel_thickness
124 , e_grid_line_spacing
125 , e_gridline_spacing_mode
126 , e_is_dynamic_texture
127 , e_model_space_material
128 , e_color_value_palette
129 , e_draw_by_property_channel
130
131 , e_extra_property_color_min
132 , e_extra_property_color_mid
133 , e_extra_property_color_max
134
135 , e_extra_property_value_min
136 , e_extra_property_value_mid
137 , e_extra_property_value_max
138
139 , e_override_parent_material
140 , e_override_camera_material
141
142 , e_tile_texture_mode
143 , e_texture_coord_mode
144 , e_use_normal_for_tex_coord
145 , e_ignore_depth
146 , e_write_to_depth
147 , e_depth_bias
148 , e_fade_render_distance
149 , e_max_render_distance
150 , e_ignore_color_channel_lighting
151 };
152 public:
153 Material() = default;
154 Material(uint04 index, DesignObjectBase* property_table);
155 Material(DesignObjectBase* property_table);
156 explicit Material(const DesignObject& obj);
157 bool hasActiveImage() const;
158 bool hasImageData() const;
161 bool hasOpacity() const;
163
171 bool validate() const;
172
173 template<class t_type>
175 {
176 return m_base->material_table.get()[m_base->material_property_index[cast<uint04>(mat_index)]].get<t_type>(m_design_index);
177 }
178 template<class t_type>
179 void setMaterialProperty(MaterialProperties mat_index, const t_type& type)
180 {
181 m_base->material_table.get()[m_base->material_property_index[cast<uint04>(mat_index)]].set(m_design_index, type);
182 }
183 template<class t_type>
184 void updateMaterialProperty(MaterialProperties mat_index, const t_type& type, const void* lock_ptr = nullptr)
185 {
186 if (getMaterialProperty<t_type>(mat_index) != type)
187 {
188 WLock wLock(lock_ptr);
189 setMaterialProperty(mat_index, type);
190 updateModifiedTime();
191 }
192 }
193 void colorBy(const DesignParameterAccumulator& accumulator);
195 void copyFrom(const Material& mesh);
196 void combineFrom(const Material& mesh);
197
199
200
201 template<class t_type>
202 void setUVImage(UVType uv_index, const t_type& type)
203 {
204 uint04 column = m_base->uv_image_file[cast<uint04>(uv_index)];
205 m_base->material_table.get()[column].set(m_design_index, type);
206 }
207 template<class t_type>
208 void setUVColor(const t_type& type)
209 {
210 for (uint04 i = 0; i < cast<uint04>(UVType::e_uv_size); i++)
211 setUVColor(cast<UVType>(i), type);
212 }
213 template<class t_type>
214 void setUVColor(UVType uv_index, const t_type& type)
215 {
216 uint04 column = m_base->uv_color[cast<uint04>(uv_index)];
217 m_base->material_table.get()[column].set(m_design_index, type);
218 }
219 template<class t_type>
220 void updateUVColor(const t_type& type, const void* lock_ptr = nullptr)
221 {
222 for (uint04 i = 0; i < cast<uint04>(UVType::e_uv_size); i++)
223 updateUVColor(cast<UVType>(i), type, lock_ptr);
224 }
225 template<class t_type>
226 void updateUVColor(UVType uv_index, const t_type& value, const void* lock_ptr = nullptr)
227 {
228 if (getUVColor(uv_index) != value)
229 {
230 WLock lock(lock_ptr);
231 uint04 column = m_base->uv_color[cast<uint04>(uv_index)];
232 m_base->material_table.get()[column].set(m_design_index, value);
233 updateModifiedTime();
234 }
235 }
236 template<class t_type>
237 void setUVIntensity(UVType uv_index, const t_type& type)
238 {
239 uint04 column = m_base->uv_intensity[cast<uint04>(uv_index)];
240 m_base->material_table.get()[column].set(m_design_index, type);
241 }
242 template<class t_type>
243 void setUVLayer(UVType uv_index, const t_type& type)
244 {
245 uint04 column = m_base->uv_layer[cast<uint04>(uv_index)];
246 m_base->material_table.get()[column].set(m_design_index, type);
247 }
248 void setUVMode(UVType uv_index, const UVMode& type);
249 String getUVImage(UVType uv_index) const;
250 RGBColor getUVColor(UVType uv_index) const;
251 fltp04 getUVIntensity(UVType uv_index) const;
252 uint04 getUVLayer(UVType uv_index) const;
253 UVMode getUVMode(UVType uv_index) const;
254 bool hasActiveUVImage(UVType index) const;
255 bool hasUVIntensity(UVType index) const;
257 bool hasUVLayer(UVType index) const;
258 bool hasUVColor(UVType index) const;
259 bool hasPerVertexColoring(UVType type = UVType::e_KD) const;
262 [[nodiscard]] RGBColor constantColor(Model model, RGBColor background_color = RGBColor(255, 255, 255), UVType type = UVType::e_KD) const;
264 void setPalette(const Buffer<RGBColor>& palette);
265 void updateModifiedTime(const Time& time = Time::SystemTime());
266 };
267 template<>
268 struct ObjectInfo<Material, false, false>
269 {
270 static const uint01 Dimensions = 0;
271 static const bool Vector = false;
272 static const bool Buffer = false;
273 static const bool Primitive = DESIGN_PRIM;
274 static const bool Pointer = false;
275 static const bool Unsigned = false;
276 static const bool Float = false;
277 static const bool Integer = false;
278 static const bool Number = false;
279 static const bool Enum = false;
280 static const bool String = false;
281 static const bool Color = false;
282 static const bool Boolean = false;
283 static constexpr ObjectInfo<Material, false, false> VectorSub() { return ObjectInfo<Material, false, false>(); }
284 };
285 template class NDEVR_DESIGN_API StringStream<Material::GridLineMode>;
286 template class NDEVR_DESIGN_API StringStream<Material::TextureCoordMode>;
287 template class NDEVR_DESIGN_API StringStream<Material::TileTextureMode>;
288 template class NDEVR_DESIGN_API StringStream<Material::UVMode>;
289 template class NDEVR_DESIGN_API StringStream<Material::ShadingModel>;
290 template class NDEVR_DESIGN_API StringStream<Material::MaterialProperties>;
291}
292namespace std//Define things to allow use within std libs
293{
294 template <>
295 struct hash<NDEVR::Material>
296 {
297 std::size_t operator()(const NDEVR::Material& d) const noexcept
298 {
299 NDEVR::UUID s = d.uuid();
300 std::size_t value = 0;
301 for (NDEVR::uint01 i = 0; i < 8; i++)
302 value = value * 256 + (s[i + 0U] ^ s[i + 8U]);
303 return value;
304 }
305 };
306};
307
308
309
#define NDEVR_DESIGN_API
Definition DLLInfo.h:55
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
The core Color class in the NDEVR API. Colors can be defined in several ways. The ACIColor is compact...
Definition Color.h:41
Provides the underlying data storage for the NDEVR Scene Model heirarchy.
Definition DesignObjectBase.h:150
A low-level database object that can be used to access general stored properties within the NDEVR Mod...
Definition DesignObject.h:67
Searches a model heirarchy and pulls all parameter data based on the AccumationMode settings.
Definition DesignParameterAccumulator.h:67
Container responsible for storing and setting the appearance of a Model or Geometry within the NDEVR ...
Definition Material.h:51
ShadingModel
Definition Material.h:54
bool hasOpacity() const
void setPalette(const Buffer< RGBColor > &palette)
bool hasUVLayer(UVType index) const
PrimitiveProperty defaultRenderProperty() const
RGBColor convertValueToColor(fltp08 value) const
bool hasUVColor(UVType index) const
bool hasImageData() const
TileTextureMode
Definition Material.h:96
t_type getMaterialProperty(MaterialProperties mat_index) const
Definition Material.h:174
Material(uint04 index, DesignObjectBase *property_table)
bool validate() const
void setTileTextureMode(const Vector< 3, TileTextureMode > &modes)
void setMaterialProperty(MaterialProperties mat_index, const t_type &type)
Definition Material.h:179
void updateModifiedTime(const Time &time=Time::SystemTime())
bool hasUVIntensity(UVType index) const
UVMode getUVMode(UVType uv_index) const
GridLineMode
Definition Material.h:89
bool hasActiveImage() const
void setUVLayer(UVType uv_index, const t_type &type)
Definition Material.h:243
TextureCoordMode getTextureCoordinateMode() const
Vector< 3, TileTextureMode > getTileTextureMode() const
bool hasModelDependentColor(UVType type) const
void cleanupMaterial()
MaterialProperties
Definition Material.h:114
void updateMaterialProperty(MaterialProperties mat_index, const t_type &type, const void *lock_ptr=nullptr)
Definition Material.h:184
void setUVColor(const t_type &type)
Definition Material.h:208
uint04 getUVLayer(UVType uv_index) const
RGBColor constantColor(Model model, RGBColor background_color=RGBColor(255, 255, 255), UVType type=UVType::e_KD) const
String getUVImage(UVType uv_index) const
fltp04 getUVIntensity(UVType uv_index) const
void setupAsDefault()
Material(DesignObjectBase *property_table)
void setShadingModel(ShadingModel model)
ShadingModel getShadingModel() const
void updateUVColor(const t_type &type, const void *lock_ptr=nullptr)
Definition Material.h:220
Buffer< RGBColor > palette() const
bool hasPerVertexColoring(UVType type=UVType::e_KD) const
TextureCoordMode
Definition Material.h:104
UVMode
Definition Material.h:74
void setUVMode(UVType uv_index, const UVMode &type)
Material(const DesignObject &obj)
bool hasModelDependentColor() const
bool isSupportedByShadingModel(UVType type) const
void setUVColor(UVType uv_index, const t_type &type)
Definition Material.h:214
TranslatedString appearanceName() const
void colorBy(const DesignParameterAccumulator &accumulator)
void setUVImage(UVType uv_index, const t_type &type)
Definition Material.h:202
void updateUVColor(UVType uv_index, const t_type &value, const void *lock_ptr=nullptr)
Definition Material.h:226
void setUVIntensity(UVType uv_index, const t_type &type)
Definition Material.h:237
RGBColor getUVColor(UVType uv_index) const
void setTextureCoordinateMode(const TextureCoordMode &mode)
Material()=default
bool hasActiveUVImage(UVType index) const
void combineFrom(const Material &mesh)
TranslatedString displayName() const
void copyFrom(const Material &mesh)
A core class that represents a node on model heirarchy. This node may contain a Geometry or one or mo...
Definition Model.h:58
Provides shared ownership of a dynamically allocated object.
Definition Pointer.hpp:71
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:54
The core String class for the NDEVR API.
Definition String.h:69
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
Used to lock a particular variable for writing. Only one write lock can be created when no read locks...
Definition RWLock.h:115
Definition ACIColor.h:37
@ e_background_contrast
Definition CADEntities.h:49
constexpr bool DESIGN_PRIM
Definition DesignObject.h:47
PrimitiveProperty
Definition DesignObjectBase.h:44
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
Definition BaseValues.hpp:127
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
UVType
Channels that describe how an object should interact with light.
Definition DesignObjectBase.h:133
Definition File.h:211
Information about the object.
Definition ObjectInfo.h:54