Loading...
Searching...
No Matches
idMap.h
1//
2// Copyright 2026 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef EXT_RMANPKG_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_ID_MAP_H
8#define EXT_RMANPKG_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_ID_MAP_H
9
10#include "hdPrman/api.h"
11#include "pxr/pxr.h"
12#include <tbb/concurrent_unordered_map.h>
13#include <cstdint>
14#include "Riley.h"
15
16PXR_NAMESPACE_OPEN_SCOPE
17
31{
32public:
33 // The u64 global ID for a geometry instance.
34 // This is expected to be a stable ID that will be consistently
35 // assigned based on scene path, and which does not depend
36 // on the presence or absence of unrelated geometry.
37 // In RenderMan, this is split as two u32 attributes:
38 // identifier:id and identifier:id2.
39 using Key = uint64_t;
40
41 // Details associated with each Key.
42 struct IdDetails {
43 std::string name; // Riley k_identifier_name value
44 int primId = -1; // HdRenderIndex primId
45 int instanceId = -1; // HdRenderIndex instanceId
46 };
47
48 // Split a Key into id and id2.
49 inline static void SplitKey(Key key, int *id, int *id2) {
50 *id = (key & 0xFFFFFFFF);
51 *id2 = (key >> 32);
52 }
53
54 // Join id and id2 values into a Key.
55 inline static Key KeyFromAttrs(int id, int id2) {
56 return (uint64_t(unsigned(id2)) << 32) | uint64_t(unsigned(id));
57 }
58
59 // Assign identifier:id and identifier:id2 attribute values for
60 // the given geometry instance, and store the association.
61 // Sets *idAttr and *id2Attr.
62 void RegisterId(
63 IdDetails const& details,
64 RtParamList *paramList);
65
66 // Look up the details for the given ID.
67 bool GetDetails(Key key, IdDetails *details) const;
68
69 // Clear ID map.
70 void Clear();
71
72 // Write the path to id mapping to a file with the provided name.
73 void WriteIdMap(const std::string& filename);
74
75private:
76 using _IdMap = tbb::concurrent_unordered_map<Key, IdDetails>;
77 _IdMap _idMap;
78};
79
80PXR_NAMESPACE_CLOSE_SCOPE
81
82#endif
HdPrman_IdMap associates RenderMan id and id2 instance attribute values with corresponding Hydra scen...
Definition idMap.h:31