aboutsummaryrefslogtreecommitdiff
path: root/libexe/lotswf.c
blob: 5cd846e382e22f9dbc56306d9939c49fe5e2d9bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// 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);
	}

}