-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathinstancer.h
executable file
·75 lines (61 loc) · 2.31 KB
/
instancer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2019 Autodesk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/// @file instancer.h
///
/// Utilities to support point instancers.
#pragma once
#include "api.h"
#include <ai_matrix.h>
#include <pxr/pxr.h>
#include <pxr/base/gf/vec3f.h>
#include <pxr/base/vt/array.h>
#include <pxr/imaging/hd/instancer.h>
#include <mutex>
#include <unordered_map>
#include <vector>
#include "render_delegate.h"
PXR_NAMESPACE_OPEN_SCOPE
/// Utility class for the point instancer.
class HdArnoldInstancer : public HdInstancer {
public:
/// Creates an instance of HdArnoldInstancer.
///
/// @param renderDelegate Pointer to the render delegate creating the
/// instancer.
HDARNOLD_API
HdArnoldInstancer(
HdArnoldRenderDelegate* renderDelegate, HdSceneDelegate* sceneDelegate, const SdfPath& id,
const SdfPath& parentInstancerId = SdfPath());
/// Destructor for HdArnoldInstancer.
~HdArnoldInstancer() override = default;
/// Calculates the matrices for all instances for a given shape.
///
/// Values are cached and only updated when the primvars are dirtied.
///
/// @param prototypeId ID of the instanced shape.
/// @return All the matrices for the shape.
HDARNOLD_API
VtMatrix4dArray CalculateInstanceMatrices(const SdfPath& prototypeId);
using PrimvarMap = std::unordered_map<TfToken, VtValue, TfToken::HashFunctor>; ///< Type to store primvars.
protected:
/// Syncs the primvars for the instancer.
///
/// Safe to call on multiple threads.
HDARNOLD_API
void _SyncPrimvars();
HdArnoldRenderDelegate* _delegate; ///< The active render delegate.
std::mutex _mutex; ///< Mutex to safe-guard calls to _SyncPrimvars.
PrimvarMap _primvars; ///< Generic map to store all the primvars.
};
PXR_NAMESPACE_CLOSE_SCOPE