コード例 #1
0
ファイル: colortools.c プロジェクト: BHCLL/blendocv
void curvemapping_table_RGBA(CurveMapping *cumap, float **array, int *size)
{
	int a;
	
	*size = CM_TABLE+1;
	*array = MEM_callocN(sizeof(float)*(*size)*4, "CurveMapping");
	curvemapping_initialize(cumap);

	for(a=0; a<*size; a++) {
		if(cumap->cm[0].table)
			(*array)[a*4+0]= cumap->cm[0].table[a].y;
		if(cumap->cm[1].table)
			(*array)[a*4+1]= cumap->cm[1].table[a].y;
		if(cumap->cm[2].table)
			(*array)[a*4+2]= cumap->cm[2].table[a].y;
		if(cumap->cm[3].table)
			(*array)[a*4+3]= cumap->cm[3].table[a].y;
	}
}
コード例 #2
0
ファイル: light.c プロジェクト: wangyxuan/blender
void BKE_light_init(Light *la)
{
  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(la, id));

  la->r = la->g = la->b = la->k = 1.0f;
  la->energy = 10.0f;
  la->dist = 25.0f;
  la->spotsize = DEG2RADF(45.0f);
  la->spotblend = 0.15f;
  la->att2 = 1.0f;
  la->mode = LA_SHADOW;
  la->bufsize = 512;
  la->clipsta = 0.5f;
  la->clipend = 40.0f;
  la->bleedexp = 2.5f;
  la->samp = 3;
  la->bias = 1.0f;
  la->soft = 3.0f;
  la->area_size = la->area_sizey = la->area_sizez = 0.25f;
  la->buffers = 1;
  la->preview = NULL;
  la->falloff_type = LA_FALLOFF_INVSQUARE;
  la->coeff_const = 1.0f;
  la->coeff_lin = 0.0f;
  la->coeff_quad = 0.0f;
  la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
  la->cascade_max_dist = 200.0f;
  la->cascade_count = 4;
  la->cascade_exponent = 0.8f;
  la->cascade_fade = 0.1f;
  la->contact_dist = 0.2f;
  la->contact_bias = 0.03f;
  la->contact_spread = 0.2f;
  la->contact_thickness = 0.2f;
  la->spec_fac = 1.0f;
  la->att_dist = 40.0f;

  curvemapping_initialize(la->curfalloff);
}
コード例 #3
0
ファイル: brush.c プロジェクト: wangyxuan/blender
/**** Radial Control ****/
struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary)
{
  ImBuf *im = MEM_callocN(sizeof(ImBuf), "radial control texture");
  unsigned int *texcache;
  int side = 128;
  int half = side / 2;
  int i, j;

  curvemapping_initialize(br->curve);
  texcache = BKE_brush_gen_texture_cache(br, half, secondary);
  im->rect_float = MEM_callocN(sizeof(float) * side * side, "radial control rect");
  im->x = im->y = side;

  for (i = 0; i < side; ++i) {
    for (j = 0; j < side; ++j) {
      float magn = sqrtf(pow2f(i - half) + pow2f(j - half));
      im->rect_float[i * side + j] = BKE_brush_curve_strength_clamped(br, magn, half);
    }
  }

  /* Modulate curve with texture */
  if (texcache) {
    for (i = 0; i < side; ++i) {
      for (j = 0; j < side; ++j) {
        const int col = texcache[i * side + j];
        im->rect_float[i * side + j] *= (((char *)&col)[0] + ((char *)&col)[1] +
                                         ((char *)&col)[2]) /
                                        3.0f / 255.0f;
      }
    }

    MEM_freeN(texcache);
  }

  return im;
}
コード例 #4
0
ファイル: rna_color.c プロジェクト: diekev/blender
static void rna_CurveMap_initialize(struct CurveMapping *cumap)
{
	curvemapping_initialize(cumap);
}
コード例 #5
0
ファイル: node_util.c プロジェクト: pawkoz/dyplom
void *node_initexec_curves(bNodeExecContext *UNUSED(context), bNode *node, bNodeInstanceKey UNUSED(key))
{
	curvemapping_initialize(node->storage);
	return NULL;  /* unused return */
}
コード例 #6
0
ファイル: MOD_warp.c プロジェクト: dfelinto/blender
static void warpModifier_do(WarpModifierData *wmd,
                            const ModifierEvalContext *ctx,
                            Mesh *mesh,
                            float (*vertexCos)[3],
                            int numVerts)
{
  Object *ob = ctx->object;
  float obinv[4][4];
  float mat_from[4][4];
  float mat_from_inv[4][4];
  float mat_to[4][4];
  float mat_unit[4][4];
  float mat_final[4][4];

  float tmat[4][4];

  const float falloff_radius_sq = SQUARE(wmd->falloff_radius);
  float strength = wmd->strength;
  float fac = 1.0f, weight;
  int i;
  int defgrp_index;
  MDeformVert *dvert, *dv = NULL;

  float(*tex_co)[3] = NULL;

  if (!(wmd->object_from && wmd->object_to)) {
    return;
  }

  MOD_get_vgroup(ob, mesh, wmd->defgrp_name, &dvert, &defgrp_index);
  if (dvert == NULL) {
    defgrp_index = -1;
  }

  if (wmd->curfalloff == NULL) { /* should never happen, but bad lib linking could cause it */
    wmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
  }

  if (wmd->curfalloff) {
    curvemapping_initialize(wmd->curfalloff);
  }

  invert_m4_m4(obinv, ob->obmat);

  mul_m4_m4m4(mat_from, obinv, wmd->object_from->obmat);
  mul_m4_m4m4(mat_to, obinv, wmd->object_to->obmat);

  invert_m4_m4(tmat, mat_from);  // swap?
  mul_m4_m4m4(mat_final, tmat, mat_to);

  invert_m4_m4(mat_from_inv, mat_from);

  unit_m4(mat_unit);

  if (strength < 0.0f) {
    float loc[3];
    strength = -strength;

    /* inverted location is not useful, just use the negative */
    copy_v3_v3(loc, mat_final[3]);
    invert_m4(mat_final);
    negate_v3_v3(mat_final[3], loc);
  }
  weight = strength;

  Tex *tex_target = wmd->texture;
  if (mesh != NULL && tex_target != NULL) {
    tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "warpModifier_do tex_co");
    MOD_get_texture_coords((MappingInfoModifierData *)wmd, ctx, ob, mesh, vertexCos, tex_co);

    MOD_init_texture((MappingInfoModifierData *)wmd, ctx);
  }

  for (i = 0; i < numVerts; i++) {
    float *co = vertexCos[i];

    if (wmd->falloff_type == eWarp_Falloff_None ||
        ((fac = len_squared_v3v3(co, mat_from[3])) < falloff_radius_sq &&
         (fac = (wmd->falloff_radius - sqrtf(fac)) / wmd->falloff_radius))) {
      /* skip if no vert group found */
      if (defgrp_index != -1) {
        dv = &dvert[i];
        weight = defvert_find_weight(dv, defgrp_index) * strength;
        if (weight <= 0.0f) {
          continue;
        }
      }

      /* closely match PROP_SMOOTH and similar */
      switch (wmd->falloff_type) {
        case eWarp_Falloff_None:
          fac = 1.0f;
          break;
        case eWarp_Falloff_Curve:
          fac = curvemapping_evaluateF(wmd->curfalloff, 0, fac);
          break;
        case eWarp_Falloff_Sharp:
          fac = fac * fac;
          break;
        case eWarp_Falloff_Smooth:
          fac = 3.0f * fac * fac - 2.0f * fac * fac * fac;
          break;
        case eWarp_Falloff_Root:
          fac = sqrtf(fac);
          break;
        case eWarp_Falloff_Linear:
          /* pass */
          break;
        case eWarp_Falloff_Const:
          fac = 1.0f;
          break;
        case eWarp_Falloff_Sphere:
          fac = sqrtf(2 * fac - fac * fac);
          break;
        case eWarp_Falloff_InvSquare:
          fac = fac * (2.0f - fac);
          break;
      }

      fac *= weight;

      if (tex_co) {
        struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
        TexResult texres;
        texres.nor = NULL;
        BKE_texture_get_value(scene, tex_target, tex_co[i], &texres, false);
        fac *= texres.tin;
      }

      if (fac != 0.0f) {
        /* into the 'from' objects space */
        mul_m4_v3(mat_from_inv, co);

        if (fac == 1.0f) {
          mul_m4_v3(mat_final, co);
        }
        else {
          if (wmd->flag & MOD_WARP_VOLUME_PRESERVE) {
            /* interpolate the matrix for nicer locations */
            blend_m4_m4m4(tmat, mat_unit, mat_final, fac);
            mul_m4_v3(tmat, co);
          }
          else {
            float tvec[3];
            mul_v3_m4v3(tvec, mat_final, co);
            interp_v3_v3v3(co, co, tvec, fac);
          }
        }

        /* out of the 'from' objects space */
        mul_m4_v3(mat_from, co);
      }
    }
  }

  if (tex_co) {
    MEM_freeN(tex_co);
  }
}
コード例 #7
0
ファイル: MOD_warp.c プロジェクト: 244xiao/blender
static void warpModifier_do(WarpModifierData *wmd, Object *ob,
                            DerivedMesh *dm, float (*vertexCos)[3], int numVerts)
{
	float obinv[4][4];
	float mat_from[4][4];
	float mat_from_inv[4][4];
	float mat_to[4][4];
	float mat_unit[4][4];
	float mat_final[4][4];

	float tmat[4][4];

	float strength = wmd->strength;
	float fac = 1.0f, weight;
	int i;
	int defgrp_index;
	MDeformVert *dvert, *dv = NULL;

	float (*tex_co)[3] = NULL;

	if (!(wmd->object_from && wmd->object_to))
		return;

	modifier_get_vgroup(ob, dm, wmd->defgrp_name, &dvert, &defgrp_index);

	if (wmd->curfalloff == NULL) /* should never happen, but bad lib linking could cause it */
		wmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);

	if (wmd->curfalloff) {
		curvemapping_initialize(wmd->curfalloff);
	}

	invert_m4_m4(obinv, ob->obmat);

	mul_m4_m4m4(mat_from, obinv, wmd->object_from->obmat);
	mul_m4_m4m4(mat_to, obinv, wmd->object_to->obmat);

	invert_m4_m4(tmat, mat_from); // swap?
	mul_m4_m4m4(mat_final, tmat, mat_to);

	invert_m4_m4(mat_from_inv, mat_from);

	unit_m4(mat_unit);

	if (strength < 0.0f) {
		float loc[3];
		strength = -strength;

		/* inverted location is not useful, just use the negative */
		copy_v3_v3(loc, mat_final[3]);
		invert_m4(mat_final);
		negate_v3_v3(mat_final[3], loc);

	}
	weight = strength;

	if (wmd->texture) {
		tex_co = MEM_mallocN(sizeof(*tex_co) * numVerts, "warpModifier_do tex_co");
		get_texture_coords((MappingInfoModifierData *)wmd, ob, dm, vertexCos, tex_co, numVerts);

		modifier_init_texture(wmd->modifier.scene, wmd->texture);
	}

	for (i = 0; i < numVerts; i++) {
		float *co = vertexCos[i];

		if (wmd->falloff_type == eWarp_Falloff_None ||
		    ((fac = len_v3v3(co, mat_from[3])) < wmd->falloff_radius &&
		     (fac = (wmd->falloff_radius - fac) / wmd->falloff_radius)))
		{
			/* skip if no vert group found */
			if (dvert && defgrp_index != -1) {
				dv = &dvert[i];

				if (dv) {
					weight = defvert_find_weight(dv, defgrp_index) * strength;
					if (weight <= 0.0f) /* Should never occure... */
						continue;
				}
			}


			/* closely match PROP_SMOOTH and similar */
			switch (wmd->falloff_type) {
				case eWarp_Falloff_None:
					fac = 1.0f;
					break;
				case eWarp_Falloff_Curve:
					fac = curvemapping_evaluateF(wmd->curfalloff, 0, fac);
					break;
				case eWarp_Falloff_Sharp:
					fac = fac * fac;
					break;
				case eWarp_Falloff_Smooth:
					fac = 3.0f * fac * fac - 2.0f * fac * fac * fac;
					break;
				case eWarp_Falloff_Root:
					fac = (float)sqrt(fac);
					break;
				case eWarp_Falloff_Linear:
					/* pass */
					break;
				case eWarp_Falloff_Const:
					fac = 1.0f;
					break;
				case eWarp_Falloff_Sphere:
					fac = (float)sqrt(2 * fac - fac * fac);
					break;
			}

			fac *= weight;

			if (tex_co) {
				TexResult texres;
				texres.nor = NULL;
				get_texture_value(wmd->modifier.scene, wmd->texture, tex_co[i], &texres, false);
				fac *= texres.tin;
			}

			/* into the 'from' objects space */
			mul_m4_v3(mat_from_inv, co);

			if (fac >= 1.0f) {
				mul_m4_v3(mat_final, co);
			}
			else if (fac > 0.0f) {
				if (wmd->flag & MOD_WARP_VOLUME_PRESERVE) {
					/* interpolate the matrix for nicer locations */
					blend_m4_m4m4(tmat, mat_unit, mat_final, fac);
					mul_m4_v3(tmat, co);
				}
				else {
					float tvec[3];
					mul_v3_m4v3(tvec, mat_final, co);
					interp_v3_v3v3(co, co, tvec, fac);
				}
			}

			/* out of the 'from' objects space */
			mul_m4_v3(mat_from, co);
		}
	}

	if (tex_co)
		MEM_freeN(tex_co);

}
コード例 #8
0
static void deformVerts_do(HookModifierData *hmd, Object *ob, DerivedMesh *dm,
                           float (*vertexCos)[3], int numVerts)
{
	bPoseChannel *pchan = BKE_pose_channel_find_name(hmd->object->pose, hmd->subtarget);
	float dmat[4][4];
	int i, *index_pt;
	struct HookData_cb hd;
	
	if (hmd->curfalloff == NULL) {
		/* should never happen, but bad lib linking could cause it */
		hmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
	}

	if (hmd->curfalloff) {
		curvemapping_initialize(hmd->curfalloff);
	}

	/* Generic data needed for applying per-vertex calculations (initialize all members) */
	hd.vertexCos = vertexCos;
	modifier_get_vgroup(ob, dm, hmd->name, &hd.dvert, &hd.defgrp_index);

	hd.curfalloff = hmd->curfalloff;

	hd.falloff_type = hmd->falloff_type;
	hd.falloff = (hmd->falloff_type == eHook_Falloff_None) ? 0.0f : hmd->falloff;
	hd.falloff_sq = SQUARE(hd.falloff);
	hd.fac_orig = hmd->force;

	hd.use_falloff = (hd.falloff_sq != 0.0f);
	hd.use_uniform = (hmd->flag & MOD_HOOK_UNIFORM_SPACE) != 0;

	if (hd.use_uniform) {
		copy_m3_m4(hd.mat_uniform, hmd->parentinv);
		mul_v3_m3v3(hd.cent, hd.mat_uniform, hmd->cent);
	}
	else {
		unit_m3(hd.mat_uniform);  /* unused */
		copy_v3_v3(hd.cent, hmd->cent);
	}

	/* get world-space matrix of target, corrected for the space the verts are in */
	if (hmd->subtarget[0] && pchan) {
		/* bone target if there's a matching pose-channel */
		mul_m4_m4m4(dmat, hmd->object->obmat, pchan->pose_mat);
	}
	else {
		/* just object target */
		copy_m4_m4(dmat, hmd->object->obmat);
	}
	invert_m4_m4(ob->imat, ob->obmat);
	mul_m4_series(hd.mat, ob->imat, dmat, hmd->parentinv);
	/* --- done with 'hd' init --- */


	/* Regarding index range checking below.
	 *
	 * This should always be true and I don't generally like 
	 * "paranoid" style code like this, but old files can have
	 * indices that are out of range because old blender did
	 * not correct them on exit editmode. - zr
	 */

	if (hmd->force == 0.0f) {
		/* do nothing, avoid annoying checks in the loop */
	}
	else if (hmd->indexar) { /* vertex indices? */
		const int *origindex_ar;
		
		/* if DerivedMesh is present and has original index data, use it */
		if (dm && (origindex_ar = dm->getVertDataArray(dm, CD_ORIGINDEX))) {
			for (i = 0, index_pt = hmd->indexar; i < hmd->totindex; i++, index_pt++) {
				if (*index_pt < numVerts) {
					int j;
					
					for (j = 0; j < numVerts; j++) {
						if (origindex_ar[j] == *index_pt) {
							hook_co_apply(&hd, j);
						}
					}
				}
			}
		}
		else { /* missing dm or ORIGINDEX */
			for (i = 0, index_pt = hmd->indexar; i < hmd->totindex; i++, index_pt++) {
				if (*index_pt < numVerts) {
					hook_co_apply(&hd, *index_pt);
				}
			}
		}
	}
	else if (hd.dvert) {  /* vertex group hook */
		for (i = 0; i < numVerts; i++) {
			hook_co_apply(&hd, i);
		}
	}
}
コード例 #9
0
/**
 * Update defaults in startup.blend, without having to save and embed the file.
 * This function can be emptied each time the startup.blend is updated. */
void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
{
  /* For all builtin templates shipped with Blender. */
  const bool builtin_template =
      (!app_template ||
       STR_ELEM(app_template, "2D_Animation", "Sculpting", "VFX", "Video_Editing"));

  /* For all startup.blend files. */
  for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
    for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
      for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
        /* Remove all stored panels, we want to use defaults
         * (order, open/closed) as defined by UI code here! */
        BKE_area_region_panels_free(&ar->panels);

        /* some toolbars have been saved as initialized,
         * we don't want them to have odd zoom-level or scrolling set, see: T47047 */
        if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) {
          ar->v2d.flag &= ~V2D_IS_INITIALISED;
        }
      }

      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
        switch (sl->spacetype) {
          case SPACE_VIEW3D: {
            View3D *v3d = (View3D *)sl;
            v3d->overlay.texture_paint_mode_opacity = 1.0f;
            v3d->overlay.weight_paint_mode_opacity = 1.0f;
            v3d->overlay.vertex_paint_mode_opacity = 1.0f;
            /* grease pencil settings */
            v3d->vertex_opacity = 1.0f;
            v3d->gp_flag |= V3D_GP_SHOW_EDIT_LINES;
            /* Skip startups that use the viewport color by default. */
            if (v3d->shading.background_type != V3D_SHADING_BACKGROUND_VIEWPORT) {
              copy_v3_fl(v3d->shading.background_color, 0.05f);
            }
            break;
          }
          case SPACE_FILE: {
            SpaceFile *sfile = (SpaceFile *)sl;
            if (sfile->params) {
              const char *dir_default = BKE_appdir_folder_default();
              if (dir_default) {
                STRNCPY(sfile->params->dir, dir_default);
                sfile->params->file[0] = '\0';
              }
            }
            break;
          }
        }
      }
    }
  }

  if (builtin_template) {
    /* Name all screens by their workspaces (avoids 'Default.###' names). */
    /* Default only has one window. */
    wmWindow *win = ((wmWindowManager *)bmain->wm.first)->windows.first;
    for (WorkSpace *workspace = bmain->workspaces.first; workspace;
         workspace = workspace->id.next) {
      WorkSpaceLayout *layout = BKE_workspace_hook_layout_for_workspace_get(win->workspace_hook,
                                                                            workspace);
      bScreen *screen = layout->screen;
      BLI_strncpy(screen->id.name + 2, workspace->id.name + 2, sizeof(screen->id.name) - 2);
      BLI_libblock_ensure_unique_name(bmain, screen->id.name);
    }
  }

  if (app_template == NULL) {
    /* 'UV Editing' should use UV mode. */
    bScreen *screen = BLI_findstring(&bmain->screens, "UV Editing", offsetof(ID, name) + 2);
    for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
        if (sl->spacetype == SPACE_IMAGE) {
          SpaceImage *sima = (SpaceImage *)sl;
          if (sima->mode == SI_MODE_VIEW) {
            sima->mode = SI_MODE_UV;
          }
        }
      }
    }
  }

  /* For 2D animation template. */
  if (app_template && STREQ(app_template, "2D_Animation")) {
    for (WorkSpace *workspace = bmain->workspaces.first; workspace;
         workspace = workspace->id.next) {
      const char *name = workspace->id.name + 2;

      if (STREQ(name, "Drawing")) {
        workspace->object_mode = OB_MODE_PAINT_GPENCIL;
      }
    }
    /* set object in drawing mode */
    for (Object *object = bmain->objects.first; object; object = object->id.next) {
      if (object->type == OB_GPENCIL) {
        bGPdata *gpd = (bGPdata *)object->data;
        object->mode = OB_MODE_PAINT_GPENCIL;
        gpd->flag |= GP_DATA_STROKE_PAINTMODE;
        break;
      }
    }

    /* Be sure curfalloff and primitive are initializated */
    for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
      ToolSettings *ts = scene->toolsettings;
      if (ts->gp_sculpt.cur_falloff == NULL) {
        ts->gp_sculpt.cur_falloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
        CurveMapping *gp_falloff_curve = ts->gp_sculpt.cur_falloff;
        curvemapping_initialize(gp_falloff_curve);
        curvemap_reset(gp_falloff_curve->cm,
                       &gp_falloff_curve->clipr,
                       CURVE_PRESET_GAUSS,
                       CURVEMAP_SLOPE_POSITIVE);
      }
      if (ts->gp_sculpt.cur_primitive == NULL) {
        ts->gp_sculpt.cur_primitive = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
        CurveMapping *gp_primitive_curve = ts->gp_sculpt.cur_primitive;
        curvemapping_initialize(gp_primitive_curve);
        curvemap_reset(gp_primitive_curve->cm,
                       &gp_primitive_curve->clipr,
                       CURVE_PRESET_BELL,
                       CURVEMAP_SLOPE_POSITIVE);
      }
    }
  }

  if (builtin_template) {
    /* Clear all tools to use default options instead, ignore the tool saved in the file. */
    for (WorkSpace *workspace = bmain->workspaces.first; workspace;
         workspace = workspace->id.next) {
      while (!BLI_listbase_is_empty(&workspace->tools)) {
        BKE_workspace_tool_remove(workspace, workspace->tools.first);
      }
    }

    for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
      for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
        if (sa->spacetype == SPACE_ACTION) {
          /* Show marker lines, hide channels and collapse summary in timelines. */
          SpaceAction *saction = sa->spacedata.first;
          saction->flag |= SACTION_SHOW_MARKER_LINES;

          if (saction->mode == SACTCONT_TIMELINE) {
            saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED;

            for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
              if (ar->regiontype == RGN_TYPE_CHANNELS) {
                ar->flag |= RGN_FLAG_HIDDEN;
              }
            }
          }
        }
        else if (sa->spacetype == SPACE_GRAPH) {
          SpaceGraph *sipo = sa->spacedata.first;
          sipo->flag |= SIPO_MARKER_LINES;
        }
        else if (sa->spacetype == SPACE_NLA) {
          SpaceNla *snla = sa->spacedata.first;
          snla->flag |= SNLA_SHOW_MARKER_LINES;
        }
        else if (sa->spacetype == SPACE_TEXT) {
          /* Show syntax and line numbers in Script workspace text editor. */
          SpaceText *stext = sa->spacedata.first;
          stext->showsyntax = true;
          stext->showlinenrs = true;
        }
        else if (sa->spacetype == SPACE_VIEW3D) {
          /* Screen space cavity by default for faster performance. */
          View3D *v3d = sa->spacedata.first;
          v3d->shading.cavity_type = V3D_SHADING_CAVITY_CURVATURE;
        }
        else if (sa->spacetype == SPACE_CLIP) {
          SpaceClip *sclip = sa->spacedata.first;
          sclip->around = V3D_AROUND_CENTER_MEDIAN;
        }
      }
    }

    /* Show toopbar for sculpt/paint modes. */
    for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
      bool show_tool_header = false;
      if (app_template == NULL) {
        if (STR_ELEM(screen->id.name + 2, "Sculpting", "Texture Paint")) {
          show_tool_header = true;
        }
      }
      else if (STREQ(app_template, "2D_Animation")) {
        if (STR_ELEM(screen->id.name + 2, "2D Animation", "2D Full Canvas")) {
          show_tool_header = true;
        }
      }
      else if (STREQ(app_template, "Sculpting")) {
        if (STR_ELEM(screen->id.name + 2, "Sculpting")) {
          show_tool_header = true;
        }
      }

      if (show_tool_header) {
        for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
          for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
            ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
            for (ARegion *ar = regionbase->first; ar; ar = ar->next) {
              if (ar->regiontype == RGN_TYPE_TOOL_HEADER) {
                ar->flag &= ~(RGN_FLAG_HIDDEN | RGN_FLAG_HIDDEN_BY_USER);
              }
            }
          }
        }
      }
    }

    for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
      BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));

      scene->r.cfra = 1.0f;
      scene->r.displaymode = R_OUTPUT_WINDOW;

      if (app_template && STREQ(app_template, "Video_Editing")) {
        /* Filmic is too slow, use default until it is optimized. */
        STRNCPY(scene->view_settings.view_transform, "Default");
        STRNCPY(scene->view_settings.look, "None");
      }
      else {
        /* AV Sync break physics sim caching, disable until that is fixed. */
        scene->audio.flag &= ~AUDIO_SYNC;
        scene->flag &= ~SCE_FRAME_DROP;
      }

      /* Don't enable compositing nodes. */
      if (scene->nodetree) {
        ntreeFreeNestedTree(scene->nodetree);
        MEM_freeN(scene->nodetree);
        scene->nodetree = NULL;
        scene->use_nodes = false;
      }

      /* Rename render layers. */
      BKE_view_layer_rename(bmain, scene, scene->view_layers.first, "View Layer");

      /* New EEVEE defaults. */
      scene->eevee.bloom_intensity = 0.05f;
      scene->eevee.bloom_clamp = 0.0f;
      scene->eevee.motion_blur_shutter = 0.5f;
    }

    /* Rename light objects. */
    rename_id_for_versioning(bmain, ID_OB, "Lamp", "Light");
    rename_id_for_versioning(bmain, ID_LA, "Lamp", "Light");

    for (Mesh *mesh = bmain->meshes.first; mesh; mesh = mesh->id.next) {
      /* Match default for new meshes. */
      mesh->smoothresh = DEG2RADF(30);
    }
  }

  for (bScreen *sc = bmain->screens.first; sc; sc = sc->id.next) {
    for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
        if (sl->spacetype == SPACE_VIEW3D) {
          View3D *v3d = (View3D *)sl;
          v3d->shading.flag |= V3D_SHADING_SPECULAR_HIGHLIGHT;
        }
      }
    }
  }

  for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
    copy_v3_v3(scene->display.light_direction, (float[3]){M_SQRT1_3, M_SQRT1_3, M_SQRT1_3});
    copy_v2_fl2(scene->safe_areas.title, 0.1f, 0.05f);
    copy_v2_fl2(scene->safe_areas.action, 0.035f, 0.035f);
  }
コード例 #10
0
static void do_curves(bNode *node, float *out, float *in)
{
	curvemapping_initialize(node->storage);
	curvemapping_evaluate_premulRGBF(node->storage, out, in);
	out[3] = in[3];
}
コード例 #11
0
ファイル: brush.c プロジェクト: wangyxuan/blender
/* create a set of grease pencil presets */
void BKE_brush_gpencil_presets(bContext *C)
{
#define SMOOTH_STROKE_RADIUS 40
#define SMOOTH_STROKE_FACTOR 0.9f

  ToolSettings *ts = CTX_data_tool_settings(C);
  Paint *paint = &ts->gp_paint->paint;
  Main *bmain = CTX_data_main(C);

  Brush *brush, *deft;
  CurveMapping *custom_curve;

  /* Pencil brush */
  brush = BKE_brush_add_gpencil(bmain, ts, "Draw Pencil");
  brush->size = 25.0f;
  brush->gpencil_settings->flag |= (GP_BRUSH_USE_PRESSURE | GP_BRUSH_ENABLE_CURSOR);
  brush->gpencil_settings->draw_sensitivity = 1.0f;

  brush->gpencil_settings->draw_strength = 0.6f;
  brush->gpencil_settings->flag |= GP_BRUSH_USE_STENGTH_PRESSURE;

  brush->gpencil_settings->draw_random_press = 0.0f;

  brush->gpencil_settings->draw_jitter = 0.0f;
  brush->gpencil_settings->flag |= GP_BRUSH_USE_JITTER_PRESSURE;

  brush->gpencil_settings->draw_angle = 0.0f;
  brush->gpencil_settings->draw_angle_factor = 0.0f;

  brush->gpencil_settings->flag |= GP_BRUSH_GROUP_SETTINGS;
  brush->gpencil_settings->draw_smoothfac = 0.1f;
  brush->gpencil_settings->draw_smoothlvl = 1;
  brush->gpencil_settings->thick_smoothfac = 1.0f;
  brush->gpencil_settings->thick_smoothlvl = 3;
  brush->gpencil_settings->draw_subdivide = 1;
  brush->gpencil_settings->draw_random_sub = 0.0f;
  brush->gpencil_settings->icon_id = GP_BRUSH_ICON_PENCIL;
  brush->gpencil_tool = GPAINT_TOOL_DRAW;

  brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS;
  brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR;

  brush->gpencil_settings->gradient_f = 1.0f;
  brush->gpencil_settings->gradient_s[0] = 1.0f;
  brush->gpencil_settings->gradient_s[1] = 1.0f;

  /* Pen brush */
  brush = BKE_brush_add_gpencil(bmain, ts, "Draw Pen");
  deft = brush; /* save default brush */
  brush->size = 30.0f;
  brush->gpencil_settings->flag |= (GP_BRUSH_USE_PRESSURE | GP_BRUSH_ENABLE_CURSOR);
  brush->gpencil_settings->draw_sensitivity = 1.0f;

  brush->gpencil_settings->draw_strength = 1.0f;
  brush->gpencil_settings->flag |= GP_BRUSH_USE_STENGTH_PRESSURE;

  brush->gpencil_settings->draw_random_press = 0.0f;
  brush->gpencil_settings->draw_random_strength = 0.0f;

  brush->gpencil_settings->draw_jitter = 0.0f;
  brush->gpencil_settings->flag |= GP_BRUSH_USE_JITTER_PRESSURE;

  brush->gpencil_settings->draw_angle = 0.0f;
  brush->gpencil_settings->draw_angle_factor = 0.0f;

  brush->gpencil_settings->flag |= GP_BRUSH_GROUP_SETTINGS;
  brush->gpencil_settings->draw_smoothfac = 0.1f;
  brush->gpencil_settings->draw_smoothlvl = 1;
  brush->gpencil_settings->draw_subdivide = 1;
  brush->gpencil_settings->thick_smoothfac = 1.0f;
  brush->gpencil_settings->thick_smoothlvl = 3;
  brush->gpencil_settings->draw_random_sub = 0.0f;
  brush->gpencil_settings->icon_id = GP_BRUSH_ICON_PEN;
  brush->gpencil_tool = GPAINT_TOOL_DRAW;

  brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS;
  brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR;

  brush->gpencil_settings->gradient_f = 1.0f;
  brush->gpencil_settings->gradient_s[0] = 1.0f;
  brush->gpencil_settings->gradient_s[1] = 1.0f;

  /* Ink brush */
  brush = BKE_brush_add_gpencil(bmain, ts, "Draw Ink");
  brush->size = 60.0f;
  brush->gpencil_settings->flag |= (GP_BRUSH_USE_PRESSURE | GP_BRUSH_ENABLE_CURSOR);
  brush->gpencil_settings->draw_sensitivity = 1.6f;

  brush->gpencil_settings->draw_strength = 1.0f;

  brush->gpencil_settings->draw_random_press = 0.0f;

  brush->gpencil_settings->draw_jitter = 0.0f;
  brush->gpencil_settings->flag |= GP_BRUSH_USE_JITTER_PRESSURE;

  brush->gpencil_settings->draw_angle = 0.0f;
  brush->gpencil_settings->draw_angle_factor = 0.0f;

  brush->gpencil_settings->flag |= GP_BRUSH_GROUP_SETTINGS;
  brush->gpencil_settings->draw_smoothfac = 0.1f;
  brush->gpencil_settings->draw_smoothlvl = 1;
  brush->gpencil_settings->thick_smoothfac = 1.0f;
  brush->gpencil_settings->thick_smoothlvl = 3;
  brush->gpencil_settings->draw_subdivide = 1;
  brush->gpencil_settings->draw_random_sub = 0.0f;
  brush->gpencil_settings->icon_id = GP_BRUSH_ICON_INK;
  brush->gpencil_tool = GPAINT_TOOL_DRAW;

  brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS;
  brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR;

  brush->gpencil_settings->gradient_f = 1.0f;
  brush->gpencil_settings->gradient_s[0] = 1.0f;
  brush->gpencil_settings->gradient_s[1] = 1.0f;

  /* Curve */
  custom_curve = brush->gpencil_settings->curve_sensitivity;
  curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
  curvemapping_initialize(custom_curve);
  brush_gpencil_curvemap_reset(custom_curve->cm, 3, GPCURVE_PRESET_INK);

  /* Ink Noise brush */
  brush = BKE_brush_add_gpencil(bmain, ts, "Draw Noise");
  brush->size = 60.0f;
  brush->gpencil_settings->flag |= (GP_BRUSH_USE_PRESSURE | GP_BRUSH_ENABLE_CURSOR);
  brush->gpencil_settings->draw_sensitivity = 1.0f;

  brush->gpencil_settings->draw_strength = 1.0f;

  brush->gpencil_settings->flag |= GP_BRUSH_GROUP_RANDOM;
  brush->gpencil_settings->draw_random_press = 0.7f;
  brush->gpencil_settings->draw_random_strength = 0.0f;

  brush->gpencil_settings->draw_jitter = 0.0f;
  brush->gpencil_settings->flag |= GP_BRUSH_USE_JITTER_PRESSURE;

  brush->gpencil_settings->draw_angle = 0.0f;
  brush->gpencil_settings->draw_angle_factor = 0.0f;

  brush->gpencil_settings->flag |= GP_BRUSH_GROUP_SETTINGS;
  brush->gpencil_settings->draw_smoothfac = 0.1f;
  brush->gpencil_settings->draw_smoothlvl = 2;
  brush->gpencil_settings->thick_smoothfac = 0.5f;
  brush->gpencil_settings->thick_smoothlvl = 2;
  brush->gpencil_settings->draw_subdivide = 1;
  brush->gpencil_settings->draw_random_sub = 0.0f;
  brush->gpencil_settings->icon_id = GP_BRUSH_ICON_INKNOISE;
  brush->gpencil_tool = GPAINT_TOOL_DRAW;

  brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS;
  brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR;

  /* Curve */
  custom_curve = brush->gpencil_settings->curve_sensitivity;
  curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
  curvemapping_initialize(custom_curve);
  brush_gpencil_curvemap_reset(custom_curve->cm, 3, GPCURVE_PRESET_INKNOISE);

  brush->gpencil_settings->gradient_f = 1.0f;
  brush->gpencil_settings->gradient_s[0] = 1.0f;
  brush->gpencil_settings->gradient_s[1] = 1.0f;

  /* Block Basic brush */
  brush = BKE_brush_add_gpencil(bmain, ts, "Draw Block");
  brush->size = 150.0f;
  brush->gpencil_settings->flag |= (GP_BRUSH_USE_PRESSURE | GP_BRUSH_ENABLE_CURSOR);
  brush->gpencil_settings->draw_sensitivity = 1.0f;

  brush->gpencil_settings->draw_strength = 1.0f;

  brush->gpencil_settings->draw_random_press = 0.0f;

  brush->gpencil_settings->draw_jitter = 0.0f;
  brush->gpencil_settings->flag |= GP_BRUSH_USE_JITTER_PRESSURE;

  brush->gpencil_settings->draw_angle = 0.0f;
  brush->gpencil_settings->draw_angle_factor = 0.0f;

  brush->gpencil_settings->draw_smoothfac = 0.1f;
  brush->gpencil_settings->draw_smoothlvl = 1;
  brush->gpencil_settings->thick_smoothfac = 1.0f;
  brush->gpencil_settings->thick_smoothlvl = 3;
  brush->gpencil_settings->draw_subdivide = 0;
  brush->gpencil_settings->draw_random_sub = 0;
  brush->gpencil_settings->icon_id = GP_BRUSH_ICON_BLOCK;
  brush->gpencil_tool = GPAINT_TOOL_DRAW;

  brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS;
  brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR;

  brush->gpencil_settings->gradient_f = 1.0f;
  brush->gpencil_settings->gradient_s[0] = 1.0f;
  brush->gpencil_settings->gradient_s[1] = 1.0f;

  /* Marker brush */
  brush = BKE_brush_add_gpencil(bmain, ts, "Draw Marker");
  brush->size = 80.0f;
  brush->gpencil_settings->flag |= (GP_BRUSH_USE_PRESSURE | GP_BRUSH_ENABLE_CURSOR);
  brush->gpencil_settings->draw_sensitivity = 1.0f;

  brush->gpencil_settings->draw_strength = 1.0f;

  brush->gpencil_settings->flag |= GP_BRUSH_GROUP_RANDOM;
  brush->gpencil_settings->draw_random_press = 0.374f;
  brush->gpencil_settings->draw_random_strength = 0.0f;

  brush->gpencil_settings->draw_jitter = 0.0f;
  brush->gpencil_settings->flag |= GP_BRUSH_USE_JITTER_PRESSURE;

  brush->gpencil_settings->draw_angle = DEG2RAD(20.0f);
  brush->gpencil_settings->draw_angle_factor = 1.0f;

  brush->gpencil_settings->flag |= GP_BRUSH_GROUP_SETTINGS;
  brush->gpencil_settings->draw_smoothfac = 0.1f;
  brush->gpencil_settings->draw_smoothlvl = 1;
  brush->gpencil_settings->thick_smoothfac = 1.0f;
  brush->gpencil_settings->thick_smoothlvl = 3;
  brush->gpencil_settings->draw_subdivide = 1;
  brush->gpencil_settings->draw_random_sub = 0.0f;
  brush->gpencil_settings->icon_id = GP_BRUSH_ICON_MARKER;
  brush->gpencil_tool = GPAINT_TOOL_DRAW;

  brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS;
  brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR;
  /* Curve */
  custom_curve = brush->gpencil_settings->curve_sensitivity;
  curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
  curvemapping_initialize(custom_curve);
  brush_gpencil_curvemap_reset(custom_curve->cm, 4, GPCURVE_PRESET_MARKER);

  brush->gpencil_settings->gradient_f = 1.0f;
  brush->gpencil_settings->gradient_s[0] = 1.0f;
  brush->gpencil_settings->gradient_s[1] = 1.0f;

  /* Fill brush */
  brush = BKE_brush_add_gpencil(bmain, ts, "Fill Area");
  brush->size = 1.0f;
  brush->gpencil_settings->flag |= GP_BRUSH_ENABLE_CURSOR;
  brush->gpencil_settings->draw_sensitivity = 1.0f;
  brush->gpencil_settings->fill_leak = 3;
  brush->gpencil_settings->fill_threshold = 0.1f;
  brush->gpencil_settings->fill_simplylvl = 1;
  brush->gpencil_settings->fill_factor = 1;
  brush->gpencil_settings->icon_id = GP_BRUSH_ICON_FILL;
  brush->gpencil_tool = GPAINT_TOOL_FILL;

  brush->gpencil_settings->draw_smoothfac = 0.1f;
  brush->gpencil_settings->draw_smoothlvl = 1;
  brush->gpencil_settings->thick_smoothfac = 1.0f;
  brush->gpencil_settings->thick_smoothlvl = 3;
  brush->gpencil_settings->draw_subdivide = 1;

  brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS;
  brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR;

  brush->gpencil_settings->draw_strength = 1.0f;

  brush->gpencil_settings->gradient_f = 1.0f;
  brush->gpencil_settings->gradient_s[0] = 1.0f;
  brush->gpencil_settings->gradient_s[1] = 1.0f;

  /* Soft Eraser brush */
  brush = BKE_brush_add_gpencil(bmain, ts, "Eraser Soft");
  brush->size = 30.0f;
  brush->gpencil_settings->draw_strength = 0.5f;
  brush->gpencil_settings->flag |= (GP_BRUSH_ENABLE_CURSOR | GP_BRUSH_DEFAULT_ERASER);
  brush->gpencil_settings->flag |= GP_BRUSH_USE_PRESSURE;
  brush->gpencil_settings->flag |= GP_BRUSH_USE_STENGTH_PRESSURE;
  brush->gpencil_settings->icon_id = GP_BRUSH_ICON_ERASE_SOFT;
  brush->gpencil_tool = GPAINT_TOOL_ERASE;
  brush->gpencil_settings->eraser_mode = GP_BRUSH_ERASER_SOFT;
  brush->gpencil_settings->era_strength_f = 100.0f;
  brush->gpencil_settings->era_thickness_f = 10.0f;

  /* Hard Eraser brush */
  brush = BKE_brush_add_gpencil(bmain, ts, "Eraser Hard");
  brush->size = 30.0f;
  brush->gpencil_settings->draw_strength = 1.0f;
  brush->gpencil_settings->flag |= (GP_BRUSH_ENABLE_CURSOR | GP_BRUSH_DEFAULT_ERASER);
  brush->gpencil_settings->icon_id = GP_BRUSH_ICON_ERASE_HARD;
  brush->gpencil_tool = GPAINT_TOOL_ERASE;
  brush->gpencil_settings->eraser_mode = GP_BRUSH_ERASER_SOFT;
  brush->gpencil_settings->era_strength_f = 100.0f;
  brush->gpencil_settings->era_thickness_f = 50.0f;

  /* Point Eraser brush */
  brush = BKE_brush_add_gpencil(bmain, ts, "Eraser Point");
  brush->size = 30.0f;
  brush->gpencil_settings->flag |= GP_BRUSH_ENABLE_CURSOR;
  brush->gpencil_settings->icon_id = GP_BRUSH_ICON_ERASE_HARD;
  brush->gpencil_tool = GPAINT_TOOL_ERASE;
  brush->gpencil_settings->eraser_mode = GP_BRUSH_ERASER_HARD;

  /* Stroke Eraser brush */
  brush = BKE_brush_add_gpencil(bmain, ts, "Eraser Stroke");
  brush->size = 30.0f;
  brush->gpencil_settings->flag |= GP_BRUSH_ENABLE_CURSOR;
  brush->gpencil_settings->icon_id = GP_BRUSH_ICON_ERASE_STROKE;
  brush->gpencil_tool = GPAINT_TOOL_ERASE;
  brush->gpencil_settings->eraser_mode = GP_BRUSH_ERASER_STROKE;

  /* set default brush */
  BKE_paint_brush_set(paint, deft);
}