Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MOD_bparticles_output.c « intern « modifiers « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0482a17feace8357e5613ba1179862e5ee35fcc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * 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,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * The Original Code is Copyright (C) 2019 by the Blender Foundation.
 * All rights reserved.
 * ***** END GPL LICENSE BLOCK *****
 *
 */

/** \file blender/modifiers/intern/MOD_bparticles_output.c
 *  \ingroup modifiers
 *
 */

#include "MEM_guardedalloc.h"

#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"

#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_scene.h"

#include "BLI_math.h"

#include "MOD_bparticles.h"
#include "MOD_util.h"

#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"

#include "BParticles.h"

static Mesh *applyModifier(ModifierData *md,
                           const struct ModifierEvalContext *UNUSED(ctx),
                           Mesh *mesh)
{
  BParticlesOutputModifierData *bpmd = (BParticlesOutputModifierData *)md;
  if (bpmd->source_object == NULL) {
    return mesh;
  }

  BParticlesSimulationState simulation_state = MOD_bparticles_find_simulation_state(
      bpmd->source_object);
  if (simulation_state == NULL) {
    return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
  }

  if (bpmd->output_type == MOD_BPARTICLES_OUTPUT_TETRAHEDONS) {
    Mesh *new_mesh = BParticles_state_extract_type__tetrahedons(simulation_state,
                                                                bpmd->source_particle_system);
    BKE_mesh_copy_settings(new_mesh, mesh);
    return new_mesh;
  }
  else if (bpmd->output_type == MOD_BPARTICLES_OUTPUT_POINTS) {
    return BParticles_state_extract_type__points(simulation_state, bpmd->source_particle_system);
  }
  else {
    return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
  }
}

static void initData(ModifierData *UNUSED(md))
{
}

static void freeData(ModifierData *UNUSED(md))
{
}

static void copyData(const ModifierData *md, ModifierData *target, const int flag)
{
  modifier_copyData_generic(md, target, flag);
}

static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
  BParticlesOutputModifierData *bpmd = (BParticlesOutputModifierData *)md;
  if (bpmd->source_object) {
    DEG_add_object_relation(
        ctx->node, bpmd->source_object, DEG_OB_COMP_GEOMETRY, "BParticles Output Modifier");
  }
}

static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
{
  BParticlesOutputModifierData *bpmd = (BParticlesOutputModifierData *)md;
  walk(userData, ob, &bpmd->source_object, IDWALK_CB_NOP);
}

ModifierTypeInfo modifierType_BParticlesOutput = {
    /* name */ "BParticles Output",
    /* structName */ "BParticlesOutputModifierData",
    /* structSize */ sizeof(BParticlesOutputModifierData),
    /* type */ eModifierTypeType_Constructive,
    /* flags */ eModifierTypeFlag_AcceptsMesh,
    /* copyData */ copyData,

    /* deformVerts */ NULL,
    /* deformMatrices */ NULL,
    /* deformVertsEM */ NULL,
    /* deformMatricesEM */ NULL,
    /* applyModifier */ applyModifier,

    /* initData */ initData,
    /* requiredDataMask */ NULL,
    /* freeData */ freeData,
    /* isDisabled */ NULL,
    /* updateDepsgraph */ updateDepsgraph,
    /* dependsOnTime */ NULL,
    /* dependsOnNormals */ NULL,
    /* foreachObjectLink */ foreachObjectLink,
    /* foreachIDLink */ NULL,
    /* foreachTexLink */ NULL,
    /* freeRuntimeData */ NULL,
};