[Bf-blender-cvs] [740c83782fd] new-object-types: Objects: use separate location and radius arrays for hair and point cloud
Brecht Van Lommel
noreply at git.blender.org
Sun Jan 26 19:45:06 CET 2020
Commit: 740c83782fd48891c8f11d71cb3ec1243e1e89e8
Author: Brecht Van Lommel
Date: Sun Jan 26 17:18:36 2020 +0100
Branches: new-object-types
https://developer.blender.org/rB740c83782fd48891c8f11d71cb3ec1243e1e89e8
Objects: use separate location and radius arrays for hair and point cloud
===================================================================
M source/blender/blenkernel/intern/customdata.c
M source/blender/blenkernel/intern/hair.c
M source/blender/blenkernel/intern/pointcloud.c
M source/blender/makesdna/DNA_customdata_types.h
M source/blender/makesdna/DNA_hair_types.h
M source/blender/makesdna/DNA_pointcloud_types.h
M source/blender/makesrna/intern/rna_hair.c
M source/blender/makesrna/intern/rna_pointcloud.c
===================================================================
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 033c68002e3..32ba1cd954a 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1623,14 +1623,14 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
{sizeof(short[4][3]), "", 0, NULL, NULL, NULL, NULL, layerSwap_flnor, NULL},
/* 41: CD_CUSTOMLOOPNORMAL */
{sizeof(short[2]), "vec2s", 1, NULL, NULL, NULL, NULL, NULL, NULL},
- /* 42: CD_HAIRPOINT */
- {sizeof(HairPoint), "HairPoint", 1, NULL, NULL, NULL, NULL, NULL, NULL},
- /* 43: CD_HAIRCURVE */
+ /* 42: CD_LOCATION */
+ {sizeof(float[3]), "vec3f", 1, NULL, NULL, NULL, NULL, NULL, NULL},
+ /* 43: CD_RADIUS */
+ {sizeof(float), "MFloatProperty", 1, NULL, NULL, NULL, NULL, NULL, NULL},
+ /* 44: CD_HAIRCURVE */
{sizeof(HairCurve), "HairCurve", 1, NULL, NULL, NULL, NULL, NULL, NULL},
- /* 44: CD_HAIRMAPPING */
+ /* 45: CD_HAIR_MAPPING */
{sizeof(HairMapping), "HairMapping", 1, NULL, NULL, NULL, NULL, NULL, NULL},
- /* 45: CD_POINT */
- {sizeof(Point), "Point", 1, NULL, NULL, NULL, NULL, NULL, NULL},
};
static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 8aaacbc75aa..b0811355287 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -29,6 +29,7 @@
#include "BLI_listbase.h"
#include "BLI_math.h"
+#include "BLI_rand.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -57,15 +58,15 @@ static void hair_random(Hair *hair)
CustomData_realloc(&hair->cdata, hair->totcurve);
BKE_hair_update_customdata_pointers(hair);
+ RNG *rng = BLI_rng_new(0);
+
for (int i = 0; i < hair->totcurve; i++) {
HairCurve *curve = &hair->curves[i];
- HairPoint *point = &hair->points[i * numpoints];
-
curve->firstpoint = i * numpoints;
curve->numpoints = numpoints;
- float theta = 2.0f * M_PI * drand48();
- float phi = saacosf(2.0f * drand48() - 1.0f);
+ float theta = 2.0f * M_PI * BLI_rng_get_float(rng);
+ float phi = saacosf(2.0f * BLI_rng_get_float(rng) - 1.0f);
float no[3] = {sinf(theta) * sinf(phi), cosf(theta) * sinf(phi), cosf(phi)};
normalize_v3(no);
@@ -73,17 +74,22 @@ static void hair_random(Hair *hair)
float co[3];
copy_v3_v3(co, no);
- for (int key = 0; key < numpoints; key++, point++) {
+ float(*curve_co)[3] = hair->co + curve->firstpoint;
+ float *curve_radius = hair->radius + curve->firstpoint;
+ for (int key = 0; key < numpoints; key++) {
float t = key / (float)(numpoints - 1);
- copy_v3_v3(point->co, co);
- point->radius = 0.002f * (1.0f - t);
+ copy_v3_v3(curve_co[key], co);
+ curve_radius[key] = 0.002f * (1.0f - t);
- float offset[3] = {
- 2.0f * drand48() - 1.0f, 2.0f * drand48() - 1.0f, 2.0f * drand48() - 1.0f};
+ float offset[3] = {2.0f * BLI_rng_get_float(rng) - 1.0f,
+ 2.0f * BLI_rng_get_float(rng) - 1.0f,
+ 2.0f * BLI_rng_get_float(rng) - 1.0f};
add_v3_v3(offset, no);
madd_v3_v3fl(co, offset, 1.0f / numpoints);
}
}
+
+ BLI_rng_free(rng);
}
void BKE_hair_init(Hair *hair)
@@ -97,7 +103,8 @@ void BKE_hair_init(Hair *hair)
CustomData_reset(&hair->pdata);
CustomData_reset(&hair->cdata);
- CustomData_add_layer(&hair->pdata, CD_HAIRPOINT, CD_CALLOC, NULL, hair->totpoint);
+ CustomData_add_layer(&hair->pdata, CD_LOCATION, CD_CALLOC, NULL, hair->totpoint);
+ CustomData_add_layer(&hair->pdata, CD_RADIUS, CD_CALLOC, NULL, hair->totpoint);
CustomData_add_layer(&hair->cdata, CD_HAIRCURVE, CD_CALLOC, NULL, hair->totcurve);
BKE_hair_update_customdata_pointers(hair);
@@ -161,16 +168,16 @@ BoundBox *BKE_hair_boundbox_get(Object *ob)
if (ob->runtime.bb == NULL) {
ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "hair boundbox");
- HairPoint *point = hair->points;
float min[3], max[3];
INIT_MINMAX(min, max);
- for (int a = 0; a < hair->totpoint; a++, point++) {
- float co_min[3] = {point->co[0] - point->radius,
- point->co[1] - point->radius,
- point->co[2] - point->radius};
- float co_max[3] = {point->co[0] + point->radius,
- point->co[1] + point->radius,
- point->co[2] + point->radius};
+
+ float(*hair_co)[3] = hair->co;
+ float *hair_radius = hair->radius;
+ for (int a = 0; a < hair->totpoint; a++) {
+ float *co = hair_co[a];
+ float radius = (hair_radius) ? hair_radius[a] : 0.0f;
+ float co_min[3] = {co[0] - radius, co[1] - radius, co[2] - radius};
+ float co_max[3] = {co[0] + radius, co[1] + radius, co[2] + radius};
DO_MIN(co_min, min);
DO_MAX(co_max, max);
}
@@ -183,7 +190,8 @@ BoundBox *BKE_hair_boundbox_get(Object *ob)
void BKE_hair_update_customdata_pointers(Hair *hair)
{
- hair->points = CustomData_get_layer(&hair->pdata, CD_HAIRPOINT);
+ hair->co = CustomData_get_layer(&hair->pdata, CD_LOCATION);
+ hair->radius = CustomData_get_layer(&hair->pdata, CD_RADIUS);
hair->curves = CustomData_get_layer(&hair->cdata, CD_HAIRCURVE);
hair->mapping = CustomData_get_layer(&hair->cdata, CD_HAIRMAPPING);
}
diff --git a/source/blender/blenkernel/intern/pointcloud.c b/source/blender/blenkernel/intern/pointcloud.c
index 3ac8ff85ddc..86fd5275b17 100644
--- a/source/blender/blenkernel/intern/pointcloud.c
+++ b/source/blender/blenkernel/intern/pointcloud.c
@@ -29,6 +29,7 @@
#include "BLI_listbase.h"
#include "BLI_math.h"
+#include "BLI_rand.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -50,13 +51,16 @@ static void pointcloud_random(PointCloud *pointcloud)
CustomData_realloc(&pointcloud->pdata, pointcloud->totpoint);
BKE_pointcloud_update_customdata_pointers(pointcloud);
+ RNG *rng = BLI_rng_new(0);
+
for (int i = 0; i < pointcloud->totpoint; i++) {
- Point *point = &pointcloud->points[i];
- point->co[0] = 2.0f * drand48() - 1.0f;
- point->co[1] = 2.0f * drand48() - 1.0f;
- point->co[2] = 2.0f * drand48() - 1.0f;
- point->radius = 0.05f * drand48();
+ pointcloud->co[i][0] = 2.0f * BLI_rng_get_float(rng) - 1.0f;
+ pointcloud->co[i][1] = 2.0f * BLI_rng_get_float(rng) - 1.0f;
+ pointcloud->co[i][2] = 2.0f * BLI_rng_get_float(rng) - 1.0f;
+ pointcloud->radius[i] = 0.05f * BLI_rng_get_float(rng);
}
+
+ BLI_rng_free(rng);
}
void BKE_pointcloud_init(PointCloud *pointcloud)
@@ -67,7 +71,8 @@ void BKE_pointcloud_init(PointCloud *pointcloud)
pointcloud->totpoint = 0;
CustomData_reset(&pointcloud->pdata);
- CustomData_add_layer(&pointcloud->pdata, CD_POINT, CD_CALLOC, NULL, pointcloud->totpoint);
+ CustomData_add_layer(&pointcloud->pdata, CD_LOCATION, CD_CALLOC, NULL, pointcloud->totpoint);
+ CustomData_add_layer(&pointcloud->pdata, CD_RADIUS, CD_CALLOC, NULL, pointcloud->totpoint);
BKE_pointcloud_update_customdata_pointers(pointcloud);
pointcloud_random(pointcloud);
@@ -130,16 +135,16 @@ BoundBox *BKE_pointcloud_boundbox_get(Object *ob)
if (ob->runtime.bb == NULL) {
ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "pointcloud boundbox");
- Point *point = pointcloud->points;
float min[3], max[3];
INIT_MINMAX(min, max);
- for (int a = 0; a < pointcloud->totpoint; a++, point++) {
- float co_min[3] = {point->co[0] - point->radius,
- point->co[1] - point->radius,
- point->co[2] - point->radius};
- float co_max[3] = {point->co[0] + point->radius,
- point->co[1] + point->radius,
- point->co[2] + point->radius};
+
+ float(*pointcloud_co)[3] = pointcloud->co;
+ float *pointcloud_radius = pointcloud->radius;
+ for (int a = 0; a < pointcloud->totpoint; a++) {
+ float *co = pointcloud_co[a];
+ float radius = (pointcloud_radius) ? pointcloud_radius[a] : 0.0f;
+ float co_min[3] = {co[0] - radius, co[1] - radius, co[2] - radius};
+ float co_max[3] = {co[0] + radius, co[1] + radius, co[2] + radius};
DO_MIN(co_min, min);
DO_MAX(co_max, max);
}
@@ -152,7 +157,8 @@ BoundBox *BKE_pointcloud_boundbox_get(Object *ob)
void BKE_pointcloud_update_customdata_pointers(PointCloud *pointcloud)
{
- pointcloud->points = CustomData_get_layer(&pointcloud->pdata, CD_POINT);
+ pointcloud->co = CustomData_get_layer(&pointcloud->pdata, CD_LOCATION);
+ pointcloud->radius = CustomData_get_layer(&pointcloud->pdata, CD_RADIUS);
}
/* Dependency Graph */
diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h
index 9d30d58813f..97c8f9dae4f 100644
--- a/source/blender/makesdna/DNA_customdata_types.h
+++ b/source/blender/makesdna/DNA_customdata_types.h
@@ -147,13 +147,11 @@ typedef enum CustomDataType {
CD_TESSLOOPNORMAL = 40,
CD_CUSTOMLOOPNORMAL = 41,
- /* Hair */
- CD_HAIRPOINT = 42,
- CD_HAIRCURVE = 43,
- CD_HAIRMAPPING = 44,
-
- /* PointCloud */
- CD_POINT = 45,
+ /* Hair and PointCloud */
+ CD_LOCATION = 42,
+ CD_RADIUS = 43,
+ CD_HAIRCURVE = 44,
+ CD_HAIRMAPPING = 45,
CD_NUMTYPES = 46,
} CustomDataType;
diff --git a/source/blender/makesdna/DNA_hair_types.h b/source/blender/makesdna/DNA_hair_types.h
index 4c0166ad152..5efb9ec769b 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -28,18 +28,11 @@
#include "DNA_ID.h"
#include "DNA_customdata_types.h"
-/* TODO: for compatibility with node systems and renderers, separate
- * data layers for coordinate and radius seems better? */
-typedef struct HairPoint {
- float co[3];
- float radius;
-} HairPoint;
-
-/* TODO: make numpoints implicit? It can be automatically computed from
- * next firstpoint. */
typedef struct HairCurve {
+ /* Index of first point of hair curve. */
int firstpoint;
- int numpoints; /* Must be 2 or higher. */
+ /* Number of points in hair curve, must be 2 or higher. */
+ int numpoints;
} HairCurve;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list