2
* Copyright 2011, Blender Foundation.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
#include "util_foreach.h"
27
#include "util_progress.h"
28
#include "util_vector.h"
34
void curvebounds(float *lower, float *upper, float3 *p, int dim)
42
curve_coef[0] = p1[dim];
43
curve_coef[1] = -fc*p0[dim] + fc*p2[dim];
44
curve_coef[2] = 2.0f * fc * p0[dim] + (fc - 3.0f) * p1[dim] + (3.0f - 2.0f * fc) * p2[dim] - fc * p3[dim];
45
curve_coef[3] = -fc * p0[dim] + (2.0f - fc) * p1[dim] + (fc - 2.0f) * p2[dim] + fc * p3[dim];
46
float discroot = curve_coef[2] * curve_coef[2] - 3 * curve_coef[3] * curve_coef[1];
50
discroot = sqrt(discroot);
51
ta = (-curve_coef[2] - discroot) / (3 * curve_coef[3]);
52
tb = (-curve_coef[2] + discroot) / (3 * curve_coef[3]);
53
ta = (ta > 1.0f || ta < 0.0f) ? -1.0f : ta;
54
tb = (tb > 1.0f || tb < 0.0f) ? -1.0f : tb;
57
*upper = max(p1[dim],p2[dim]);
58
*lower = min(p1[dim],p2[dim]);
66
exa = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * ta + curve_coef[0];
71
exb = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * tb + curve_coef[0];
73
*upper = max(*upper, max(exa,exb));
74
*lower = min(*lower, min(exa,exb));
78
/* Hair System Manager */
80
CurveSystemManager::CurveSystemManager()
82
primitive = CURVE_LINE_SEGMENTS;
83
line_method = CURVE_CORRECTED;
84
interpolation = CURVE_CARDINAL;
85
triangle_method = CURVE_CAMERA_TRIANGLES;
91
encasing_ratio = 1.01f;
97
use_backfacing = false;
99
use_tangent_normal = false;
100
use_tangent_normal_geometry = false;
101
use_tangent_normal_correction = false;
104
need_mesh_update = false;
107
CurveSystemManager::~CurveSystemManager()
111
void CurveSystemManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
116
device_free(device, dscene);
118
progress.set_status("Updating Hair settings", "Copying Hair settings to device");
120
KernelCurves *kcurve= &dscene->data.curve_kernel_data;
122
kcurve->curveflags = 0;
125
if(primitive == CURVE_SEGMENTS || primitive == CURVE_RIBBONS)
126
kcurve->curveflags |= CURVE_KN_INTERPOLATE;
127
if(primitive == CURVE_RIBBONS)
128
kcurve->curveflags |= CURVE_KN_RIBBONS;
130
if(line_method == CURVE_ACCURATE)
131
kcurve->curveflags |= CURVE_KN_ACCURATE;
132
if(line_method == CURVE_CORRECTED)
133
kcurve->curveflags |= CURVE_KN_INTERSECTCORRECTION;
134
if(line_method == CURVE_POSTCORRECTED)
135
kcurve->curveflags |= CURVE_KN_POSTINTERSECTCORRECTION;
137
if(use_tangent_normal)
138
kcurve->curveflags |= CURVE_KN_TANGENTGNORMAL;
139
if(use_tangent_normal_correction)
140
kcurve->curveflags |= CURVE_KN_NORMALCORRECTION;
141
if(use_tangent_normal_geometry)
142
kcurve->curveflags |= CURVE_KN_TRUETANGENTGNORMAL;
144
kcurve->curveflags |= CURVE_KN_CURVEDATA;
146
kcurve->curveflags |= CURVE_KN_BACKFACING;
148
kcurve->curveflags |= CURVE_KN_ENCLOSEFILTER;
150
kcurve->normalmix = normalmix;
151
kcurve->encasing_ratio = encasing_ratio;
152
kcurve->subdivisions = subdivisions;
155
if(progress.get_cancel()) return;
160
void CurveSystemManager::device_free(Device *device, DeviceScene *dscene)
165
bool CurveSystemManager::modified(const CurveSystemManager& CurveSystemManager)
167
return !(line_method == CurveSystemManager.line_method &&
168
interpolation == CurveSystemManager.interpolation &&
169
primitive == CurveSystemManager.primitive &&
170
use_encasing == CurveSystemManager.use_encasing &&
171
use_tangent_normal == CurveSystemManager.use_tangent_normal &&
172
use_tangent_normal_correction == CurveSystemManager.use_tangent_normal_correction &&
173
use_tangent_normal_geometry == CurveSystemManager.use_tangent_normal_geometry &&
174
encasing_ratio == CurveSystemManager.encasing_ratio &&
175
use_backfacing == CurveSystemManager.use_backfacing &&
176
normalmix == CurveSystemManager.normalmix &&
177
use_smooth == CurveSystemManager.use_smooth &&
178
triangle_method == CurveSystemManager.triangle_method &&
179
resolution == CurveSystemManager.resolution &&
180
use_curves == CurveSystemManager.use_curves &&
181
use_joined == CurveSystemManager.use_joined &&
182
segments == CurveSystemManager.segments &&
183
use_parents == CurveSystemManager.use_parents &&
184
subdivisions == CurveSystemManager.subdivisions);
187
bool CurveSystemManager::modified_mesh(const CurveSystemManager& CurveSystemManager)
189
return !(primitive == CurveSystemManager.primitive &&
190
interpolation == CurveSystemManager.interpolation &&
191
use_parents == CurveSystemManager.use_parents &&
192
use_smooth == CurveSystemManager.use_smooth &&
193
triangle_method == CurveSystemManager.triangle_method &&
194
resolution == CurveSystemManager.resolution &&
195
use_curves == CurveSystemManager.use_curves &&
196
use_joined == CurveSystemManager.use_joined &&
197
segments == CurveSystemManager.segments);
200
void CurveSystemManager::tag_update(Scene *scene)
205
void CurveSystemManager::tag_update_mesh()
207
need_mesh_update = true;