3ds Max USD API Reference
Loading...
Searching...
No Matches
ShaderWriterRegistry.h
1
#pragma once
2
//**************************************************************************/
3
// Copyright (c) 2022 Autodesk, Inc.
4
// All rights reserved.
5
//
6
// These coded instructions, statements, and computer programs contain
7
// unpublished proprietary information written by Autodesk, Inc., and are
8
// protected by Federal copyright law. They may not be disclosed to third
9
// parties or copied or duplicated in any form, in whole or in part, without
10
// the prior written consent of Autodesk, Inc.
11
//**************************************************************************/
12
13
#include "WriteJobContext.h"
14
#include "ShaderWriter.h"
15
#include "MaxUsd/Builders/USDSceneBuilderOptions.h"
16
17
#include <pxr/pxr.h>
18
#include <pxr/usd/sdf/path.h>
19
20
#include <maxtypes.h>
21
22
#include <functional>
23
24
PXR_NAMESPACE_OPEN_SCOPE
25
26
struct
MaxUsdShaderWriterRegistry
27
{
28
// Writer factory function, i.e. a function that creates a shader writer
29
// for the given 3ds Max node/USD paths and context.
30
using
WriterFactoryFn = std::function<MaxUsdShaderWriterSharedPtr(
31
Mtl*,
32
const
SdfPath&,
33
MaxUsdWriteJobContext
&)>;
34
35
// Predicate function, i.e. a function that can tell the level of support
36
// the writer function will provide for a given set of export options.
37
using
ContextPredicateFn = std::function<
MaxUsdShaderWriter::ContextSupport
(
const
USDSceneBuilderOptions
&)>;
38
39
// Register 'fn' as a factory function providing a
40
// MaxUsdShaderWriter subclass that can be used to write the material ClassID.
41
// If you can't provide a valid MaxUsdShaderWriter for the given arguments,
42
// return a null pointer from the factory function 'fn'.
43
MaxUSDAPI
static
void
Register(
44
const
TfToken& maxClassName,
45
ContextPredicateFn pred,
46
WriterFactoryFn fn,
47
bool
fromPython =
false
);
48
MaxUSDAPI
static
void
Register(
49
const
Class_ID& maxClassID,
50
ContextPredicateFn pred,
51
WriterFactoryFn fn,
52
bool
fromPython =
false
);
53
54
// Finds a writer if one exists for 3ds Max material ClassID using the context
55
// found in 'exportArgs'
56
// If there is no writer plugin for 3ds Max material ClassID, returns nullptr.
57
MaxUSDAPI
static
WriterFactoryFn Find(
58
const
Class_ID& maxTypeName,
59
const
USDSceneBuilderOptions
& exportArgs);
60
};
61
64
template
<
typename
T>
class
HasCanExport
65
{
66
typedef
char
_One;
67
struct
_Two
68
{
69
char
_x[2];
70
};
71
72
template
<
typename
C>
static
_One _Test(
decltype
(&C::CanExport));
73
template
<
typename
C>
static
_Two _Test(...);
74
75
public
:
76
enum
77
{
78
value =
sizeof
(_Test<T>(0)) ==
sizeof
(
char
)
79
};
80
};
81
82
#define PXR_MAXUSD_REGISTER_SHADER_WRITER(maxClassID, writerClass) \
83
TF_REGISTRY_FUNCTION_WITH_TAG(MaxUsdShaderWriterRegistry, writerClass) \
84
{ \
85
static_assert(std::is_base_of<MaxUsdShaderWriter, writerClass>::value, \
86
#writerClass " must derive from MaxUsdShaderWriter"
); \
87
static_assert( \
88
HasCanExport<writerClass>::value, \
89
#writerClass " must define a static CanExport() function"); \
90
MaxUsdShaderWriterRegistry::Register( \
91
maxClassID, \
92
&writerClass::CanExport, \
93
[](Mtl* material, \
94
const SdfPath& usd_path, \
95
MaxUsdWriteJobContext& job_ctx) \
96
{ \
97
return std::make_shared<writerClass>(material, usd_path, job_ctx); \
98
}); \
99
}
100
101
PXR_NAMESPACE_CLOSE_SCOPE
HasCanExport
Definition:
ShaderWriterRegistry.h:65
MaxUsdShaderWriter::ContextSupport
ContextSupport
Definition:
ShaderWriter.h:47
MaxUsdWriteJobContext
Provides basic functionality and access to shared data for prim and shader writers.
Definition:
WriteJobContext.h:19
USDSceneBuilderOptions
USD Scene Build configuration options.
Definition:
USDSceneBuilderOptions.h:49
MaxUsdShaderWriterRegistry
Definition:
ShaderWriterRegistry.h:27
maxusd
include
maxUsd
Translators
ShaderWriterRegistry.h
Generated by
1.9.5