[Bf-blender-cvs] [47cf41c] hair_immediate_fixes: More work on particle conversion methods for hair edit mode.
Lukas Tönne
noreply at git.blender.org
Tue Nov 25 14:44:50 CET 2014
Commit: 47cf41cae41c9190a89f96e0014d0c1dc09fe625
Author: Lukas Tönne
Date: Thu Oct 9 10:33:18 2014 +0200
Branches: hair_immediate_fixes
https://developer.blender.org/rB47cf41cae41c9190a89f96e0014d0c1dc09fe625
More work on particle conversion methods for hair edit mode.
===================================================================
M source/blender/editors/hair/CMakeLists.txt
M source/blender/editors/hair/hair_edit.c
M source/blender/editors/hair/hair_intern.h
A source/blender/editors/hair/hair_particles.c
===================================================================
diff --git a/source/blender/editors/hair/CMakeLists.txt b/source/blender/editors/hair/CMakeLists.txt
index 22a9d57..eb57949 100644
--- a/source/blender/editors/hair/CMakeLists.txt
+++ b/source/blender/editors/hair/CMakeLists.txt
@@ -35,6 +35,7 @@ set(INC_SYS
set(SRC
hair_edit.c
hair_ops.c
+ hair_particles.c
hair_intern.h
)
diff --git a/source/blender/editors/hair/hair_edit.c b/source/blender/editors/hair/hair_edit.c
index fb8f090..b34e6e3 100644
--- a/source/blender/editors/hair/hair_edit.c
+++ b/source/blender/editors/hair/hair_edit.c
@@ -33,20 +33,13 @@
#include "hair_intern.h"
-HairEditData *hair_edit_create(int totcurves, int totverts)
+HairEditData *ED_hair_edit_create(void)
{
HairEditData *hedit = MEM_callocN(sizeof(HairEditData), "hair edit data");
-
- hedit->curves = MEM_callocN(sizeof(HairEditCurve) * totcurves, "hair edit curves");
- hedit->totcurves = totcurves;
-
- hedit->verts = MEM_callocN(sizeof(HairEditVertex) * totverts, "hair edit verts");
- hedit->totverts = totverts;
-
return hedit;
}
-HairEditData *hair_edit_copy(HairEditData *hedit)
+HairEditData *ED_hair_edit_copy(HairEditData *hedit)
{
HairEditData *thedit = MEM_dupallocN(hedit);
@@ -61,7 +54,7 @@ HairEditData *hair_edit_copy(HairEditData *hedit)
return thedit;
}
-void hair_edit_free(HairEditData *hedit)
+void ED_hair_edit_free(HairEditData *hedit)
{
if (hedit->curves) {
MEM_freeN(hedit->curves);
@@ -73,3 +66,25 @@ void hair_edit_free(HairEditData *hedit)
MEM_freeN(hedit);
}
+
+void ED_hair_edit_clear(HairEditData *hedit)
+{
+ if (hedit->curves) {
+ MEM_freeN(hedit->curves);
+ hedit->curves = NULL;
+ }
+ hedit->totcurves = 0;
+ hedit->alloc_curves = 0;
+
+ if (hedit->verts) {
+ MEM_freeN(hedit->verts);
+ hedit->verts = NULL;
+ }
+ hedit->totverts = 0;
+ hedit->alloc_verts = 0;
+}
+
+void ED_hair_edit_reserve(HairEditData *hedit, int alloc_curves, int alloc_verts, bool shrink)
+{
+ if (hedit)
+}
diff --git a/source/blender/editors/hair/hair_intern.h b/source/blender/editors/hair/hair_intern.h
index bb3fa2a..4298810 100644
--- a/source/blender/editors/hair/hair_intern.h
+++ b/source/blender/editors/hair/hair_intern.h
@@ -40,6 +40,7 @@ struct ParticleSystem;
/* hair curve */
typedef struct HairEditCurve {
int start; /* first vertex index */
+ int numverts; /* number of vertices in the curve */
} HairEditCurve;
typedef struct HairEditVertex {
@@ -50,20 +51,23 @@ typedef struct HairEditData {
HairEditCurve *curves;
HairEditVertex *verts;
- int totcurves;
- int totverts;
+ int totcurves, alloc_curves;
+ int totverts, alloc_verts;
CustomData hdata; /* curve data */
CustomData vdata; /* vertex data */
} HairEditData;
-struct HairEditData *hair_edit_create(int totcurves, int totverts);
-struct HairEditData *hair_edit_copy(struct HairEditData *hedit);
-void hair_edit_free(struct HairEditData *hedit);
+struct HairEditData *ED_hair_edit_create(void);
+struct HairEditData *ED_hair_edit_copy(struct HairEditData *hedit);
+void ED_hair_edit_free(struct HairEditData *hedit);
+
+void ED_hair_edit_clear(struct HairEditData *hedit);
+void ED_hair_edit_reserve(struct HairEditData *hedit, int alloc_curves, int alloc_verts, bool shrink);
/* === particle conversion === */
-struct HairEditData *hair_edit_from_particles(struct Object *ob, struct ParticleSystem *psys);
+void hair_edit_from_particles(struct HairEditData *hedit, struct Object *ob, struct ParticleSystem *psys);
void hair_edit_to_particles(struct HairEditData *hedit, struct Object *ob, struct ParticleSystem *psys);
#endif
diff --git a/source/blender/editors/hair/hair_particles.c b/source/blender/editors/hair/hair_particles.c
new file mode 100644
index 0000000..ccf0801
--- /dev/null
+++ b/source/blender/editors/hair/hair_particles.c
@@ -0,0 +1,119 @@
+/*
+ * ***** 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) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/hair/hair_particles.c
+ * \ingroup edhair
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+
+#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
+
+#include "BKE_particle.h"
+
+#include "hair_intern.h"
+
+/* ==== convert particle data to hair edit ==== */
+
+void hair_edit_from_particles(HairEditData *hedit, Object *UNUSED(ob), ParticleSystem *psys)
+{
+ ED_hair_edit_clear(hedit);
+}
+
+/* ==== convert hair edit to particle data ==== */
+
+static void free_particle_data(ParticleSystem *psys)
+{
+ if (psys->particles) {
+ ParticleData *pa;
+ int p;
+
+ for (p = 0, pa = psys->particles; p < psys->totpart; ++p, ++pa) {
+ if (pa->hair)
+ MEM_freeN(pa->hair);
+ }
+
+ MEM_freeN(psys->particles);
+ psys->particles = NULL;
+ psys->totpart = 0;
+ }
+}
+
+static void create_particle_curve(ParticleData *pa, HairEditData *hedit, HairEditCurve *curve)
+{
+ int ntotkey = curve->numverts;
+ HairKey *nhair = MEM_callocN(sizeof(HairKey) * ntotkey, "hair keys");
+ HairEditVertex *vert;
+ int k;
+ HairKey *hkey;
+ int j;
+
+ for (k = 0, vert = hedit->verts + curve->start, j = 0, hkey = nhair;
+ k < curve->numverts;
+ ++k, ++vert, ++j, ++hkey) {
+
+ copy_v3_v3(hkey->co, vert->co);
+ // TODO define other key stuff ...
+ }
+
+ pa->totkey = ntotkey;
+ pa->hair = nhair;
+}
+
+static void create_particle_data(ParticleSystem *psys, HairEditData *hedit)
+{
+ int ntotpart = hedit->totcurves;
+ ParticleData *nparticles = MEM_callocN(sizeof(ParticleData) * ntotpart, "particle data");
+ HairEditCurve *curve;
+ int i;
+ ParticleData *pa;
+ int p;
+
+ for (i = 0, curve = hedit->curves, p = 0, pa = nparticles;
+ i < hedit->totcurves;
+ ++i, ++curve, ++p, ++pa) {
+
+ // TODO copy particle stuff ...
+
+ create_particle_curve(pa, hedit, curve);
+ }
+
+ psys->particles = nparticles;
+ psys->totpart = hedit->totcurves;
+}
+
+void hair_edit_to_particles(HairEditData *hedit, Object *UNUSED(ob), ParticleSystem *psys)
+{
+ psys->flag |= PSYS_EDITED;
+
+ free_particle_data(psys);
+
+ create_particle_data(psys, hedit);
+}
More information about the Bf-blender-cvs
mailing list