-
Notifications
You must be signed in to change notification settings - Fork 0
/
HoudiniEngine.h
246 lines (203 loc) · 6.03 KB
/
HoudiniEngine.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef HAPI_CPP_H
#define HAPI_CPP_H
#include <HAPI/HAPI.h>
#include <string>
#include <vector>
#include <map>
#include <max.h>
#include "resource.h"
#include "HoudiniEngine_id.h"
extern TCHAR *GetString(int id);
extern HINSTANCE hInstance;
namespace hapi
{
std::string getString( int string_handle );
//----------------------------------------------------------------------------
// Classes:
class Object;
class Parm;
class Asset
{
public:
Asset(int id);
Asset(const Asset &asset);
~Asset();
Asset &operator=(const Asset &asset);
const HAPI_AssetInfo &info() const;
const HAPI_NodeInfo &nodeInfo() const;
std::vector<Object> objects() const;
std::vector<Parm> parms() const;
std::map<std::string, Parm> parmMap() const;
bool isValid() const;
std::string name() const;
std::string label() const;
std::string filePath() const;
void destroyAsset() const;
void cook() const;
HAPI_TransformEuler getTransform(
HAPI_RSTOrder rst_order, HAPI_XYZOrder rot_order) const;
void getTransformAsMatrix(float result_matrix[16]) const;
std::string getInputName( int input, int input_type = HAPI_INPUT_GEOMETRY ) const;
int id;
private:
mutable HAPI_AssetInfo *_info;
mutable HAPI_NodeInfo *_nodeInfo;
};
class Geo;
class Object
{
public:
Object(int asset_id, int object_id);
Object(const Asset &asset, int id);
Object(const Object &object);
~Object();
Object &operator=(const Object &object);
const HAPI_ObjectInfo &info() const;
std::vector<Geo> geos() const;
std::string name() const;
std::string objectInstancePath() const;
Asset asset;
int id;
private:
mutable HAPI_ObjectInfo *_info;
};
class Part;
class Geo
{
public:
Geo(const Object &object, int id);
Geo(int asset_id, int object_id, int geo_id);
Geo(const Geo &geo);
~Geo();
Geo &operator=(const Geo &geo);
const HAPI_GeoInfo &info() const;
std::string name() const;
std::vector<Part> parts() const;
Object object;
int id;
private:
mutable HAPI_GeoInfo *_info;
};
class Part
{
public:
Part(const Geo &geo, int id);
Part(int asset_id, int object_id, int geo_id, int part_id);
Part(const Part &part);
~Part();
Part &operator=(const Part &part);
const HAPI_PartInfo &info() const;
std::string name() const;
int numAttribs(HAPI_AttributeOwner attrib_owner) const;
std::vector<std::string> attribNames(HAPI_AttributeOwner attrib_owner) const;
HAPI_AttributeInfo attribInfo(
HAPI_AttributeOwner attrib_owner, const char *attrib_name) const;
float *getNewFloatAttribData(
HAPI_AttributeInfo &attrib_info, const char *attrib_name,
int start=0, int length=-1) const;
Geo geo;
int id;
private:
mutable HAPI_PartInfo *_info;
};
class ParmChoice;
class Parm
{
public:
// This constructor is required only for std::map::operator[] for the case
// where a Parm object does not exist in the map.
Parm();
Parm(int node_id, const HAPI_ParmInfo &info,
HAPI_ParmChoiceInfo *all_choice_infos);
const HAPI_ParmInfo &info() const;
std::string name() const;
std::string label() const;
int getIntValue(int sub_index) const;
float getFloatValue(int sub_index) const;
std::string getStringValue(int sub_index) const;
void setIntValue(int sub_index, int value);
void setFloatValue(int sub_index, float value);
void setStringValue(int sub_index, const char *value);
void insertMultiparmInstance(int instance_position);
void removeMultiparmInstance(int instance_position);
int node_id;
std::vector<ParmChoice> choices;
private:
HAPI_ParmInfo _info;
};
class ParmChoice
{
public:
ParmChoice(HAPI_ParmChoiceInfo &info);
const HAPI_ParmChoiceInfo &info() const;
std::string label() const;
std::string value() const;
private:
HAPI_ParmChoiceInfo _info;
};
class Engine
{
public:
Engine();
~Engine();
public:
bool initializeFromIniFile();
bool initialize( const char * otl_search_path = 0,
const char * dso_search_path= 0,
const char * image_dso_search_path = 0,
const char * audio_dso_search_path = 0,
bool use_cooking_thread = true,
int cooking_thread_stack_size = -1,
int session_mode = 1,
const char * thrift_address = 0,
int thrift_port = 9090,
const char * thrift_pipe = 0
);
void cleanup();
bool isInitialize();
HAPI_Result getLastResult();
std::string getLastError();
int loadAssetLibrary( const char* otl_file );
int getAvailableAssetCount( int library_id );
std::string getAssetName( int library_id, int id );
int instantiateAsset( const char* name, bool cook_on_load = true );
bool destroyAsset( int asset_id );
void syncTimeline();
HAPI_Session* session();
static Engine* instance();
static Engine* create();
static void release();
private:
bool mInitialized;
HAPI_Result mResult;
std::map<std::string, int> mAssetLib;
HAPI_Session mSession;
};
//----------------------------------------------------------------------------
// Common error handling:
// Instances of this class are thrown whenever an underlying HAPI function
// call fails.
class Failure
{
public:
Failure(HAPI_Result result)
: result(result)
{}
// Retrieve details about the last non-successful HAPI function call.
// You would typically call this method after catching a Failure exception,
// but it can be called as a static method after calling a C HAPI function.
static std::string lastErrorMessage()
{
int buffer_length;
HAPI_GetStatusStringBufLength(Engine::instance()->session(),
HAPI_STATUS_CALL_RESULT, HAPI_STATUSVERBOSITY_ERRORS, &buffer_length);
char * buf = new char[buffer_length];
HAPI_GetStatusString(Engine::instance()->session(),
HAPI_STATUS_CALL_RESULT, buf, buffer_length);
std::string result(buf);
return result;
}
HAPI_Result result;
};
}
#endif // HAPI_CPP_H