opennurbs_mapchan.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_MAPPING_CHANNEL_INC_)
18 #define OPENNURBS_MAPPING_CHANNEL_INC_
19 
20 ///////////////////////////////////////////////////////////////////////////////
21 //
22 // Class ON_MappingChannel
23 //
24 // Description:
25 // ON_3dmObjectAttributes uses ON_MappingChannel to record
26 // which texture mapping function to use when applying a texture
27 // with a matching mapping channel id.
28 // When an object is rendered, if the material has textures and
29 // ON_Texture::m_mapping_channel_id = ON_MappingChannel::m_mapping_channel_id,
30 // then the mapping with id m_mapping_id is used to map the texture.
31 // Otherwise, the mesh m_T[] texture coordinates are used to
32 // apply the texture.
33 //
34 class ON_CLASS ON_MappingChannel
35 {
36 public:
38  void Default();
39  int Compare( const ON_MappingChannel& other ) const;
40  bool Write( ON_BinaryArchive& archive ) const;
41  bool Read( ON_BinaryArchive& archive );
42 
43  ON_UUID m_mapping_id; // Identifies an ON_TextureMapping
44 
45  // RUNTIME textrure mapping table index.
46  // If -1, it needs to be set. This value is not saved int files.
47  int m_mapping_index;
48 
49  // ON_Texture's with a matching m_mapping_channel_id value
50  // use the mapping identified by m_mapping_id. This id
51  // must be > 0 and <= 2147483647 (0x7FFFFFFF)
52  int m_mapping_channel_id;
53 
54  // The default value of m_object_xform is the identity.
55  // When an object that uses this mapping is transformed
56  // by "T", m_object_xform is updated using the formula
57  // m_object_xform = T*m_object_xform. If texture coordinates
58  // are lost and need to be recalculated and m_object_xform
59  // is not the identity, then m_object_xform should be passed
60  // to ON_TextureMapping::Evaluate() as the mesh_xform parameter.
61  // When validating mapping coordinates, m_object_xform itself
62  // be passed to HasMatchingTextureCoordinates() as the
63  // object_transform parameter.
64  ON_Xform m_object_xform;
65 };
66 
67 #if defined(ON_DLL_TEMPLATE)
68 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_MappingChannel>;
69 #endif
70 
71 ///////////////////////////////////////////////////////////////////////////////
72 //
73 // Class ON_MaterialRef
74 //
75 // Description:
76 // ON_3dmObjectAttributes uses ON_MaterialRef to record which
77 // rendering material and mappings a rendering plug-in wants to
78 // use. This allows different rendering plug-ins to have different
79 // materials on the same object. The values of
80 // ON_3dmObjectAttributes.m_material_index and
81 // ON_3dmObjectAttributes.m_matrial_source reflect the settings
82 // of the renderer that is currently active.
83 //
84 
85 class ON_CLASS ON_MappingRef
86 {
87 public:
88  ON_MappingRef();
89  void Default();
90  int Compare( const ON_MappingRef& other ) const;
91  bool Write( ON_BinaryArchive& archive ) const;
92  bool Read( ON_BinaryArchive& archive );
93 
94  bool IsValid( ON_TextLog* text_log ) const;
95 
96 
97  bool Transform( const ON_Xform& xform );
98 
99  ON_UUID m_plugin_id; // Identifies a rendering plugin
100 
101  /*
102  Parameters:
103  mapping_channel_id - [in]
104  mapping_id - [in]
105  ON_TextureMapping id
106  Returns:
107  A pointer to the plug-in's mapping channel, if there
108  is one. Otherwise nullptr is returned.
109  */
110  const ON_MappingChannel* MappingChannel(
111  int mapping_channel_id
112  ) const;
113 
114  const ON_MappingChannel* MappingChannel(
115  const ON_UUID& mapping_id
116  ) const;
117 
118 
119  /*
120  Parameters:
121  mapping_channel_id - [in]
122  mapping_id - [in]
123  ON_TextureMapping id
124  Returns:
125  True if the mapping channel was added or a pefect
126  match already existed. False if a mapping channel
127  with a different mapping_id already exists for this
128  plug-in and channel.
129  */
130  bool AddMappingChannel(
131  int mapping_channel_id,
132  const ON_UUID& mapping_id
133  );
134 
135  /*
136  Parameters:
137  mapping_channel_id - [in]
138  mapping_id - [in]
139  ON_TextureMapping id
140  Returns:
141  True if a matching mapping channel was deleted.
142  */
143  bool DeleteMappingChannel(
144  int mapping_channel_id
145  );
146 
147  bool DeleteMappingChannel(
148  const ON_UUID& mapping_id
149  );
150 
151  /*
152  Parameters:
153  old_mapping_channel_id - [in]
154  new_mapping_channel_id - [in]
155  Returns:
156  True if a matching mapping channel was found and changed.
157  */
158  bool ChangeMappingChannel(
159  int old_mapping_channel_id,
160  int new_mapping_channel_id
161  );
162 
163  // Use AddMappingChannel() if you want to add an
164  // element to this array.
165  //
166  // Every mapping channel in this array must have
167  // a distinct value of ON_MappingChannel.m_mapping_channel_id
168  ON_SimpleArray<ON_MappingChannel> m_mapping_channels;
169 };
170 
171 class ON_CLASS ON_MaterialRef
172 {
173 public:
174  // If m_material_id = ON_MaterialRef::material_from_layer,
175  // then the object's layer determine the material.
176  // See ON::material_from_layer.
177  //static const ON_UUID material_from_layer; // TOD0 - remove this
178 
179  // If m_material_id = ON_MaterialRef::material_from_layer,
180  // then the object's parent determine the material.
181  // See ON::material_from_parent.
182  //static const ON_UUID material_from_parent; // TODO - remove this
183 
184  ON_MaterialRef();
185  void Default();
186  int Compare( const ON_MaterialRef& other ) const;
187  bool Write( ON_BinaryArchive& archive ) const;
188  bool Read( ON_BinaryArchive& archive );
189 
190  ON_UUID m_plugin_id; // Identifies a rendering plugin
192  ON_UUID m_material_id; // Identifies an ON_Material
193 
194  // If nil, then m_material_id is used for front and back faces
195  ON_UUID m_material_backface_id; // Identifies an ON_Material
196 
197  ON::object_material_source MaterialSource() const;
198  void SetMaterialSource(
199  ON::object_material_source
200  );
201  unsigned char m_material_source; // ON::object_material_source values
202  unsigned char m_reserved1;
203  unsigned char m_reserved2;
204  unsigned char m_reserved3;
206  // RUNTIME material table index for m_material_id.
207  // This value is not saved in files. If -1, then it
208  // needs to be set.
209  int m_material_index;
211  // RUNTIME material table index for m_material_id.
212  // This value is not saved in files. If -1, then it
213  // needs to be set.
214  int m_material_backface_index;
215 };
216 
217 #if defined(ON_DLL_TEMPLATE)
218 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_MaterialRef>;
219 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_MappingRef>;
220 #endif
221 
222 #endif
223 
224 
ON_UUID is a 16 byte universally unique identifier.
Definition: opennurbs_uuid.h:32
Definition: opennurbs_mapchan.h:167
ON_3dmObjectAttributes uses ON_MappingChannel to record which texture mapping function to use when ap...
Definition: opennurbs_mapchan.h:36
Definition: opennurbs_xform.h:28
ON_3dmObjectAttributes uses ON_MaterialRef to record which rendering material and mappings a renderin...
Definition: opennurbs_mapchan.h:89
Definition: opennurbs_textlog.h:20
Definition: opennurbs_archive.h:1783