SpiecsEngine
 
Loading...
Searching...
No Matches
HoudiniTestSource.h
Go to the documentation of this file.
1#pragma once
2
3#include "../HoudiniCore.h"
4#include <iostream>
5#include <sstream>
6
7namespace HoudiniEngine {
8
9 static std::string GetString(HAPI_Session& session, HAPI_StringHandle stringHandle)
10 {
11 if (stringHandle == 0)
12 {
13 return "";
14 }
15
16 int bufferLength;
17 HAPI_GetStringBufLength(&session, stringHandle, &bufferLength);
18
19 char* buffer = new char[bufferLength];
20 HAPI_GetString(&session, stringHandle, buffer, bufferLength);
21
22 std::string result(buffer);
23 delete[] buffer;
24
25 return result;
26 }
27
28 static void PrintChildNodeInfo(HAPI_Session& session, std::vector<HAPI_NodeId>& childrenNodes)
29 {
30 std::cout << "Child Node Ids" << std::endl;
31 for (int i = 0; i < childrenNodes.size(); ++i)
32 {
33 HAPI_NodeInfo nInfo;
34 HE_CHECK(HAPI_GetNodeInfo(&session, childrenNodes[i], &nInfo))
35
36 std::cout << " " << childrenNodes[i] << " - " << (nInfo.createdPostAssetLoad ? "NEW" : "EXISTING") << std::endl;
37 }
38 }
39
40 static void ProcessFloatAttrib(HAPI_Session& session, HAPI_AssetInfo& assetInfo, HAPI_NodeId objectNode, HAPI_NodeId geoNode, HAPI_PartId partId, HAPI_AttributeOwner owner, std::string name)
41 {
42 HAPI_AttributeInfo attribInfo;
43 HE_CHECK(HAPI_GetAttributeInfo(&session, geoNode, partId, name.c_str(), owner, &attribInfo))
44
45 std::vector<float> attribData(attribInfo.count * attribInfo.tupleSize);
46 HE_CHECK(HAPI_GetAttributeFloatData(&session, geoNode, partId, name.c_str(), &attribInfo, -1, attribData.data(), 0, attribInfo.count))
47
48 for (int elemIndex = 0; elemIndex < attribInfo.count; ++elemIndex)
49 {
50 for (int tupleIndex = 0; tupleIndex < attribInfo.count; ++tupleIndex)
51 {
52 std::cout << attribData[elemIndex * attribInfo.tupleSize + tupleIndex] << " ";
53 }
54 std::cout << std::endl;
55 }
56 }
57
58 static void ProcessGeoPart(HAPI_Session& session, HAPI_AssetInfo& assetInfo, HAPI_NodeId objectNode, HAPI_NodeId geoNode, HAPI_PartId partId)
59 {
60 std::cout << "Object" << objectNode << ", Geo" << geoNode << ", Part" << partId << std::endl;
61
62 HAPI_PartInfo partInfo;
63 HE_CHECK(HAPI_GetPartInfo(&session, geoNode, partId, &partInfo))
64
65 std::vector<HAPI_StringHandle> attributeNameSh(partInfo.attributeCounts[HAPI_ATTROWNER_POINT]);
66 HE_CHECK(HAPI_GetAttributeNames(&session, geoNode, partInfo.id, HAPI_ATTROWNER_POINT, attributeNameSh.data(), partInfo.attributeCounts[HAPI_ATTROWNER_POINT]))
67
68 for (int attribIndex = 0; attribIndex < partInfo.attributeCounts[HAPI_ATTROWNER_POINT]; ++attribIndex)
69 {
70 std::string attribName = GetString(session, attributeNameSh[attribIndex]);
71 std::cout << " " << attribName << std::endl;
72 }
73
74 std::cout << "Point Positions: " << std::endl;
75
76 ProcessFloatAttrib(session, assetInfo, objectNode, geoNode, partId, HAPI_ATTROWNER_POINT, "P");
77
78 std::cout << "Number of Faces: " << partInfo.faceCount << std::endl;
79
80 if (partInfo.type != HAPI_PARTTYPE_CURVE)
81 {
82 std::vector<int> faceCounts(partInfo.faceCount);
83
84 HE_CHECK(HAPI_GetFaceCounts(&session, geoNode, partId, faceCounts.data(), 0, partInfo.faceCount))
85
86 for (int ii = 0; ii < partInfo.faceCount; ++ii)
87 {
88 std::cout << faceCounts[ii] << ", ";
89 }
90
91 std::cout << std::endl;
92
93 std::vector<int> vertexList(partInfo.vertexCount);
94 HE_CHECK(HAPI_GetVertexList(&session, geoNode, partId, vertexList.data(), 0, partInfo.vertexCount))
95
96 std::cout << "Vertex Indices into Points array: " << std::endl;
97 int currIndex = 0;
98 for (int ii = 0; ii < partInfo.faceCount; ii++)
99 {
100 for (int jj = 0; jj < faceCounts[ii]; jj++)
101 {
102 std::cout << "Vertex: " << currIndex << ", belonging to face: "
103 << ii << ", index: "
104 << vertexList[currIndex] << "of points array\n";
105 currIndex++;
106 }
107 }
108 }
109 }
110
111 static void PrintPartInfo(HAPI_Session& session, HAPI_NodeId nodeId, HAPI_PartId partId, std::string indent)
112 {
113 HAPI_PartInfo partInfo;
114 HE_CHECK(HAPI_GetPartInfo(&session, nodeId, partId, &partInfo))
115
116 if (partInfo.type == HAPI_PARTTYPE_MESH)
117 {
118 std::cout << indent << "Part " << partId << ":" << std::endl;
119 std::cout << indent << " Type = Mesh" << std::endl;
120 std::cout << indent << " Point Count = " << partInfo.pointCount << std::endl;
121 }
122 else if(partInfo.type == HAPI_PARTTYPE_CURVE)
123 {
124 std::cout << indent << "Part " << partId << ":" << std::endl;
125 std::cout << indent << " Type = Curve" << std::endl;
126 std::cout << indent << " Point Count = " << partInfo.pointCount << std::endl;
127 }
128 else if (partInfo.type == HAPI_PARTTYPE_INSTANCER)
129 {
130 std::cout << indent << "Part " << partId << ":" << std::endl;
131 std::cout << indent << " Type = Instancer" << std::endl;
132 std::cout << indent << " Point Count = " << partInfo.pointCount << std::endl;
133 std::cout << indent << " Instance Count = " << partInfo.instanceCount << std::endl;
134 std::cout << indent << " Instanced Part Count = " << partInfo.instancedPartCount << std::endl;
135
136 std::vector<HAPI_Transform> instanceTransforms(partInfo.instanceCount);
137 HE_CHECK(HAPI_GetInstancerPartTransforms(&session, nodeId, partId, HAPI_RSTORDER_DEFAULT, instanceTransforms.data(), 0, partInfo.instanceCount))
138
139 std::cout << indent << " Instance Transforms: " << std::endl;
140
141 for (auto instanceTransform : instanceTransforms)
142 {
143 float* p = &instanceTransform.position[0];
144 std::cout << indent << " " << p[0] << "." << p[1] << "." << p[2] << std::endl;
145 }
146
147 std::vector<HAPI_PartId> instancedPartIds(partInfo.instancedPartCount);
148 HE_CHECK(HAPI_GetInstancedPartIds(&session, nodeId, partId, instancedPartIds.data(), 0, partInfo.instancedPartCount))
149
150 std::cout << indent << " Instanced Parts: " << std::endl;
151
152 for (auto instancedPartId : instancedPartIds)
153 {
154 PrintPartInfo(session, nodeId, instancedPartId, " ->");
155 }
156 }
157 }
158
159 static void CookAndPrintNode(HAPI_Session& session, HAPI_CookOptions& co, HAPI_NodeId nodeId, HAPI_PackedPrimInstancingMode mode)
160 {
161 switch (mode)
162 {
163 case HAPI_PACKEDPRIM_INSTANCING_MODE_DISABLED:
164 std::cout << "Using: HAPI_PACKEDPRIM_INSTANCING_MODE_DISABLED" << std::endl;
165 break;
166 case HAPI_PACKEDPRIM_INSTANCING_MODE_HIERARCHY:
167 std::cout << "Using: HAPI_PACKEDPRIM_INSTANCING_MODE_HIERARCHY" << std::endl;
168 break;
169 case HAPI_PACKEDPRIM_INSTANCING_MODE_FLAT:
170 std::cout << "Using: HAPI_PACKEDPRIM_INSTANCING_MODE_FLAT" << std::endl;
171 break;
172 }
173
174 co.packedPrimInstancingMode = mode;
175
176 HE_CHECK(HAPI_CookNode(&session, nodeId, &co))
177
178 int cookStatus;
179 HAPI_Result cookResult;
180
181 do
182 {
183 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
184 }
185 while(cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
186
187 HE_CHECK(cookResult)
188 HE_CHECK_COOK(cookStatus)
189
190 HAPI_NodeInfo nodeInfo;
191 HE_CHECK(HAPI_GetNodeInfo(&session, nodeId, &nodeInfo))
192
193 int childCount;
194 HE_CHECK(HAPI_ComposeChildNodeList(&session, nodeId, HAPI_NODETYPE_SOP, HAPI_NODEFLAGS_ANY, false, &childCount))
195
196 std::vector<HAPI_NodeId> childIds(childCount);
197 HE_CHECK(HAPI_GetComposedChildNodeList(&session, nodeId, childIds.data(), childCount))
198
199 for (int i = 0; i < childCount; ++i)
200 {
201 HAPI_GeoInfo geoInfo;
202 HE_CHECK(HAPI_GetGeoInfo(&session, childIds[i], &geoInfo))
203 std::cout << "Part count for geo node " << i << ": " << geoInfo.partCount << std::endl;
204
205 for (int j = 0; j < geoInfo.partCount; ++j)
206 {
207 PrintPartInfo(session, childIds[i], j, "");
208 }
209 }
210 }
211
212 static void PrintCompleteNodeInfo(HAPI_Session& session, HAPI_NodeId nodeId, HAPI_AssetInfo& assetInfo)
213 {
214 HAPI_NodeInfo nodeInfo;
215 HE_CHECK(HAPI_GetNodeInfo(&session, nodeId, &nodeInfo))
216
217 int objectCount = 0;
218 HAPI_ObjectInfo* objectInfos = 0;
219
220 if (nodeInfo.type == HAPI_NODETYPE_SOP)
221 {
222 // For pure SOP asset, a parent object will be created automatically,
223 // so use parent's ID to get the object info
224 objectCount = 1;
225 objectInfos = new HAPI_ObjectInfo[objectCount];
226 HE_CHECK(HAPI_GetObjectInfo(&session, nodeInfo.parentId, &objectInfos[0]))
227 }
228 else if (nodeInfo.type == HAPI_NODETYPE_OBJ)
229 {
230 // This could have children objects or not.
231 // If has children, get child object infos.
232 // If no children, presume this node is the only object.
233
234 HE_CHECK(HAPI_ComposeObjectList(&session, nodeId, nullptr, &objectCount))
235
236 if (objectCount > 0)
237 {
238 objectInfos = new HAPI_ObjectInfo[objectCount];
239 HE_CHECK(HAPI_GetComposedObjectList(&session, nodeInfo.parentId, objectInfos, 0, objectCount))
240 }
241 else
242 {
243 objectCount = 1;
244 objectInfos = new HAPI_ObjectInfo[objectCount];
245 HE_CHECK(HAPI_GetObjectInfo(&session, nodeId, &objectInfos[0]))
246 }
247 }
248 else
249 {
250 std::cout << "Unsupported node type: " << HAPI_NODETYPE_OBJ << std::endl;
251 return;
252 }
253
254 for (int objectIndex = 0; objectIndex < objectCount; ++objectIndex)
255 {
256 HAPI_ObjectInfo& objectInfo = objectInfos[objectIndex];
257 HAPI_GeoInfo geoInfo;
258 HE_CHECK(HAPI_GetDisplayGeoInfo(&session, objectInfo.nodeId, &geoInfo))
259
260 for (int partIndex = 0; partIndex < geoInfo.partCount; ++partIndex)
261 {
262 ProcessGeoPart(session, assetInfo, objectInfo.nodeId, geoInfo.nodeId, partIndex);
263 }
264 }
265
266 delete[] objectInfos;
267 }
268
270 {
271 // Create Session
272 HAPI_Session session;
273
274 HAPI_ThriftServerOptions serverOptions{ 0 };
275 serverOptions.autoClose = true;
276 serverOptions.timeoutMs = 3000.0f;
277
278 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
279
280 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
281
282 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
283
284 // Initialize Session
285 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
286 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
287
288 // create null node
289 HAPI_NodeId newNode;
290 HE_CHECK(HAPI_CreateInputNode(&session, -1, &newNode, "Marshalling_Point_Clouds"))
291 // cook null node
292 HE_CHECK(HAPI_CookNode(&session, newNode, &cookOptions))
293
294 // Wait for cook over.
295 int cookStatus;
296 HAPI_Result cookResult;
297
298 do
299 {
300 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
301 }
302 while (cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
303 HE_CHECK(cookResult)
304 HE_CHECK_COOK(cookStatus)
305
306 // null node part info
307 HAPI_PartInfo newNodePart = HAPI_PartInfo_Create();
308 newNodePart.type = HAPI_PARTTYPE_MESH;
309 newNodePart.faceCount = 1;
310 newNodePart.vertexCount = 3;
311 newNodePart.pointCount = 3;
312 HE_CHECK(HAPI_SetPartInfo(&session, newNode, 0, &newNodePart))
313
314 // null node attribute info
315 HAPI_AttributeInfo newNodePointInfo = HAPI_AttributeInfo_Create();
316 newNodePointInfo.count = 3;
317 newNodePointInfo.tupleSize = 3;
318 newNodePointInfo.exists = true;
319 newNodePointInfo.storage = HAPI_STORAGETYPE_FLOAT;
320 newNodePointInfo.owner = HAPI_ATTROWNER_POINT;
321 HE_CHECK(HAPI_AddAttribute(&session, newNode, 0, "P", &newNodePointInfo))
322
323 // set null node attribute
324 float positions[9] = { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f };
325 HE_CHECK(HAPI_SetAttributeFloatData(&session, newNode, 0, "P", &newNodePointInfo, positions, 0, 3))
326
327 // set null node vertices
328 int vertices[3] = { 0, 1, 2 };
329 HE_CHECK(HAPI_SetVertexList(&session, newNode, 0, vertices, 0, 3))
330
331 // set null node faces
332 int face_counts[1] = { 3 };
333 HE_CHECK(HAPI_SetFaceCounts(&session, newNode, 0, face_counts, 0, 1))
334
335 // set null node str attriute
336 std::array<char*, 3> strs;
337 strs[0] = _strdup("strPoint1");
338 strs[1] = _strdup("strPoint2");
339 strs[2] = _strdup("strPoint3");
340
341 newNodePointInfo.count = 3;
342 newNodePointInfo.tupleSize = 1;
343 newNodePointInfo.exists = true;
344 newNodePointInfo.storage = HAPI_STORAGETYPE_STRING;
345 newNodePointInfo.owner = HAPI_ATTROWNER_POINT;
346
347 HE_CHECK(HAPI_AddAttribute(&session, newNode, 0, "srcData", &newNodePointInfo))
348 HE_CHECK(HAPI_SetAttributeStringData(&session, newNode, 0, "srcData", &newNodePointInfo, (const char**)strs.data(), 0, 3))
349
350 // commit null node
351 HE_CHECK(HAPI_CommitGeo(&session, newNode));
352
353 // save to hip file
354 HE_CHECK(HAPI_SaveHIPFile(&session, "C:/Users/Administrator/Desktop/Marshalling_Point_Clouds.hip", false))
355
356 // clean up session, needs recall initialize
357 HE_CHECK(HAPI_Cleanup(&session))
358
359 return;
360 }
361
363 {
364 // Create Session
365 HAPI_Session session;
366
367 HAPI_ThriftServerOptions serverOptions{ 0 };
368 serverOptions.autoClose = true;
369 serverOptions.timeoutMs = 3000.0f;
370
371 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
372
373 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
374
375 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
376
377 // Initialize Session
378 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
379 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
380
381 // create null node
382 HAPI_NodeId newNode;
383 HE_CHECK(HAPI_CreateInputNode(&session, -1, &newNode, "Marshalling_Point_Clouds"))
384 // cook null node
385 HE_CHECK(HAPI_CookNode(&session, newNode, &cookOptions))
386
387 int cookStatus;
388 HAPI_Result cookResult;
389
390 do
391 {
392 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
393 }
394 while(cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
395
396 HE_CHECK(cookResult)
397 HE_CHECK_COOK(cookStatus)
398
399 // get null node geo info
400 HAPI_GeoInfo newNodeGeoInfo;
401 HE_CHECK(HAPI_GetDisplayGeoInfo(&session, newNode, &newNodeGeoInfo))
402
403 HAPI_NodeId sopNodeId = newNodeGeoInfo.nodeId;
404
405 HAPI_PartInfo newNodePart = HAPI_PartInfo_Create();
406 newNodePart.type = HAPI_PARTTYPE_MESH;
407 newNodePart.faceCount = 0;
408 newNodePart.vertexCount = 0;
409 newNodePart.pointCount = 8;
410 HE_CHECK(HAPI_SetPartInfo(&session, sopNodeId, 0, &newNodePart))
411
412 HAPI_AttributeInfo newNodePointInfo = HAPI_AttributeInfo_Create();
413 newNodePointInfo.count = 8;
414 newNodePointInfo.tupleSize = 3;
415 newNodePointInfo.exists = true;
416 newNodePointInfo.storage = HAPI_STORAGETYPE_FLOAT;
417 newNodePointInfo.owner = HAPI_ATTROWNER_POINT;
418 HE_CHECK(HAPI_AddAttribute(&session, sopNodeId, 0, "P", &newNodePointInfo))
419
420 float positions[24] = {
421 0.0f, 0.0f, 0.0f,
422 1.0f, 0.0f, 0.0f,
423 1.0f, 0.0f, 1.0f,
424 0.0f, 0.0f, 1.0f,
425 0.0f, 1.0f, 0.0f,
426 1.0f, 1.0f, 0.0f,
427 1.0f, 1.0f, 1.0f,
428 0.0f, 1.0f, 1.0f
429 };
430
431 HE_CHECK(HAPI_SetAttributeFloatData(&session, sopNodeId, 0, "P", &newNodePointInfo, positions, 0, 8))
432
433 HE_CHECK(HAPI_CommitGeo(&session, sopNodeId))
434
435 HE_CHECK(HAPI_SaveHIPFile(&session, "C:/Users/Administrator/Desktop/Marshalling_Point_Clouds.hip", false))
436
437 HE_CHECK(HAPI_Cleanup(&session))
438
439 return;
440 }
441
442 static void Connecting_Assets()
443 {
444 HAPI_Session session;
445
446 HAPI_ThriftServerOptions serverOptions{ 0 };
447 serverOptions.autoClose = true;
448 serverOptions.timeoutMs = 3000.0f;
449
450 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
451
452 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
453
454 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
455
456 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
457 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
458
459 HAPI_NodeId newNode;
460
461 HE_CHECK(HAPI_CreateInputNode(&session, -1, &newNode, "Connecting_Assets"))
462 HE_CHECK(HAPI_CookNode(&session, newNode, &cookOptions))
463
464 int cookStatus;
465 HAPI_Result cookResult;
466
467 do
468 {
469 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
470 }
471 while(cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
472
473 HE_CHECK(cookResult)
474 HE_CHECK_COOK(cookStatus)
475
476 HAPI_PartInfo newNodePart = HAPI_PartInfo_Create();
477
478 newNodePart.type = HAPI_PARTTYPE_MESH;
479 newNodePart.faceCount = 6;
480 newNodePart.vertexCount = 24;
481 newNodePart.pointCount = 8;
482
483 HE_CHECK(HAPI_SetPartInfo(&session, newNode, 0 , &newNodePart))
484
485 HAPI_AttributeInfo newNodePointInfo = HAPI_AttributeInfo_Create();
486 newNodePointInfo.count = 8;
487 newNodePointInfo.tupleSize = 3;
488 newNodePointInfo.exists = true;
489 newNodePointInfo.storage = HAPI_STORAGETYPE_FLOAT;
490 newNodePointInfo.owner = HAPI_ATTROWNER_POINT;
491
492 HE_CHECK(HAPI_AddAttribute(&session, newNode, 0, "P", &newNodePointInfo))
493
494 float positions[24] = {
495 0.0f, 0.0f, 0.0f,
496 0.0f, 0.0f, 1.0f,
497 0.0f, 1.0f, 0.0f,
498 0.0f, 1.0f, 1.0f,
499 1.0f, 0.0f, 0.0f,
500 1.0f, 0.0f, 1.0f,
501 1.0f, 1.0f, 0.0f,
502 1.0f, 1.0f, 1.0f
503 };
504
505 HE_CHECK(HAPI_SetAttributeFloatData(&session, newNode, 0, "P", &newNodePointInfo, positions, 0, 8))
506
507 int vertices[24] = {
508 0, 2, 6, 4,
509 2, 3, 7, 6,
510 2, 0, 1, 3,
511 1, 5, 7, 3,
512 5, 4, 6, 7,
513 0, 4, 5, 1
514 };
515
516 HE_CHECK(HAPI_SetVertexList(&session, newNode, 0, vertices, 0, 24))
517
518 int face_counts[6] = {4, 4, 4, 4, 4, 4};
519 HE_CHECK(HAPI_SetFaceCounts(&session, newNode, 0, face_counts, 0, 6))
520 HE_CHECK(HAPI_CommitGeo(&session, newNode))
521
522 HAPI_NodeId subdivideNode;
523 HE_CHECK(HAPI_CreateNode(&session, -1, "Sop/subdivide", "Cube Subdivider", true, &subdivideNode))
524 HE_CHECK(HAPI_ConnectNodeInput(&session, subdivideNode, 0, newNode, 0))
525 HE_CHECK(HAPI_SaveHIPFile(&session, "C:/Users/Administrator/Desktop/Connecting_Assets.hip", false))
526 HE_CHECK(HAPI_Cleanup(&session))
527
528 return;
529 }
530
531 static void Curve_Node()
532 {
533 HAPI_Session session;
534
535 HAPI_ThriftServerOptions serverOptions{ 0 };
536 serverOptions.autoClose = true;
537 serverOptions.timeoutMs = 3000.0f;
538
539 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
540
541 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
542
543 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
544
545 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
546 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
547
548 HAPI_NodeId curveNode;
549
550 HE_CHECK(HAPI_CreateNode(&session, -1, "sop/curve", "NURBS", false, &curveNode))
551 HE_CHECK(HAPI_CookNode(&session, curveNode, &cookOptions))
552
553 int cookStatus;
554 HAPI_Result cookResult;
555
556 do
557 {
558 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
559 }
560 while(cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
561
562 HE_CHECK(cookResult)
563 HE_CHECK_COOK(cookStatus)
564
565 HAPI_NodeInfo curveNodeInfo;
566 HE_CHECK(HAPI_GetNodeInfo(&session, curveNode, &curveNodeInfo))
567
568 std::vector<HAPI_ParmInfo> paramInfos;
569 paramInfos.resize(curveNodeInfo.parmCount);
570 HE_CHECK(HAPI_GetParameters(&session, curveNode, paramInfos.data(), 0, curveNodeInfo.parmCount))
571
572 int coordsParmIndex = -1;
573 int typeParmIndex = -1;
574 for (int i = 0; i < curveNodeInfo.parmCount; i++)
575 {
576 std::string parmName = GetString(session, paramInfos[i].nameSH);
577 if (parmName == "coords")
578 {
579 coordsParmIndex = i;
580 }
581 if (parmName == "type")
582 {
583 typeParmIndex = i;
584 }
585 }
586
587 if (coordsParmIndex == -1 || typeParmIndex == -1)
588 {
589 std::stringstream ss;
590 ss << "Could not find coords/type parameter on curve node";
591
592 SPICES_CORE_WARN(ss.str());
593 HE_CHECK(HAPI_Cleanup(&session))
594 return;
595 }
596
597 HAPI_ParmInfo parm;
598 HE_CHECK(HAPI_GetParameters(&session, curveNode, &parm, typeParmIndex, 1))
599
600 int typeValue = 1;
601 HE_CHECK(HAPI_SetParmIntValues(&session, curveNode, &typeValue, parm.intValuesIndex, 1))
602
603 HE_CHECK(HAPI_GetParameters(&session, curveNode, &parm, coordsParmIndex, 1))
604 HE_CHECK(HAPI_SetParmStringValue(&session, curveNode, "-4, 0, 4, -4, 0, -4, 4, 0, -4, 4, 0, 4", parm.id, 0))
605 HE_CHECK(HAPI_SaveHIPFile(&session, "C:/Users/Administrator/Desktop/Curve_Node.hip", true))
606
607 HE_CHECK(HAPI_Cleanup(&session))
608
609 return;
610 }
611
612 static void Curve_Marshalling()
613 {
614 HAPI_Session session;
615
616 HAPI_ThriftServerOptions serverOptions{ 0 };
617 serverOptions.autoClose = true;
618 serverOptions.timeoutMs = 3000.0f;
619
620 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
621
622 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
623
624 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
625
626 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
627 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
628
629 HAPI_NodeId newNode;
630 HE_CHECK(HAPI_CreateInputNode(&session, -1, &newNode, "Curve"))
631 HE_CHECK(HAPI_CookNode(&session, newNode, &cookOptions))
632
633 int cookStatus;
634 HAPI_Result cookResult;
635
636 do
637 {
638 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
639 }
640 while(cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
641
642 HE_CHECK(cookResult)
643 HE_CHECK_COOK(cookStatus)
644
645 HAPI_PartInfo newNodePart = HAPI_PartInfo_Create();
646 newNodePart.type = HAPI_PARTTYPE_CURVE;
647 newNodePart.faceCount = 1;
648 newNodePart.vertexCount = 4;
649 newNodePart.pointCount = 4;
650 HE_CHECK(HAPI_SetPartInfo(&session, newNode, 0, &newNodePart))
651
652 HAPI_CurveInfo curveInfo;
653 curveInfo.curveType = HAPI_CURVETYPE_NURBS;
654 curveInfo.curveCount = 1;
655 curveInfo.vertexCount = 4;
656 curveInfo.knotCount = 8;
657 curveInfo.isPeriodic = false;
658 curveInfo.order = 4;
659 curveInfo.hasKnots = true;
660 HE_CHECK(HAPI_SetCurveInfo(&session, newNode, 0, &curveInfo))
661
662 int curveCount = 4;
663 HE_CHECK(HAPI_SetCurveCounts(&session, newNode, newNodePart.id, &curveCount, 0, 1))
664
665 float curveKnots[8] = { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f };
666 HE_CHECK(HAPI_SetCurveKnots(&session, newNode, newNodePart.id, curveKnots, 0, 8))
667
668 HAPI_AttributeInfo attrInfo = HAPI_AttributeInfo_Create();
669 attrInfo.count = 4;
670 attrInfo.tupleSize = 3;
671 attrInfo.exists = true;
672 attrInfo.storage = HAPI_STORAGETYPE_FLOAT;
673 attrInfo.owner = HAPI_ATTROWNER_POINT;
674
675 HE_CHECK(HAPI_AddAttribute(&session, newNode, 0, "P", &attrInfo))
676
677 float positions[12] = { -4.0f, 0.0f, 4.0f, -4.0f, 0.0f, -4.0f, 4.0f, 0.0f, -4.0f, 4.0f, 0.0f, 4.0f };
678 HE_CHECK(HAPI_SetAttributeFloatData(&session, newNode, 0, "P", &attrInfo, positions, 0, 4))
679
680 HE_CHECK(HAPI_CommitGeo(&session, newNode))
681 HE_CHECK(HAPI_SaveHIPFile(&session, "C:/Users/Administrator/Desktop/Curve_Marshalling.hip", true))
682
683 HE_CHECK(HAPI_Cleanup(&session))
684
685 return;
686 }
687
688 static void Curve_Output()
689 {
690 const char* hdaFile = "examples/nurbs_curve.hda";
691 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
692
693 HAPI_Session session;
694 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
695 HE_CHECK(HAPI_CreateInProcessSession(&session, &sessionInfo))
696 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
697
698 HAPI_AssetLibraryId assetLibId;
699 HE_CHECK(HAPI_LoadAssetLibraryFromFile(&session, hdaFile, true, &assetLibId))
700
701 int assetCount;
702 HE_CHECK(HAPI_GetAvailableAssetCount(&session, assetLibId, &assetCount))
703
704 if(assetCount > 1)
705 {
706 std::cout << "Should only be loading 1 asset here" << std::endl;
707 HE_CHECK(HAPI_Cleanup(&session))
708 return;
709 }
710
711
712 }
713
714 static void Groups_Sample()
715 {
716 HAPI_Session session;
717
718 HAPI_ThriftServerOptions serverOptions{ 0 };
719 serverOptions.autoClose = true;
720 serverOptions.timeoutMs = 3000.0f;
721
722 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
723
724 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
725
726 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
727
728 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
729 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
730
731 HAPI_NodeId cubeNode;
732
733 HE_CHECK(HAPI_CreateInputNode(&session, -1, &cubeNode, "Cube"))
734 HE_CHECK(HAPI_CookNode(&session, cubeNode, &cookOptions))
735
736 int cookStatus;
737 HAPI_Result cookResult;
738
739 do
740 {
741 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
742 }
743 while(cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
744
745 HE_CHECK(cookResult)
746 HE_CHECK_COOK(cookStatus)
747
748 HAPI_PartInfo cubePart = HAPI_PartInfo_Create();
749
750 cubePart.type = HAPI_PARTTYPE_MESH;
751 cubePart.faceCount = 6;
752 cubePart.vertexCount = 24;
753 cubePart.pointCount = 8;
754
755 HE_CHECK(HAPI_SetPartInfo(&session, cubeNode, 0, &cubePart))
756
757 HAPI_AttributeInfo attrInfo = HAPI_AttributeInfo_Create();
758
759 attrInfo.count = 8;
760 attrInfo.tupleSize = 3;
761 attrInfo.exists = true;
762 attrInfo.storage = HAPI_STORAGETYPE_FLOAT;
763 attrInfo.owner = HAPI_ATTROWNER_POINT;
764
765 HE_CHECK(HAPI_AddAttribute(&session, cubeNode, 0, "P", &attrInfo))
766
767 float positions[24] = {
768 0.0f, 0.0f, 0.0f,
769 0.0f, 0.0f, 1.0f,
770 0.0f, 1.0f, 0.0f,
771 0.0f, 1.0f, 1.0f,
772 1.0f, 0.0f, 0.0f,
773 1.0f, 0.0f, 1.0f,
774 1.0f, 1.0f, 0.0f,
775 1.0f, 1.0f, 1.0f
776 };
777
778 HE_CHECK(HAPI_SetAttributeFloatData(&session, cubeNode, 0, "P", &attrInfo, positions, 0, 8))
779
780 int vertices[24] = {
781 0, 2, 6, 4,
782 2, 3, 7, 6,
783 2, 0, 1, 3,
784 1, 5, 7, 3,
785 5, 4, 6, 7,
786 0, 4, 5, 1
787 };
788
789 HE_CHECK(HAPI_SetVertexList(&session, cubeNode, 0, vertices, 0, 24))
790
791 int face_counts[6] = {4, 4, 4, 4, 4, 4};
792 HE_CHECK(HAPI_SetFaceCounts(&session, cubeNode, 0, face_counts, 0, 6))
793
794 HE_CHECK(HAPI_AddGroup(&session, cubeNode, cubePart.id, HAPI_GROUPTYPE_POINT, "pointGroup"))
795 int groupElementCount = HAPI_PartInfo_GetElementCountByGroupType(&cubePart, HAPI_GROUPTYPE_POINT);
796
797 int* pointMembership = new int[groupElementCount];
798 for (int ii = 0; ii < groupElementCount; ++ii)
799 {
800 if (ii % 2)
801 {
802 pointMembership[ii] = 1;
803 }
804 else
805 {
806 pointMembership[ii] = 0;
807 }
808 }
809 HE_CHECK(HAPI_SetGroupMembership(&session, cubeNode, cubePart.id, HAPI_GROUPTYPE_POINT, "pointGroup", pointMembership, 0, groupElementCount))
810 HE_CHECK(HAPI_CommitGeo(&session, cubeNode))
811
812 HAPI_NodeId xformNode;
813 HE_CHECK(HAPI_CreateNode(&session, -1, "Sop/xform", "PointGroupManipulator", false, &xformNode))
814 HE_CHECK(HAPI_ConnectNodeInput(&session, xformNode, 0, cubeNode, 0))
815
816 HAPI_NodeInfo xformInfo;
817 HE_CHECK(HAPI_GetNodeInfo(&session, xformNode, &xformInfo))
818
819 HAPI_ParmInfo* parmInfos = new HAPI_ParmInfo[xformInfo.parmCount];
820 HE_CHECK(HAPI_GetParameters(&session, xformNode, parmInfos, 0, xformInfo.parmCount))
821
822 int groupParmIndex = -1;
823 int tParmIndex = -1;
824
825 for (int ii = 0; ii < xformInfo.parmCount; ++ii)
826 {
827 std::string parmName = GetString(session, parmInfos[ii].nameSH);
828 if (parmName == "group")
829 {
830 groupParmIndex = ii;
831 }
832 if (parmName == "t")
833 {
834 tParmIndex = ii;
835 }
836 }
837
838 if (groupParmIndex < 0 || tParmIndex < 0)
839 {
840 std::stringstream ss;
841 ss << "Could not find coords/type parameter on curve node";
842
843 SPICES_CORE_WARN(ss.str());
844 HE_CHECK(HAPI_Cleanup(&session))
845 return;
846 }
847
848 float tParmValue[3] = { 0.0f, 1.0f, 0.0f };
849 HE_CHECK(HAPI_SetParmFloatValues(&session, xformNode, tParmValue, parmInfos[tParmIndex].floatValuesIndex, 3))
850 HE_CHECK(HAPI_SetParmStringValue(&session, xformNode, "pointGroup", groupParmIndex, 0))
851 HE_CHECK(HAPI_CookNode(&session, xformNode, &cookOptions))
852
853 int xformCookStatus;
854 HAPI_Result xformCookResult;
855
856 do
857 {
858 xformCookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_RESULT, &xformCookStatus);
859 }
860 while(xformCookStatus > HAPI_STATE_MAX_READY_STATE && xformCookResult == HAPI_RESULT_SUCCESS);
861
862 HE_CHECK(xformCookResult)
863 HE_CHECK_COOK(xformCookStatus)
864
865 HE_CHECK(HAPI_SaveHIPFile(&session, "C:/Users/Administrator/Desktop/Groups_Sample.hip", false))
866
867 HAPI_GeoInfo xformGeoInfo;
868 HE_CHECK(HAPI_GetGeoInfo(&session, xformNode, &xformGeoInfo))
869
870 int numGroups = HAPI_GeoInfo_GetGroupCountByType(&xformGeoInfo, HAPI_GROUPTYPE_POINT);
871
872 HAPI_PartInfo partInfo;
873 HE_CHECK(HAPI_GetPartInfo(&session, xformNode, 0, &partInfo))
874
875 int numElementsInGroup = HAPI_PartInfo_GetElementCountByGroupType(&partInfo, HAPI_GROUPTYPE_POINT);
876
877 int* memberShip = new int[numElementsInGroup];
878 HE_CHECK(HAPI_GetGroupMembership(&session, xformNode, partInfo.id, HAPI_GROUPTYPE_POINT, "pointGroup", nullptr, memberShip, 0, numElementsInGroup))
879
880 for(int ii = 0; ii < numElementsInGroup; ++ii)
881 {
882 if (memberShip[ii])
883 {
884 std::cout << "Point" << ii << "is in pointGroup" << std::endl;
885 }
886 }
887
888 delete[] pointMembership;
889 delete[] memberShip;
890 HE_CHECK(HAPI_Cleanup(&session))
891
892 return;
893 }
894
895 static void Materials_Sample()
896 {
897 const char* hdaFile = "";
898
899 HAPI_Session session;
900
901 HAPI_ThriftServerOptions serverOptions{ 0 };
902 serverOptions.autoClose = true;
903 serverOptions.timeoutMs = 3000.0f;
904
905 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
906
907 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
908 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
909
910 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
911 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
912
913 HAPI_AssetLibraryId assetLibId;
914 HE_CHECK(HAPI_LoadAssetLibraryFromFile(&session, hdaFile, true, &assetLibId));
915
916 int assetCount;
917 HE_CHECK(HAPI_GetAvailableAssetCount(&session, assetLibId, &assetCount))
918
919 if (assetCount > 1)
920 {
921 std::cout << "Should only be loading 1 asset here" << std::endl;
922 }
923
924 HAPI_StringHandle assetSh;
925 HE_CHECK(HAPI_GetAvailableAssets(&session, assetLibId, &assetSh, assetCount))
926
927 std::string assetName = GetString(session, assetSh);
928
929 HAPI_NodeId nodeId;
930 HE_CHECK(HAPI_CreateNode(&session, -1, assetName.c_str(), "BrandonTest", false, &nodeId))
931
932 HE_CHECK(HAPI_CookNode(&session, nodeId, &cookOptions))
933
934 int cookStatus;
935 HAPI_Result cookResult;
936
937 do
938 {
939 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
940 }
941 while (cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
942
943 HE_CHECK(cookResult);
944 HE_CHECK_COOK(cookStatus);
945
946 HAPI_GeoInfo geoInfo;
947 HE_CHECK(HAPI_GetDisplayGeoInfo(&session, nodeId, &geoInfo))
948
949 HAPI_PartInfo partInfo;
950 HE_CHECK(HAPI_GetPartInfo(&session, geoInfo.nodeId, 0, &partInfo))
951
952 bool areAllTheSame = false;
953 std::vector<HAPI_NodeId> materialIds(partInfo.faceCount);
954 HE_CHECK(HAPI_GetMaterialNodeIdsOnFaces(&session, geoInfo.nodeId, partInfo.id, &areAllTheSame, &materialIds.front(), 0, partInfo.faceCount))
955
956 if(!areAllTheSame)
957 {
958 std::cout << "All materials should be the same." << std::endl;
959 }
960
961 for (int i = 0; i < partInfo.faceCount; ++i)
962 {
963 if (materialIds[i] != materialIds[0])
964 {
965 std::cout << "All material ids should be the same." << std::endl;
966 }
967 }
968
969 HAPI_MaterialInfo materialInfo;
970 HE_CHECK(HAPI_GetMaterialInfo(&session, materialIds[0], &materialInfo))
971
972 if (materialInfo.nodeId != materialIds[0] ||
973 materialInfo.nodeId < 0 ||
974 materialInfo.exists != true ||
975 materialInfo.hasChanged != true)
976 {
977 std::cout << "Did not successfully extract the first material" << std::endl;
978 }
979
980 HAPI_NodeInfo materialNodeInfo;
981 HE_CHECK(HAPI_GetNodeInfo(&session, materialInfo.nodeId, &materialNodeInfo))
982
983 std::cout << GetString(session, materialNodeInfo.nameSH) << std::endl;
984
985 std::vector<HAPI_ParmInfo> parmInfos(materialNodeInfo.parmCount);
986 HE_CHECK(HAPI_GetParameters(&session, materialNodeInfo.id, parmInfos.data(), 0, materialNodeInfo.parmCount))
987
988 int baseColorMapIndex = -1;
989 for (int i = 0; i < materialNodeInfo.parmCount; ++i)
990 {
991 if (GetString(session, parmInfos[i].nameSH) == "baseColorMap")
992 {
993 baseColorMapIndex = i;
994 break;
995 }
996 }
997
998 if (baseColorMapIndex < 0)
999 {
1000 std::cout << "Could not find the base color map parameter" << std::endl;
1001 }
1002
1003 HAPI_StringHandle basePath;
1004 HE_CHECK(HAPI_GetParmStringValue(&session, materialNodeInfo.id, "baseColorMap", 0, true, &basePath))
1005
1006 std::cout << "Base Color Map Path: " << GetString(session, basePath) << std::endl;
1007
1008 HE_CHECK(HAPI_RenderTextureToImage(&session, materialNodeInfo.id, baseColorMapIndex))
1009
1010 HAPI_ImageInfo imgInfo;
1011 HE_CHECK(HAPI_GetImageInfo(&session, materialNodeInfo.id, &imgInfo))
1012
1013 std::cout << "Image Width = " << imgInfo.xRes << std::endl
1014 << "Image Height = " << imgInfo.yRes << std::endl
1015 << "Image Format = " << GetString(session, imgInfo.imageFileFormatNameSH) << std::endl;
1016
1017 HE_CHECK(HAPI_SetImageInfo(&session, materialNodeInfo.id, &imgInfo))
1018
1019 int imagePlaneCount;
1020 HE_CHECK(HAPI_GetImagePlaneCount(&session, materialNodeInfo.id, &imagePlaneCount))
1021
1022 std::vector<HAPI_StringHandle> imagePlanes(imagePlaneCount);
1023 HE_CHECK(HAPI_GetImagePlanes(&session, materialNodeInfo.id, imagePlanes.data(), imagePlaneCount))
1024
1025 for (int j = 0; j < imagePlaneCount; ++j)
1026 {
1027 std::string imagePlaneName = GetString(session, imagePlanes[j]);
1028 std::cout << "Image Plane [ " << j << " ] = " << imagePlaneName << std::endl;
1029
1030 int destinationFilePath;
1031 HE_CHECK(HAPI_ExtractImageToFile(&session, materialNodeInfo.id, nullptr, imagePlaneName.c_str(), "./examples/", nullptr, &destinationFilePath))
1032 }
1033
1034 HE_CHECK(HAPI_Cleanup(&session));
1035 }
1036
1038 {
1039 const char* hdaFile = "";
1040
1041 HAPI_Session session;
1042
1043 HAPI_ThriftServerOptions serverOptions{ 0 };
1044 serverOptions.autoClose = true;
1045 serverOptions.timeoutMs = 3000.0f;
1046
1047 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
1048
1049 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
1050 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
1051
1052 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
1053 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
1054
1055 HAPI_AssetLibraryId assetLibId;
1056 HE_CHECK(HAPI_LoadAssetLibraryFromFile(&session, hdaFile, true, &assetLibId))
1057
1058 int assetCount;
1059 HE_CHECK(HAPI_GetAvailableAssetCount(&session, assetLibId, &assetCount))
1060
1061 if (assetCount > 1)
1062 {
1063 std::cout << "Should only be loading 1 asset here" << std::endl;
1064 }
1065
1066 HAPI_StringHandle assetSh;
1067 HE_CHECK(HAPI_GetAvailableAssets(&session, assetLibId, &assetSh, assetCount))
1068
1069 std::string assetName = GetString(session, assetSh);
1070
1071 HAPI_NodeId editableNetworkId;
1072 HE_CHECK(HAPI_CreateNode(&session, -1, assetName.c_str(), "FourShape", false, &editableNetworkId))
1073
1074 HE_CHECK(HAPI_CookNode(&session, editableNetworkId, &cookOptions))
1075
1076 int cookStatus;
1077 HAPI_Result cookResult;
1078
1079 do
1080 {
1081 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
1082 }
1083 while(cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
1084
1085 HE_CHECK(cookResult);
1086 HE_CHECK_COOK(cookStatus);
1087
1088 int childCount;
1089 HE_CHECK(HAPI_ComposeChildNodeList(&session, editableNetworkId, HAPI_NODETYPE_ANY, HAPI_NODEFLAGS_ANY, false, &childCount))
1090
1091 std::cout << "Editable Node Network Child Count: " << childCount << std::endl;
1092
1093 std::vector<HAPI_NodeId> childNodeIds(childCount);
1094 HE_CHECK(HAPI_GetComposedChildNodeList(&session, editableNetworkId, &childNodeIds.front(), childCount))
1095
1096 PrintChildNodeInfo(session, childNodeIds);
1097
1098 HAPI_NodeId anotherBoxNode;
1099 HE_CHECK(HAPI_CreateNode(&session, editableNetworkId, "geo", "ProgrammaticBox", false, &anotherBoxNode))
1100
1101 HE_CHECK(HAPI_ConnectNodeInput(&session, anotherBoxNode, 0, childNodeIds[0], 0))
1102 HE_CHECK(HAPI_CookNode(&session, anotherBoxNode, &cookOptions))
1103
1104 int boxCookStatus;
1105 HAPI_Result boxCookResult;
1106
1107 do
1108 {
1109 boxCookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &boxCookStatus);
1110 }
1111 while (boxCookStatus > HAPI_STATE_MAX_READY_STATE && boxCookResult == HAPI_RESULT_SUCCESS);
1112
1113 HE_CHECK(boxCookResult)
1114 HE_CHECK_COOK(boxCookStatus)
1115
1116 HAPI_NodeId connectedNodeId;
1117 HE_CHECK(HAPI_QueryNodeInput(&session, anotherBoxNode, 0, &connectedNodeId))
1118
1119 if (connectedNodeId != childNodeIds[0])
1120 {
1121 std::cout << "The connected node id is" << connectedNodeId << " When it should be " << editableNetworkId << std::endl;
1122 }
1123
1124 HE_CHECK(HAPI_ComposeChildNodeList(&session, editableNetworkId, HAPI_NODETYPE_ANY, HAPI_NODEFLAGS_ANY, false, &childCount))
1125
1126 std::vector<HAPI_NodeId> newChildNodes(childCount);
1127 HE_CHECK(HAPI_GetComposedChildNodeList(&session, editableNetworkId, &newChildNodes.front(), childCount))
1128
1129 std::cout << "After CONNECT NODE" << std::endl;
1130 PrintChildNodeInfo(session, newChildNodes);
1131
1132 HE_CHECK(HAPI_SaveHIPFile(&session, "", false))
1133 HE_CHECK(HAPI_DisconnectNodeInput(&session, anotherBoxNode, 0))
1134 HE_CHECK(HAPI_DeleteNode(&session, anotherBoxNode))
1135
1136 std::cout << "After DELETING NODE" << std::endl;
1137
1138 HE_CHECK(HAPI_ComposeChildNodeList(&session, editableNetworkId, HAPI_NODETYPE_ANY, HAPI_NODEFLAGS_ANY, false, &childCount))
1139
1140 std::vector<HAPI_NodeId> finalChildList(childCount);
1141 HE_CHECK(HAPI_GetComposedChildNodeList(&session, editableNetworkId, &finalChildList.front(), childCount))
1142 PrintChildNodeInfo(session, finalChildList);
1143
1144 HE_CHECK(HAPI_Cleanup(&session));
1145 }
1146
1147 static void Parts_Sample()
1148 {
1149 const char* hdaFile = "";
1150
1151 HAPI_Session session;
1152 HAPI_ThriftServerOptions serverOptions{ 0 };
1153 serverOptions.autoClose = true;
1154 serverOptions.timeoutMs = 3000.0f;
1155
1156 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
1157
1158 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
1159 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
1160
1161 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
1162 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
1163
1164 HAPI_AssetLibraryId assetLibId;
1165 HE_CHECK(HAPI_LoadAssetLibraryFromFile(&session, hdaFile, true, &assetLibId))
1166
1167 int assetCount;
1168 HE_CHECK(HAPI_GetAvailableAssetCount(&session, assetLibId, &assetCount))
1169
1170 if (assetCount > 1)
1171 {
1172 std::cout << "Should only be loading 1 asset here" << std::endl;
1173 }
1174
1175 HAPI_StringHandle assetSh;
1176 HE_CHECK(HAPI_GetAvailableAssets(&session, assetLibId, &assetSh, assetCount))
1177
1178 std::string assetName = GetString(session, assetSh);
1179
1180 HAPI_NodeId nodeId;
1181 HE_CHECK(HAPI_CreateNode(&session, -1, assetName.c_str(), "TestObject", false, &nodeId))
1182 HE_CHECK(HAPI_CookNode(&session, nodeId, &cookOptions))
1183
1184 int cookStatus;
1185 HAPI_Result cookResult;
1186
1187 do
1188 {
1189 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
1190 }
1191 while(cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
1192
1193 HE_CHECK(cookResult)
1194 HE_CHECK_COOK(cookStatus)
1195
1196 HAPI_AssetInfo assetInfo;
1197 HE_CHECK(HAPI_GetAssetInfo(&session, nodeId, &assetInfo))
1198
1199 PrintCompleteNodeInfo(session, nodeId, assetInfo);
1200
1201 HE_CHECK(HAPI_Cleanup(&session));
1202 }
1203
1205 {
1206 const char* hdaFile = "";
1207
1208 HAPI_Session session;
1209 HAPI_ThriftServerOptions serverOptions{ 0 };
1210 serverOptions.autoClose = true;
1211 serverOptions.timeoutMs = 3000.0f;
1212
1213 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
1214
1215 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
1216 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
1217
1218 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
1219 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
1220
1221 HAPI_AssetLibraryId assetLibId;
1222 HE_CHECK(HAPI_LoadAssetLibraryFromFile(&session, hdaFile, true, &assetLibId))
1223
1224 int assetCount;
1225 HE_CHECK(HAPI_GetAvailableAssetCount(&session, assetLibId, &assetCount))
1226
1227 if (assetCount > 1)
1228 {
1229 std::cout << "Should only be loading 1 asset here" << std::endl;
1230 }
1231
1232 HAPI_StringHandle assetSh;
1233 HE_CHECK(HAPI_GetAvailableAssets(&session, assetLibId, &assetSh, assetCount))
1234
1235 std::string assetName = GetString(session, assetSh);
1236
1237 HAPI_NodeId nodeId;
1238 HE_CHECK(HAPI_CreateNode(&session, -1, assetName.c_str(), "PackedPrimitive", false, &nodeId))
1239
1240 CookAndPrintNode(session, cookOptions, nodeId, HAPI_PACKEDPRIM_INSTANCING_MODE_DISABLED);
1241 CookAndPrintNode(session, cookOptions, nodeId, HAPI_PACKEDPRIM_INSTANCING_MODE_HIERARCHY);
1242 CookAndPrintNode(session, cookOptions, nodeId, HAPI_PACKEDPRIM_INSTANCING_MODE_FLAT);
1243
1244 HE_CHECK(HAPI_Cleanup(&session))
1245 }
1246
1247 static void Parameters_Sample()
1248 {
1249 const char* hdaFile = "";
1250
1251 HAPI_Session session;
1252 HAPI_ThriftServerOptions serverOptions{ 0 };
1253 serverOptions.autoClose = true;
1254 serverOptions.timeoutMs = 3000.0f;
1255
1256 HE_CHECK(HAPI_StartThriftNamedPipeServer(&serverOptions, "hapi", nullptr, nullptr))
1257
1258 HAPI_SessionInfo sessionInfo = HAPI_SessionInfo_Create();
1259 HE_CHECK(HAPI_CreateThriftNamedPipeSession(&session, "hapi", &sessionInfo))
1260
1261 HAPI_CookOptions cookOptions = HAPI_CookOptions_Create();
1262 HE_CHECK(HAPI_Initialize(&session, &cookOptions, true, -1, nullptr, nullptr, nullptr, nullptr, nullptr))
1263
1264 HAPI_AssetLibraryId assetLibId;
1265 HE_CHECK(HAPI_LoadAssetLibraryFromFile(&session, hdaFile, true, &assetLibId))
1266
1267 int assetCount;
1268 HE_CHECK(HAPI_GetAvailableAssetCount(&session, assetLibId, &assetCount))
1269
1270 if (assetCount > 1)
1271 {
1272 std::cout << "Should only be loading 1 asset here" << std::endl;
1273 }
1274
1275 HAPI_StringHandle assetSh;
1276 HE_CHECK(HAPI_GetAvailableAssets(&session, assetLibId, &assetSh, assetCount))
1277
1278 std::string assetName = GetString(session, assetSh);
1279
1280 HAPI_NodeId nodeId;
1281 HE_CHECK(HAPI_CreateNode(&session, -1, assetName.c_str(), "AnAsset", false, &nodeId))
1282
1283 HE_CHECK(HAPI_CookNode(&session, nodeId, &cookOptions))
1284
1285 int cookStatus;
1286 HAPI_Result cookResult;
1287
1288 do
1289 {
1290 cookResult = HAPI_GetStatus(&session, HAPI_STATUS_COOK_STATE, &cookStatus);
1291 }
1292 while(cookStatus > HAPI_STATE_MAX_READY_STATE && cookResult == HAPI_RESULT_SUCCESS);
1293
1294 HE_CHECK(cookResult);
1295 HE_CHECK(cookStatus);
1296
1297 HAPI_NodeInfo nodeInfo;
1298 HE_CHECK(HAPI_GetNodeInfo(&session, nodeId, &nodeInfo))
1299
1300 std::vector<HAPI_ParmInfo> parmInfos(nodeInfo.parmCount);
1301 HE_CHECK(HAPI_GetParameters(&session, nodeId, parmInfos.data(), 0, nodeInfo.parmCount))
1302
1303 std::cout << "Parameters: " << std::endl;
1304 for (int i = 0; i < nodeInfo.parmCount; ++i)
1305 {
1306 std::cout << "===========" << std::endl;
1307
1308 std::cout << " Name: "
1309 << GetString(session, parmInfos[i].nameSH)
1310 << std::endl;
1311
1312 std::cout << " Value: (";
1313
1314 if (HAPI_ParmInfo_IsInt(&parmInfos[i]))
1315 {
1316 int parmIntCount = HAPI_ParmInfo_GetIntValueCount(&parmInfos[i]);
1317
1318 std::vector<int> parmIntValues(parmIntCount);
1319
1320 HE_CHECK(HAPI_GetParmIntValues(&session, nodeId, parmIntValues.data(), parmInfos[i].intValuesIndex, parmIntCount))
1321
1322 for (int v = 0; v < parmIntCount; ++v)
1323 {
1324 if (v != 0)
1325 {
1326 std::cout << ", ";
1327 }
1328 std::cout << parmIntValues[v];
1329 }
1330 }
1331 else if (HAPI_ParmInfo_IsFloat(&parmInfos[i]))
1332 {
1333
1334 int parmFloatCount = HAPI_ParmInfo_GetFloatValueCount(&parmInfos[i]);
1335
1336 std::vector<float> parmFloatValues(parmFloatCount);
1337
1338 HE_CHECK(HAPI_GetParmFloatValues(&session, nodeId, parmFloatValues.data(), parmInfos[i].floatValuesIndex, parmFloatCount))
1339
1340 for (int v = 0; v < parmFloatCount; ++v)
1341 {
1342 if (v != 0)
1343 {
1344 std::cout << ", ";
1345 }
1346 std::cout << parmFloatValues[v];
1347 }
1348 }
1349 else if (HAPI_ParmInfo_IsString(&parmInfos[i]))
1350 {
1351 int parmStringCount = HAPI_ParmInfo_GetStringValueCount(&parmInfos[i]);
1352 std::vector<HAPI_StringHandle> parmSHValues(parmStringCount);
1353
1354 HE_CHECK(HAPI_GetParmStringValues(&session, nodeId, true, parmSHValues.data(), parmInfos[i].stringValuesIndex, parmStringCount));
1355
1356 for (int v = 0; v < parmStringCount; ++v)
1357 {
1358 if (v != 0)
1359 {
1360 std::cout << ", ";
1361 }
1362
1363 std::cout << GetString(session, parmSHValues[v]);
1364 }
1365 }
1366
1367 HE_CHECK(HAPI_Cleanup(&session))
1368 }
1369 }
1370
1372 {
1373
1374 }
1375}
#define HE_CHECK_COOK(expr)
HoudiniEngine Check Cook macro. Verify HoudiniEngine Cook API Effectiveness.
Definition HoudiniCore.h:32
#define HE_CHECK(expr)
HoudiniEngine Check macro. Verify HoudiniEngine API Effectiveness.
Definition HoudiniCore.h:17
virtual ~HoudiniSession()=default
static void PDG_Cooking_With_Events()
static void Marshalling_Geometry_Into_Houdini()
static std::string GetHoudiniLastError()
Definition HoudiniCore.h:43
static void ProcessFloatAttrib(HAPI_Session &session, HAPI_AssetInfo &assetInfo, HAPI_NodeId objectNode, HAPI_NodeId geoNode, HAPI_PartId partId, HAPI_AttributeOwner owner, std::string name)
static void Parameters_Sample()
static void Curve_Node()
static std::string GetHoudiniLastCookError()
Definition HoudiniCore.h:57
static void Groups_Sample()
static void Connecting_Assets()
static void Parts_Sample()
static void Curve_Output()
static void Curve_Marshalling()
static void Materials_Sample()
static std::string GetString(HAPI_Session &session, HAPI_StringHandle stringHandle)
static void Marshalling_Point_Clouds()
static void CookAndPrintNode(HAPI_Session &session, HAPI_CookOptions &co, HAPI_NodeId nodeId, HAPI_PackedPrimInstancingMode mode)
static void PrintChildNodeInfo(HAPI_Session &session, std::vector< HAPI_NodeId > &childrenNodes)
static void PrintCompleteNodeInfo(HAPI_Session &session, HAPI_NodeId nodeId, HAPI_AssetInfo &assetInfo)
static void PrintPartInfo(HAPI_Session &session, HAPI_NodeId nodeId, HAPI_PartId partId, std::string indent)
static void Packed_Primitives_Sample()
static void ProcessGeoPart(HAPI_Session &session, HAPI_AssetInfo &assetInfo, HAPI_NodeId objectNode, HAPI_NodeId geoNode, HAPI_PartId partId)
static void Node_Creation_Sample()