Merged changes in the trunk up to revision 41225.
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sat, 29 Oct 2011 15:46:14 +0000 (15:46 +0000)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sat, 29 Oct 2011 15:46:14 +0000 (15:46 +0000)
Conflicts resolved:
source/blender/render/intern/source/pipeline.c

33 files changed:
1  2 
build_files/scons/tools/Blender.py
doc/python_api/sphinx_doc_gen.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenkernel/SConscript
source/blender/blenkernel/intern/BME_conversions.c
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/linestyle.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenlib/CMakeLists.txt
source/blender/blenlib/intern/bpath.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/resources.c
source/blender/editors/render/render_shading.c
source/blender/editors/space_file/filelist.c
source/blender/editors/space_nla/nla_buttons.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_orientations.c
source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
source/blender/makesrna/RNA_access.h
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_action.c
source/blender/makesrna/intern/rna_mesh.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_userdef.c
source/blender/render/CMakeLists.txt
source/blender/render/SConscript
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/source/pipeline.c
source/blenderplayer/bad_level_call_stubs/stubs.c
source/creator/CMakeLists.txt
source/creator/creator.c

Simple merge
Simple merge
Simple merge
index faf4b11f489d4dc6a43a190f3ac1656576b7938b,0000000000000000000000000000000000000000..177cc64aa40dc84a3fd88bced11529a7290daf73
mode 100644,000000..100644
--- /dev/null
@@@ -1,578 -1,0 +1,578 @@@
-       BLI_uniquename(lb, m, modifier_name[m->type], '.', BLI_STRUCT_OFFSET(LineStyleModifier, name), sizeof(m->name));
 +/* linestyle.c
 + *
 + * $Id$
 + *
 + * ***** BEGIN GPL LICENSE BLOCK *****
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * The Original Code is Copyright (C) 2010 Blender Foundation.
 + * All rights reserved.
 + *
 + * The Original Code is: all of this file.
 + *
 + * Contributor(s): none yet.
 + *
 + * ***** END GPL LICENSE BLOCK *****
 + */
 +
 +#include <stdio.h>
 +#include <stdlib.h>
 +#include <string.h>
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "DNA_material_types.h" /* for ramp blend */
 +#include "DNA_texture_types.h"
 +
 +#include "BKE_global.h"
 +#include "BKE_library.h"
 +#include "BKE_linestyle.h"
 +#include "BKE_main.h"
 +#include "BKE_texture.h"
 +#include "BKE_colortools.h"
 +#include "BKE_animsys.h"
 +
 +#include "BLI_blenlib.h"
 +
 +static char *modifier_name[LS_MODIFIER_NUM] = {
 +      NULL,
 +      "Along Stroke",
 +      "Distance from Camera",
 +      "Distance from Object",
 +      "Material",
 +      "Sampling",
 +      "Bezier Curve",
 +      "Sinus Displacement",
 +      "Spatial Noise",
 +      "Perlin Noise 1D",
 +      "Perlin Noise 2D",
 +      "Backbone Stretcher",
 +      "Tip Remover",
 +      "Calligraphy"};
 +
 +static void default_linestyle_settings(FreestyleLineStyle *linestyle)
 +{
 +      linestyle->panel = LS_PANEL_STROKES;
 +      linestyle->r = linestyle->g = linestyle->b = 0.0;
 +      linestyle->alpha = 1.0;
 +      linestyle->thickness = 1.0;
 +      linestyle->chaining = LS_CHAINING_PLAIN;
 +      linestyle->rounds = 3;
 +      linestyle->min_length = 0.0f;
 +      linestyle->max_length = 10000.0f;
 +
 +      linestyle->color_modifiers.first = linestyle->color_modifiers.last = NULL;
 +      linestyle->alpha_modifiers.first = linestyle->alpha_modifiers.last = NULL;
 +      linestyle->thickness_modifiers.first = linestyle->thickness_modifiers.last = NULL;
 +      linestyle->geometry_modifiers.first = linestyle->geometry_modifiers.last = NULL;
 +
 +      FRS_add_linestyle_geometry_modifier(linestyle, LS_MODIFIER_SAMPLING);
 +
 +      linestyle->caps = LS_CAPS_BUTT;
 +}
 +
 +FreestyleLineStyle *FRS_new_linestyle(char *name, struct Main *main)
 +{
 +      FreestyleLineStyle *linestyle;
 +
 +      if (!main)
 +              main = G.main;
 +
 +      linestyle = (FreestyleLineStyle *)alloc_libblock(&main->linestyle, ID_LS, name);
 +      
 +      default_linestyle_settings(linestyle);
 +
 +      return linestyle;
 +}
 +
 +void FRS_free_linestyle(FreestyleLineStyle *linestyle)
 +{
 +      LineStyleModifier *m;
 +
 +      BKE_free_animdata(&linestyle->id);
 +      while ((m = (LineStyleModifier *)linestyle->color_modifiers.first))
 +              FRS_remove_linestyle_color_modifier(linestyle, m);
 +      while ((m = (LineStyleModifier *)linestyle->alpha_modifiers.first))
 +              FRS_remove_linestyle_alpha_modifier(linestyle, m);
 +      while ((m = (LineStyleModifier *)linestyle->thickness_modifiers.first))
 +              FRS_remove_linestyle_thickness_modifier(linestyle, m);
 +      while ((m = (LineStyleModifier *)linestyle->geometry_modifiers.first))
 +              FRS_remove_linestyle_geometry_modifier(linestyle, m);
 +}
 +
 +static LineStyleModifier *new_modifier(int type, size_t size)
 +{
 +      LineStyleModifier *m;
 +
 +      m = (LineStyleModifier *)MEM_callocN(size, "line style modifier");
 +      if (m) {
 +              m->type = type;
 +              strcpy(m->name, modifier_name[type]);
 +              m->influence = 1.0f;
 +              m->flags = LS_MODIFIER_ENABLED | LS_MODIFIER_EXPANDED;
 +      }
 +      return m;
 +}
 +
 +static void add_to_modifier_list(ListBase *lb, LineStyleModifier *m)
 +{
 +      BLI_addtail(lb, (void *)m);
++      BLI_uniquename(lb, m, modifier_name[m->type], '.', offsetof(LineStyleModifier, name), sizeof(m->name));
 +}
 +
 +int FRS_add_linestyle_color_modifier(FreestyleLineStyle *linestyle, int type)
 +{
 +      size_t size;
 +      LineStyleModifier *m;
 +
 +      switch (type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              size = sizeof(LineStyleColorModifier_AlongStroke);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              size = sizeof(LineStyleColorModifier_DistanceFromCamera);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              size = sizeof(LineStyleColorModifier_DistanceFromObject);
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              size = sizeof(LineStyleColorModifier_Material);
 +              break;
 +      default:
 +              return -1; /* unknown modifier type */
 +      }
 +      m = new_modifier(type, size);
 +      if (!m)
 +              return -1;
 +      m->blend = MA_RAMP_BLEND;
 +      switch (type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              ((LineStyleColorModifier_AlongStroke *)m)->color_ramp = add_colorband(1);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp = add_colorband(1);
 +              ((LineStyleColorModifier_DistanceFromCamera *)m)->range_min = 0.0f;
 +              ((LineStyleColorModifier_DistanceFromCamera *)m)->range_max = 10000.0f;
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              ((LineStyleColorModifier_DistanceFromObject *)m)->target = NULL;
 +              ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp = add_colorband(1);
 +              ((LineStyleColorModifier_DistanceFromObject *)m)->range_min = 0.0f;
 +              ((LineStyleColorModifier_DistanceFromObject *)m)->range_max = 10000.0f;
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              ((LineStyleColorModifier_Material *)m)->color_ramp = add_colorband(1);
 +              ((LineStyleColorModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_DIFF;
 +              break;
 +      default:
 +              return -1; /* unknown modifier type */
 +      }
 +      add_to_modifier_list(&linestyle->color_modifiers, m);
 +
 +      return 0;
 +}
 +
 +void FRS_remove_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
 +{
 +      switch (m->type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              MEM_freeN(((LineStyleColorModifier_AlongStroke *)m)->color_ramp);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              MEM_freeN(((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              MEM_freeN(((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp);
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              MEM_freeN(((LineStyleColorModifier_Material *)m)->color_ramp);
 +              break;
 +      }
 +      BLI_freelinkN(&linestyle->color_modifiers, m);
 +}
 +
 +int FRS_add_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, int type)
 +{
 +      size_t size;
 +      LineStyleModifier *m;
 +
 +      switch (type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              size = sizeof(LineStyleAlphaModifier_AlongStroke);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              size = sizeof(LineStyleAlphaModifier_DistanceFromCamera);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              size = sizeof(LineStyleAlphaModifier_DistanceFromObject);
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              size = sizeof(LineStyleAlphaModifier_Material);
 +              break;
 +      default:
 +              return -1; /* unknown modifier type */
 +      }
 +      m = new_modifier(type, size);
 +      if (!m)
 +              return -1;
 +      m->blend = LS_VALUE_BLEND;
 +      switch (type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              ((LineStyleAlphaModifier_AlongStroke *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
 +              ((LineStyleAlphaModifier_DistanceFromCamera *)m)->range_min = 0.0f;
 +              ((LineStyleAlphaModifier_DistanceFromCamera *)m)->range_max = 10000.0f;
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              ((LineStyleAlphaModifier_DistanceFromObject *)m)->target = NULL;
 +              ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
 +              ((LineStyleAlphaModifier_DistanceFromObject *)m)->range_min = 0.0f;
 +              ((LineStyleAlphaModifier_DistanceFromObject *)m)->range_max = 10000.0f;
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              ((LineStyleAlphaModifier_Material *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
 +              ((LineStyleAlphaModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_DIFF;
 +              break;
 +      }
 +      add_to_modifier_list(&linestyle->alpha_modifiers, m);
 +
 +      return 0;
 +}
 +
 +void FRS_remove_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
 +{
 +      switch (m->type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              curvemapping_free(((LineStyleAlphaModifier_AlongStroke *)m)->curve);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              curvemapping_free(((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              curvemapping_free(((LineStyleAlphaModifier_DistanceFromObject *)m)->curve);
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              curvemapping_free(((LineStyleAlphaModifier_Material *)m)->curve);
 +              break;
 +      }
 +      BLI_freelinkN(&linestyle->alpha_modifiers, m);
 +}
 +
 +int FRS_add_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, int type)
 +{
 +      size_t size;
 +      LineStyleModifier *m;
 +
 +      switch (type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              size = sizeof(LineStyleThicknessModifier_AlongStroke);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              size = sizeof(LineStyleThicknessModifier_DistanceFromCamera);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              size = sizeof(LineStyleThicknessModifier_DistanceFromObject);
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              size = sizeof(LineStyleThicknessModifier_Material);
 +              break;
 +      case LS_MODIFIER_CALLIGRAPHY:
 +              size = sizeof(LineStyleThicknessModifier_Calligraphy);
 +              break;
 +      default:
 +              return -1; /* unknown modifier type */
 +      }
 +      m = new_modifier(type, size);
 +      if (!m)
 +              return -1;
 +      m->blend = LS_VALUE_BLEND;
 +      switch (type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              ((LineStyleThicknessModifier_AlongStroke *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
 +              ((LineStyleThicknessModifier_AlongStroke *)m)->value_min = 0.0f;
 +              ((LineStyleThicknessModifier_AlongStroke *)m)->value_max = 1.0f;
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
 +              ((LineStyleThicknessModifier_DistanceFromCamera *)m)->range_min = 0.0f;
 +              ((LineStyleThicknessModifier_DistanceFromCamera *)m)->range_max = 1000.0f;
 +              ((LineStyleThicknessModifier_DistanceFromCamera *)m)->value_min = 0.0f;
 +              ((LineStyleThicknessModifier_DistanceFromCamera *)m)->value_max = 1.0f;
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              ((LineStyleThicknessModifier_DistanceFromObject *)m)->target = NULL;
 +              ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
 +              ((LineStyleThicknessModifier_DistanceFromObject *)m)->range_min = 0.0f;
 +              ((LineStyleThicknessModifier_DistanceFromObject *)m)->range_max = 1000.0f;
 +              ((LineStyleThicknessModifier_DistanceFromObject *)m)->value_min = 0.0f;
 +              ((LineStyleThicknessModifier_DistanceFromObject *)m)->value_max = 1.0f;
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              ((LineStyleThicknessModifier_Material *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
 +              ((LineStyleThicknessModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_DIFF;
 +              ((LineStyleThicknessModifier_Material *)m)->value_min = 0.0f;
 +              ((LineStyleThicknessModifier_Material *)m)->value_max = 1.0f;
 +              break;
 +      case LS_MODIFIER_CALLIGRAPHY:
 +              ((LineStyleThicknessModifier_Calligraphy *)m)->min_thickness = 1.0f;
 +              ((LineStyleThicknessModifier_Calligraphy *)m)->max_thickness = 10.0f;
 +              ((LineStyleThicknessModifier_Calligraphy *)m)->orientation = 60.0f;
 +              break;
 +      }
 +      add_to_modifier_list(&linestyle->thickness_modifiers, m);
 +
 +      return 0;
 +}
 +
 +void FRS_remove_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
 +{
 +      switch (m->type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              curvemapping_free(((LineStyleThicknessModifier_AlongStroke *)m)->curve);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              curvemapping_free(((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve);
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              curvemapping_free(((LineStyleThicknessModifier_DistanceFromObject *)m)->curve);
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              curvemapping_free(((LineStyleThicknessModifier_Material *)m)->curve);
 +              break;
 +      case LS_MODIFIER_CALLIGRAPHY:
 +              break;
 +      }
 +      BLI_freelinkN(&linestyle->thickness_modifiers, m);
 +}
 +
 +int FRS_add_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, int type)
 +{
 +      size_t size;
 +      LineStyleModifier *m;
 +
 +      switch (type) {
 +      case LS_MODIFIER_SAMPLING:
 +              size = sizeof(LineStyleGeometryModifier_Sampling);
 +              break;
 +      case LS_MODIFIER_BEZIER_CURVE:
 +              size = sizeof(LineStyleGeometryModifier_BezierCurve);
 +              break;
 +      case LS_MODIFIER_SINUS_DISPLACEMENT:
 +              size = sizeof(LineStyleGeometryModifier_SinusDisplacement);
 +              break;
 +      case LS_MODIFIER_SPATIAL_NOISE:
 +              size = sizeof(LineStyleGeometryModifier_SpatialNoise);
 +              break;
 +      case LS_MODIFIER_PERLIN_NOISE_1D:
 +              size = sizeof(LineStyleGeometryModifier_PerlinNoise1D);
 +              break;
 +      case LS_MODIFIER_PERLIN_NOISE_2D:
 +              size = sizeof(LineStyleGeometryModifier_PerlinNoise2D);
 +              break;
 +      case LS_MODIFIER_BACKBONE_STRETCHER:
 +              size = sizeof(LineStyleGeometryModifier_BackboneStretcher);
 +              break;
 +      case LS_MODIFIER_TIP_REMOVER:
 +              size = sizeof(LineStyleGeometryModifier_TipRemover);
 +              break;
 +      default:
 +              return -1; /* unknown modifier type */
 +      }
 +      m = new_modifier(type, size);
 +      if (!m)
 +              return -1;
 +      switch (type) {
 +      case LS_MODIFIER_SAMPLING:
 +              ((LineStyleGeometryModifier_Sampling *)m)->sampling = 10.0;
 +              break;
 +      case LS_MODIFIER_BEZIER_CURVE:
 +              ((LineStyleGeometryModifier_BezierCurve *)m)->error = 10.0;
 +              break;
 +      case LS_MODIFIER_SINUS_DISPLACEMENT:
 +              ((LineStyleGeometryModifier_SinusDisplacement *)m)->wavelength = 20.0;
 +              ((LineStyleGeometryModifier_SinusDisplacement *)m)->amplitude = 5.0;
 +              ((LineStyleGeometryModifier_SinusDisplacement *)m)->phase = 0.0;
 +              break;
 +      case LS_MODIFIER_SPATIAL_NOISE:
 +              ((LineStyleGeometryModifier_SpatialNoise *)m)->amplitude = 5.0;
 +              ((LineStyleGeometryModifier_SpatialNoise *)m)->scale = 20.0;
 +              ((LineStyleGeometryModifier_SpatialNoise *)m)->octaves = 4;
 +              ((LineStyleGeometryModifier_SpatialNoise *)m)->flags = LS_MODIFIER_SPATIAL_NOISE_SMOOTH | LS_MODIFIER_SPATIAL_NOISE_PURERANDOM;
 +              break;
 +      case LS_MODIFIER_PERLIN_NOISE_1D:
 +              ((LineStyleGeometryModifier_PerlinNoise1D *)m)->frequency = 10.0;
 +              ((LineStyleGeometryModifier_PerlinNoise1D *)m)->amplitude = 10.0;
 +              ((LineStyleGeometryModifier_PerlinNoise1D *)m)->octaves = 4;
 +              ((LineStyleGeometryModifier_PerlinNoise1D *)m)->angle = 45.0;
 +              break;
 +      case LS_MODIFIER_PERLIN_NOISE_2D:
 +              ((LineStyleGeometryModifier_PerlinNoise2D *)m)->frequency = 10.0;
 +              ((LineStyleGeometryModifier_PerlinNoise2D *)m)->amplitude = 10.0;
 +              ((LineStyleGeometryModifier_PerlinNoise2D *)m)->octaves = 4;
 +              ((LineStyleGeometryModifier_PerlinNoise2D *)m)->angle = 45.0;
 +              break;
 +      case LS_MODIFIER_BACKBONE_STRETCHER:
 +              ((LineStyleGeometryModifier_BackboneStretcher *)m)->amount = 10.0;
 +              break;
 +      case LS_MODIFIER_TIP_REMOVER:
 +              ((LineStyleGeometryModifier_TipRemover *)m)->tip_length = 10.0;
 +              break;
 +      }
 +      add_to_modifier_list(&linestyle->geometry_modifiers, m);
 +      return 0;
 +}
 +
 +void FRS_remove_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
 +{
 +      switch (m->type) {
 +      case LS_MODIFIER_SAMPLING:
 +              break;
 +      case LS_MODIFIER_BEZIER_CURVE:
 +              break;
 +      case LS_MODIFIER_SINUS_DISPLACEMENT:
 +              break;
 +      case LS_MODIFIER_SPATIAL_NOISE:
 +              break;
 +      case LS_MODIFIER_PERLIN_NOISE_1D:
 +              break;
 +      case LS_MODIFIER_PERLIN_NOISE_2D:
 +              break;
 +      case LS_MODIFIER_BACKBONE_STRETCHER:
 +              break;
 +      case LS_MODIFIER_TIP_REMOVER:
 +              break;
 +      }
 +      BLI_freelinkN(&linestyle->geometry_modifiers, m);
 +}
 +
 +static void move_modifier(ListBase *lb, LineStyleModifier *modifier, int direction)
 +{
 +      BLI_remlink(lb, modifier);
 +      if (direction > 0)
 +              BLI_insertlinkbefore(lb, modifier->prev, modifier);
 +      else
 +              BLI_insertlinkafter(lb, modifier->next, modifier);
 +}
 +
 +void FRS_move_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
 +{
 +      move_modifier(&linestyle->color_modifiers, modifier, direction);
 +}
 +
 +void FRS_move_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
 +{
 +      move_modifier(&linestyle->alpha_modifiers, modifier, direction);
 +}
 +
 +void FRS_move_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
 +{
 +      move_modifier(&linestyle->thickness_modifiers, modifier, direction);
 +}
 +
 +void FRS_move_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
 +{
 +      move_modifier(&linestyle->geometry_modifiers, modifier, direction);
 +}
 +
 +void FRS_list_modifier_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase)
 +{
 +      LineStyleModifier *m;
 +      ColorBand *color_ramp;
 +      LinkData *link;
 +
 +      listbase->first = listbase->last = NULL;
 +      for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      color_ramp = ((LineStyleColorModifier_AlongStroke *)m)->color_ramp;
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      color_ramp = ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp;
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      color_ramp = ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp;
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      color_ramp = ((LineStyleColorModifier_Material *)m)->color_ramp;
 +                      break;
 +              default:
 +                      continue;
 +              }
 +              link = (LinkData *) MEM_callocN( sizeof(LinkData), "link to color ramp");
 +              link->data = color_ramp;
 +              BLI_addtail(listbase, link);
 +      }
 +}
 +
 +char *FRS_path_from_ID_to_color_ramp(FreestyleLineStyle *linestyle, ColorBand *color_ramp)
 +{
 +      LineStyleModifier *m;
 +
 +      for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      if (color_ramp == ((LineStyleColorModifier_AlongStroke *)m)->color_ramp)
 +                              goto found;
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      if (color_ramp == ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp)
 +                              goto found;
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      if (color_ramp == ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp)
 +                              goto found;
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      if (color_ramp == ((LineStyleColorModifier_Material *)m)->color_ramp)
 +                              goto found;
 +                      break;
 +              }
 +      }
 +      printf("FRS_path_from_ID_to_color_ramp: No color ramps correspond to the given pointer.\n");
 +      return NULL;
 +
 +found:
 +      return BLI_sprintfN("color_modifiers[\"%s\"].color_ramp", m->name);
 +}
 +
 +void FRS_unlink_linestyle_target_object(FreestyleLineStyle *linestyle, struct Object *ob)
 +{
 +      LineStyleModifier *m;
 +
 +      for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) {
 +              if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
 +                      if (((LineStyleColorModifier_DistanceFromObject *)m)->target == ob) {
 +                              ((LineStyleColorModifier_DistanceFromObject *)m)->target = NULL;
 +                      }
 +              }
 +      }
 +      for (m = (LineStyleModifier *)linestyle->alpha_modifiers.first; m; m = m->next) {
 +              if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
 +                      if (((LineStyleAlphaModifier_DistanceFromObject *)m)->target == ob) {
 +                              ((LineStyleAlphaModifier_DistanceFromObject *)m)->target = NULL;
 +                      }
 +              }
 +      }
 +      for (m = (LineStyleModifier *)linestyle->thickness_modifiers.first; m; m = m->next) {
 +              if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
 +                      if (((LineStyleThicknessModifier_DistanceFromObject *)m)->target == ob) {
 +                              ((LineStyleThicknessModifier_DistanceFromObject *)m)->target = NULL;
 +                      }
 +              }
 +      }
 +}
Simple merge
index 65b9ba9ea4a3887090bae71b969e12f74845c3c6,293f824c5fdf5bce0f9a74480dd33e572aecaeb7..624b726e27e9ec292731092d8ea2f51ac49c5feb
@@@ -962,15 -898,15 +962,15 @@@ void findMissingFiles(Main *bmain, cons
        char filepath[FILE_MAX];
        const char *libpath;
        int filesize, recur_depth;
 -
 +      
        char dirname[FILE_MAX], filename_new[FILE_MAX];
 -
 +      
        //XXX waitcursor( 1 );
 -
 +      
-       BLI_split_dirfile(str, dirname, NULL, sizeof(dirname), 0);
+       BLI_split_dir_part(str, dirname, sizeof(dirname));
 -
 +      
        BLI_bpathIterator_init(&bpi, bmain, bmain->name, 0);
 -
 +      
        while (!BLI_bpathIterator_isDone(bpi)) {
                BLI_bpathIterator_getPath(bpi, filepath);
                libpath= BLI_bpathIterator_getLib(bpi);
index ab1d9e371e7f6aac816e8114dae4f5b1f29b69e6,0000000000000000000000000000000000000000..03a6e1ff861c95c5e273fee6e66199207cef84d5
mode 100644,000000..100644
--- /dev/null
@@@ -1,651 -1,0 +1,651 @@@
-               BLI_uniquename(&config->linesets, lineset, "FreestyleLineSet", '.', BLI_STRUCT_OFFSET(FreestyleLineSet, name), sizeof(lineset->name));
 +#include "../application/Controller.h"
 +#include "../application/AppView.h"
 +#include "../application/AppConfig.h"
 +#include "../application/AppCanvas.h"
 +
 +#include <iostream>
 +#include <map>
 +#include <set>
 +using namespace std;
 +
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "DNA_camera_types.h"
 +#include "DNA_text_types.h"
 +#include "DNA_group_types.h"
 +#include "DNA_freestyle_types.h"
 +
 +#include "BKE_global.h"
 +#include "BKE_library.h"
 +#include "BKE_linestyle.h"
 +#include "BKE_main.h"
 +#include "BKE_text.h"
 +#include "BLI_blenlib.h"
 +#include "BLI_math.h"
 +#include "BPY_extern.h"
 +
 +#include "renderpipeline.h"
 +#include "pixelblending.h"
 +
 +#include "../../FRS_freestyle.h"
 +#include "../../FRS_freestyle_config.h"
 +
 +      // Freestyle configuration
 +      static short freestyle_is_initialized = 0;
 +      static Config::Path *pathconfig = NULL;
 +      static Controller *controller = NULL;
 +      static AppView *view = NULL;
 +
 +      // camera information
 +      float freestyle_viewpoint[3];
 +      float freestyle_mv[4][4];
 +      float freestyle_proj[4][4];
 +      int freestyle_viewport[4];
 +      
 +      // current scene
 +      Scene *freestyle_scene;
 +
 +      string default_module_path;
 +
 +      //=======================================================
 +      //   Initialization 
 +      //=======================================================
 +
 +      void FRS_initialize() {
 +              
 +              if( freestyle_is_initialized )
 +                      return;
 +
 +              pathconfig = new Config::Path;
 +              controller = new Controller();
 +              view = new AppView;
 +              controller->setView(view);
 +              controller->Clear();
 +              freestyle_scene = NULL;
 +                      
 +              default_module_path = pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py";
 +                      
 +              freestyle_is_initialized = 1;
 +      }
 +      
 +      void FRS_set_context(bContext* C) {
 +              cout << "FRS_set_context: context 0x" << C << " scene 0x" << CTX_data_scene(C) << endl;
 +              controller->setContext(C);
 +      }
 +
 +      void FRS_exit() {
 +              delete pathconfig;
 +              delete controller;
 +              delete view;
 +      }
 +
 +      //=======================================================
 +      //   Rendering 
 +      //=======================================================
 +
 +      static void init_view(Render* re){
 +              float ycor = ((float)re->r.yasp) / ((float)re->r.xasp);
 +              int width = re->r.xsch;
 +              int height = (int)(((float)re->r.ysch) * ycor);
 +              int xmin = re->r.border.xmin * width;
 +              int xmax = re->r.border.xmax * width;
 +              int ymin = re->r.border.ymin * height;
 +              int ymax = re->r.border.ymax * height;
 +              
 +              freestyle_viewport[0] = freestyle_viewport[1] = 0;
 +              freestyle_viewport[2] = width;
 +              freestyle_viewport[3] = height;
 +              
 +              view->setWidth( width );
 +              view->setHeight( height );
 +              view->setBorder( xmin, ymin, xmax, ymax );
 +
 +              cout << "\n===  Dimensions of the 2D image coordinate system  ===" << endl;
 +              cout << "Width  : " << width << endl;
 +              cout << "Height : " << height << endl;
 +              if (re->r.mode & R_BORDER)
 +                      cout << "Border : (" << xmin << ", " << ymin << ") - (" << xmax << ", " << ymax << ")" << endl;
 +      }
 +
 +      static void init_camera(Render* re){
 +              // It is assumed that imported meshes are in the camera coordinate system.
 +              // Therefore, the view point (i.e., camera position) is at the origin, and
 +              // the the model-view matrix is simply the identity matrix.
 +
 +              freestyle_viewpoint[0] = 0.0;
 +              freestyle_viewpoint[1] = 0.0;
 +              freestyle_viewpoint[2] = 0.0;
 +              
 +              for( int i = 0; i < 4; i++ )
 +                 for( int j = 0; j < 4; j++ )
 +                      freestyle_mv[i][j] = (i == j) ? 1.0 : 0.0;
 +              
 +              for( int i = 0; i < 4; i++ )
 +                 for( int j = 0; j < 4; j++ )
 +                      freestyle_proj[i][j] = re->winmat[i][j];
 +
 +              //print_m4("mv", freestyle_mv);
 +              //print_m4("proj", freestyle_proj);
 +      }
 +
 +      static char *escape_quotes(char *name)
 +      {
 +              char *s= (char *)MEM_mallocN(strlen(name) * 2 + 1, "escape_quotes");
 +              char *p= s;
 +              while (*name) {
 +                      if (*name == '\'')
 +                              *p++= '\\';
 +                      *p++ = *name++;
 +              }
 +              *p = '\0';
 +              return s;
 +      }
 +
 +      static Text *create_lineset_handler(char *layer_name, char *lineset_name)
 +      {
 +              char *s1= escape_quotes(layer_name);
 +              char *s2= escape_quotes(lineset_name);
 +              Text *text= add_empty_text(lineset_name);
 +              write_text(text, "import parameter_editor; parameter_editor.process('");
 +              write_text(text, s1);
 +              write_text(text, "', '");
 +              write_text(text, s2);
 +              write_text(text, "')\n");
 +              MEM_freeN(s1);
 +              MEM_freeN(s2);
 +              return text;
 +      }
 +
 +      struct edge_type_condition {
 +              int edge_type, value;
 +      };
 +
 +      // examines the conditions and returns true if the target edge type needs to be computed
 +      static bool test_edge_type_conditions(struct edge_type_condition *conditions,
 +              int num_edge_types, bool logical_and, int target, bool distinct)
 +      {
 +              int target_condition = 0;
 +              int num_non_target_positive_conditions = 0;
 +              int num_non_target_negative_conditions = 0;
 +
 +              for (int i = 0; i < num_edge_types; i++) {
 +                      if (conditions[i].edge_type == target)
 +                              target_condition = conditions[i].value;
 +                      else if (conditions[i].value > 0)
 +                              ++num_non_target_positive_conditions;
 +                      else if (conditions[i].value < 0)
 +                              ++num_non_target_negative_conditions;
 +              }
 +              if (distinct) {
 +                      // In this case, the 'target' edge type is assumed to appear on distinct edge
 +                      // of its own and never together with other edge types.
 +                      if (logical_and) {
 +                              if (num_non_target_positive_conditions > 0)
 +                                      return false;
 +                              if (target_condition > 0)
 +                                      return true;
 +                              if (target_condition < 0)
 +                                      return false;
 +                              if (num_non_target_negative_conditions > 0)
 +                                      return true;
 +                      } else {
 +                              if (target_condition > 0)
 +                                      return true;
 +                              if (num_non_target_negative_conditions > 0)
 +                                      return true;
 +                              if (target_condition < 0)
 +                                      return false;
 +                              if (num_non_target_positive_conditions > 0)
 +                                      return false;
 +                      }
 +              } else {
 +                      // In this case, the 'target' edge type may appear together with other edge types.
 +                      if (target_condition > 0)
 +                              return true;
 +                      if (target_condition < 0)
 +                              return true;
 +                      if (logical_and) {
 +                              if (num_non_target_positive_conditions > 0)
 +                                      return false;
 +                              if (num_non_target_negative_conditions > 0)
 +                                      return true;
 +                      } else {
 +                              if (num_non_target_negative_conditions > 0)
 +                                      return true;
 +                              if (num_non_target_positive_conditions > 0)
 +                                      return false;
 +                      }
 +              }
 +              return true;
 +      }
 +
 +      static void prepare(Render* re, SceneRenderLayer* srl ) {
 +                              
 +              // load mesh
 +        re->i.infostr= "Freestyle: Mesh loading";
 +              re->stats_draw(re->sdh, &re->i);
 +        re->i.infostr= NULL;
 +              if( controller->LoadMesh(re, srl) ) // returns if scene cannot be loaded or if empty
 +                      return;
 +        if( re->test_break(re->tbh) )
 +            return;
 +              
 +              // add style modules
 +              FreestyleConfig* config = &srl->freestyleConfig;
 +              
 +              cout << "\n===  Rendering options  ===" << endl;
 +              int layer_count = 0;
 +              
 +              switch (config->mode) {
 +              case FREESTYLE_CONTROL_SCRIPT_MODE:
 +                      cout << "Modules :"<< endl;
 +                      for (FreestyleModuleConfig* module_conf = (FreestyleModuleConfig *)config->modules.first; module_conf; module_conf = module_conf->next) {
 +                              if( module_conf->is_displayed ) {
 +                                      cout << "  " << layer_count+1 << ": " << module_conf->module_path << endl;
 +                                      controller->InsertStyleModule( layer_count, module_conf->module_path );
 +                                      controller->toggleLayer(layer_count, true);
 +                                      layer_count++;
 +                              }
 +                      }
 +                      cout << endl;
 +                      controller->setComputeRidgesAndValleysFlag( (config->flags & FREESTYLE_RIDGES_AND_VALLEYS_FLAG) ? true : false);
 +                      controller->setComputeSuggestiveContoursFlag( (config->flags & FREESTYLE_SUGGESTIVE_CONTOURS_FLAG) ? true : false);
 +                      controller->setComputeMaterialBoundariesFlag( (config->flags & FREESTYLE_MATERIAL_BOUNDARIES_FLAG) ? true : false);
 +                      break;
 +              case FREESTYLE_CONTROL_EDITOR_MODE:
 +                      int use_ridges_and_valleys = 0;
 +                      int use_suggestive_contours = 0;
 +                      int use_material_boundaries = 0;
 +                      struct edge_type_condition conditions[] = {
 +                              {FREESTYLE_FE_SILHOUETTE, 0},
 +                              {FREESTYLE_FE_BORDER, 0},
 +                              {FREESTYLE_FE_CREASE, 0},
 +                              {FREESTYLE_FE_RIDGE, 0},
 +                              {FREESTYLE_FE_VALLEY, 0},
 +                              {FREESTYLE_FE_SUGGESTIVE_CONTOUR, 0},
 +                              {FREESTYLE_FE_MATERIAL_BOUNDARY, 0},
 +                              {FREESTYLE_FE_CONTOUR, 0},
 +                              {FREESTYLE_FE_EXTERNAL_CONTOUR, 0},
 +                              {FREESTYLE_FE_EDGE_MARK, 0}};
 +                      int num_edge_types = sizeof(conditions) / sizeof(struct edge_type_condition);
 +                      cout << "Linesets:"<< endl;
 +                      for (FreestyleLineSet *lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) {
 +                              if (lineset->flags & FREESTYLE_LINESET_ENABLED) {
 +                                      cout << "  " << layer_count+1 << ": " << lineset->name << " - " << lineset->linestyle->id.name+2 << endl;
 +                                      Text *text = create_lineset_handler(srl->name, lineset->name);
 +                                      controller->InsertStyleModule( layer_count, lineset->name, text );
 +                                      controller->toggleLayer(layer_count, true);
 +                                      if (!(lineset->selection & FREESTYLE_SEL_EDGE_TYPES) || !lineset->edge_types) {
 +                                              ++use_ridges_and_valleys;
 +                                              ++use_suggestive_contours;
 +                                              ++use_material_boundaries;
 +                                      } else {
 +                                              // conditions for feature edge selection by edge types
 +                                              for (int i = 0; i < num_edge_types; i++) {
 +                                                      if (!(lineset->edge_types & conditions[i].edge_type))
 +                                                              conditions[i].value = 0; // no condition specified
 +                                                      else if (!(lineset->exclude_edge_types & conditions[i].edge_type))
 +                                                              conditions[i].value = 1; // condition: X
 +                                                      else
 +                                                              conditions[i].value = -1; // condition: NOT X
 +                                              }
 +                                              // logical operator for the selection conditions
 +                                              bool logical_and = ((lineset->flags & FREESTYLE_LINESET_FE_AND) != 0);
 +                                              // negation operator
 +                                              if (lineset->flags & FREESTYLE_LINESET_FE_NOT) {
 +                                                      // convert an Exclusive condition into an Inclusive equivalent using De Morgan's laws:
 +                                                      //   NOT (X OR Y) --> (NOT X) AND (NOT Y)
 +                                                      //   NOT (X AND Y) --> (NOT X) OR (NOT Y)
 +                                                      for (int i = 0; i < num_edge_types; i++)
 +                                                              conditions[i].value *= -1;
 +                                                      logical_and = !logical_and;
 +                                              }
 +                                              if (test_edge_type_conditions(conditions, num_edge_types, logical_and, FREESTYLE_FE_RIDGE, true) ||
 +                                                      test_edge_type_conditions(conditions, num_edge_types, logical_and, FREESTYLE_FE_VALLEY, true))
 +                                                      ++use_ridges_and_valleys;
 +                                              if (test_edge_type_conditions(conditions, num_edge_types, logical_and, FREESTYLE_FE_SUGGESTIVE_CONTOUR, true))
 +                                                      ++use_suggestive_contours;
 +                                              if (test_edge_type_conditions(conditions, num_edge_types, logical_and, FREESTYLE_FE_MATERIAL_BOUNDARY, true))
 +                                                      ++use_material_boundaries;
 +                                      }
 +                                      layer_count++;
 +                              }
 +                      }
 +                      controller->setComputeRidgesAndValleysFlag( use_ridges_and_valleys > 0 );
 +                      controller->setComputeSuggestiveContoursFlag( use_suggestive_contours > 0 );
 +                      controller->setComputeMaterialBoundariesFlag( use_material_boundaries > 0 );
 +                      break;
 +              }
 +              
 +              // set parameters
 +              controller->setFaceSmoothness( (config->flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) ? true : false);
 +              controller->setCreaseAngle( config->crease_angle );
 +              controller->setSphereRadius( config->sphere_radius );
 +              controller->setSuggestiveContourKrDerivativeEpsilon( config->dkr_epsilon ) ;
 +              controller->setVisibilityAlgo( config->raycasting_algorithm );
 +
 +              cout << "Crease angle : " << controller->getCreaseAngle() << endl;
 +              cout << "Sphere radius : " << controller->getSphereRadius() << endl;
 +              cout << "Face smoothness : " << (controller->getFaceSmoothness() ? "enabled" : "disabled") << endl;
 +              cout << "Redges and valleys : " << (controller->getComputeRidgesAndValleysFlag() ? "enabled" : "disabled") << endl;
 +              cout << "Suggestive contours : " << (controller->getComputeSuggestiveContoursFlag() ? "enabled" : "disabled") << endl;
 +              cout << "Suggestive contour Kr derivative epsilon : " << controller->getSuggestiveContourKrDerivativeEpsilon() << endl;
 +              cout << "Material boundaries : " << (controller->getComputeMaterialBoundariesFlag() ? "enabled" : "disabled") << endl;
 +              cout << endl;
 +
 +        // set diffuse and z depth passes
 +        RenderLayer *rl = RE_GetRenderLayer(re->result, srl->name);
 +              bool diffuse = false, z = false;
 +              for (RenderPass *rpass = (RenderPass *)rl->passes.first; rpass; rpass = rpass->next) {
 +                      switch (rpass->passtype) {
 +                      case SCE_PASS_DIFFUSE:
 +                              controller->setPassDiffuse(rpass->rect, rpass->rectx, rpass->recty);
 +                              diffuse = true;
 +                              break;
 +                      case SCE_PASS_Z:
 +                              controller->setPassZ(rpass->rect, rpass->rectx, rpass->recty);
 +                              z = true;
 +                              break;
 +                      }
 +              }
 +        cout << "Passes :" << endl;
 +        cout << "  Diffuse = " << (diffuse ? "enabled" : "disabled") << endl;
 +        cout << "  Z = " << (z ? "enabled" : "disabled") << endl;
 +
 +              // compute view map
 +        re->i.infostr= "Freestyle: View map creation";
 +              re->stats_draw(re->sdh, &re->i);
 +        re->i.infostr= NULL;
 +              controller->ComputeViewMap();
 +      }
 +      
 +      void FRS_composite_result(Render* re, SceneRenderLayer* srl, Render* freestyle_render)
 +      {
 +              RenderLayer *rl;
 +          float *src, *dest, *pixSrc, *pixDest;
 +              int x, y, rectx, recty;
 +              
 +              if( freestyle_render == NULL || freestyle_render->result == NULL )
 +                      return;
 +
 +              rl = render_get_active_layer( freestyle_render, freestyle_render->result );
 +          if( !rl || rl->rectf == NULL) { cout << "Cannot find Freestyle result image" << endl; return; }
 +              src  = rl->rectf;
 +              //cout << "src: " << rl->rectx << " x " << rl->recty << endl;
 +              
 +              rl = RE_GetRenderLayer(re->result, srl->name);
 +          if( !rl || rl->rectf == NULL) { cout << "No layer to composite to" << endl; return; }
 +              dest  = rl->rectf;
 +              //cout << "dest: " << rl->rectx << " x " << rl->recty << endl;
 +
 +              rectx = re->rectx;
 +              recty = re->recty;
 +          for( y = 0; y < recty; y++) {
 +              for( x = 0; x < rectx; x++) {
 +                  pixSrc = src + 4 * (rectx * y + x);
 +                  if( pixSrc[3] > 0.0) {
 +                                      pixDest = dest + 4 * (rectx * y + x);
 +                                      addAlphaOverFloat(pixDest, pixSrc);
 +                              }
 +                      }
 +          }
 +      }
 +      
 +      static int displayed_layer_count( SceneRenderLayer* srl ) {
 +              int count = 0;
 +
 +              switch (srl->freestyleConfig.mode) {
 +              case FREESTYLE_CONTROL_SCRIPT_MODE:
 +                      for (FreestyleModuleConfig* module = (FreestyleModuleConfig *)srl->freestyleConfig.modules.first; module; module = module->next) {
 +                              if( module->is_displayed )
 +                                      count++;
 +                      }
 +                      break;
 +              case FREESTYLE_CONTROL_EDITOR_MODE:
 +                      for (FreestyleLineSet *lineset = (FreestyleLineSet *)srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
 +                              if (lineset->flags & FREESTYLE_LINESET_ENABLED)
 +                                      count++;
 +                      }
 +                      break;
 +              }
 +              return count;
 +      }
 +
 +      int FRS_is_freestyle_enabled(SceneRenderLayer* srl) {
 +              return (!(srl->layflag & SCE_LAY_DISABLE) &&
 +                              srl->layflag & SCE_LAY_FRS &&
 +                              displayed_layer_count(srl) > 0);
 +      }
 +      
 +      void FRS_init_stroke_rendering(Render* re) {
 +
 +              cout << "\n#===============================================================" << endl;
 +              cout << "#  Freestyle" << endl;
 +              cout << "#===============================================================" << endl;
 +              
 +              init_view(re);
 +              init_camera(re);
 +
 +              controller->ResetRenderCount();
 +      }
 +      
 +      Render* FRS_do_stroke_rendering(Render* re, SceneRenderLayer *srl) {
 +              
 +              Render* freestyle_render = NULL;
 +              
 +              cout << "\n----------------------------------------------------------" << endl;
 +              cout << "|  " << (re->scene->id.name+2) << "|" << srl->name << endl;
 +              cout << "----------------------------------------------------------" << endl;
 +              
 +              // prepare Freestyle:
 +              //   - load mesh
 +              //   - add style modules
 +              //   - set parameters
 +              //   - compute view map
 +              prepare(re, srl);
 +
 +        if( re->test_break(re->tbh) ) {
 +                      controller->CloseFile();
 +            return NULL;
 +        }
 +
 +              // render and composite Freestyle result
 +              if( controller->_ViewMap ) {
 +                      
 +                      // render strokes                                       
 +            re->i.infostr= "Freestyle: Stroke rendering";
 +            re->stats_draw(re->sdh, &re->i);
 +              re->i.infostr= NULL;
 +                      freestyle_scene = re->scene;
 +                      controller->DrawStrokes();
 +                      freestyle_render = controller->RenderStrokes(re);
 +                      controller->CloseFile();
 +                      freestyle_scene = NULL;
 +                      
 +                      // composite result
 +                      FRS_composite_result(re, srl, freestyle_render);
 +                      RE_FreeRenderResult(freestyle_render->result);
 +                      freestyle_render->result = NULL;
 +              }
 +
 +              return freestyle_render;
 +      }
 +
 +      void FRS_finish_stroke_rendering(Render* re) {
 +              // clear canvas
 +              controller->Clear();
 +      }
 +
 +      //=======================================================
 +      //   Freestyle Panel Configuration
 +      //=======================================================
 +
 +      void FRS_add_freestyle_config( SceneRenderLayer* srl )
 +      {               
 +              FreestyleConfig* config = &srl->freestyleConfig;
 +              
 +              config->mode = FREESTYLE_CONTROL_SCRIPT_MODE;
 +
 +              config->modules.first = config->modules.last = NULL;
 +              config->flags = 0;
 +              config->sphere_radius = 1.0f;
 +              config->dkr_epsilon = 0.001f;
 +              config->crease_angle = 134.43f;
 +
 +              config->linesets.first = config->linesets.last = NULL;
 +
 +              config->raycasting_algorithm = FREESTYLE_ALGO_REGULAR;
 +      }
 +      
 +      void FRS_free_freestyle_config( SceneRenderLayer* srl )
 +      {               
 +              FreestyleLineSet *lineset;
 +
 +              for(lineset=(FreestyleLineSet *)srl->freestyleConfig.linesets.first; lineset; lineset=lineset->next) {
 +                      if (lineset->group) {
 +                              lineset->group->id.us--;
 +                              lineset->group = NULL;
 +                      }
 +                      lineset->linestyle->id.us--;
 +                      lineset->linestyle = NULL;
 +              }
 +              BLI_freelistN( &srl->freestyleConfig.linesets );
 +              BLI_freelistN( &srl->freestyleConfig.modules );
 +      }
 +
 +      void FRS_add_module(FreestyleConfig *config)
 +      {
 +              FreestyleModuleConfig* module_conf = (FreestyleModuleConfig*) MEM_callocN( sizeof(FreestyleModuleConfig), "style module configuration");
 +              BLI_addtail(&config->modules, (void*) module_conf);
 +              
 +              strcpy( module_conf->module_path, default_module_path.c_str() );
 +              module_conf->is_displayed = 1;  
 +      }
 +      
 +      void FRS_delete_module(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
 +      {
 +              BLI_freelinkN(&config->modules, module_conf);
 +      }
 +      
 +      void FRS_move_module_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
 +      {
 +              BLI_remlink(&config->modules, module_conf);
 +              BLI_insertlinkbefore(&config->modules, module_conf->prev, module_conf);
 +      }
 +      
 +      void FRS_move_module_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
 +      {                       
 +              BLI_remlink(&config->modules, module_conf);
 +              BLI_insertlinkafter(&config->modules, module_conf->next, module_conf);
 +      }
 +
 +      void FRS_add_lineset(FreestyleConfig *config)
 +      {
 +              int lineset_index = BLI_countlist(&config->linesets);
 +
 +              FreestyleLineSet *lineset = (FreestyleLineSet *) MEM_callocN( sizeof(FreestyleLineSet), "Freestyle line set");
 +              BLI_addtail(&config->linesets, (void *) lineset);
 +              FRS_set_active_lineset_index(config, lineset_index);
 +
 +              lineset->linestyle = FRS_new_linestyle("LineStyle", NULL);
 +              lineset->flags |= FREESTYLE_LINESET_ENABLED;
 +              lineset->selection = FREESTYLE_SEL_IMAGE_BORDER;
 +              lineset->qi = FREESTYLE_QI_VISIBLE;
 +              lineset->qi_start = 0;
 +              lineset->qi_end = 100;
 +              lineset->edge_types = FREESTYLE_FE_SILHOUETTE | FREESTYLE_FE_BORDER | FREESTYLE_FE_CREASE;
 +              lineset->group = NULL;
 +              if (lineset_index > 0)
 +                      sprintf(lineset->name, "LineSet %i", lineset_index+1);
 +              else
 +                      strcpy(lineset->name, "LineSet");
++              BLI_uniquename(&config->linesets, lineset, "FreestyleLineSet", '.', offsetof(FreestyleLineSet, name), sizeof(lineset->name));
 +      }
 +
 +      void FRS_delete_active_lineset(FreestyleConfig *config)
 +      {
 +              FreestyleLineSet *lineset = FRS_get_active_lineset(config);
 +
 +              if (lineset) {
 +                      if (lineset->group) {
 +                              lineset->group->id.us--;
 +                              lineset->group = NULL;
 +                      }
 +                      lineset->linestyle->id.us--;
 +                      lineset->linestyle = NULL;
 +                      BLI_remlink(&config->linesets, lineset);
 +                      MEM_freeN(lineset);
 +                      FRS_set_active_lineset_index(config, 0);
 +              }
 +      }
 +
 +      void FRS_move_active_lineset_up(FreestyleConfig *config)
 +      {
 +              FreestyleLineSet *lineset = FRS_get_active_lineset(config);
 +
 +              if (lineset) {
 +                      BLI_remlink(&config->linesets, lineset);
 +                      BLI_insertlinkbefore(&config->linesets, lineset->prev, lineset);
 +              }
 +      }
 +
 +      void FRS_move_active_lineset_down(FreestyleConfig *config)
 +      {
 +              FreestyleLineSet *lineset = FRS_get_active_lineset(config);
 +
 +              if (lineset) {
 +                      BLI_remlink(&config->linesets, lineset);
 +                      BLI_insertlinkafter(&config->linesets, lineset->next, lineset);
 +              }
 +      }
 +
 +      FreestyleLineSet *FRS_get_active_lineset(FreestyleConfig *config)
 +      {
 +              FreestyleLineSet *lineset;
 +
 +              for(lineset=(FreestyleLineSet *)config->linesets.first; lineset; lineset=lineset->next)
 +                      if(lineset->flags & FREESTYLE_LINESET_CURRENT)
 +                              return lineset;
 +              return NULL;
 +      }
 +
 +      short FRS_get_active_lineset_index(FreestyleConfig *config)
 +      {
 +              FreestyleLineSet *lineset;
 +              short i;
 +
 +              for(lineset=(FreestyleLineSet *)config->linesets.first, i=0; lineset; lineset=lineset->next, i++)
 +                      if(lineset->flags & FREESTYLE_LINESET_CURRENT)
 +                              return i;
 +              return 0;
 +      }
 +
 +      void FRS_set_active_lineset_index(FreestyleConfig *config, short index)
 +      {
 +              FreestyleLineSet *lineset;
 +              short i;
 +
 +              for(lineset=(FreestyleLineSet *)config->linesets.first, i=0; lineset; lineset=lineset->next, i++) {
 +                      if(i == index)
 +                              lineset->flags |= FREESTYLE_LINESET_CURRENT;
 +                      else
 +                              lineset->flags &= ~FREESTYLE_LINESET_CURRENT;
 +              }
 +      }
 +
 +      void FRS_unlink_target_object(FreestyleConfig *config, Object *ob)
 +      {
 +              FreestyleLineSet *lineset;
 +
 +              for(lineset=(FreestyleLineSet *)config->linesets.first; lineset; lineset=lineset->next) {
 +                      FRS_unlink_linestyle_target_object(lineset->linestyle, ob);
 +              }
 +      }
 +
 +#ifdef __cplusplus
 +}
 +#endif
Simple merge
index 8cee0987c2e91820771400d7b5a3c568a045be4b,2a2c9c279ddf0a3b9c631d20abb1867c5355fdac..4a105e08a852e5b81b7b2eb4f7fca40d4228db0b
@@@ -201,10 -199,8 +200,10 @@@ EnumPropertyItem image_color_mode_items
  #include "ED_mesh.h"
  #include "ED_keyframing.h"
  
- #include "RE_pipeline.h"
+ #include "RE_engine.h"
  
 +#include "FRS_freestyle.h"
 +
  static int rna_Scene_object_bases_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
  {
        Scene *scene= (Scene*)ptr->data;
Simple merge
Simple merge
index 08e9278ce46acede1725abf909ad9cac6515b27a,bbe32765443f81ee85fb4a3ed426cd181decd8d5..0fcf01e235a33d84796be70a31eeff87b456a9f7
  
  #include "intern/openexr/openexr_multi.h"
  
+ #include "RE_engine.h"
  #include "RE_pipeline.h"
  
 +#include "FRS_freestyle.h"
 +#include "FRS_freestyle_config.h"
 +
  /* internal */
  #include "render_types.h"
  #include "renderpipeline.h"
@@@ -1816,9 -1811,6 +1816,8 @@@ void RE_TileProcessor(Render *re
  
  /* ************  This part uses API, for rendering Blender scenes ********** */
  
- static int external_render_3d(Render *re, int do_all);
 +static void add_freestyle(Render *re);
 +
  static void do_render_3d(Render *re)
  {
        /* try external */
Simple merge
Simple merge