// Shave and a Haircut // (c) 2019 Epic Games // US Patent 6720962 #include "basehair_tools.c" #include "lotswfrs.c" void MTcolor_clumpy( BASEHAIR *,BASEHAIR *, GLOBS * ); extern void MAYAmake_a_curve( int current_samp, int slg, int hairnum, int segs, WFTYPE * ret, CURVEINFO * cret ) { VERT offs; WFTYPE geom; int th = 0; int x; //float rr; int hc = 0; int hc2 = 0; //char tmp[255]; int tv = 0; //int didit; offs.x = 0; offs.y = 0; offs.z = 0; global_segs = 56; cret->killme = 1; if( ret->totalverts > 0 ) free_geomWF( ret ); ret->totalverts = 0; ret->totalfaces = 0; ret->totalfverts = 0; geom.totalverts = 0; init_geomWF( ret ); init_geomWF( &geom ); // free_geom(ret); ret->totalverts = 0; ret->totalfaces = 0; ret->totalfverts = 0; if( LOCAL_PASSES[slg] > 0 ) current_samp = current_samp % LOCAL_PASSES[slg]; GhairID = hairnum; Gcurpass=current_samp; Gpass = Gcurpass; cret->depthpass = Gcurpass; cret->hairID = hairnum; if( total_slgfaces[slg] > 0 ) if( LOCAL_CNT[slg] > 0 ) if( LOCAL_PASSES[slg] > 0 ) { int clones = 0; int q; clones = make_spline_hair( slg, hairnum, 0, segs, &geom, cret ); if( cret->killme == 0 ) { if( clones == 0 ) clones = 1; ret->totalverts = geom.totalverts * ( clones + 1 ); ret->totalfverts = geom.totalfverts * ( clones + 1 ); ret->totalfaces = geom.totalfaces * ( clones + 1 ); if( ret->totalverts > 0 ) alloc_geomWF( ret ); ret->totalverts = 0; ret->totalfverts = 0; ret->totalfaces = 0; for( q = 0; q < clones; q++ ) { int off, foff; int jnk; if( q != 0 ) jnk = make_spline_hair( slg, hairnum, q, segs, &geom, cret ); if( geom.totalverts > 0 ) { off = geom.totalverts * q; for( x = 0; x < geom.totalverts; x++ ) { ret->v[ret->totalverts] = geom.v[x]; ret->v[ret->totalverts].z *= -1.0f; ret->uv[ret->totalverts].x = cret->u; ret->uv[ret->totalverts].y = cret->v; ret->uv[ret->totalverts].z = geom.uv[x].z; ret->velocity[ret->totalverts] = geom.velocity[x]; ret->velocity[ret->totalverts].z *= -1.0f; ret->color[ret->totalverts] = geom.color[x]; ret->totalverts++; } for( x = 0; x < geom.totalfverts; x++ ) { ret->facelist[ret->totalfverts] = geom.facelist[x] + off; ret->totalfverts++; } foff = geom.totalfverts * q; for( x = 0; x < geom.totalfaces; x++ ) { ret->face_start[ret->totalfaces] = geom.face_start[x] + off; ret->face_end[ret->totalfaces] = geom.face_end[x] + off; ret->totalfaces++; } } } } free_geomWF( &geom ); } for( x = 0; x < ret->totalfaces; x++ ) { float tp; int y; tp = ( float ) ( ret->face_end[x] - ret->face_start[x] ); tp -= 1; if( tp < 1 ) tp = 1; for( y = ret->face_start[x]; y < ret->face_end[x]; y++ ) { ret->uv[ret->facelist[y]].z = ( float ) ( y - ret->face_start[x] ) / tp; } } cret->depthpass = current_samp; cret->hairID = hairnum; } int MTmake_spline_hair( int slg, int hairnum, int clone, int segs, WFTYPE * geom, CURVEINFO * cinfo, GLOBS * gs ) { VERT offs; int index = 0; // float rr; // int x; BASEHAIR lowhair; init_a_hair(&lowhair); //static BASEHAIR hh[1]; ////WFTYPE tmpwf; global_segs = 56; //// init_geomWF(&tmpwf); ////tmpwf.v=NULL; ////tmpwf.totalverts=segs; // offs.x=0.0f; // offs.y=0.0f; // offs.z=0.0f; offs.x = 0.0f; offs.y = 0.0f; offs.z = 0.0f; // geom->totalverts=0; ////if (clone==0) { // int yy; //lowhair[0]= //#ifndef NOLIB gs->segs=segs; MTdraw_lotsWF( slg, hairnum, offs, clone, &lowhair, cinfo, gs ); // fprintf (stdout,"A lowhair.index = %d\n",lowhair.index);fflush(stdout); //#endif //#ifdef NOLIB // draw_lotsWFFAST(slg,hairnum,offs,clone,&lowhair,cinfo); //#endif } // lowhair[0]=draw_lotsWFNEW(0,0,offs,1,junkh); /// resample(lowhair[0],&hh[0]); // hh[0]=cut_single_hair(hh[0]); // hh[0]=cut_single_base_hair(hh[0]); index = 1; free_geomWF( geom ); // if (lowhair.killme==0) if( cinfo->killme == 0 ) //// if (lowhair.restlength>0) if( lowhair.cutlength == 0.0f ) cinfo->killme = 1; if( cinfo->killme == 0 ) if (lowhair.cutlength>0) { int xx; //geom will get allocated in here? resize_base_hair( &lowhair, geom, cinfo, segs ); // fprintf (stdout,"B geom->index[0] = %d\n",geom->index[0]);fflush(stdout); //geom->totalverts=segs; geom->totalfaces = 1; //geom->totalfverts=segs; //alloc_geomWF(geom); for( xx = 0; xx < geom->totalverts; xx++ ) geom->facelist[xx] = xx; geom->face_start[0] = 0; geom->face_end[0] = geom->totalverts; if( lowhair.cutlength == 0 ) cinfo->killme = 1; //mk_spline_geom(&hh[0], geom, segs); } if( cinfo->killme ) { // lowhair.dreadcount = 0; geom->totalverts = 0; geom->totalfaces = 0; geom->totalfverts = 0; } return ( ( int ) lowhair.dreadcount ); } void MTcolor_clumpy( BASEHAIR *h,BASEHAIR *centerClump, GLOBS *gs ) { int x; for (x=0;x<15;x++) { float qq; qq=h->clump_color_strength; if (qq>1.0f) qq=1.0f; if (qq<0.0f) qq=0.0f; h->color[x].x=h->color[x].x*(1.0-qq)+centerClump->color[x].x*(qq); h->color[x].y=h->color[x].y*(1.0-qq)+centerClump->color[x].y*(qq); h->color[x].z=h->color[x].z*(1.0-qq)+centerClump->color[x].z*(qq); } }