Blender  V2.93
multires_versioning.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2020 by Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "MEM_guardedalloc.h"
25 
26 #include "DNA_mesh_types.h"
27 #include "DNA_modifier_types.h"
28 #include "DNA_object_types.h"
29 
30 #include "BKE_subdiv.h"
31 #include "BKE_subdiv_eval.h"
32 
33 #include "multires_reshape.h"
35 #include "subdiv_converter.h"
36 
38  const OpenSubdiv_Converter *UNUSED(converter), int UNUSED(manifold_edge_index))
39 {
40  return 10.0f;
41 }
42 
44  const OpenSubdiv_Converter *UNUSED(converter), int UNUSED(manifold_vertex_index))
45 {
46  return true;
47 }
48 
50 {
51  SubdivSettings subdiv_settings;
52  BKE_multires_subdiv_settings_init(&subdiv_settings, mmd);
53 
54  Mesh *base_mesh = object->data;
55 
56  OpenSubdiv_Converter converter;
57  BKE_subdiv_converter_init_for_mesh(&converter, &subdiv_settings, base_mesh);
60 
61  Subdiv *subdiv = BKE_subdiv_new_from_converter(&subdiv_settings, &converter);
62  BKE_subdiv_converter_free(&converter);
63 
64  if (!BKE_subdiv_eval_begin_from_mesh(subdiv, base_mesh, NULL)) {
65  BKE_subdiv_free(subdiv);
66  return NULL;
67  }
68 
69  return subdiv;
70 }
71 
73 {
74  const Mesh *base_mesh = object->data;
75  if (base_mesh->totloop == 0) {
76  return;
77  }
78 
79  /* Store the grids displacement in object space against the simple limit surface. */
80  {
81  Subdiv *subdiv = subdiv_for_simple_to_catmull_clark(object, mmd);
82  MultiresReshapeContext reshape_context;
84  &reshape_context, object, mmd, subdiv, mmd->totlvl)) {
85  BKE_subdiv_free(subdiv);
86  return;
87  }
88 
89  multires_reshape_store_original_grids(&reshape_context);
91  multires_reshape_context_free(&reshape_context);
92 
93  BKE_subdiv_free(subdiv);
94  }
95 
96  /* Calculate the new tangent displacement against the new Catmull-Clark limit surface. */
97  {
98  MultiresReshapeContext reshape_context;
100  &reshape_context, object, mmd, mmd->totlvl)) {
101  return;
102  }
104  multires_reshape_context_free(&reshape_context);
105  }
106 }
void BKE_multires_subdiv_settings_init(struct SubdivSettings *settings, const struct MultiresModifierData *mmd)
void BKE_subdiv_free(Subdiv *subdiv)
Definition: subdiv.c:189
Subdiv * BKE_subdiv_new_from_converter(const SubdivSettings *settings, struct OpenSubdiv_Converter *converter)
Definition: subdiv.c:103
bool BKE_subdiv_eval_begin_from_mesh(struct Subdiv *subdiv, const struct Mesh *mesh, const float(*coarse_vertex_cos)[3])
#define UNUSED(x)
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
void multires_reshape_assign_final_coords_from_mdisps(const MultiresReshapeContext *reshape_context)
void multires_reshape_context_free(MultiresReshapeContext *reshape_context)
void multires_reshape_store_original_grids(MultiresReshapeContext *reshape_context)
bool multires_reshape_context_create_from_modifier(MultiresReshapeContext *reshape_context, struct Object *object, struct MultiresModifierData *mmd, int top_level)
bool multires_reshape_context_create_from_subdiv(MultiresReshapeContext *reshape_context, struct Object *object, struct MultiresModifierData *mmd, struct Subdiv *subdiv, int top_level)
void multires_reshape_object_grids_to_tangent_displacement(const MultiresReshapeContext *reshape_context)
static float simple_to_catmull_clark_get_edge_sharpness(const OpenSubdiv_Converter *UNUSED(converter), int UNUSED(manifold_edge_index))
static bool simple_to_catmull_clark_is_infinite_sharp_vertex(const OpenSubdiv_Converter *UNUSED(converter), int UNUSED(manifold_vertex_index))
static Subdiv * subdiv_for_simple_to_catmull_clark(Object *object, MultiresModifierData *mmd)
void multires_do_versions_simple_to_catmull_clark(Object *object, MultiresModifierData *mmd)
int totloop
bool(* isInfiniteSharpVertex)(const struct OpenSubdiv_Converter *converter, const int vertex_index)
float(* getEdgeSharpness)(const struct OpenSubdiv_Converter *converter, const int edge_index)
void BKE_subdiv_converter_free(struct OpenSubdiv_Converter *converter)
void BKE_subdiv_converter_init_for_mesh(struct OpenSubdiv_Converter *converter, const struct SubdivSettings *settings, const struct Mesh *mesh)