/* ****************************************************************************** * Function Name : instanceCube() * * Description : * * Input Arguments : GU_Detail *inst_gdp, GU_Detail *mb_gdp * * Return Value : int * ***************************************************************************** */ int VRAY_clusterThis::instanceCube(GU_Detail * inst_gdp, GU_Detail * mb_gdp) { #ifdef DEBUG std::cout << "VRAY_clusterThis::instanceCube()" << std::endl; #endif GEO_Primitive * myCube; GEO_Point * ppt; UT_Matrix4 xform(1.0); // UT_XformOrder xformOrder(UT_XformOrder::TRS, UT_XformOrder::XYZ); UT_Matrix3 rot_xform(1.0); // UT_Vector3 myDir = myPointAttributes.N; UT_Vector3 myUp = UT_Vector3(0,1,0); rot_xform.orient(myPointAttributes.N, myUp); xform = rot_xform; myCube = (GEO_Primitive *) inst_gdp->cube( myPointAttributes.myNewPos[0] - ((mySize[0] * myPointAttributes.pscale) / 2), myPointAttributes.myNewPos[0] + ((mySize[0] * myPointAttributes.pscale) / 2), myPointAttributes.myNewPos[1] - ((mySize[1] * myPointAttributes.pscale) / 2), myPointAttributes.myNewPos[1] + ((mySize[1] * myPointAttributes.pscale) / 2), myPointAttributes.myNewPos[2] - ((mySize[2] * myPointAttributes.pscale) / 2), myPointAttributes.myNewPos[2] + ((mySize[2] * myPointAttributes.pscale) / 2)); for(int i=0; i < myCube->getVertexCount(); i++) { ppt = myCube->getVertexElement(i).getPt(); UT_Vector4 P = ppt->getPos(); P *= xform; ppt->setPos(P); } VRAY_clusterThis::setInstanceAttributes(myCube); if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) { myCube = (GEO_Primitive *) mb_gdp->cube(myPointAttributes.myMBPos[0] - ((mySize[0] * myPointAttributes.pscale) / 2), myPointAttributes.myMBPos[0] + ((mySize[0] * myPointAttributes.pscale) / 2), myPointAttributes.myMBPos[1] - ((mySize[1] * myPointAttributes.pscale) / 2), myPointAttributes.myMBPos[1] + ((mySize[1] * myPointAttributes.pscale) / 2), myPointAttributes.myMBPos[2] - ((mySize[2] * myPointAttributes.pscale) / 2), myPointAttributes.myMBPos[2] + ((mySize[2] * myPointAttributes.pscale) / 2)); for(int i=0; i < myCube->getVertexCount(); i++) { ppt = myCube->getVertexElement(i).getPt(); UT_Vector4 P = ppt->getPos(); P *= xform; ppt->setPos(P); } VRAY_clusterThis::setInstanceAttributes(myCube); } if(myCVEX_Exec) VRAY_clusterThis::runCVEX(inst_gdp, mb_gdp, myCVEXFname, CLUSTER_CVEX_POINT); if(myCVEX_Exec_prim) VRAY_clusterThis::runCVEX(inst_gdp, mb_gdp, myCVEXFname_prim, CLUSTER_CVEX_PRIM); return 0; }
/* ****************************************************************************** * Function Name : instanceGrid() * * Description : Instance a grid * * Input Arguments : GU_Detail *inst_gdp, GU_Detail *mb_gdp * * Return Value : int * ***************************************************************************** */ int VRAY_clusterThis::instanceGrid(GU_Detail * inst_gdp, GU_Detail * mb_gdp) { #ifdef DEBUG std::cout << "VRAY_clusterThis::instanceGrid()" << std::endl; #endif GEO_Primitive * myGrid; GU_GridParms grid_parms; UT_XformOrder xformOrder(UT_XformOrder::TRS, UT_XformOrder::XYZ); UT_Matrix4 xform(1.0); xform.rotate(myPointAttributes.N[0], myPointAttributes.N[1], myPointAttributes.N[2], xformOrder); grid_parms.rows = 2; grid_parms.cols = 2; grid_parms.xsize = mySize[0] * myPointAttributes.pscale; grid_parms.ysize = mySize[1] * myPointAttributes.pscale; grid_parms.xcenter = myPointAttributes.myNewPos[0]; grid_parms.ycenter = myPointAttributes.myNewPos[1]; grid_parms.zcenter = myPointAttributes.myNewPos[2]; grid_parms.plane = GU_PLANE_XY; myGrid = inst_gdp->buildGrid(grid_parms, GU_GRID_POLY); for(int i = 0; i < myGrid->getVertexCount(); i++) { GEO_Point * ppt = myGrid->getVertexElement(i).getPt(); UT_Vector4 P = ppt->getPos(); P *= xform; ppt->setPos(P); } VRAY_clusterThis::setInstanceAttributes(myGrid); if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) { grid_parms.xcenter = myPointAttributes.myMBPos[0]; grid_parms.ycenter = myPointAttributes.myMBPos[1]; grid_parms.zcenter = myPointAttributes.myMBPos[2]; myGrid = mb_gdp->buildGrid(grid_parms, GU_GRID_POLY); for(int i = 0; i < myGrid->getVertexCount(); i++) { GEO_Point * ppt = myGrid->getVertexElement(i).getPt(); UT_Vector4 P = ppt->getPos(); P *= xform; ppt->setPos(P); } VRAY_clusterThis::setInstanceAttributes(myGrid); } if(myCVEX_Exec) VRAY_clusterThis::runCVEX(inst_gdp, mb_gdp, myCVEXFname, CLUSTER_CVEX_POINT); if(myCVEX_Exec_prim) VRAY_clusterThis::runCVEX(inst_gdp, mb_gdp, myCVEXFname_prim, CLUSTER_CVEX_PRIM); return 0; }
OP_ERROR SOP_Cleave::cookMySop(OP_Context &context) { const GA_PrimitiveGroup *polyGroup; GEO_Primitive *prim; GQ_Detail *gqd; int i,j,k; UT_Vector4 np,p; // Before we do anything, we must lock our inputs. Before returning, // we have to make sure that the inputs get unlocked. if (lockInputs(context) >= UT_ERROR_ABORT) return error(); float now = context.getTime(); duplicateSource(0, context, 0, 1); // Here we determine which groups we have to work on. We only // handle poly groups. UT_String groups; getGroups(groups); if (groups.isstring()) polyGroup = parsePrimitiveGroups(groups); else polyGroup = 0; if (error() >= UT_ERROR_ABORT) { unlockInputs(); return error(); } UT_Interrupt* boss = UTgetInterrupt(); // Start the interrupt server boss->opStart("Cleaving Polys"); // separate out all polys to be cleaved GA_PrimitiveGroup* cleave_group = gdp->newPrimitiveGroup("cleave",1); GA_PrimitiveGroup* not_cleave_group = gdp->newPrimitiveGroup("not_cleave",1); if (polyGroup) { GA_FOR_ALL_PRIMITIVES(gdp,prim) { if ( (prim->getTypeId()==GEO_PRIMPOLY) && (polyGroup->contains(prim)!=0)) cleave_group->add(prim); else not_cleave_group->add(prim); } } else {
OP_ERROR SOP_Rain::cookMySop(OP_Context &context) { //UT_Interrupt *boss; if (error() < UT_ERROR_ABORT) { //boss = UTgetInterrupt(); //boss->opStart("Start generating rain"); fpreal now = TIME(context.getTime()); long nPoints = NPOINTS( now ); UT_Vector3 rainDirection = RAINDIRECTION(now); //rainDirection.normalize(); //TODO: check for (0,0,0) vector RainData rain( now, nPoints, BOUNDMIN (now), BOUNDMAX (now), rainDirection, DICEMIN(now), DICEMAX(now), SEED(now), SPEED (now), SPEEDVARIENCE (now)); if(rain.getAllocationState() == false || isPointsNumberChanged_ == true) { rain.allocate(nPoints); } if( rain.getAllocationState() == true && ( rain.getCachedState() == false || isParameterChanged_ == true ) ) { rain.computeInitialPositions(); rain.setCachedState(true); } if (isPointsGenerated_ == false) { printf("Generate Points procedure\n"); gdp->clearAndDestroy(); generatePoints(gdp, nPoints); isPointsGenerated_ = true; } for ( GA_Iterator pr_it(gdp->getPrimitiveRange()); !pr_it.atEnd(); ++pr_it) { GEO_Primitive* prim = gdp->getGEOPrimitive(*pr_it); GA_Range range = prim->getPointRange(); rain.shiftPositions( gdp, range); } //boss->opEnd(); } isParameterChanged_ = false; isPointsNumberChanged_ = false; //unlockInputs(); return error(); }