Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_bake_api.c
| Show First 20 Lines • Show All 679 Lines • ▼ Show 20 Lines | if (is_cage && custom_cage[0] != '\0') { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| pixel_array_low = MEM_mallocN(sizeof(BakePixel) * num_pixels, "bake pixels low poly"); | pixel_array_low = MEM_mallocN(sizeof(BakePixel) * num_pixels, "bake pixels low poly"); | ||||
| result = MEM_callocN(sizeof(float) * depth * num_pixels, "bake return pixels"); | result = MEM_callocN(sizeof(float) * depth * num_pixels, "bake return pixels"); | ||||
| /* get the mesh as it arrives in the renderer */ | /* get the mesh as it arrives in the renderer */ | ||||
| me_low = BKE_mesh_new_from_object(bmain, scene, ob_low, 1, 2, 1, 0); | me_low = BKE_mesh_new_from_object(bmain, scene, ob_low, 1, 2, 0, 0); | ||||
| BKE_mesh_split_faces(me_low); | |||||
| BKE_mesh_tessface_ensure(me_low); | |||||
| /* populate the pixel array with the face data */ | /* populate the pixel array with the face data */ | ||||
| if ((is_selected_to_active && (ob_cage == NULL) && is_cage) == false) | if ((is_selected_to_active && (ob_cage == NULL) && is_cage) == false) | ||||
| RE_bake_pixels_populate(me_low, pixel_array_low, num_pixels, &bake_images, uv_layer); | RE_bake_pixels_populate(me_low, pixel_array_low, num_pixels, &bake_images, uv_layer); | ||||
| /* else populate the pixel array with the 'cage' mesh (the smooth version of the mesh) */ | /* else populate the pixel array with the 'cage' mesh (the smooth version of the mesh) */ | ||||
| if (is_selected_to_active) { | if (is_selected_to_active) { | ||||
| CollectionPointerLink *link; | CollectionPointerLink *link; | ||||
| ModifierData *md, *nmd; | ModifierData *md, *nmd; | ||||
| ListBase modifiers_tmp, modifiers_original; | ListBase modifiers_tmp, modifiers_original; | ||||
| int i = 0; | int i = 0; | ||||
| /* prepare cage mesh */ | /* prepare cage mesh */ | ||||
| if (ob_cage) { | if (ob_cage) { | ||||
| me_cage = BKE_mesh_new_from_object(bmain, scene, ob_cage, 1, 2, 1, 0); | me_cage = BKE_mesh_new_from_object(bmain, scene, ob_cage, 1, 2, 0, 0); | ||||
| BKE_mesh_split_faces(me_cage); | |||||
| BKE_mesh_tessface_ensure(me_cage); | |||||
| if (me_low->totface != me_cage->totface) { | if (me_low->totface != me_cage->totface) { | ||||
| BKE_report(reports, RPT_ERROR, | BKE_report(reports, RPT_ERROR, | ||||
| "Invalid cage object, the cage mesh must have the same number " | "Invalid cage object, the cage mesh must have the same number " | ||||
| "of faces as the active object"); | "of faces as the active object"); | ||||
| goto cleanup; | goto cleanup; | ||||
| } | } | ||||
| } | } | ||||
| else if (is_cage) { | else if (is_cage) { | ||||
| Show All 15 Lines | else if (is_cage) { | ||||
| modifier_copyData(md, nmd); | modifier_copyData(md, nmd); | ||||
| BLI_addtail(&modifiers_tmp, nmd); | BLI_addtail(&modifiers_tmp, nmd); | ||||
| } | } | ||||
| /* temporarily replace the modifiers */ | /* temporarily replace the modifiers */ | ||||
| ob_low->modifiers = modifiers_tmp; | ob_low->modifiers = modifiers_tmp; | ||||
| /* get the cage mesh as it arrives in the renderer */ | /* get the cage mesh as it arrives in the renderer */ | ||||
| me_cage = BKE_mesh_new_from_object(bmain, scene, ob_low, 1, 2, 1, 0); | me_cage = BKE_mesh_new_from_object(bmain, scene, ob_low, 1, 2, 0, 0); | ||||
| BKE_mesh_split_faces(me_cage); | |||||
| BKE_mesh_tessface_ensure(me_cage); | |||||
| RE_bake_pixels_populate(me_cage, pixel_array_low, num_pixels, &bake_images, uv_layer); | RE_bake_pixels_populate(me_cage, pixel_array_low, num_pixels, &bake_images, uv_layer); | ||||
| } | } | ||||
| highpoly = MEM_callocN(sizeof(BakeHighPolyData) * tot_highpoly, "bake high poly objects"); | highpoly = MEM_callocN(sizeof(BakeHighPolyData) * tot_highpoly, "bake high poly objects"); | ||||
| /* populate highpoly array */ | /* populate highpoly array */ | ||||
| for (link = selected_objects->first; link; link = link->next) { | for (link = selected_objects->first; link; link = link->next) { | ||||
| TriangulateModifierData *tmd; | TriangulateModifierData *tmd; | ||||
| Show All 11 Lines | for (link = selected_objects->first; link; link = link->next) { | ||||
| /* triangulating so BVH returns the primitive_id that will be used for rendering */ | /* triangulating so BVH returns the primitive_id that will be used for rendering */ | ||||
| highpoly[i].tri_mod = ED_object_modifier_add( | highpoly[i].tri_mod = ED_object_modifier_add( | ||||
| reports, bmain, scene, highpoly[i].ob, | reports, bmain, scene, highpoly[i].ob, | ||||
| "TmpTriangulate", eModifierType_Triangulate); | "TmpTriangulate", eModifierType_Triangulate); | ||||
| tmd = (TriangulateModifierData *)highpoly[i].tri_mod; | tmd = (TriangulateModifierData *)highpoly[i].tri_mod; | ||||
| tmd->quad_method = MOD_TRIANGULATE_QUAD_FIXED; | tmd->quad_method = MOD_TRIANGULATE_QUAD_FIXED; | ||||
| tmd->ngon_method = MOD_TRIANGULATE_NGON_EARCLIP; | tmd->ngon_method = MOD_TRIANGULATE_NGON_EARCLIP; | ||||
| highpoly[i].me = BKE_mesh_new_from_object(bmain, scene, highpoly[i].ob, 1, 2, 1, 0); | highpoly[i].me = BKE_mesh_new_from_object(bmain, scene, highpoly[i].ob, 1, 2, 0, 0); | ||||
| highpoly[i].ob->restrictflag &= ~OB_RESTRICT_RENDER; | highpoly[i].ob->restrictflag &= ~OB_RESTRICT_RENDER; | ||||
| BKE_mesh_split_faces(highpoly[i].me); | |||||
| BKE_mesh_tessface_ensure(highpoly[i].me); | |||||
| /* lowpoly to highpoly transformation matrix */ | /* lowpoly to highpoly transformation matrix */ | ||||
| copy_m4_m4(highpoly[i].obmat, highpoly[i].ob->obmat); | copy_m4_m4(highpoly[i].obmat, highpoly[i].ob->obmat); | ||||
| invert_m4_m4(highpoly[i].imat, highpoly[i].obmat); | invert_m4_m4(highpoly[i].imat, highpoly[i].obmat); | ||||
| /* rotation */ | /* rotation */ | ||||
| normalize_m4_m4(highpoly[i].rotmat, highpoly[i].imat); | normalize_m4_m4(highpoly[i].rotmat, highpoly[i].imat); | ||||
| zero_v3(highpoly[i].rotmat[3]); | zero_v3(highpoly[i].rotmat[3]); | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | switch (normal_space) { | ||||
| md = modifiers_findByType(ob_low, eModifierType_Multires); | md = modifiers_findByType(ob_low, eModifierType_Multires); | ||||
| if (md) { | if (md) { | ||||
| mode = md->mode; | mode = md->mode; | ||||
| md->mode &= ~eModifierMode_Render; | md->mode &= ~eModifierMode_Render; | ||||
| } | } | ||||
| me_nores = BKE_mesh_new_from_object(bmain, scene, ob_low, 1, 2, 1, 0); | me_nores = BKE_mesh_new_from_object(bmain, scene, ob_low, 1, 2, 0, 0); | ||||
| BKE_mesh_split_faces(me_nores); | |||||
| BKE_mesh_tessface_ensure(me_nores); | |||||
| RE_bake_pixels_populate(me_nores, pixel_array_low, num_pixels, &bake_images, uv_layer); | RE_bake_pixels_populate(me_nores, pixel_array_low, num_pixels, &bake_images, uv_layer); | ||||
| RE_bake_normal_world_to_tangent(pixel_array_low, num_pixels, depth, result, me_nores, normal_swizzle, ob_low->obmat); | RE_bake_normal_world_to_tangent(pixel_array_low, num_pixels, depth, result, me_nores, normal_swizzle, ob_low->obmat); | ||||
| BKE_libblock_free(bmain, me_nores); | BKE_libblock_free(bmain, me_nores); | ||||
| if (md) | if (md) | ||||
| md->mode = mode; | md->mode = mode; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 487 Lines • Show Last 20 Lines | |||||