OP_ERROR SOP_CudaParticles::cookMySop(OP_Context &context) { oldf = f; f = context.getFrame(); GEO_ParticleVertex* pvtx; double t = context.getTime(); particlesSystem->dt = 1/(OPgetDirector()->getChannelManager()->getSamplesPerSec() * SUBSTEPS(t)); particlesSystem->preview = PREVIEW(t); particlesSystem->partsLife = LIFE(t); particlesSystem->partsLifeVar = LIFEVAR(t); particlesSystem->velDamp = VELDAMP(t); particlesSystem->gravityStrength = GRAVITYSTR(t); particlesSystem->gravityDir = cu::make_float3(GRAVITYX(t),GRAVITYY(t),GRAVITYZ(t)); particlesSystem->fluidStrength = FLUIDSTR(t); particlesSystem->noiseAmp = cu::make_float3(NOISEAMP(t),NOISEAMP(t),NOISEAMP(t)); particlesSystem->noiseOct = NOISEOCT(t); particlesSystem->noiseFreq = NOISEFREQ(t); particlesSystem->noiseLac = NOISELACUN(t); particlesSystem->noiseOffset = cu::make_float3(NOISEOFFSETX(t),NOISEOFFSETY(t),NOISEOFFSETZ(t)); particlesSystem->pointSize = POINTSIZE(t); particlesSystem->opacity = OPACITY(t); particlesSystem->startColor = cu::make_float3(STARTCOLORX(t),STARTCOLORY(t),STARTCOLORZ(t)); particlesSystem->endColor = cu::make_float3(ENDCOLORX(t),ENDCOLORY(t),ENDCOLORZ(t)); UT_Interrupt *boss; OP_Node::flags().timeDep = 1; if (error() < UT_ERROR_ABORT) { boss = UTgetInterrupt(); // Start the interrupt server if (boss->opStart("Building Particles")){ //gdp->clearAndDestroy(); static float zero = 0.0; GB_AttributeRef partsAtt = gdp->addAttrib("cudaParticlesPreview", sizeof(int), GB_ATTRIB_INT, &zero); gdp->attribs().getElement().setValue<int>(partsAtt, particlesSystem->preview); GB_AttributeRef systemIdAtt = gdp->addAttrib("systemId", sizeof(int), GB_ATTRIB_INT, &zero); gdp->attribs().getElement().setValue<int>(systemIdAtt, particlesSystem->id); if (f < STARTFRAME(t)) { gdp->clearAndDestroy(); particlesSystem->resetParticles(); } else if (f == STARTFRAME(t)) { gdp->clearAndDestroy(); particlesSystem->resetParticles(); int maxParts = MAXPARTS(t); if (particlesSystem->nParts!=maxParts) particlesSystem->changeMaxParts(maxParts); //hSystem = (GEO_PrimParticle *)gdp->appendPrimitive(GEOPRIMPART); //hSystem->clearAndDestroy(); GB_AttributeRef hVelocity = gdp->addPointAttrib("v", sizeof(UT_Vector3),GB_ATTRIB_VECTOR, 0); GB_AttributeRef hLife = gdp->addPointAttrib("life", sizeof(float)*2,GB_ATTRIB_FLOAT, 0); if(particlesSystem->preview!=1) { UT_Vector4 orig = UT_Vector4(0,0,0,1); for (int i = 0; i<particlesSystem->nParts; i++) { GEO_Point* newPoint = gdp->appendPoint(); newPoint->setPos(orig); /*pvtx = hSystem->giveBirth(); GEO_Point* ppt = pvtx->getPt(); //ppt->getPos().assign(0,0,0,1);*/ hSystemInit = 1; } } } else { if(particlesSystem->nParts != -1) { if(lockInputs(context) >= UT_ERROR_ABORT) return error(); if(getInput(0)){ GU_Detail* emittersInput = (GU_Detail*)inputGeo(0, context); GEO_PointList emittersList = emittersInput->points(); int numEmitters = emittersList.entries(); if (numEmitters != particlesSystem->nEmit) { delete particlesSystem->emitters; particlesSystem->nEmit = numEmitters; particlesSystem->emitters = new ParticlesEmitter[numEmitters]; } GEO_AttributeHandle radAh, amountAh; GEO_AttributeHandle initVelAh, radVelAmpAh, noiseVelAmpAh, noiseVelOffsetAh, noiseVelOctAh, noiseVelLacAh, noiseVelFreqAh; radAh = emittersInput->getPointAttribute("radius"); amountAh = emittersInput->getPointAttribute("amount"); initVelAh = emittersInput->getPointAttribute("initVel"); radVelAmpAh = emittersInput->getPointAttribute("radVelAmp"); noiseVelAmpAh = emittersInput->getPointAttribute("noiseVelAmp"); noiseVelOffsetAh = emittersInput->getPointAttribute("noiseVelOffset"); noiseVelOctAh = emittersInput->getPointAttribute("noiseVelOct"); noiseVelLacAh = emittersInput->getPointAttribute("noiseVelLac"); noiseVelFreqAh = emittersInput->getPointAttribute("noiseVelFreq"); for (int i = 0; i < numEmitters; i++) { UT_Vector4 emitPos = emittersList[i]->getPos(); UT_Vector3 emitPos3(emitPos); particlesSystem->emitters[i].posX = emitPos.x(); particlesSystem->emitters[i].posY = emitPos.y(); particlesSystem->emitters[i].posZ = emitPos.z(); radAh.setElement(emittersList[i]); amountAh.setElement(emittersList[i]); initVelAh.setElement(emittersList[i]); radVelAmpAh.setElement(emittersList[i]); noiseVelAmpAh.setElement(emittersList[i]); noiseVelOffsetAh.setElement(emittersList[i]); noiseVelOctAh.setElement(emittersList[i]); noiseVelLacAh.setElement(emittersList[i]); noiseVelFreqAh.setElement(emittersList[i]); particlesSystem->emitters[i].radius = radAh.getF(0); particlesSystem->emitters[i].amount = amountAh.getF(0); particlesSystem->emitters[i].velX = initVelAh.getF(0); particlesSystem->emitters[i].velY = initVelAh.getF(1); particlesSystem->emitters[i].velZ = initVelAh.getF(2); particlesSystem->emitters[i].radVelAmp = radVelAmpAh.getF(0); particlesSystem->emitters[i].noiseVelAmpX = noiseVelAmpAh.getF(0); particlesSystem->emitters[i].noiseVelAmpY = noiseVelAmpAh.getF(1); particlesSystem->emitters[i].noiseVelAmpZ = noiseVelAmpAh.getF(2); particlesSystem->emitters[i].noiseVelOffsetX = noiseVelOffsetAh.getF(0); particlesSystem->emitters[i].noiseVelOffsetY = noiseVelOffsetAh.getF(1); particlesSystem->emitters[i].noiseVelOffsetZ = noiseVelOffsetAh.getF(2); particlesSystem->emitters[i].noiseVelOct = noiseVelOctAh.getF(0); particlesSystem->emitters[i].noiseVelLac = noiseVelLacAh.getF(0); particlesSystem->emitters[i].noiseVelFreq = noiseVelFreqAh.getF(0); } } else { particlesSystem->nEmit = 0; } if(getInput(1)){ GU_Detail* fluidInput = (GU_Detail*)inputGeo(1, context); GEO_AttributeHandle fluidIdAh= fluidInput->getDetailAttribute("solverId"); fluidIdAh.setElement(fluidInput); int sId = fluidIdAh.getI(); VHFluidSolver3D* curr3DSolver = VHFluidSolver3D::solverList[sId]; particlesSystem->fluidSolver = curr3DSolver; } unlockInputs(); if (f!=oldf) { particlesSystem->emitParticles(); particlesSystem->updateParticles(); } if(particlesSystem->preview!=1 && hSystemInit == 1) { cu::cudaMemcpy( particlesSystem->host_pos, particlesSystem->dev_pos, particlesSystem->nParts*sizeof(cu::float3), cu::cudaMemcpyDeviceToHost ); GEO_Point* ppt; int i = 0; UT_Vector4 p; FOR_ALL_GPOINTS(gdp, ppt) { ppt->getPos() = UT_Vector4(particlesSystem->host_pos[i*3], particlesSystem->host_pos[i*3+1], particlesSystem->host_pos[i*3+2], 1); i++; } /*pvtx = hSystem->iterateInit(); for (int i =0; i<particlesSystem->nParts; i++){ pvtx->getPos().assign(particlesSystem->host_pos[i*3], particlesSystem->host_pos[i*3+1], particlesSystem->host_pos[i*3+2], 1); pvtx = hSystem->iterateFastNext(pvtx); }*/ } } }
/* ****************************************************************************** * Function Name : runCVEX() * * Description : Run VEX code on the instanced geometry from an external .vex file * * Input Arguments : GU_Detail *inst_gdp, GU_Detail *mb_gdp * * Return Value : int * ***************************************************************************** */ int VRAY_clusterThis::runCVEX(GU_Detail * inst_gdp, GU_Detail * mb_gdp, UT_String theCVEXFname, uint method) { if (myVerbose == CLUSTER_MSG_DEBUG) { std::cout << "VRAY_clusterThis::runCVEX() - Processing CVEX arrays - points: " << inst_gdp->points().entries() << " primitives: " << inst_gdp->primitives().entries() << std::endl; } UT_Vector3 * P = NULL, *POut = NULL, *N = NULL, *NOut = NULL, *v = NULL, *vOut = NULL, *Cd = NULL, *CdOut = NULL; fpreal * weight = NULL, *weightOut = NULL, *Alpha = NULL, *AlphaOut = NULL, *pscale = NULL, *pscaleOut = NULL; int * id = NULL, *inst_id = NULL; // helper local class to clean up memory class cleanUpCVEXMem { public: void cleanUp(UT_Vector3 * P, UT_Vector3 * POut, UT_Vector3 * N, UT_Vector3 * NOut, UT_Vector3 * v, UT_Vector3 * vOut, UT_Vector3 * Cd, UT_Vector3 * CdOut, fpreal * weight, fpreal * weightOut, fpreal * Alpha, fpreal * AlphaOut, fpreal * pscale, fpreal * pscaleOut, int * id, int * inst_id) { if (P) delete []P; if (POut) delete []POut; if (Cd) delete []Cd; if (CdOut) delete []CdOut; if (Alpha) delete []Alpha; if (AlphaOut) delete []AlphaOut; if (N) delete []N; if (NOut) delete []NOut; if (v) delete []v; if (vOut) delete []vOut; if (pscale) delete []pscale; if (pscaleOut) delete []pscaleOut; if (weight) delete []weight; if (weightOut) delete []weightOut; if (id) delete []id; if (inst_id) delete []inst_id; return; }; } memCleaner; try { uint32 num_inst = 0, num_points = 0, num_prim = 0; long int num = 0; GEO_Point * ppt; GEO_Primitive * prim; UT_Vector4 pos; CVEX_Context cvex; GU_Detail * cvex_gdp; uint32 num_passes = 1; uint32 mb_pass = 0; fpreal time = myCurrentTime; // std::cout << "VRAY_clusterThis::runCVEX() - time: " << time << endl; if (myDoMotionBlur == CLUSTER_MB_DEFORMATION) num_passes = 2; if (myPrimType == CLUSTER_POINT) { num_inst = myInstanceNum; // num_inst = inst_gdp->points().entries(); num_points = inst_gdp->points().entries(); // std::cout << "VRAY_clusterThis::runCVEX() - num_inst: " << num_inst << std::endl; } else { num_inst = myInstanceNum; num_prim = inst_gdp->primitives().entries(); num_points = inst_gdp->points().entries(); num_inst = num_points; // std::cout << "VRAY_clusterThis::runCVEX() - num_inst: " << num_inst << " num_points: " << num_points << " num_prim: " << num_prim << std::endl; } UT_Vector3 primAttr, ptAttr; GA_RWAttributeRef primN_ref, primV_ref, primCd_ref, primAlpha_ref, primPscale_ref, primId_ref, primWeight_ref; GA_RWAttributeRef ptN_ref, ptV_ref, ptCd_ref, ptAlpha_ref, ptPscale_ref, ptId_ref, ptInstId_ref; if (myPrimType == CLUSTER_POINT) { // Allocate the space for the point positions P = new UT_Vector3[num_points]; POut = new UT_Vector3[num_points]; if (myCVEXPointVars.cvex_Cd_pt) { Cd = new UT_Vector3[num_points]; CdOut = new UT_Vector3[num_points]; } if (myCVEXPointVars.cvex_Alpha_pt) { Alpha = new fpreal[num_points]; AlphaOut = new fpreal[num_points]; } if (myCVEXPointVars.cvex_N_pt) { N = new UT_Vector3[num_points]; NOut = new UT_Vector3[num_points]; } if (myCVEXPointVars.cvex_v_pt) { v = new UT_Vector3[num_points]; vOut = new UT_Vector3[num_points]; } if (myCVEXPointVars.cvex_pscale_pt) { pscale = new fpreal[num_points]; pscaleOut = new fpreal[num_points]; } id = new int[num_points]; inst_id = new int[num_points]; } else { // If we're processing the points of the prims, allocate the space if (method == CLUSTER_CVEX_POINT) { P = new UT_Vector3[num_points]; POut = new UT_Vector3[num_points]; // Allocate space for the id and inst_id attr's id = new int[num_points]; inst_id = new int[num_points]; } // Else we're working on primitives, so allocate sace for the attrs the user wants to CVEX! else { if (myCVEXPrimVars.cvex_Cd_prim) { Cd = new UT_Vector3[num_prim]; CdOut = new UT_Vector3[num_prim]; } if (myCVEXPrimVars.cvex_Alpha_prim) { Alpha = new fpreal[num_prim]; AlphaOut = new fpreal[num_prim]; } if (myCVEXPrimVars.cvex_N_prim) { N = new UT_Vector3[num_prim]; NOut = new UT_Vector3[num_prim]; } if (myCVEXPrimVars.cvex_v_prim) { v = new UT_Vector3[num_prim]; vOut = new UT_Vector3[num_prim]; } if (myCVEXPrimVars.cvex_pscale_prim) { pscale = new fpreal[num_prim]; pscaleOut = new fpreal[num_prim]; } if (myPrimType == VRAY_clusterThis::CLUSTER_PRIM_METABALL && myCVEXPrimVars.cvex_weight_prim) { weight = new fpreal[num_prim]; weightOut = new fpreal[num_prim]; } // Allocate space for the id and inst_id attr's id = new int[num_prim]; inst_id = new int[num_prim]; } } // Retrieve the attribute offsets for (uint32 pass = 0; pass < num_passes; pass++) { if (pass == 0) { cvex_gdp = inst_gdp; mb_pass = 0; } else { cvex_gdp = mb_gdp; mb_pass = 1; } if (myPrimType == CLUSTER_POINT) { if (myCVEXPointVars.cvex_Cd_pt) { ptCd_ref = cvex_gdp->findDiffuseAttribute(GEO_POINT_DICT); } if (myCVEXPointVars.cvex_Alpha_pt) { ptAlpha_ref = cvex_gdp->findFloatTuple(GA_ATTRIB_POINT, "Alpha", 1); } if (myCVEXPointVars.cvex_N_pt) { ptN_ref = cvex_gdp->findNormalAttribute(GEO_POINT_DICT); } if (myCVEXPointVars.cvex_v_pt) { ptV_ref = cvex_gdp->findVelocityAttribute(GEO_POINT_DICT); } if (myCVEXPointVars.cvex_pscale_pt) { ptPscale_ref = cvex_gdp->findFloatTuple(GA_ATTRIB_POINT, "pscale", 1); } ptId_ref = cvex_gdp->findIntTuple(GA_ATTRIB_POINT, "id", 1); ptInstId_ref = cvex_gdp->findIntTuple(GA_ATTRIB_POINT, "inst_id", 1); } else { // If we're not processing the points of the prims, get the attr's offset for the attrs the user wants to use if (method != CLUSTER_CVEX_POINT) { if (myCVEXPrimVars.cvex_Cd_prim) { primCd_ref = cvex_gdp->findDiffuseAttribute(GEO_PRIMITIVE_DICT); } if (myCVEXPrimVars.cvex_Alpha_prim) { primAlpha_ref = cvex_gdp->findFloatTuple(GA_ATTRIB_POINT, "Alpha", 1); } if (myCVEXPrimVars.cvex_N_prim) { primN_ref = cvex_gdp->findFloatTuple(GA_ATTRIB_POINT, "N", 3); // primN_ref = cvex_gdp->findNormalAttribute ( GEO_PRIMITIVE_DICT ); } if (myCVEXPrimVars.cvex_v_prim) { primV_ref = cvex_gdp->findVelocityAttribute(GEO_PRIMITIVE_DICT); } if (myCVEXPrimVars.cvex_pscale_prim) { ptPscale_ref = cvex_gdp->findFloatTuple(GA_ATTRIB_POINT, "pscale", 1); } if (myPrimType == VRAY_clusterThis::CLUSTER_PRIM_METABALL && myCVEXPrimVars.cvex_weight_prim) { primWeight_ref = cvex_gdp->findFloatTuple(GA_ATTRIB_POINT, "weight", 1); } } // Get the offset for id attr ptId_ref = cvex_gdp->findIntTuple(GA_ATTRIB_POINT, "id", 1); ptInstId_ref = cvex_gdp->findIntTuple(GA_ATTRIB_POINT, "inst_id", 1); } #ifdef DEBUG std::cout << "VRAY_clusterThis::runCVEX() - Retrieved attribute offsets" << std::endl; #endif // Set the values of the incoming arrays if (myPrimType == CLUSTER_POINT) { num = 0; GA_FOR_ALL_GPOINTS(cvex_gdp, ppt) { pos = ppt->getPos(); P[num][0] = pos.x(); P[num][1] = pos.y(); P[num][2] = pos.z(); // P[num] = ppt->getPos(); id[num] = static_cast<int>(ppt->getValue<int>(ptId_ref, 0)); if (ptInstId_ref.isValid()) inst_id[num] = static_cast<int>(ppt->getValue<int>(ptInstId_ref, 0)); else inst_id[num] = id[num]; // cout << "IN - id : " << id[num] << "\tinst_id " << inst_id[num] << "\tnum " << num << endl; ++num; } if (myCVEXPointVars.cvex_Cd_pt) { num = 0; GA_FOR_ALL_GPOINTS(cvex_gdp, ppt) { ptAttr = static_cast<UT_Vector3>(ppt->getValue<UT_Vector3>(ptCd_ref, 0)); Cd[num][0] = ptAttr.x(); Cd[num][1] = ptAttr.y(); Cd[num][2] = ptAttr.z(); // cout << "IN - Cd: " << Cd[num] << endl; ++num; } }
void GR_rmanPtc::renderWire( GU_Detail *gdp, RE_Render &ren, const GR_AttribOffset &ptinfo, const GR_DisplayOption *dopt, float lod, const GU_PrimGroupClosure *hidden_geometry ) { int i, nprim; GEO_Primitive *prim; UT_Vector3 v3; rmanPtcSop::rmanPtcDetail *detail = dynamic_cast<rmanPtcSop::rmanPtcDetail*>(gdp); if ( !detail ) return; // rebuild our display list if ( detail->redraw ) { srand(0); GEO_PointList &points = detail->points(); int display_channel = detail->display_channel; // render as points GEO_Point *pt = 0; UT_Vector4 pos; float col[3] = {1.0,1.0,1.0}; if ( !detail->use_disk ) { ren.pushPointSize(detail->point_size); ren.beginPoint(); } for ( unsigned int i=0; i<points.entries(); ++i ) { if ( rand()/(float)RAND_MAX<=detail->display_probability ) { // point position pt = points[i]; pos = pt->getPos(); // display colour float *ptr = NULL; if (detail->attributes.size() >0) { ptr = pt->castAttribData<float>( detail->attributes[display_channel] ); if (ptr) { if ( detail->attribute_size[display_channel]==1) col[0] = col[1] = col[2] = ptr[0]; else { col[0] = ptr[0]; col[1] = ptr[1]; col[2] = ptr[2]; } } } // draw point if ( !detail->use_cull_bbox || detail->cull_bbox.isInside( pos ) ) { if ( !detail->use_disk ) { // render as points ren.setColor( col[0], col[1], col[2], 1 ); ren.vertex3DW( pos.x(), pos.y(), pos.z() ); } else { // render as disks UT_Vector3 n = *pt->castAttribData<UT_Vector3>(detail->N_attrib); float r = *pt->castAttribData<float>(detail->R_attrib); n.normalize(); UT_Vector3 ref(1,0,0); UT_Vector3 up = ref; up.cross(n); up.normalize(); UT_Vector3 right = up; right.cross(n); right.normalize(); UT_DMatrix4 mat( right.x(), right.y(), right.z(), 0, up.x(), up.y(), up.z(), 0, n.x(), n.y(), n.z(), 0, pos.x(), pos.y(), pos.z(), 1 ); ren.pushMatrix(); ren.multiplyMatrix(mat); ren.pushColor( UT_Color( UT_RGB, col[0], col[1], col[2] ) ); ren.circlefW( 0, 0, detail->point_size * r, 8 ); ren.popColor(); ren.popMatrix(); } } } } if ( !detail->use_disk ) { ren.endPoint(); } } }