2012-12-28 14:21:30 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2012-12-28 14:21:30 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2012-12-28 14:21:30 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-12-28 14:21:30 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License
|
2012-12-28 14:21:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "device.h"
|
|
|
|
#include "curves.h"
|
|
|
|
#include "mesh.h"
|
|
|
|
#include "object.h"
|
|
|
|
#include "scene.h"
|
|
|
|
|
|
|
|
#include "util_foreach.h"
|
|
|
|
#include "util_map.h"
|
|
|
|
#include "util_progress.h"
|
|
|
|
#include "util_vector.h"
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2013-01-15 19:44:41 +00:00
|
|
|
/* Curve functions */
|
|
|
|
|
|
|
|
void curvebounds(float *lower, float *upper, float3 *p, int dim)
|
|
|
|
{
|
|
|
|
float *p0 = &p[0].x;
|
|
|
|
float *p1 = &p[1].x;
|
|
|
|
float *p2 = &p[2].x;
|
|
|
|
float *p3 = &p[3].x;
|
2013-08-23 12:19:35 +00:00
|
|
|
|
2013-01-15 19:44:41 +00:00
|
|
|
float fc = 0.71f;
|
|
|
|
float curve_coef[4];
|
|
|
|
curve_coef[0] = p1[dim];
|
|
|
|
curve_coef[1] = -fc*p0[dim] + fc*p2[dim];
|
|
|
|
curve_coef[2] = 2.0f * fc * p0[dim] + (fc - 3.0f) * p1[dim] + (3.0f - 2.0f * fc) * p2[dim] - fc * p3[dim];
|
|
|
|
curve_coef[3] = -fc * p0[dim] + (2.0f - fc) * p1[dim] + (fc - 2.0f) * p2[dim] + fc * p3[dim];
|
2013-08-23 12:19:35 +00:00
|
|
|
|
2013-01-15 19:44:41 +00:00
|
|
|
float discroot = curve_coef[2] * curve_coef[2] - 3 * curve_coef[3] * curve_coef[1];
|
|
|
|
float ta = -1.0f;
|
|
|
|
float tb = -1.0f;
|
|
|
|
if(discroot >= 0) {
|
|
|
|
discroot = sqrt(discroot);
|
|
|
|
ta = (-curve_coef[2] - discroot) / (3 * curve_coef[3]);
|
|
|
|
tb = (-curve_coef[2] + discroot) / (3 * curve_coef[3]);
|
|
|
|
ta = (ta > 1.0f || ta < 0.0f) ? -1.0f : ta;
|
|
|
|
tb = (tb > 1.0f || tb < 0.0f) ? -1.0f : tb;
|
|
|
|
}
|
|
|
|
|
|
|
|
*upper = max(p1[dim],p2[dim]);
|
|
|
|
*lower = min(p1[dim],p2[dim]);
|
|
|
|
float exa = p1[dim];
|
|
|
|
float exb = p2[dim];
|
|
|
|
float t2;
|
|
|
|
float t3;
|
|
|
|
if(ta >= 0.0f) {
|
|
|
|
t2 = ta * ta;
|
|
|
|
t3 = t2 * ta;
|
|
|
|
exa = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * ta + curve_coef[0];
|
|
|
|
}
|
|
|
|
if(tb >= 0.0f) {
|
|
|
|
t2 = tb * tb;
|
|
|
|
t3 = t2 * tb;
|
|
|
|
exb = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * tb + curve_coef[0];
|
|
|
|
}
|
|
|
|
*upper = max(*upper, max(exa,exb));
|
|
|
|
*lower = min(*lower, min(exa,exb));
|
|
|
|
}
|
|
|
|
|
2012-12-28 14:21:30 +00:00
|
|
|
/* Hair System Manager */
|
|
|
|
|
|
|
|
CurveSystemManager::CurveSystemManager()
|
|
|
|
{
|
|
|
|
primitive = CURVE_LINE_SEGMENTS;
|
2013-08-18 13:41:53 +00:00
|
|
|
curve_shape = CURVE_THICK;
|
2012-12-28 14:21:30 +00:00
|
|
|
line_method = CURVE_CORRECTED;
|
2013-01-15 19:44:41 +00:00
|
|
|
triangle_method = CURVE_CAMERA_TRIANGLES;
|
2012-12-28 14:21:30 +00:00
|
|
|
resolution = 3;
|
2013-01-15 19:44:41 +00:00
|
|
|
subdivisions = 3;
|
2012-12-28 14:21:30 +00:00
|
|
|
|
|
|
|
encasing_ratio = 1.01f;
|
2013-04-15 21:38:31 +00:00
|
|
|
minimum_width = 0.0f;
|
|
|
|
maximum_width = 0.0f;
|
2012-12-28 14:21:30 +00:00
|
|
|
|
|
|
|
use_curves = true;
|
|
|
|
use_encasing = true;
|
|
|
|
use_backfacing = false;
|
|
|
|
use_tangent_normal = false;
|
|
|
|
use_tangent_normal_geometry = false;
|
|
|
|
|
|
|
|
need_update = true;
|
|
|
|
need_mesh_update = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CurveSystemManager::~CurveSystemManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CurveSystemManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
|
|
|
|
{
|
|
|
|
if(!need_update)
|
|
|
|
return;
|
|
|
|
|
|
|
|
device_free(device, dscene);
|
|
|
|
|
|
|
|
progress.set_status("Updating Hair settings", "Copying Hair settings to device");
|
|
|
|
|
2013-08-11 15:27:04 +00:00
|
|
|
KernelCurves *kcurve= &dscene->data.curve;
|
2012-12-28 14:21:30 +00:00
|
|
|
|
|
|
|
kcurve->curveflags = 0;
|
|
|
|
|
2013-01-15 19:44:41 +00:00
|
|
|
if(use_curves) {
|
|
|
|
if(primitive == CURVE_SEGMENTS || primitive == CURVE_RIBBONS)
|
|
|
|
kcurve->curveflags |= CURVE_KN_INTERPOLATE;
|
|
|
|
if(primitive == CURVE_RIBBONS)
|
|
|
|
kcurve->curveflags |= CURVE_KN_RIBBONS;
|
|
|
|
|
|
|
|
if(line_method == CURVE_ACCURATE)
|
|
|
|
kcurve->curveflags |= CURVE_KN_ACCURATE;
|
|
|
|
if(line_method == CURVE_CORRECTED)
|
|
|
|
kcurve->curveflags |= CURVE_KN_INTERSECTCORRECTION;
|
|
|
|
if(line_method == CURVE_POSTCORRECTED)
|
|
|
|
kcurve->curveflags |= CURVE_KN_POSTINTERSECTCORRECTION;
|
|
|
|
|
|
|
|
if(use_tangent_normal)
|
|
|
|
kcurve->curveflags |= CURVE_KN_TANGENTGNORMAL;
|
|
|
|
if(use_tangent_normal_geometry)
|
|
|
|
kcurve->curveflags |= CURVE_KN_TRUETANGENTGNORMAL;
|
|
|
|
if(use_backfacing)
|
|
|
|
kcurve->curveflags |= CURVE_KN_BACKFACING;
|
|
|
|
if(use_encasing)
|
|
|
|
kcurve->curveflags |= CURVE_KN_ENCLOSEFILTER;
|
|
|
|
|
|
|
|
kcurve->encasing_ratio = encasing_ratio;
|
2013-04-15 21:38:31 +00:00
|
|
|
kcurve->minimum_width = minimum_width;
|
|
|
|
kcurve->maximum_width = maximum_width;
|
2013-01-15 19:44:41 +00:00
|
|
|
kcurve->subdivisions = subdivisions;
|
|
|
|
}
|
2012-12-28 14:21:30 +00:00
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
|
|
|
need_update = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CurveSystemManager::device_free(Device *device, DeviceScene *dscene)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CurveSystemManager::modified(const CurveSystemManager& CurveSystemManager)
|
|
|
|
{
|
2013-08-18 13:41:53 +00:00
|
|
|
return !(curve_shape == CurveSystemManager.curve_shape &&
|
|
|
|
line_method == CurveSystemManager.line_method &&
|
2012-12-28 14:21:30 +00:00
|
|
|
primitive == CurveSystemManager.primitive &&
|
|
|
|
use_encasing == CurveSystemManager.use_encasing &&
|
|
|
|
use_tangent_normal == CurveSystemManager.use_tangent_normal &&
|
|
|
|
use_tangent_normal_geometry == CurveSystemManager.use_tangent_normal_geometry &&
|
|
|
|
encasing_ratio == CurveSystemManager.encasing_ratio &&
|
2013-04-15 21:38:31 +00:00
|
|
|
minimum_width == CurveSystemManager.minimum_width &&
|
|
|
|
maximum_width == CurveSystemManager.maximum_width &&
|
2012-12-28 14:21:30 +00:00
|
|
|
use_backfacing == CurveSystemManager.use_backfacing &&
|
|
|
|
triangle_method == CurveSystemManager.triangle_method &&
|
|
|
|
resolution == CurveSystemManager.resolution &&
|
|
|
|
use_curves == CurveSystemManager.use_curves &&
|
2013-01-15 19:44:41 +00:00
|
|
|
subdivisions == CurveSystemManager.subdivisions);
|
2012-12-28 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CurveSystemManager::modified_mesh(const CurveSystemManager& CurveSystemManager)
|
|
|
|
{
|
|
|
|
return !(primitive == CurveSystemManager.primitive &&
|
2013-08-18 13:41:53 +00:00
|
|
|
curve_shape == CurveSystemManager.curve_shape &&
|
2012-12-28 14:21:30 +00:00
|
|
|
triangle_method == CurveSystemManager.triangle_method &&
|
|
|
|
resolution == CurveSystemManager.resolution &&
|
2013-08-18 13:41:53 +00:00
|
|
|
use_curves == CurveSystemManager.use_curves);
|
2012-12-28 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CurveSystemManager::tag_update(Scene *scene)
|
|
|
|
{
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CurveSystemManager::tag_update_mesh()
|
|
|
|
{
|
|
|
|
need_mesh_update = true;
|
|
|
|
}
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|