9
9
#include " sg/scene/geometry/Geometry.h"
10
10
#include " sg/Util.h"
11
11
12
+ using namespace rkcommon ::utility;
13
+ using namespace rkcommon ::containers;
14
+
12
15
namespace ospray {
13
16
namespace sg {
14
17
@@ -35,7 +38,7 @@ namespace ospray {
35
38
36
39
static inline void parseParameterString (std::string typeAndValueString,
37
40
std::string ¶mType,
38
- rkcommon::utility:: Any ¶mValue)
41
+ Any ¶mValue)
39
42
{
40
43
std::stringstream typeAndValueStream (typeAndValueString);
41
44
std::string paramValueString;
@@ -192,6 +195,56 @@ namespace ospray {
192
195
return {};
193
196
}
194
197
198
+ void addTextureWrapModes (std::shared_ptr<Texture2D> ospTex,
199
+ std::string mapName,
200
+ std::map<std::string, std::string> unknown_parameter)
201
+ {
202
+ // Parse texture wrapMode
203
+ // Check whether this map has a wrapMode parameter add it to the
204
+ // texture node if it does.
205
+ // Need to find based on "param.first" and not paramName,
206
+ // paramName may have been modified to convert naming style
207
+ auto it = unknown_parameter.find (mapName + " .wrapMode" );
208
+ if (it != unknown_parameter.end ()) {
209
+ auto wrapModeStr = it->second ;
210
+
211
+ bool error = false ;
212
+
213
+ // Convert from wrapMode string to OSPTextureWrapMode enum
214
+ std::function<OSPTextureWrapMode (std::string)> convertWrapMode =
215
+ [&](std::string wrapMode) {
216
+ static std::map<std::string, OSPTextureWrapMode> WrapModesMap = {
217
+ {" repeat" , OSP_TEXTURE_WRAP_REPEAT}, // default
218
+ {" mirror" , OSP_TEXTURE_WRAP_MIRRORED_REPEAT},
219
+ {" clamp" , OSP_TEXTURE_WRAP_CLAMP_TO_EDGE}};
220
+ auto ospMode = OSP_TEXTURE_WRAP_REPEAT;
221
+ if (WrapModesMap.count (wrapMode))
222
+ ospMode = WrapModesMap[wrapMode];
223
+ else
224
+ error |= true ;
225
+ return ospMode;
226
+ };
227
+
228
+ auto modes = split (wrapModeStr, ' ' );
229
+ if (modes.size () >= 1 && modes.size () <= 2 ) {
230
+ auto s = convertWrapMode (modes[0 ]);
231
+ if (modes.size () == 1 ) {
232
+ // If only one param, set s and it affects both s and t
233
+ ospTex->createChild (" wrapMode" , " uint32_t" , uint32_t (s));
234
+ } else {
235
+ // else set both s and t params
236
+ auto t = convertWrapMode (modes[1 ]);
237
+ ospTex->createChild (" wrapMode" , " vec2ui" , vec2ui (s, t));
238
+ }
239
+ } else
240
+ error = true ;
241
+
242
+ if (error)
243
+ std::cerr << " #ospsg: obj parsing errors(s)... Uknown wrapMode "
244
+ << it->first << " " << wrapModeStr << std::endl;
245
+ }
246
+ }
247
+
195
248
static std::vector<NodePtr> createMaterials (const OBJData &objData,
196
249
FileName fileName)
197
250
{
@@ -263,8 +316,8 @@ namespace ospray {
263
316
preferLinear,
264
317
nearestFilter);
265
318
266
- // If texture is UDIM, set appropriate scale/translation
267
319
if (map_misc) {
320
+ // If texture is UDIM, set appropriate scale/translation
268
321
auto &ospTex = *map_misc->nodeAs <Texture2D>();
269
322
if (ospTex.hasUDIM ()) {
270
323
auto scale = ospTex.getUDIM_scale ();
@@ -275,11 +328,16 @@ namespace ospray {
275
328
paramNodes.push_back (createNode (
276
329
paramName + " .translation" , " vec2f" , translation));
277
330
}
331
+
332
+ // Need to find based on "param.first" and not paramName,
333
+ // paramName may have been modified to convert naming style
334
+ addTextureWrapModes (map_misc, param.first , m.unknown_parameter );
335
+
278
336
paramNodes.push_back (map_misc);
279
337
}
280
338
281
339
} else {
282
- rkcommon::utility:: Any paramValue;
340
+ Any paramValue;
283
341
parseParameterString (paramValueStr, paramType, paramValue);
284
342
// Principled::thin is the only non-float material parameter and
285
343
// needs to be converted to a "bool" paramType, imported as a float
@@ -291,6 +349,11 @@ namespace ospray {
291
349
paramType = " rgb" ;
292
350
}
293
351
352
+ // texture wrapMode is handled entirely above, with the texture
353
+ // creation.
354
+ if (paramName.find (" .wrapMode" ) != std::string::npos)
355
+ continue ;
356
+
294
357
try {
295
358
auto newParam = createNode (paramName, paramType, paramValue);
296
359
paramNodes.push_back (newParam);
@@ -322,36 +385,46 @@ namespace ospray {
322
385
if (!m.diffuse_texname .empty ()) {
323
386
// sRGB gamma encoded, texture format may override this preference
324
387
auto tex = createSGTex (" map_kd" , m.diffuse_texname , containingPath);
325
- if (tex)
388
+ if (tex) {
389
+ addTextureWrapModes (tex, " map_kd" , m.unknown_parameter );
326
390
mat.add (tex);
391
+ }
327
392
}
328
393
329
394
if (!m.specular_texname .empty ()) {
330
395
// sRGB gamma encoded, texture format may override this preference
331
396
auto tex = createSGTex (" map_ks" , m.specular_texname , containingPath);
332
- if (tex)
397
+ if (tex) {
398
+ addTextureWrapModes (tex, " map_ks" , m.unknown_parameter );
333
399
mat.add (tex);
400
+ }
334
401
}
335
402
336
403
if (!m.specular_highlight_texname .empty ()) {
337
404
auto tex = createSGTex (
338
405
" map_ns" , m.specular_highlight_texname , containingPath, true );
339
- if (tex)
406
+ if (tex) {
407
+ addTextureWrapModes (tex, " map_nd" , m.unknown_parameter );
340
408
mat.add (tex);
409
+ }
341
410
}
342
411
343
412
if (!m.bump_texname .empty ()) {
344
413
auto tex =
345
414
createSGTex (" map_bump" , m.bump_texname , containingPath, true );
346
- if (tex)
415
+ if (tex) {
416
+ addTextureWrapModes (tex, " map_bump" , m.unknown_parameter );
347
417
mat.add (tex);
418
+ }
348
419
}
349
420
350
421
if (!m.alpha_texname .empty ()) {
351
422
auto tex =
352
423
createSGTex (" map_d" , m.alpha_texname , containingPath, true );
353
- if (tex)
424
+ if (tex) {
425
+ addTextureWrapModes (tex, " map_d" , m.unknown_parameter );
354
426
mat.add (tex);
427
+ }
355
428
}
356
429
for (auto ¶m : paramNodes)
357
430
mat.add (param);
0 commit comments