void doFrame(int fNum, size_t cur, int fft_size, fftw_complex *fft_data[], char *fName) { RiFrameBegin(fNum); char buffer[256]; sprintf(buffer, "images/%s%05d.tif", fName, fNum); RiDisplay(buffer,(char*)"file",(char*)"rgba",RI_NULL); RiFormat(800, 600, 1.25); RiLightSource((char*)"distantlight",RI_NULL); RiProjection((char*)"perspective",RI_NULL); RiTranslate(0.0,0.0,0.8*fft_size); RiRotate( -120.0, 1.0, 0.0, 0.0); RiRotate(90.0, 0.0,0.0, 1.0); RiWorldBegin(); RiSurface((char*)"matte", RI_NULL); RiTranslate(-fft_size/2.0, -fft_size/2.0+fft_size/4.0, 0); size_t real_i = cur; RtPoint *pts = malloc(sizeof(RtPoint)*(fft_size*fft_size/2)); RtColor *colors = malloc(sizeof(RtColor)*(fft_size*fft_size/2)); RtInt *numCurves = malloc(sizeof(RtInt)*fft_size); size_t cp = 0; for (int i=fft_size-1; i>=0; --i) { real_i += 1; if (real_i == fft_size) { real_i = 0; } numCurves[i] = fft_size/2; for (size_t j=0; j<fft_size/2; ++j) { colors[cp][0] = real_i/(double)(fft_size-1); colors[cp][1] = cabs(fft_data[real_i][j]); if (colors[cp][1]>1.0) { colors[cp][1] = 1.0; } colors[cp][2] = j/(double)(fft_size/2); pts[cp][0] = fft_size-i; pts[cp][2] = cabs(fft_data[real_i][j]); pts[cp][1] = j; cp += 1; } } RiCurves( "linear", fft_size, numCurves, "nonperiodic", "P", (RtPointer)pts, "Cs", (RtPointer)colors, RI_NULL ); free(numCurves); free(colors); free(pts); RiWorldEnd(); RiFrameEnd(); }
int main() { std::ostringstream output; // Test setting of options. const char* outputType = "Ascii"; RiOption((char*)"RI2RIB_Output", "Type", &outputType, "OStream", &output, RI_NULL); int indentSize = 2; const char* indentType = "Space"; RiOption((char*)"RI2RIB_Indentation", "Size", &indentSize, "Type", &indentType, RI_NULL); RtPointer badHandle = RtPointer(0xDEADBEEF); // Create RIB RiBegin(0); RiFrameBegin(0); RiBasis(RiCatmullRomBasis, 2, RiHermiteBasis, 3); RiFrameEnd(); RiArchiveRecord((char*)"comment", (char*)" Note that we expect a bad handle error " "regarding %p somewhere here!", badHandle); RiFrameBegin(1); RiDisplay((char*)"blah.tif", (char*)"framebuffer", (char*)"rgb", RI_NULL); RiBasis(RiBezierBasis, 3, RiCatmullRomBasis, 1); RiPixelFilter(RiGaussianFilter, 2, 2); RiProjection((char*)"perspective", RI_NULL); RiTranslate(0,0,5); RiWorldBegin(); RtLightHandle h = RiLightSource((char*)"pointlight", RI_NULL); RiIlluminate(h, RI_FALSE); RiIlluminate(badHandle, RI_TRUE); // Invalid handle! float Cs[] = {1,0,0, 0,1,0, 0,0,1, 2,2,2}; RiSphere(1, -1, 1, 360, "Cs", Cs, RI_NULL); float blah[] = {42}; RiSphere(2, -2, 2, 360, "float blah", blah, RI_NULL); int nvertices[] = {5}; float P[] = {-1,-1,0, 1,-1,0, 1,1,0, -1,1,0, -1,-1,2}; float width[] = {1, 2, 3}; RiCurves((char*)"cubic", 1, nvertices, (char*)"nonperiodic", "P", P, "width", width, RI_NULL); RiWorldEnd(); RiFrameEnd(); RiEnd(); // Stream the output buffer to stdout std::cout << output.str(); return 0; }
RtVoid Subdivide(RtPointer data, RtFloat detail) { RtFloat *curve_width = (RtFloat *)data; RtInt nverts[1] = {2}; RtFloat plist[6]={0.0,0.0,0.0,0.0,1.0,0.0}; RtFloat wlist[2]={*curve_width, 0.0}; RiDeclare("width","[varying] [float] []"); /* output a curve with the given width */ RiCurves ( (RtToken)"linear", 1, nverts, (RtToken)"periodic", (RtToken)"P", plist, (RtToken)"width", wlist); }
void RVane::generateRIB(RtFloat detail) { int g_seed = 13; float bnoi, vnoi; FVane* fv = new FVane(); FBSpline* lenspline = new FBSpline(); lenspline->create(NUMSPLCV, plencv); lenspline->setEnd(-5,-5); FBSpline* angspline = new FBSpline(); angspline->create(NUMSPLCV, pangcv); angspline->setEnd(30, 90); int n_cv=0; int n_curve, n_curve_up, n_curve_down; int jn; float epsilon_up, epsilon_down, S, T, rT, ss, sv, vane_length, rang, lsegup, lsegdown, rot; while(map->getVane(n_cv)) { XYZ* plist = new XYZ[n_cv]; XYZ* ulist = new XYZ[n_cv]; XYZ* dlist = new XYZ[n_cv]; XYZ* nknot = new XYZ[n_cv]; map->getData(plist, ulist, dlist, nknot); fv->create(n_cv, plist, ulist, dlist, nknot); vane_length = fv->getLength(); n_curve_up = vane_length*0.99/m_g_width/1.19;//n_curve_up/=10; epsilon_up = 1.0/n_curve_up; n_curve_down = n_curve_up;//n_curve_down/=10; epsilon_down = epsilon_up; n_curve = n_curve_up + n_curve_down; int* nvertices = new int[n_curve]; float* widtharray = new float[n_curve*NUMPARAM]; // setup vertex width for(int i=0; i<n_curve; i++) { nvertices[i] = NUMCV; widtharray[i*NUMPARAM]= m_g_width*1.f; widtharray[i*NUMPARAM+1]= m_g_width*1.f; widtharray[i*NUMPARAM+2]= m_g_width*1.f; widtharray[i*NUMPARAM+3]= m_g_width*1.f; widtharray[i*NUMPARAM+4]= m_g_width*1.f; widtharray[i*NUMPARAM+5]= m_g_width*1.f; widtharray[i*NUMPARAM+6]= m_g_width*0.8f; widtharray[i*NUMPARAM+7]= m_g_width*0.3f; } float unitsup = ulist[0].length()*2; float unitsdown = dlist[0].length()*2; float unitt = fv->getLength(); // get up curve seg length float glsegup = ulist[0].length()*1.414f/NUMSEG; // get down curve seg length float glsegdown = dlist[0].length()*1.414f/NUMSEG; // set mean angle float ang_mean; XYZ* pp = new XYZ[n_curve*NUMCV]; XYZ* pnormal = new XYZ[n_curve*NUMPARAM]; float* pCoordS = new float[n_curve*NUMPARAM]; float* pCoordT = new float[n_curve*NUMPARAM]; bnoi = randfint( g_seed )*0.13; g_seed++; vnoi = randfint( g_seed ); g_seed++; int vxacc = 0, paramacc = 0; for(int i=0; i<n_curve_up; i++) { // init start coordinate S = 0.5; T = epsilon_up*i; lsegup = glsegup*lenspline->getValue(T); ang_mean = angspline->getValue(T)*0.01745331; if(T>bnoi) { vnoi = randfint( g_seed ); g_seed++; bnoi += randfint( g_seed )*0.1; g_seed++; } if(i%7==0) { rot = (randfint( g_seed )-.5) * 0.06; g_seed++; } ang_mean = angspline->getValue(T)*0.01745331 + vnoi*.05f; pp[vxacc] = fv->getPointAt(S, T, pnormal[paramacc]); pp[vxacc+1] = pp[vxacc+2] = pp[vxacc]; pnormal[paramacc+1] = pnormal[paramacc]; pCoordS[paramacc] = pCoordS[paramacc+1] = S; pCoordT[paramacc] = pCoordT[paramacc+1] = 1.-T; for(int j=1; j<=NUMSEG; j++) { rang = ang_offset[j-1]* 0.01745331; if(j>3) { rang += rot; } S -= lsegup*cos(ang_mean + rang)/unitsup; T += lsegup*sin(ang_mean + rang)/unitt; pp[vxacc+j+2] = fv->getPointAt(S, T, pnormal[paramacc+j+1]); pCoordS[paramacc+j+1] = S; pCoordT[paramacc+j+1] = 1.-T; } pp[vxacc+NUMSEG+3] = pp[vxacc+NUMSEG+4] = pp[vxacc+NUMSEG+2]; pnormal[paramacc+NUMSEG+2] = pnormal[paramacc+NUMSEG+1]; pCoordS[paramacc+NUMSEG+2] = S; pCoordT[paramacc+NUMSEG+2] = 1.-T; vxacc += NUMCV; paramacc += NUMPARAM; } bnoi = randfint( g_seed )*0.13; g_seed++; vnoi = randfint( g_seed ); g_seed++; for(int i=0; i<n_curve_down; i++) { // init start coordinate S = 0.5; T = epsilon_down*i; lsegdown = glsegdown*lenspline->getValue(T); ang_mean = angspline->getValue(T)*0.01745331; if(T>bnoi) { vnoi = randfint( g_seed ); g_seed++; bnoi += randfint( g_seed )*0.13; g_seed++; } if(i%7==0) { rot = (randfint( g_seed )-.5) * 0.06; g_seed++; } ang_mean = angspline->getValue(T)*0.01745331 + vnoi*.05f; pp[vxacc] = fv->getPointAt(S, T, pnormal[paramacc]); pp[vxacc+1] = pp[vxacc+2] = pp[vxacc]; pnormal[paramacc+1] = pnormal[paramacc]; pCoordS[paramacc] = pCoordS[paramacc+1] = S; pCoordT[paramacc] = pCoordT[paramacc+1] = 1.-T; for(int j=1; j<=NUMSEG; j++) { rang = ang_offset[j-1]* 0.01745331; if(j>3) rang += rot; S += lsegdown*cos(ang_mean + rang)/unitsdown; T += lsegdown*sin(ang_mean + rang)/unitt; pp[vxacc+j+2] = fv->getPointAt(S, T, pnormal[paramacc+j+1]); pCoordS[paramacc+j+1] = S; pCoordT[paramacc+j+1] = 1.-T; } pp[vxacc+NUMSEG+3] = pp[vxacc+NUMSEG+4] = pp[vxacc+NUMSEG+2]; pnormal[paramacc+NUMSEG+2] = pnormal[paramacc+NUMSEG+1]; pCoordS[paramacc+NUMSEG+2] = S; pCoordT[paramacc+NUMSEG+2] = 1.-T; vxacc += NUMCV; paramacc += NUMPARAM; } RiCurves ( "cubic", (RtInt)n_curve, (RtInt*) nvertices, "nonperiodic", "P", (RtPoint*)pp, "width", (RtFloat*)widtharray, "varying normal surface_n", (RtPoint*)pnormal, "varying float s", (RtFloat*)pCoordS, "varying float t", (RtFloat*)pCoordT, RI_NULL); delete[] pp; delete[] pnormal; delete[] pCoordS; delete[] pCoordT; delete[] nvertices; delete[] widtharray; delete[] plist; delete[] ulist; delete[] dlist; delete[] nknot; map->next(); } return; }
MStatus ribGenCmd::doIt( const MArgList& args) { /*=========================================* * the parameters of command * =========================================*/ MString ribPath, shaderPath; unsigned index; index = args.flagIndex("p", "ribPath"); if(MArgList::kInvalidArgIndex != index) args.get(index+1, ribPath); index = args.flagIndex("sp", "shaderPath"); if(MArgList::kInvalidArgIndex != index) args.get(index+1, shaderPath); /*=========================================* * shaderPath & ribPath *=========================================*/ RtToken shader= new char[50] , path=new char[50]; strcpy(shader, shaderPath.asChar()); strcpy(path, ribPath.asChar()); char *curve[] = {"curves"}; RtMatrix identityMatrix = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 }}; RtInt ustep, vstep; ustep = vstep =1; /*=====================================* * Begenning of writting out the .rib file. *=====================================*/ RiBegin(path); RiAttributeBegin(); RiTransformBegin(); //RiSurface(shader); RiTransformEnd(); //RiAttribute("identifier", "name", curve); RiConcatTransform(identityMatrix); RiShadingInterpolation(RI_SMOOTH); RiBasis(RiBezierBasis, ustep, RiBezierBasis, vstep); int nodeId = 0, knotNum = 0; float baseWidth = 0.0f, tipWidth = 0.0f; MObject surface, node; /*=========================================* * get the informations of selected Objects in scene. *=========================================*/ MSelectionList selection; MGlobal::getActiveSelectionList(selection); MItSelectionList iter(selection, MFn::kNurbsSurface ); for(; !iter.isDone(); iter.next()) { RtInt numCurves = 0; RtInt numVertexs = 0; /*======================================* * get the drawHairNode from selected NurbsSurface. *======================================*/ iter.getDependNode(surface); MFnDependencyNode surfaceFn(surface); MStatus state; MPlug plug = surfaceFn.findPlug("worldSpace",false, &state); plug = plug.elementByLogicalIndex(0); MPlugArray desPlugs; plug.connectedTo(desPlugs,false,true); plug = desPlugs[0]; node = plug.node(); //drawHairNode has found here!! /*=====================================* * get the attributes of drawHairNode. *=====================================*/ MFnDependencyNode hairNodeFn(node); plug = hairNodeFn.findPlug("nodeId"); plug.getValue(nodeId); MGlobal::displayInfo(MString(" nodeId: ")+nodeId); plug = hairNodeFn.findPlug("number"); plug.getValue(numCurves); plug= hairNodeFn.findPlug("smooth"); plug.getValue(knotNum); plug = hairNodeFn.findPlug("baseWidth"); plug.getValue(baseWidth); plug = hairNodeFn.findPlug("tipWidth"); plug.getValue(tipWidth); /*=====================================* * caculate the linear interpolate of the width of the curve. *=====================================*/ numVertexs = numCurves * knotNum; int widthNum = numCurves * (knotNum -2 ); float *curveWidth = new float[widthNum]; float widthStep = 0.0f; for(int c=0; c<widthNum; ++c){ widthStep = ((c%(knotNum-2)) / (float)(knotNum-3)) *(tipWidth - baseWidth); if(widthStep < epslion) widthStep = 0.0f; curveWidth[c] = baseWidth + widthStep; } RtInt *nvertices = new RtInt[numCurves]; //the numbers of vertices on each curve. RtPoint *vertexs = new RtPoint[numVertexs]; //the total vertexs. /*=====================================* * nvertices[] assignment. *=====================================*/ for(int j=0; j<numCurves ; ++j){ nvertices[j] = knotNum; } /*=====================================* * get the hair's datas from the static member * named "nodeManager" of the drawHairNode class. *=====================================*/ nodeMap::iterator iter = drawHairNode::nodeManager.find(nodeId); vector<MPointArray> helixVec = iter->second; /*=====================================* * vertexs[] assignment. *=====================================*/ float x=0, y=0, z=0; int countVT=0; for(vector<MPointArray>::iterator it=helixVec.begin(); it != helixVec.end(); ++it){ MPointArray helixCurve = (MPointArray)(*it); for(int k=0; k < helixCurve.length() ; ++k){ x = helixCurve[k].x; if(fabs(x) < epslion) vertexs[countVT][0] = 0; else vertexs[countVT][0] = helixCurve[k].x; y = helixCurve[k].y; if(fabs(y) < epslion) vertexs[countVT][1] = 0; else vertexs[countVT][1] = helixCurve[k].y; z = helixCurve[k].z; if(fabs(z) < epslion) vertexs[countVT++][2] = 0; else vertexs[countVT++][2] = helixCurve[k].z; } } RiCurves( RI_CUBIC, numCurves, nvertices, RI_NONPERIODIC, RI_P, vertexs, RI_WIDTH, curveWidth, RI_NULL); } RiAttributeEnd(); RiEnd(); return redoIt(); }