static void exportParticles( const char *node_path, const char *filePath, const std::map<std::string, channel_type>& channels ) { OP_Node *op_node = OPgetDirector()->findNode( node_path ); if ( !op_node ) throw HOM_OperationFailed( "Internal error (could not find node)" ); float t = HOM().time(); SOP_Node* sopNode = CAST_SOPNODE( op_node ); if( !sopNode ) throw HOM_OperationFailed( "Internal error (not a valid node type)" ); // Get our parent. OP_Node *parent_node = sopNode->getParent(); // Store the cooking status of our parent node. bool was_cooking = false; if( parent_node ){ was_cooking = parent_node->isCookingRender(); parent_node->setCookingRender( true ); } // Create a context with the time we want the geometry at. OP_Context context( t ); // Get a handle to the geometry. GU_DetailHandle gd_handle = sopNode->getCookedGeoHandle( context ); // Restore the cooking flag, if we changed it. if( parent_node ) parent_node->setCookingRender( was_cooking ); // Check if we have a valid detail handle. if( gd_handle.isNull() ) throw HOM_OperationFailed( "Internal error (not a valid detail handle)" ); // Lock it for reading. GU_DetailHandleAutoReadLock gd_lock( gd_handle ); // Finally, get at the actual GU_Detail. const GU_Detail* gdp = gd_lock.getGdp(); exportParticlesDetail( gdp, filePath, channels ); }
ROP_RENDER_CODE ROP_partio::renderFrame(fpreal time, UT_Interrupt *) { SOP_Node *sop; UT_String soppath, savepath; if( !executePreFrameScript(time) ) { return ROP_ABORT_RENDER; } // From here, establish the SOP that will be rendered, if it cannot // be found, return 0. // This is needed to be done here as the SOPPATH may be time // dependent (ie: OUT$F) or the perframe script may have // rewired the input to this node. sop = CAST_SOPNODE(getInput(0)); if( sop ) { // If we have an input, get the full path to that SOP. sop->getFullPath(soppath); } else { // Otherwise get the SOP Path from our parameter. SOPPATH(soppath, time); } if( !soppath.isstring() ) { UT_String filename; addError(ROP_MESSAGE, "Invalid SOP path"); return ROP_ABORT_RENDER; } sop = getSOPNode(soppath, 1); if (!sop) { addError(ROP_COOK_ERROR, (const char *)soppath); return ROP_ABORT_RENDER; } // Get the gdp OP_Context context(time); GU_DetailHandle gdh; gdh = sop->getCookedGeoHandle(context); GU_DetailHandleAutoReadLock gdl(gdh); const GU_Detail *gdp = gdl.getGdp(); if (!gdp) { addError(ROP_COOK_ERROR, (const char *)soppath); return ROP_ABORT_RENDER; } OUTPUT(savepath, time); UT_String filename; OUTPUT(filename, time); int verbosity = VERBOSITY(); int successWrite = partioSave(filename, gdp, verbosity); if(!successWrite) { addError(ROP_MESSAGE, "ROP can't write to invalid path"); return ROP_ABORT_RENDER; } //update progess if (ALFPROGRESS() && (myEndTime != myStartTime)) { float fpercent = (time - myStartTime) / (myEndTime - myStartTime); int percent = (int)SYSrint(fpercent * 100); percent = SYSclamp(percent, 0, 100); fprintf(stdout, "ALF_PROGRESS %d%%\n", percent); fflush(stdout); } if (error() < UT_ERROR_ABORT) { if( !executePostFrameScript(time) ) { return ROP_ABORT_RENDER; } } return ROP_CONTINUE_RENDER; }