Blender  V2.93
subdiv_ccg_material.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) 2018 by Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "BKE_subdiv_ccg.h"
25 
26 #include "MEM_guardedalloc.h"
27 
28 #include "DNA_mesh_types.h"
29 
30 typedef struct CCGMaterialFromMeshData {
31  const Mesh *mesh;
33 
35  SubdivCCGMaterialFlagsEvaluator *material_flags_evaluator, const int coarse_face_index)
36 {
37  CCGMaterialFromMeshData *data = (CCGMaterialFromMeshData *)material_flags_evaluator->user_data;
38  const Mesh *mesh = data->mesh;
39  BLI_assert(coarse_face_index < mesh->totpoly);
40  const MPoly *mpoly = mesh->mpoly;
41  const MPoly *poly = &mpoly[coarse_face_index];
42  DMFlagMat material_flags;
43  material_flags.flag = poly->flag;
44  material_flags.mat_nr = poly->mat_nr;
45  return material_flags;
46 }
47 
49  SubdivCCGMaterialFlagsEvaluator *material_flags_evaluator)
50 {
51  MEM_freeN(material_flags_evaluator->user_data);
52 }
53 
55  SubdivCCGMaterialFlagsEvaluator *material_flags_evaluator, const Mesh *mesh)
56 {
58  "ccg material eval");
59  data->mesh = mesh;
60  material_flags_evaluator->eval_material_flags = subdiv_ccg_material_flags_eval;
61  material_flags_evaluator->free = subdiv_ccg_material_flags_free;
62  material_flags_evaluator->user_data = data;
63 }
#define BLI_assert(a)
Definition: BLI_assert.h:58
Read Guarded memory(de)allocation.
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
short mat_nr
struct MPoly * mpoly
DMFlagMat(* eval_material_flags)(struct SubdivCCGMaterialFlagsEvaluator *material_flags_evaluator, const int coarse_face_index)
void(* free)(struct SubdivCCGMaterialFlagsEvaluator *material_flags_evaluator)
struct CCGMaterialFromMeshData CCGMaterialFromMeshData
void BKE_subdiv_ccg_material_flags_init_from_mesh(SubdivCCGMaterialFlagsEvaluator *material_flags_evaluator, const Mesh *mesh)
static void subdiv_ccg_material_flags_free(SubdivCCGMaterialFlagsEvaluator *material_flags_evaluator)
static DMFlagMat subdiv_ccg_material_flags_eval(SubdivCCGMaterialFlagsEvaluator *material_flags_evaluator, const int coarse_face_index)