[Bf-blender-cvs] [6ba383d] bake-cycles: Cycles-Bake: RE_populate_bake_pixels working for triangulated faces
Dalai Felinto
noreply at git.blender.org
Wed Apr 23 02:46:21 CEST 2014
Commit: 6ba383dfeb84162fd9a0a6bf626fe3657705b0a1
Author: Dalai Felinto
Date: Sun Jan 5 15:02:37 2014 -0200
https://developer.blender.org/rB6ba383dfeb84162fd9a0a6bf626fe3657705b0a1
Cycles-Bake: RE_populate_bake_pixels working for triangulated faces
I suspect I need to check if the face is 3 or 4 verts,
but for triangles it's working :)
===================================================================
M intern/cycles/blender/blender_session.cpp
M source/blender/editors/object/object_bake.c
M source/blender/render/intern/source/bake_new.c
===================================================================
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index 098efb6..c08661d 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -449,6 +449,9 @@ void BlenderSession::bake(BL::Object b_object, const string& pass_type, BakePixe
int i = 0;
printf("\n<bakepixel>\n\n");
for (i=0;i < num_pixels; i++) {
+ if (pixel_array[i].primitive_id == -1)
+ continue;
+
printf("\nprimitive_id: %d\n", pixel_array[i].primitive_id);
printf("u: %4.2f\n", pixel_array[i].u);
printf("v: %4.2f\n", pixel_array[i].v);
diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c
index 5a8d1d0..95a8ad5 100644
--- a/source/blender/editors/object/object_bake.c
+++ b/source/blender/editors/object/object_bake.c
@@ -81,6 +81,7 @@
#include "WM_types.h"
#include "ED_object.h"
+#include "ED_screen.h"
#include "object_intern.h"
@@ -895,4 +896,5 @@ void OBJECT_OT_bake_image(wmOperatorType *ot)
ot->exec = bake_image_exec;
ot->invoke = objects_bake_render_invoke;
ot->modal = objects_bake_render_modal;
+ ot->poll = ED_operator_object_active;
}
diff --git a/source/blender/render/intern/source/bake_new.c b/source/blender/render/intern/source/bake_new.c
index 35dae7e..b1d7e44 100644
--- a/source/blender/render/intern/source/bake_new.c
+++ b/source/blender/render/intern/source/bake_new.c
@@ -44,6 +44,7 @@
#include "DNA_meshdata_types.h"
#include "BKE_customdata.h"
+#include "BKE_mesh.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_main.h"
@@ -104,7 +105,14 @@ void RE_populate_bake_pixels(Object *object, BakePixel pixel_array[], const int
{
BakeData bd;
const int num_pixels = width * height;
- int i;
+ int i, a;
+ MTFace *mtface;
+
+ Mesh *me = (Mesh *)object->data;
+
+ /* we can't bake in edit mode */
+ if (me->edit_btmesh)
+ return;
bd.pixel_array = pixel_array;
bd.width = width;
@@ -116,29 +124,38 @@ void RE_populate_bake_pixels(Object *object, BakePixel pixel_array[], const int
zbuf_alloc_span(&bd.zspan, width, height, R.clipcrop);
- /* TODO: * get the loop over faces to work
-
- * find whether we need to triangulate the mesh
- for zspan_scanconvert to work
- (I guess we do since baking had the splitting option)
-
- * find which primitive_id to use
- (it's the id of the original face or the new triangulated?)
- */
-#if 0
- /* pseudo code */
- for face in object.faces {
- bd.primitive_id = face_id;
- v1, v2, v3 = face.vertices[:]
-
- //TODO copy/adapt UV offset hack/trick from bake.c */
-
- zspan_scanconvert(&bd.zspan, (void *)&bd, v1, v2, v3, store_bake_pixel);
- }
-#endif
-
- /* we could preserve this if zbuffer pass is required, maybe store the zed of the
- pixel in the BakePixel struct - TBI */
+ /* remove tessface to ensure we don't hold references to invalid faces */
+ BKE_mesh_tessface_clear(me);
+ BKE_mesh_tessface_calc(me);
+
+ mtface = CustomData_get_layer(&me->fdata, CD_MTFACE);
+
+ if (mtface == NULL)
+ return;
+
+ for (i = 0; i < me->totface; i++) {
+ float vec[4][2];
+ MTFace *mtf = &mtface[i];
+
+ bd.primitive_id = i;
+
+ for (a = 0; a < 4; a++) {
+ /* Note, workaround for pixel aligned UVs which are common and can screw up our intersection tests
+ * where a pixel gets in between 2 faces or the middle of a quad,
+ * camera aligned quads also have this problem but they are less common.
+ * Add a small offset to the UVs, fixes bug #18685 - Campbell */
+ vec[a][0] = mtf->uv[a][0] * (float)width - (0.5f + 0.001f);
+ vec[a][1] = mtf->uv[a][1] * (float)height - (0.5f + 0.002f);
+ }
+
+ zspan_scanconvert(&bd.zspan, (void *)&bd, vec[0], vec[1], vec[2], store_bake_pixel);
+
+ /* XXX TODO
+ if (...) // verts == 4
+ zspan_scanconvert(&bd.zspan, (void *)&bd, vec[0], vec[2], vec[3], store_bake_pixel);
+ */
+ }
+
zbuf_free_span(&bd.zspan);
}
More information about the Bf-blender-cvs
mailing list