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
37#include <NDEVR/Pointer.h>
38#include <NDEVR/BaseValues.h>
39#include <NDEVR/VectorFunctions.h>
40namespace NDEVR
41{
42 class DesignParameterAccumulator;
43 class Model;
45 {
46 public:
48 {
49 e_flat // Flat shading. Shading is done on per - face base, diffuse only.Also known as 'faceted shading'.
50 , e_gouraud // Simple Gouraud shading.
51 , e_phong // Phong - Shading - .
52 , e_phong_blinn // Phong - Blinn - Shading.
53 , e_toon // Shading per pixel. Also known as 'comic' shader.
54 , e_oren_nayar // Shading per pixel. Extension to standard Lambertian shading, taking the roughness of the material into account
55 , e_minnaert // Shading per pixel. Extension to standard Lambertian shading, taking the "darkness" of the material into account
56 , e_cook_torrance // Special shader for metallic surfaces.
57 , e_no_shading // No shading at all. Constant light influence of 1.0.
58 , e_fresnel // Fresnel shading.
59 , e_pbr
60 , e_ibl
61 , e_water
62 , e_background_gradiant
63 , e_skybox
64 , e_number_of_shading_models
65 };
66
67 enum UVMode
68 {
69 e_none
70 , e_solid_color
71 , e_color_channel
72 , e_scaled_channel
73 , e_color_by_model
74 , e_background
76 , e_background_contrast_plus_solid
77 , e_image
78 , e_color_by_layer
79 , e_highlight
80 };
81
83 {
84 e_no_linework
85 , e_global_linework
86 , e_modelspace_linework
87 };
88
90 {
91 e_tile_tex_undefined
92 , e_tile_texture_wrap // A texture coordinate u|v is translated to u%1|v%1
93 , e_tile_texture_clamp//Texture coordinates outside [0...1] are clamped to the nearest valid value.
94 , e_tile_texture_decal // If the texture coordinates for a pixel are outside [0...1] the texture is not applied to that pixel
95 , 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
96 };
98 {
99 e_tex_coord_undefined
100 , e_use_mat_coordinates
101 , e_project_sphere
102 , e_project_cylinder
103 , e_project_box
104 , e_project_plane
105 };
106
108 {
109 e_two_sided
110 , e_shading_model
111 , e_opacity
112 , e_bump_scale
113 , e_shininess
114 , e_reflectivity
115 , e_wireframe
117 , e_pixel_thickness
118 , e_grid_line_spacing
119 , e_gridline_spacing_mode
120 , e_is_dynamic_texture
121 , e_model_space_material
122 , e_color_value_palette
123 , e_draw_by_property_channel
124
125 , e_extra_property_color_min
126 , e_extra_property_color_mid
127 , e_extra_property_color_max
128
129 , e_extra_property_value_min
130 , e_extra_property_value_mid
131 , e_extra_property_value_max
132
133 , e_override_parent_material
134 , e_override_camera_material
135
136 , e_tile_texture_mode
137 , e_texture_coord_mode
138 , e_use_normal_for_tex_coord
139 , e_ignore_depth
140 , e_write_to_depth
141 , e_depth_bias
142 , e_fade_render_distance
143 , e_max_render_distance
144 , e_ignore_color_channel_lighting
145 };
146 public:
147 Material() = default;
148 Material(uint04 index, DesignObjectBase* property_table);
149 Material(DesignObjectBase* property_table);
150 explicit Material(const DesignObject& obj);
151 bool hasActiveImage() const;
152 bool hasImageData() const;
153 TranslatedString displayName() const;
154 TranslatedString appearanceName() const;
155 bool hasOpacity() const;
156 void setupAsDefault();
157
158 bool isSupportedByShadingModel(UVType type) const;
159 void setShadingModel(ShadingModel model);
160 void setTextureCoordinateMode(const TextureCoordMode& mode);
161 TextureCoordMode getTextureCoordinateMode() const;
162 void setTileTextureMode(const Vector<3, TileTextureMode>& modes);
163 Vector<3, TileTextureMode> getTileTextureMode() const;
164 ShadingModel getShadingModel() const;
165 bool validate() const;
166
167 template<class t_type>
169 {
170 return m_base->material_table.get()[m_base->material_property_index[cast<uint04>(mat_index)]].get<t_type>(m_design_index);
171 }
172 template<class t_type>
173 void setMaterialProperty(MaterialProperties mat_index, const t_type& type)
174 {
175 m_base->material_table.get()[m_base->material_property_index[cast<uint04>(mat_index)]].set(m_design_index, type);
176 }
177 template<class t_type>
178 void updateMaterialProperty(MaterialProperties mat_index, const t_type& type, const void* lock_ptr = nullptr)
179 {
180 if (getMaterialProperty<t_type>(mat_index) != type)
181 {
182 WLock wLock(lock_ptr);
183 setMaterialProperty(mat_index, type);
184 updateModifiedTime();
185 }
186 }
187 void colorBy(const DesignParameterAccumulator& accumulator);
188 RGBColor convertValueToColor(fltp08 value) const;
189 void copyFrom(const Material& mesh);
190 void combineFrom(const Material& mesh);
191
192 PrimitiveProperty defaultRenderProperty() const;
193
194
195 template<class t_type>
196 void setUVImage(UVType uv_index, const t_type& type)
197 {
198 uint04 column = m_base->uv_image_file[cast<uint04>(uv_index)];
199 m_base->material_table.get()[column].set(m_design_index, type);
200 }
201 template<class t_type>
202 void setUVColor(const t_type& type)
203 {
204 for (uint04 i = 0; i < cast<uint04>(UVType::e_uv_size); i++)
205 setUVColor(cast<UVType>(i), type);
206 }
207 template<class t_type>
208 void setUVColor(UVType uv_index, const t_type& type)
209 {
210 uint04 column = m_base->uv_color[cast<uint04>(uv_index)];
211 m_base->material_table.get()[column].set(m_design_index, type);
212 }
213 template<class t_type>
214 void updateUVColor(const t_type& type, const void* lock_ptr = nullptr)
215 {
216 for (uint04 i = 0; i < cast<uint04>(UVType::e_uv_size); i++)
217 updateUVColor(cast<UVType>(i), type, lock_ptr);
218 }
219 template<class t_type>
220 void updateUVColor(UVType uv_index, const t_type& value, const void* lock_ptr = nullptr)
221 {
222 if (getUVColor(uv_index) != value)
223 {
224 WLock lock(lock_ptr);
225 uint04 column = m_base->uv_color[cast<uint04>(uv_index)];
226 m_base->material_table.get()[column].set(m_design_index, value);
227 updateModifiedTime();
228 }
229 }
230 template<class t_type>
231 void setUVIntensity(UVType uv_index, const t_type& type)
232 {
233 uint04 column = m_base->uv_intensity[cast<uint04>(uv_index)];
234 m_base->material_table.get()[column].set(m_design_index, type);
235 }
236 template<class t_type>
237 void setUVLayer(UVType uv_index, const t_type& type)
238 {
239 uint04 column = m_base->uv_layer[cast<uint04>(uv_index)];
240 m_base->material_table.get()[column].set(m_design_index, type);
241 }
242 void setUVMode(UVType uv_index, const UVMode& type);
243 String getUVImage(UVType uv_index) const;
244 RGBColor getUVColor(UVType uv_index) const;
245 fltp04 getUVIntensity(UVType uv_index) const;
246 uint04 getUVLayer(UVType uv_index) const;
247 UVMode getUVMode(UVType uv_index) const;
248 bool hasActiveUVImage(UVType index) const;
249 bool hasUVIntensity(UVType index) const;
250 void cleanupMaterial();
251 bool hasUVLayer(UVType index) const;
252 bool hasUVColor(UVType index) const;
253 bool hasPerVertexColoring(UVType type = UVType::e_KD) const;
254 bool hasModelDependentColor(UVType type) const;
255 bool hasModelDependentColor() const;
256 [[nodiscard]] RGBColor constantColor(Model model, RGBColor background_color = RGBColor(255, 255, 255), UVType type = UVType::e_KD) const;
257 Buffer<RGBColor> palette() const;
258 void setPalette(const Buffer<RGBColor>& palette);
259 void updateModifiedTime(const Time& time = Time::SystemTime());
260 };
261 template<>
262 struct ObjectInfo<Material, false, false>
263 {
264 static const uint01 Dimensions = 0;
265 static const bool Vector = false;
266 static const bool Buffer = false;
267 static const bool Primitive = DESIGN_PRIM;
268 static const bool Pointer = false;
269 static const bool Unsigned = false;
270 static const bool Float = false;
271 static const bool Integer = false;
272 static const bool Number = false;
273 static const bool Enum = false;
274 static const bool String = false;
275 static const bool Color = false;
276 static const bool Boolean = false;
278 };
279 template class NDEVR_DESIGN_API StringStream<Material::GridLineMode>;
280 template class NDEVR_DESIGN_API StringStream<Material::TextureCoordMode>;
281 template class NDEVR_DESIGN_API StringStream<Material::TileTextureMode>;
282 template class NDEVR_DESIGN_API StringStream<Material::UVMode>;
283 template class NDEVR_DESIGN_API StringStream<Material::ShadingModel>;
284 template class NDEVR_DESIGN_API StringStream<Material::MaterialProperties>;
285}
286namespace std//Define things to allow use within std libs
287{
288 template <>
289 struct hash<NDEVR::Material>
290 {
291 std::size_t operator()(const NDEVR::Material& d) const noexcept
292 {
293 NDEVR::UUID s = d.uuid();
294 std::size_t value = 0;
295 for (NDEVR::uint01 i = 0; i < 8; i++)
296 value = value * 256 + (s[i + 0U] ^ s[i + 8U]);
297 return value;
298 }
299 };
300};
301
302
303
#define NDEVR_DESIGN_API
Definition DLLInfo.h:77
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition Color.h:36
Definition DesignObjectBase.h:140
Definition DesignObject.h:66
Definition DesignParameterAccumulator.h:57
Definition Material.h:45
ShadingModel
Definition Material.h:48
TileTextureMode
Definition Material.h:90
t_type getMaterialProperty(MaterialProperties mat_index) const
Definition Material.h:168
void setMaterialProperty(MaterialProperties mat_index, const t_type &type)
Definition Material.h:173
GridLineMode
Definition Material.h:83
void setUVLayer(UVType uv_index, const t_type &type)
Definition Material.h:237
MaterialProperties
Definition Material.h:108
void updateMaterialProperty(MaterialProperties mat_index, const t_type &type, const void *lock_ptr=nullptr)
Definition Material.h:178
void setUVColor(const t_type &type)
Definition Material.h:202
void updateUVColor(const t_type &type, const void *lock_ptr=nullptr)
Definition Material.h:214
TextureCoordMode
Definition Material.h:98
UVMode
Definition Material.h:68
void setUVColor(UVType uv_index, const t_type &type)
Definition Material.h:208
void setUVImage(UVType uv_index, const t_type &type)
Definition Material.h:196
void updateUVColor(UVType uv_index, const t_type &value, const void *lock_ptr=nullptr)
Definition Material.h:220
void setUVIntensity(UVType uv_index, const t_type &type)
Definition Material.h:231
Material()=default
Definition Model.h:54
Definition Pointer.hpp:62
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:53
Definition String.h:40
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Definition TranslatedString.h:9
Definition UUID.h:66
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
Definition RWLock.h:99
Definition ACIColor.h:37
@ e_background_contrast
Definition CADEntities.h:46
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.
Definition BaseValues.hpp:157
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
UVType
Definition DesignObjectBase.h:127
Definition File.h:213
static constexpr ObjectInfo< Material, false, false > VectorSub()
Definition Material.h:277
Information about the object.
Definition ObjectInfo.h:56
std::size_t operator()(const NDEVR::Material &d) const noexcept
Definition Material.h:291