mymodule = inlinecpp.createLibrary( name="cpp_marc_library_points", includes=""" #include <UT/UT_String.h> #include <GU/GU_Detail.h> #include <GA/GA_AttributeRef.h> """, function_sources=[ """ void pointsInGroup(GU_Detail *gdp) { GA_PointGroup* grp; // Loop over Groups and create group attribute GA_FOR_ALL_POINTGROUPS(gdp, grp) { UT_String groupname = grp->getName(); // Create group attribute GA_RWAttributeRef grpAtt = gdp->findIntTuple(GA_ATTRIB_POINT, groupname,1); if (!grpAtt.isValid()) { grpAtt = gdp->addIntTuple(GA_ATTRIB_POINT, groupname,1); } GA_RWHandleI grpatthandle(grpAtt.getAttribute()); // Loop over points and set attribute value GA_Offset ptOff; GA_FOR_ALL_PTOFF(gdp, ptOff) { if (grp->containsOffset(ptOff)){ grpatthandle.set(ptOff, 1); } } // For all point offsets } // For all pointgroups } // inGroup() """ ], )
mymodule = inlinecpp.createLibrary( name="cpp_marc_library_prims_string", includes=""" #include <UT/UT_String.h> #include <GU/GU_Detail.h> #include <GA/GA_AttributeRef.h> #include <GEO/GEO_Primitive.h> #include <iostream> #include <string> """, function_sources=[ """ void primInGroup(GU_Detail *gdp) { using namespace std; GA_PrimitiveGroup* grp; // Loop over Groups and create group attribute GA_FOR_ALL_PRIMGROUPS(gdp, grp) { UT_String groupname = grp->getName(); const char * attname = "string_groups"; // Create group attribute GA_RWAttributeRef grpAtt = gdp->findStringTuple(GA_ATTRIB_PRIMITIVE, attname,1); if (!grpAtt.isValid()) { grpAtt = gdp->addStringTuple(GA_ATTRIB_PRIMITIVE, attname,1); } GA_RWHandleS grpatthandle( grpAtt.getAttribute() ); GEO_Primitive *prim; UT_String newname = groupname; GA_FOR_ALL_PRIMITIVES(gdp, prim) { GA_Offset primOff = prim->getMapOffset(); if (grp->containsOffset(primOff)) { UT_String oldname = grpatthandle.get(primOff); if (oldname.length() > 0) { newname = groupname; newname.append(", "); newname.append(oldname); } grpatthandle.set(primOff, newname ); }// inf contains offset } // for all primitives } // For all primgroups } // inGroup() """ ], )
cpp_methods = inlinecpp.createLibrary( "cpp_methods", acquire_hom_lock=True, catch_crashes=True, includes=""" #include <CMD/CMD_Variable.h> #include <GA/GA_AttributeRefMap.h> #include <GA/GA_Primitive.h> #include <GEO/GEO_Face.h> #include <GEO/GEO_PointTree.h> #include <GQ/GQ_Detail.h> #include <GU/GU_Detail.h> #include <GU/GU_PackedGeometry.h> #include <GU/GU_PrimPacked.h> #include <OBJ/OBJ_Node.h> #include <OP/OP_CommandManager.h> #include <OP/OP_Director.h> #include <OP/OP_Node.h> #include <OP/OP_OTLDefinition.h> #include <OP/OP_OTLLibrary.h> #include <OP/OP_OTLManager.h> #include <PRM/PRM_Parm.h> #include <ROP/ROP_RenderManager.h> #include <UT/UT_WorkArgs.h> using namespace std; // Validate a vector of strings so that it can be returned as a StringArray. // Currently we cannot return an empty vector. void validateStringVector(std::vector<std::string> &string_vec) { // Check for an empty vector. if (string_vec.size() == 0) { // An an empty string. string_vec.push_back(""); } } """, structs=[ ("IntArray", "*i"), ("FloatArray", "*d"), ("StringArray", "**c"), ("StringTuple", "*StringArray"), ("VertexMap", (("prims", "*i"), ("indices", "*i"))), ("Position3D", (("x", "d"), ("y", "d"), ("z", "d"))), ], function_sources=_FUNCTION_SOURCES)
import inlinecpp mymodule = inlinecpp.createLibrary( name="cpp_string_library", includes="#include UImain.cpp", include_dirs=[ "D:/Google_Drive/Oriol/Formation/Epitech/Tek4/AI/Files/ai_problem_solving_epitech/BackEnd/Public", "D:/Google_Drive/Oriol/Formation/Epitech/Tek4/AI/Files/ai_problem_solving_epitech/BackEnd/Private", "D:/Google_Drive/Oriol/Formation/Epitech/Tek4/AI/Files/ai_problem_solving_epitech", "D:/Google_Drive/Oriol/Formation/Epitech/Tek4/AI/Files/ai_problem_solving_epitech/UI" ], function_sources=[ """bool matchesPattern(const char *str, const char *pattern) { //GetProblem(); return false; } """ ]) def my_function(): print("Hedddeeeelelofffff from a function") string = "one" for pattern in "o*", "x*", "^o*": print repr(string), "matches", repr(pattern), ":", print mymodule.matchesPattern(string, pattern)
cpp_methods = inlinecpp.createLibrary( "cpp_methods", acquire_hom_lock=True, catch_crashes=True, includes=""" #include <CMD/CMD_Variable.h> #include <CH/CH_Channel.h> #include <CH/CH_Collection.h> #include <CH/CH_Manager.h> #include <GA/GA_AttributeRefMap.h> #include <GA/GA_AttributeInstanceMatrix.h> #include <GA/GA_Primitive.h> #include <GEO/GEO_Face.h> #include <GEO/GEO_PointTree.h> #include <GQ/GQ_Detail.h> #include <GU/GU_Detail.h> #include <GU/GU_PackedGeometry.h> #include <GU/GU_PrimPacked.h> #include <OBJ/OBJ_Node.h> #include <OP/OP_CommandManager.h> #include <OP/OP_Context.h> #include <OP/OP_Director.h> #include <OP/OP_Expression.h> #include <OP/OP_InterestRef.h> #include <OP/OP_Node.h> #include <OP/OP_OTLDefinition.h> #include <OP/OP_OTLLibrary.h> #include <OP/OP_OTLManager.h> #include <PRM/PRM_Name.h> #include <PRM/PRM_Parm.h> #include <ROP/ROP_RenderManager.h> #include <UT/UT_Version.h> #include <UT/UT_WorkArgs.h> #include <UT/UT_WorkBuffer.h> #if (UT_MAJOR_VERSION_INT >= 17) #include <UT/UT_StdUtil.h> #endif using namespace std; // Validate a vector of strings so that it can be returned as a StringArray. // Currently we cannot return an empty vector. void validateStringVector(std::vector<std::string> &string_vec) { // Check for an empty vector. if (string_vec.size() == 0) { // An an empty string. string_vec.push_back(""); } } void addDependencyOnParm(OP_Node *node, const UT_StringRef &name, int instance_index, int component_index) { int evaluating_parm_index, evaluating_sub_index, target_parm_index; OP_ExprFindCh cache; OP_Node *evaluating_node; UT_IntArray instance_numbers; UT_WorkBuffer wb; instance_numbers.append(instance_index); cache.getEvaluatingSource( evaluating_node, evaluating_parm_index, evaluating_sub_index, SYSgetSTID() ); if (evaluating_node) { PRM_Name::instanceToken(wb, name, instance_numbers); target_parm_index = node->getParmList()->getParmIndex(wb.buffer()); OP_InterestRef target_ref(*evaluating_node, evaluating_parm_index, evaluating_sub_index); OP_InterestRef source_ref(*node, target_parm_index, component_index); OP_Node::addExtraInput(target_ref, source_ref); } } """, structs=[ ("IntArray", "*i"), ("FloatArray", "*d"), ("StringArray", "**c"), ("StringTuple", "*StringArray"), ("VertexMap", (("prims", "*i"), ("indices", "*i"))), ("Position3D", (("x", "d"), ("y", "d"), ("z", "d"))), ], function_sources=_FUNCTION_SOURCES)
mymodule = inlinecpp.createLibrary( name="cpp_marc_library_points_str", includes=""" #include <UT/UT_String.h> #include <GU/GU_Detail.h> #include <GA/GA_AttributeRef.h> #include <iostream> #include <string> #include <typeinfo> """, function_sources=[ """ void pointStringGroup(GU_Detail *gdp) { using namespace std; GA_PointGroup* grp; // Loop over Groups and create group attribute GA_FOR_ALL_POINTGROUPS(gdp, grp) { const UT_String groupname = grp->getName(); const char * attname = "string_groups"; // Create group attribute GA_RWAttributeRef grpAtt = gdp->findStringTuple(GA_ATTRIB_POINT, attname,1); if (!grpAtt.isValid()) { grpAtt = gdp->addStringTuple(GA_ATTRIB_POINT, attname,1); } GA_RWHandleS grpatthandle( grpAtt.getAttribute() ); //cout << typeid(grpatthandle(grpatthandle).name(); // Loop over points and set attribute value GA_Offset ptOff; UT_String newname = groupname; GA_FOR_ALL_PTOFF(gdp, ptOff) { if (grp->containsOffset(ptOff)) { //cout << ptOff << ": groupname " << groupname << endl; UT_String oldname = grpatthandle.get(ptOff); if (oldname.length() > 0) { //cout << "\toldname " << oldname << endl; //cout << "\tnewname " << newname << endl; newname = groupname; newname.append(", "); newname.append(oldname); //cout << "\tnewname " << newname << endl; } grpatthandle.set(ptOff, newname ); } } // For all point offsets } // For all pointgroups } // inGroup() """ ], )
cpp_methods = inlinecpp.createLibrary( "cpp_methods", acquire_hom_lock=True, catch_crashes=True, includes=""" #include <CMD/CMD_Variable.h> #include <GA/GA_AttributeRefMap.h> #include <GA/GA_Primitive.h> #include <GEO/GEO_Face.h> #include <GEO/GEO_PointTree.h> #include <GQ/GQ_Detail.h> #include <GU/GU_Detail.h> #include <GU/GU_PackedGeometry.h> #include <GU/GU_PrimPacked.h> #include <OBJ/OBJ_Node.h> #include <OP/OP_CommandManager.h> #include <OP/OP_Director.h> #include <OP/OP_Node.h> #include <OP/OP_OTLDefinition.h> #include <OP/OP_OTLLibrary.h> #include <OP/OP_OTLManager.h> #include <PRM/PRM_Parm.h> #include <ROP/ROP_RenderManager.h> #include <UT/UT_Version.h> #include <UT/UT_WorkArgs.h> #if (UT_MAJOR_VERSION_INT >= 17) #include <UT/UT_StdUtil.h> #endif using namespace std; // Validate a vector of strings so that it can be returned as a StringArray. // Currently we cannot return an empty vector. void validateStringVector(std::vector<std::string> &string_vec) { // Check for an empty vector. if (string_vec.size() == 0) { // An an empty string. string_vec.push_back(""); } } """, structs=[ ("IntArray", "*i"), ("FloatArray", "*d"), ("StringArray", "**c"), ("StringTuple", "*StringArray"), ("VertexMap", (("prims", "*i"), ("indices", "*i"))), ("Position3D", (("x", "d"), ("y", "d"), ("z", "d"))), ], function_sources=_FUNCTION_SOURCES )
def exportObjGeometry(node): beg_time = time.time() if node.renderNode() is None: print(" This dosen't include any renderNode.") return # print("{}".format(node.worldTransform())) rNode = node.renderNode() # hou.SopNode rGeom = rNode.geometry() # hou.Geometry # print("{}".format(type(rNode))) primitiveType = '' for prim in rGeom.prims(): if prim.type() == hou.primType.Polygon: primitiveType = 'Polygon' break data = { 'type' : primitiveType, 'xform' : node.worldTransform().asTuple(), } # 'triangles' # traverse points # points = [] # for point in rGeom.points(): # p = point.position() # points.append(p.x()) # points.append(p.y()) # points.append(p.z()) # Get Points Attributes Points = {} for point in rGeom.pointAttribs(): # https://www.sidefx.com/docs/houdini/hom/hou/attribData.html if point.dataType() == hou.attribData.Float: values = rGeom.pointFloatAttribValues(point.name()) Points[point.name()] = values print(' PointAttrib: ' + point.name()) data['Points'] = Points # traverse primitives ( Naive, It's really slow ) # PointNum = [] # for Vertices # for prim in rGeom.prims(): # for vertex in prim.vertices(): # PointNum.append(vertex.point().number()) # traverse primitives ( Optimized ) cpp_geo_methods = inlinecpp.createLibrary("cpp_geo_methods", includes="#include <GU/GU_Detail.h>\n#include <GA/GA_GBIterators.h>", structs=[("IntArray", "*i"),], function_sources=[ """ IntArray getIndices(const GU_Detail *gdp) { std::vector<int> ids; GA_GBPrimitiveIterator iter(*gdp); GA_Primitive *prim; while( prim = iter.getPrimitive() ) { int n = prim->getVertexCount(); for(int i = 0 ; i < n ; ++i) { ids.push_back(prim->getPointIndex(i)); } iter.advance(); } return ids; } """, """ IntArray getIndexCountsPerPrim(const GU_Detail *gdp) { std::vector<int> ids; GA_GBPrimitiveIterator iter(*gdp); GA_Primitive *prim; while( prim = iter.getPrimitive() ) { int n = prim->getVertexCount(); ids.push_back(n); iter.advance(); } return ids; } """ ]) indices_cpp = cpp_geo_methods.getIndices(rGeom) indexCounts_cpp = cpp_geo_methods.getIndexCountsPerPrim(rGeom) PointNum = [] for idx in indices_cpp: PointNum.append(idx) IndexCount = [] for n in indexCounts_cpp: IndexCount.append(n) Vertices = { 'Point Num' : PointNum, 'Index Count' : IndexCount } # Get Vertices Attributes for vert in rGeom.vertexAttribs(): # https://www.sidefx.com/docs/houdini/hom/hou/attribData.html if vert.dataType() == hou.attribData.Float: values = rGeom.vertexFloatAttribValues(vert.name()) Vertices[vert.name()] = values print(' VertAttrib: ' + vert.name()) data['Vertices'] = Vertices # Get Primitive Attributes Primitives = {} data['Primitives'] = Primitives for prim in rGeom.primAttribs(): # https://www.sidefx.com/docs/houdini/hom/hou/attribData.html if prim.dataType() == hou.attribData.Float: values = rGeom.primFloatAttribValues(prim.name()) Primitives[prim.name()] = values print(' PrimAttrib: ' + prim.name()) # output Path filePath = os.path.join(hou.expandString("$HIP"), "out", node.name() + '.json') # print(json.dumps(data, indent=4)) print(" Save {} to {}".format(node.name(), filePath)) with open(filePath, 'w') as f: f.write(json.dumps(data, ensure_ascii=False)) print(" It takes {} s".format(time.time() - beg_time))
# deprecated. Houdini now does that automatically. node = hou.pwd() geo = node.geometry() import inlinecpp mymodule = inlinecpp.createLibrary( name="cpp_marc_library_kill", includes=""" #include <GU/GU_Detail.h> """, function_sources=[ """ void killEmptyGroup(GU_Detail *gdp) { gdp->destroyAllEmptyGroups(); } """ ], ) mymodule.killEmptyGroup(hou.pwd().geometry())
mymodule = inlinecpp.createLibrary( name="cpp_marc_library_primsC", includes=""" #include <UT/UT_String.h> #include <GU/GU_Detail.h> #include <GA/GA_AttributeRef.h> #include <GEO/GEO_Primitive.h> #include <iostream> """, function_sources=[ """ void primInGroup(GU_Detail *gdp) { using namespace std; GA_PrimitiveGroup* grp; // Loop over Groups and create group attribute GA_FOR_ALL_PRIMGROUPS(gdp, grp) { UT_String groupname = grp->getName(); // Create group attribute GA_RWAttributeRef grpAtt = gdp->findIntTuple(GA_ATTRIB_PRIMITIVE, groupname,1); if (!grpAtt.isValid()) { grpAtt = gdp->addIntTuple(GA_ATTRIB_PRIMITIVE, groupname,1); } GA_RWHandleI grpatthandle(grpAtt.getAttribute()); // Loop over prims and set attribute value GEO_Primitive *prim; cout << "blah"<<endl; GA_FOR_ALL_PRIMITIVES(gdp, prim) { GA_Offset primOff = prim->getMapOffset(); //cout << "blih "<< primOff << ": " << grp->containsOffset(primOff) << endl; if (grp->containsOffset(primOff)){ grpatthandle.set(primOff, 1); } } // For all prim offsets } // For all primgroups } // inGroup() """ ], )