2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-12-30 14:37:25 +00:00
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-12-30 14:37:25 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2004 by Blender Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edobj
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2009-12-30 14:37:25 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2020-12-15 10:47:58 +11:00
|
|
|
#include "DNA_material_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "DNA_world_types.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
#include "BKE_blender.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_image.h"
|
2017-05-24 23:14:32 +10:00
|
|
|
#include "BKE_material.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_mesh.h"
|
|
|
|
#include "BKE_modifier.h"
|
2010-09-23 18:26:33 +00:00
|
|
|
#include "BKE_multires.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
#include "BKE_report.h"
|
2013-05-08 13:23:17 +00:00
|
|
|
#include "BKE_scene.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "RE_multires_bake.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
#include "RE_pipeline.h"
|
2020-11-09 15:42:38 +01:00
|
|
|
#include "RE_texture.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
#include "PIL_time.h"
|
|
|
|
|
|
|
|
#include "IMB_imbuf.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "IMB_imbuf_types.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2010-09-23 18:26:33 +00:00
|
|
|
#include "ED_object.h"
|
Bake API - bpy.ops.object.bake()
New operator that can calls a bake function to the current render engine when available. This commit provides no feature for the users, but allows external engines to be accessed by the operator and be integrated with the baking api.
The API itself is simple. Blender sends a populated array of BakePixels to the renderer, and gets back an array of floats with the result.
The Blender Internal (and multires) system is still running independent, but we eventually will pipe it through the API as well. Cycles baking will come next as a separated commit
Python Operator:
----------------
The operator can be called with some arguments, or a user interface can be created for it. In that case the arguments can be ommited and the interface can expose the settings from bpy.context.scene.render.bake
bpy.ops.object.bake(type='COMBINED', filepath="", width=512, height=512, margin=16, use_selected_to_active=False, cage_extrusion=0, cage="", normal_space='TANGENT', normal_r='POS_X', normal_g='POS_Y', normal_b='POS_Z', save_mode='INTERNAL', use_clear=False, use_split_materials=False, use_automatic_name=False)
Note: external save mode is currently disabled.
Supported Features:
------------------
* Margin - Baked result is extended this many pixels beyond the border of each UV "island," to soften seams in the texture.
* Selected to Active - bake shading on the surface of selected object to the active object. The rays are cast from the lowpoly object inwards towards the highpoly object. If the highpoly object is not entirely involved by the lowpoly object, you can tweak the rays start point with Cage Extrusion. For even more control of the cage you can use a Cage object.
* Cage Extrusion - distance to use for the inward ray cast when using selected to active
* Custom Cage - object to use as cage (instead of the lowpoly object).
* Normal swizzle - change the axis that gets mapped to RGB
* Normal space - save as tangent or object normal spaces
Supported Passes:
-----------------
Any pass that is supported by Blender renderlayer system. Though it's up to the external engine to provide a valid enum with its supported passes. Normal passes get a special treatment since we post-process them to converted and "swizzled"
Development Notes for External Engines:
---------------------------------------
(read them in bake_api.c)
* For a complete implementation example look at the Cycles Bake commit (next).
Review: D421
Reviewed by: Campbell Barton, Brecht van Lommel, Sergey Sharybin, Thomas Dinge
Normal map pipeline "consulting" by Andy Davies (metalliandy)
Original design by Brecht van Lommel.
The entire commit history can be found on the branch: bake-cycles
2014-01-02 19:05:07 -02:00
|
|
|
#include "ED_screen.h"
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
#include "ED_uvedit.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
#include "object_intern.h"
|
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
static Image *bake_object_image_get(Object *ob, int mat_nr)
|
|
|
|
{
|
|
|
|
Image *image = NULL;
|
|
|
|
ED_object_get_active_image(ob, mat_nr + 1, &image, NULL, NULL, NULL);
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Image **bake_object_image_get_array(Object *ob)
|
|
|
|
{
|
|
|
|
Image **image_array = MEM_mallocN(sizeof(Material *) * ob->totcol, __func__);
|
|
|
|
for (int i = 0; i < ob->totcol; i++) {
|
|
|
|
image_array[i] = bake_object_image_get(ob, i);
|
|
|
|
}
|
|
|
|
return image_array;
|
|
|
|
}
|
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* ****************** multires BAKING ********************** */
|
|
|
|
|
|
|
|
/* holder of per-object data needed for bake job
|
2012-03-03 16:31:46 +00:00
|
|
|
* needed to make job totally thread-safe */
|
2011-06-05 20:54:04 +00:00
|
|
|
typedef struct MultiresBakerJobData {
|
|
|
|
struct MultiresBakerJobData *next, *prev;
|
2017-05-24 23:14:32 +10:00
|
|
|
/* material aligned image array (for per-face bake image) */
|
|
|
|
struct {
|
|
|
|
Image **array;
|
|
|
|
int len;
|
|
|
|
} ob_image;
|
2011-06-05 20:54:04 +00:00
|
|
|
DerivedMesh *lores_dm, *hires_dm;
|
2013-10-09 15:51:14 +00:00
|
|
|
int lvl, tot_lvl;
|
2012-12-26 20:38:20 +00:00
|
|
|
ListBase images;
|
2011-06-05 20:54:04 +00:00
|
|
|
} MultiresBakerJobData;
|
|
|
|
|
|
|
|
/* data passing to multires-baker job */
|
|
|
|
typedef struct {
|
2018-06-18 11:51:02 +02:00
|
|
|
Scene *scene;
|
2011-06-05 20:54:04 +00:00
|
|
|
ListBase data;
|
2019-01-15 23:24:20 +11:00
|
|
|
/** Clear the images before baking */
|
|
|
|
bool bake_clear;
|
|
|
|
/** Bake-filter, aka margin */
|
|
|
|
int bake_filter;
|
|
|
|
/** mode of baking (displacement, normals, AO) */
|
|
|
|
short mode;
|
|
|
|
/** Use low-resolution mesh when baking displacement maps */
|
|
|
|
bool use_lores_mesh;
|
|
|
|
/** Number of rays to be cast when doing AO baking */
|
|
|
|
int number_of_rays;
|
|
|
|
/** Bias between object and start ray point when doing AO baking */
|
|
|
|
float bias;
|
|
|
|
/** Number of threads to be used for baking */
|
|
|
|
int threads;
|
|
|
|
/** User scale used to scale displacement when baking derivative map. */
|
|
|
|
float user_scale;
|
2011-06-05 20:54:04 +00:00
|
|
|
} MultiresBakeJob;
|
|
|
|
|
2013-07-31 03:44:45 +00:00
|
|
|
static bool multiresbake_check(bContext *C, wmOperator *op)
|
2011-09-28 05:53:40 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-06-05 20:54:04 +00:00
|
|
|
Object *ob;
|
|
|
|
Mesh *me;
|
|
|
|
MultiresModifierData *mmd;
|
2013-07-31 03:44:45 +00:00
|
|
|
bool ok = true;
|
|
|
|
int a;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-30 16:22:40 +00:00
|
|
|
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
|
2012-04-28 15:42:27 +00:00
|
|
|
ob = base->object;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob->type != OB_MESH) {
|
2012-10-14 15:29:09 +00:00
|
|
|
BKE_report(
|
|
|
|
op->reports, RPT_ERROR, "Baking of multires data only works with an active mesh object");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2011-06-05 20:54:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
me = (Mesh *)ob->data;
|
|
|
|
mmd = get_multires_modifier(scene, ob, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* Multi-resolution should be and be last in the stack */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ok && mmd) {
|
2011-06-05 20:54:04 +00:00
|
|
|
ModifierData *md;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
ok = mmd->totlvl > 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
for (md = (ModifierData *)mmd->modifier.next; md && ok; md = md->next) {
|
2020-05-08 10:14:02 +02:00
|
|
|
if (BKE_modifier_is_enabled(scene, md, eModifierMode_Realtime)) {
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ok) {
|
2011-06-05 20:54:04 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Multires data baking requires multi-resolution object");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-25 15:11:00 +10:00
|
|
|
if (!me->mloopuv) {
|
2011-06-05 20:54:04 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Mesh should be unwrapped before multires data baking");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2012-02-19 22:55:37 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
a = me->totpoly;
|
2011-06-05 20:54:04 +00:00
|
|
|
while (ok && a--) {
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
Image *ima = bake_object_image_get(ob, me->mpoly[a].mat_nr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ima) {
|
2011-06-05 20:54:04 +00:00
|
|
|
BKE_report(
|
|
|
|
op->reports, RPT_ERROR, "You should have active texture to use multires baker");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2012-02-19 22:55:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-11-15 15:59:58 +00:00
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ibuf) {
|
2012-10-13 13:40:05 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Baking should happen to image with image buffer");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ibuf->rect == NULL && ibuf->rect_float == NULL) {
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ibuf->rect_float && !(ibuf->channels == 0 || ibuf->channels == 4)) {
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!ok) {
|
2011-06-05 20:54:04 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Baking to unsupported image type");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-15 15:59:58 +00:00
|
|
|
BKE_image_release_ibuf(ima, ibuf, NULL);
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!ok) {
|
2011-06-05 20:54:04 +00:00
|
|
|
break;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
static DerivedMesh *multiresbake_create_loresdm(Scene *scene, Object *ob, int *lvl)
|
2011-06-05 20:54:04 +00:00
|
|
|
{
|
|
|
|
DerivedMesh *dm;
|
2012-04-28 15:42:27 +00:00
|
|
|
MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
|
|
|
|
Mesh *me = (Mesh *)ob->data;
|
2013-10-29 16:43:56 +00:00
|
|
|
MultiresModifierData tmp_mmd = *mmd;
|
2013-12-26 08:26:41 +11:00
|
|
|
DerivedMesh *cddm = CDDM_from_mesh(me);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
DM_set_only_copy(cddm, &CD_MASK_BAREMESH);
|
2018-10-30 17:04:06 +01:00
|
|
|
|
|
|
|
if (mmd->lvl == 0) {
|
|
|
|
dm = CDDM_copy(cddm);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-10-30 17:04:06 +01:00
|
|
|
tmp_mmd.lvl = mmd->lvl;
|
|
|
|
tmp_mmd.sculptlvl = mmd->lvl;
|
|
|
|
dm = multires_make_derived_from_derived(cddm, &tmp_mmd, scene, ob, 0);
|
2013-10-29 16:43:56 +00:00
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2013-10-29 16:43:56 +00:00
|
|
|
cddm->release(cddm);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2018-10-30 17:04:06 +01:00
|
|
|
*lvl = mmd->lvl;
|
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
return dm;
|
|
|
|
}
|
|
|
|
|
2020-10-26 12:32:22 +01:00
|
|
|
static DerivedMesh *multiresbake_create_hiresdm(Scene *scene, Object *ob, int *lvl)
|
2011-06-05 20:54:04 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Mesh *me = (Mesh *)ob->data;
|
|
|
|
MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
|
|
|
|
MultiresModifierData tmp_mmd = *mmd;
|
2013-12-26 08:26:41 +11:00
|
|
|
DerivedMesh *cddm = CDDM_from_mesh(me);
|
2011-06-05 20:54:04 +00:00
|
|
|
DerivedMesh *dm;
|
|
|
|
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
DM_set_only_copy(cddm, &CD_MASK_BAREMESH);
|
2012-12-18 17:46:42 +00:00
|
|
|
|
|
|
|
/* TODO: DM_set_only_copy wouldn't set mask for loop and poly data,
|
|
|
|
* but we really need BAREMESH only to save lots of memory
|
|
|
|
*/
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
CustomData_set_only_copy(&cddm->loopData, CD_MASK_BAREMESH.lmask);
|
|
|
|
CustomData_set_only_copy(&cddm->polyData, CD_MASK_BAREMESH.pmask);
|
2012-12-18 17:46:42 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
*lvl = mmd->totlvl;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
tmp_mmd.lvl = mmd->totlvl;
|
|
|
|
tmp_mmd.sculptlvl = mmd->totlvl;
|
2018-06-18 11:21:33 +02:00
|
|
|
dm = multires_make_derived_from_derived(cddm, &tmp_mmd, scene, ob, 0);
|
2011-06-05 20:54:04 +00:00
|
|
|
cddm->release(cddm);
|
|
|
|
|
|
|
|
return dm;
|
|
|
|
}
|
|
|
|
|
2013-02-20 15:06:13 +00:00
|
|
|
typedef enum ClearFlag {
|
2013-09-20 10:14:54 +00:00
|
|
|
CLEAR_TANGENT_NORMAL = 1,
|
2019-01-15 23:57:49 +11:00
|
|
|
CLEAR_DISPLACEMENT = 2,
|
2013-02-20 15:06:13 +00:00
|
|
|
} ClearFlag;
|
|
|
|
|
2013-09-20 10:14:58 +00:00
|
|
|
static void clear_single_image(Image *image, ClearFlag flag)
|
2011-06-05 20:54:04 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
const float vec_alpha[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
const float vec_solid[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
2013-02-20 15:06:13 +00:00
|
|
|
const float nor_alpha[4] = {0.5f, 0.5f, 1.0f, 0.0f};
|
|
|
|
const float nor_solid[4] = {0.5f, 0.5f, 1.0f, 1.0f};
|
2013-09-20 10:14:54 +00:00
|
|
|
const float disp_alpha[4] = {0.5f, 0.5f, 0.5f, 0.0f};
|
|
|
|
const float disp_solid[4] = {0.5f, 0.5f, 0.5f, 1.0f};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 11:53:50 +01:00
|
|
|
if ((image->id.tag & LIB_TAG_DOIT) == 0) {
|
2013-09-20 10:14:58 +00:00
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (flag == CLEAR_TANGENT_NORMAL) {
|
2013-09-20 10:14:58 +00:00
|
|
|
IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? nor_alpha : nor_solid);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else if (flag == CLEAR_DISPLACEMENT) {
|
2013-09-20 10:14:58 +00:00
|
|
|
IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? disp_alpha : disp_solid);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2013-09-20 10:14:58 +00:00
|
|
|
IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 11:53:50 +01:00
|
|
|
image->id.tag |= LIB_TAG_DOIT;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-09-20 10:14:58 +00:00
|
|
|
BKE_image_release_ibuf(image, ibuf, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-24 23:14:32 +10:00
|
|
|
static void clear_images_poly(Image **ob_image_array, int ob_image_array_len, ClearFlag flag)
|
2013-09-20 10:14:58 +00:00
|
|
|
{
|
2017-05-24 23:14:32 +10:00
|
|
|
for (int i = 0; i < ob_image_array_len; i++) {
|
|
|
|
Image *image = ob_image_array[i];
|
|
|
|
if (image) {
|
|
|
|
image->id.tag &= ~LIB_TAG_DOIT;
|
|
|
|
}
|
2013-09-20 10:14:58 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-24 23:14:32 +10:00
|
|
|
for (int i = 0; i < ob_image_array_len; i++) {
|
|
|
|
Image *image = ob_image_array[i];
|
|
|
|
if (image) {
|
|
|
|
clear_single_image(image, flag);
|
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-24 23:14:32 +10:00
|
|
|
for (int i = 0; i < ob_image_array_len; i++) {
|
|
|
|
Image *image = ob_image_array[i];
|
|
|
|
if (image) {
|
|
|
|
image->id.tag &= ~LIB_TAG_DOIT;
|
|
|
|
}
|
2013-09-20 10:14:58 +00:00
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
Object *ob;
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
int objects_baked = 0;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!multiresbake_check(C, op)) {
|
2011-06-05 20:54:04 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (scene->r.bake_flag & R_BAKE_CLEAR) { /* clear images */
|
2012-04-30 16:22:40 +00:00
|
|
|
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
|
2013-09-20 10:14:54 +00:00
|
|
|
ClearFlag clear_flag = 0;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
ob = base->object;
|
2017-05-24 23:14:32 +10:00
|
|
|
// me = (Mesh *)ob->data;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2013-09-20 10:14:54 +00:00
|
|
|
if (scene->r.bake_mode == RE_BAKE_NORMALS) {
|
|
|
|
clear_flag = CLEAR_TANGENT_NORMAL;
|
|
|
|
}
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
else if (scene->r.bake_mode == RE_BAKE_DISPLACEMENT) {
|
2013-09-20 10:14:54 +00:00
|
|
|
clear_flag = CLEAR_DISPLACEMENT;
|
|
|
|
}
|
|
|
|
|
2017-05-24 23:14:32 +10:00
|
|
|
{
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
Image **ob_image_array = bake_object_image_get_array(ob);
|
2017-05-24 23:14:32 +10:00
|
|
|
clear_images_poly(ob_image_array, ob->totcol, clear_flag);
|
|
|
|
MEM_freeN(ob_image_array);
|
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
}
|
|
|
|
|
2012-04-30 16:22:40 +00:00
|
|
|
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
|
2013-03-22 05:34:10 +00:00
|
|
|
MultiresBakeRender bkr = {NULL};
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
ob = base->object;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2019-09-17 17:24:44 +02:00
|
|
|
multires_flush_sculpt_updates(ob);
|
2011-11-30 11:04:57 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* copy data stored in job descriptor */
|
2018-06-18 11:51:02 +02:00
|
|
|
bkr.scene = scene;
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.bake_filter = scene->r.bake_filter;
|
|
|
|
bkr.mode = scene->r.bake_mode;
|
|
|
|
bkr.use_lores_mesh = scene->r.bake_flag & R_BAKE_LORES_MESH;
|
2012-12-18 17:46:42 +00:00
|
|
|
bkr.bias = scene->r.bake_biasdist;
|
2012-12-19 12:30:39 +00:00
|
|
|
bkr.number_of_rays = scene->r.bake_samples;
|
2013-05-08 13:23:17 +00:00
|
|
|
bkr.threads = BKE_scene_num_threads(scene);
|
2013-10-09 15:51:14 +00:00
|
|
|
bkr.user_scale = (scene->r.bake_flag & R_BAKE_USERSCALE) ? scene->r.bake_user_scale : -1.0f;
|
2019-05-01 11:09:22 +10:00
|
|
|
// bkr.reports= op->reports;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
/* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
bkr.ob_image.array = bake_object_image_get_array(ob);
|
2017-05-24 23:14:32 +10:00
|
|
|
bkr.ob_image.len = ob->totcol;
|
|
|
|
|
2020-10-26 12:32:22 +01:00
|
|
|
bkr.hires_dm = multiresbake_create_hiresdm(scene, ob, &bkr.tot_lvl);
|
2018-04-05 18:20:27 +02:00
|
|
|
bkr.lores_dm = multiresbake_create_loresdm(scene, ob, &bkr.lvl);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-12-18 17:46:26 +00:00
|
|
|
RE_multires_bake_images(&bkr);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2017-05-24 23:14:32 +10:00
|
|
|
MEM_freeN(bkr.ob_image.array);
|
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
BLI_freelistN(&bkr.image);
|
|
|
|
|
|
|
|
bkr.lores_dm->release(bkr.lores_dm);
|
|
|
|
bkr.hires_dm->release(bkr.hires_dm);
|
2011-12-29 16:05:09 +00:00
|
|
|
|
|
|
|
objects_baked++;
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!objects_baked) {
|
2011-12-29 16:05:09 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No objects found to bake from");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2011-12-29 16:05:09 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Multiresbake adopted for job-system executing */
|
|
|
|
static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj)
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-06-05 20:54:04 +00:00
|
|
|
Object *ob;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* backup scene settings, so their changing in UI would take no effect on baker */
|
2018-06-18 11:51:02 +02:00
|
|
|
bkj->scene = scene;
|
2012-04-28 15:42:27 +00:00
|
|
|
bkj->bake_filter = scene->r.bake_filter;
|
|
|
|
bkj->mode = scene->r.bake_mode;
|
|
|
|
bkj->use_lores_mesh = scene->r.bake_flag & R_BAKE_LORES_MESH;
|
|
|
|
bkj->bake_clear = scene->r.bake_flag & R_BAKE_CLEAR;
|
2012-12-18 17:46:42 +00:00
|
|
|
bkj->bias = scene->r.bake_biasdist;
|
2012-12-19 12:30:39 +00:00
|
|
|
bkj->number_of_rays = scene->r.bake_samples;
|
2013-05-08 13:23:17 +00:00
|
|
|
bkj->threads = BKE_scene_num_threads(scene);
|
2013-10-09 15:51:14 +00:00
|
|
|
bkj->user_scale = (scene->r.bake_flag & R_BAKE_USERSCALE) ? scene->r.bake_user_scale : -1.0f;
|
2019-05-01 11:09:22 +10:00
|
|
|
// bkj->reports = op->reports;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-30 16:22:40 +00:00
|
|
|
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
|
2011-06-05 20:54:04 +00:00
|
|
|
MultiresBakerJobData *data;
|
2011-12-29 16:05:09 +00:00
|
|
|
int lvl;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
ob = base->object;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-09-17 17:24:44 +02:00
|
|
|
multires_flush_sculpt_updates(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
data = MEM_callocN(sizeof(MultiresBakerJobData), "multiresBaker derivedMesh_data");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
data->ob_image.array = bake_object_image_get_array(ob);
|
2017-05-24 23:14:32 +10:00
|
|
|
data->ob_image.len = ob->totcol;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 17:46:42 +00:00
|
|
|
/* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */
|
2020-10-26 12:32:22 +01:00
|
|
|
data->hires_dm = multiresbake_create_hiresdm(scene, ob, &data->tot_lvl);
|
2018-04-05 18:20:27 +02:00
|
|
|
data->lores_dm = multiresbake_create_loresdm(scene, ob, &lvl);
|
2012-12-18 17:46:42 +00:00
|
|
|
data->lvl = lvl;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
BLI_addtail(&bkj->data, data);
|
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void multiresbake_startjob(void *bkv, short *stop, short *do_update, float *progress)
|
|
|
|
{
|
|
|
|
MultiresBakerJobData *data;
|
2012-04-28 15:42:27 +00:00
|
|
|
MultiresBakeJob *bkj = bkv;
|
|
|
|
int baked_objects = 0, tot_obj;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-16 13:57:58 +01:00
|
|
|
tot_obj = BLI_listbase_count(&bkj->data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (bkj->bake_clear) { /* clear images */
|
2012-04-28 15:42:27 +00:00
|
|
|
for (data = bkj->data.first; data; data = data->next) {
|
2013-09-20 10:14:54 +00:00
|
|
|
ClearFlag clear_flag = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-09-20 10:14:54 +00:00
|
|
|
if (bkj->mode == RE_BAKE_NORMALS) {
|
|
|
|
clear_flag = CLEAR_TANGENT_NORMAL;
|
|
|
|
}
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
else if (bkj->mode == RE_BAKE_DISPLACEMENT) {
|
2013-09-20 10:14:54 +00:00
|
|
|
clear_flag = CLEAR_DISPLACEMENT;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-24 23:14:32 +10:00
|
|
|
clear_images_poly(data->ob_image.array, data->ob_image.len, clear_flag);
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
for (data = bkj->data.first; data; data = data->next) {
|
2013-03-22 05:34:10 +00:00
|
|
|
MultiresBakeRender bkr = {NULL};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* copy data stored in job descriptor */
|
2018-06-18 11:51:02 +02:00
|
|
|
bkr.scene = bkj->scene;
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.bake_filter = bkj->bake_filter;
|
|
|
|
bkr.mode = bkj->mode;
|
|
|
|
bkr.use_lores_mesh = bkj->use_lores_mesh;
|
2013-10-09 15:51:14 +00:00
|
|
|
bkr.user_scale = bkj->user_scale;
|
2019-05-01 11:09:22 +10:00
|
|
|
// bkr.reports = bkj->reports;
|
2017-05-24 23:14:32 +10:00
|
|
|
bkr.ob_image.array = data->ob_image.array;
|
|
|
|
bkr.ob_image.len = data->ob_image.len;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.lores_dm = data->lores_dm;
|
|
|
|
bkr.hires_dm = data->hires_dm;
|
|
|
|
bkr.tot_lvl = data->tot_lvl;
|
|
|
|
bkr.lvl = data->lvl;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* needed for proper progress bar */
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.tot_obj = tot_obj;
|
|
|
|
bkr.baked_objects = baked_objects;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.stop = stop;
|
|
|
|
bkr.do_update = do_update;
|
|
|
|
bkr.progress = progress;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 17:46:42 +00:00
|
|
|
bkr.bias = bkj->bias;
|
|
|
|
bkr.number_of_rays = bkj->number_of_rays;
|
2012-12-19 08:13:41 +00:00
|
|
|
bkr.threads = bkj->threads;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 17:46:26 +00:00
|
|
|
RE_multires_bake_images(&bkr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-26 20:38:20 +00:00
|
|
|
data->images = bkr.image;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
baked_objects++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void multiresbake_freejob(void *bkv)
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
MultiresBakeJob *bkj = bkv;
|
2011-06-05 20:54:04 +00:00
|
|
|
MultiresBakerJobData *data, *next;
|
2012-12-26 20:38:20 +00:00
|
|
|
LinkData *link;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
data = bkj->data.first;
|
2011-06-05 20:54:04 +00:00
|
|
|
while (data) {
|
2012-04-28 15:42:27 +00:00
|
|
|
next = data->next;
|
2011-06-05 20:54:04 +00:00
|
|
|
data->lores_dm->release(data->lores_dm);
|
|
|
|
data->hires_dm->release(data->hires_dm);
|
2012-12-26 20:38:20 +00:00
|
|
|
|
|
|
|
/* delete here, since this delete will be called from main thread */
|
|
|
|
for (link = data->images.first; link; link = link->next) {
|
|
|
|
Image *ima = (Image *)link->data;
|
2020-07-29 18:13:19 +02:00
|
|
|
BKE_image_free_gputextures(ima);
|
2012-12-26 20:38:20 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 23:14:32 +10:00
|
|
|
MEM_freeN(data->ob_image.array);
|
|
|
|
|
2012-12-26 20:38:20 +00:00
|
|
|
BLI_freelistN(&data->images);
|
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
MEM_freeN(data);
|
2012-04-28 15:42:27 +00:00
|
|
|
data = next;
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(bkj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int multiresbake_image_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-06-05 20:54:04 +00:00
|
|
|
MultiresBakeJob *bkr;
|
2012-08-15 10:03:29 +00:00
|
|
|
wmJob *wm_job;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!multiresbake_check(C, op)) {
|
2011-06-05 20:54:04 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr = MEM_callocN(sizeof(MultiresBakeJob), "MultiresBakeJob data");
|
2011-06-05 20:54:04 +00:00
|
|
|
init_multiresbake_job(C, bkr);
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!bkr->data.first) {
|
2011-12-29 16:05:09 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No objects found to bake from");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* setup job */
|
2012-08-15 10:03:29 +00:00
|
|
|
wm_job = WM_jobs_get(CTX_wm_manager(C),
|
|
|
|
CTX_wm_window(C),
|
|
|
|
scene,
|
|
|
|
"Multires Bake",
|
|
|
|
WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS,
|
|
|
|
WM_JOB_TYPE_OBJECT_BAKE_TEXTURE);
|
|
|
|
WM_jobs_customdata_set(wm_job, bkr, multiresbake_freejob);
|
2013-10-17 18:29:01 +00:00
|
|
|
WM_jobs_timer(wm_job, 0.5, NC_IMAGE, 0); /* TODO - only draw bake image, can we enforce this */
|
2012-08-15 10:03:29 +00:00
|
|
|
WM_jobs_callbacks(wm_job, multiresbake_startjob, NULL, NULL, NULL);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
G.is_break = false;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-08-15 10:03:29 +00:00
|
|
|
WM_jobs_start(CTX_wm_manager(C), wm_job);
|
2011-06-05 20:54:04 +00:00
|
|
|
WM_cursor_wait(0);
|
|
|
|
|
|
|
|
/* add modal handler for ESC */
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2009-12-30 14:37:25 +00:00
|
|
|
/* ****************** render BAKING ********************** */
|
|
|
|
|
|
|
|
/* catch esc */
|
2013-03-13 09:03:46 +00:00
|
|
|
static int objects_bake_render_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
|
2009-12-30 14:37:25 +00:00
|
|
|
{
|
|
|
|
/* no running blender, remove handler and pass through */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_BAKE_TEXTURE)) {
|
2012-04-28 15:42:27 +00:00
|
|
|
return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-12-30 14:37:25 +00:00
|
|
|
/* running render */
|
|
|
|
switch (event->type) {
|
2020-03-18 10:38:37 -06:00
|
|
|
case EVT_ESCKEY:
|
2009-12-30 14:37:25 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
}
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
static bool is_multires_bake(Scene *scene)
|
2011-06-05 20:54:04 +00:00
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ELEM(scene->r.bake_mode, RE_BAKE_NORMALS, RE_BAKE_DISPLACEMENT, RE_BAKE_AO)) {
|
2011-06-05 20:54:04 +00:00
|
|
|
return scene->r.bake_flag & R_BAKE_MULTIRES;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int objects_bake_render_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(_event))
|
2009-12-30 14:37:25 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
int result = OPERATOR_CANCELLED;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
result = multiresbake_image_exec(C, op);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
return result;
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int bake_image_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
int result = OPERATOR_CANCELLED;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2018-04-28 16:20:19 +02:00
|
|
|
if (!is_multires_bake(scene)) {
|
|
|
|
BLI_assert(0);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
result = multiresbake_image_exec_locked(C, op);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
return result;
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_bake_image(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Bake";
|
|
|
|
ot->description = "Bake image textures of selected objects";
|
|
|
|
ot->idname = "OBJECT_OT_bake_image";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-12-30 14:37:25 +00:00
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = bake_image_exec;
|
|
|
|
ot->invoke = objects_bake_render_invoke;
|
|
|
|
ot->modal = objects_bake_render_modal;
|
Bake API - bpy.ops.object.bake()
New operator that can calls a bake function to the current render engine when available. This commit provides no feature for the users, but allows external engines to be accessed by the operator and be integrated with the baking api.
The API itself is simple. Blender sends a populated array of BakePixels to the renderer, and gets back an array of floats with the result.
The Blender Internal (and multires) system is still running independent, but we eventually will pipe it through the API as well. Cycles baking will come next as a separated commit
Python Operator:
----------------
The operator can be called with some arguments, or a user interface can be created for it. In that case the arguments can be ommited and the interface can expose the settings from bpy.context.scene.render.bake
bpy.ops.object.bake(type='COMBINED', filepath="", width=512, height=512, margin=16, use_selected_to_active=False, cage_extrusion=0, cage="", normal_space='TANGENT', normal_r='POS_X', normal_g='POS_Y', normal_b='POS_Z', save_mode='INTERNAL', use_clear=False, use_split_materials=False, use_automatic_name=False)
Note: external save mode is currently disabled.
Supported Features:
------------------
* Margin - Baked result is extended this many pixels beyond the border of each UV "island," to soften seams in the texture.
* Selected to Active - bake shading on the surface of selected object to the active object. The rays are cast from the lowpoly object inwards towards the highpoly object. If the highpoly object is not entirely involved by the lowpoly object, you can tweak the rays start point with Cage Extrusion. For even more control of the cage you can use a Cage object.
* Cage Extrusion - distance to use for the inward ray cast when using selected to active
* Custom Cage - object to use as cage (instead of the lowpoly object).
* Normal swizzle - change the axis that gets mapped to RGB
* Normal space - save as tangent or object normal spaces
Supported Passes:
-----------------
Any pass that is supported by Blender renderlayer system. Though it's up to the external engine to provide a valid enum with its supported passes. Normal passes get a special treatment since we post-process them to converted and "swizzled"
Development Notes for External Engines:
---------------------------------------
(read them in bake_api.c)
* For a complete implementation example look at the Cycles Bake commit (next).
Review: D421
Reviewed by: Campbell Barton, Brecht van Lommel, Sergey Sharybin, Thomas Dinge
Normal map pipeline "consulting" by Andy Davies (metalliandy)
Original design by Brecht van Lommel.
The entire commit history can be found on the branch: bake-cycles
2014-01-02 19:05:07 -02:00
|
|
|
ot->poll = ED_operator_object_active;
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|