Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/curves.cc
| Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
| using blender::float3; | using blender::float3; | ||||
| using blender::IndexRange; | using blender::IndexRange; | ||||
| using blender::MutableSpan; | using blender::MutableSpan; | ||||
| using blender::RandomNumberGenerator; | using blender::RandomNumberGenerator; | ||||
| using blender::Span; | using blender::Span; | ||||
| static const char *ATTR_POSITION = "position"; | static const char *ATTR_POSITION = "position"; | ||||
| static void curves_random(Curves *curves); | |||||
| static void update_custom_data_pointers(Curves &curves); | static void update_custom_data_pointers(Curves &curves); | ||||
| static void curves_init_data(ID *id) | static void curves_init_data(ID *id) | ||||
| { | { | ||||
| Curves *curves = (Curves *)id; | Curves *curves = (Curves *)id; | ||||
| BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(curves, id)); | BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(curves, id)); | ||||
| MEMCPY_STRUCT_AFTER(curves, DNA_struct_default_get(Curves), id); | MEMCPY_STRUCT_AFTER(curves, DNA_struct_default_get(Curves), id); | ||||
| new (&curves->geometry) blender::bke::CurvesGeometry(); | new (&curves->geometry) blender::bke::CurvesGeometry(); | ||||
| curves_random(curves); | |||||
| } | } | ||||
| static void curves_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag) | static void curves_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag) | ||||
| { | { | ||||
| using namespace blender; | using namespace blender; | ||||
| Curves *curves_dst = (Curves *)id_dst; | Curves *curves_dst = (Curves *)id_dst; | ||||
| const Curves *curves_src = (const Curves *)id_src; | const Curves *curves_src = (const Curves *)id_src; | ||||
| ▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | IDTypeInfo IDType_ID_CV = { | ||||
| /*lib_override_apply_post */ nullptr, | /*lib_override_apply_post */ nullptr, | ||||
| }; | }; | ||||
| static void update_custom_data_pointers(Curves &curves) | static void update_custom_data_pointers(Curves &curves) | ||||
| { | { | ||||
| blender::bke::CurvesGeometry::wrap(curves.geometry).update_customdata_pointers(); | blender::bke::CurvesGeometry::wrap(curves.geometry).update_customdata_pointers(); | ||||
| } | } | ||||
| static void curves_random(Curves *curves) | |||||
| { | |||||
| const int numpoints = 8; | |||||
| blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(curves->geometry); | |||||
| geometry = blender::bke::CurvesGeometry(500 * numpoints, 500); | |||||
| MutableSpan<int> offsets = geometry.offsets(); | |||||
| MutableSpan<float3> positions = geometry.positions(); | |||||
| float *radius_data = (float *)CustomData_add_layer_named( | |||||
| &geometry.point_data, CD_PROP_FLOAT, CD_DEFAULT, nullptr, geometry.point_size, "radius"); | |||||
| MutableSpan<float> radii{radius_data, geometry.points_size()}; | |||||
| for (const int i : offsets.index_range()) { | |||||
| offsets[i] = numpoints * i; | |||||
| } | |||||
| RandomNumberGenerator rng; | |||||
| for (int i = 0; i < geometry.curve_size; i++) { | |||||
| const IndexRange curve_range = geometry.range_for_curve(i); | |||||
| MutableSpan<float3> curve_positions = positions.slice(curve_range); | |||||
| MutableSpan<float> curve_radii = radii.slice(curve_range); | |||||
| const float theta = 2.0f * M_PI * rng.get_float(); | |||||
| const float phi = saacosf(2.0f * rng.get_float() - 1.0f); | |||||
| float3 no = {std::sin(theta) * std::sin(phi), std::cos(theta) * std::sin(phi), std::cos(phi)}; | |||||
| no = blender::math::normalize(no); | |||||
| float3 co = no; | |||||
| for (int key = 0; key < numpoints; key++) { | |||||
| float t = key / (float)(numpoints - 1); | |||||
| curve_positions[key] = co; | |||||
| curve_radii[key] = 0.02f * (1.0f - t); | |||||
| float3 offset = float3(rng.get_float(), rng.get_float(), rng.get_float()) * 2.0f - 1.0f; | |||||
| co += (offset + no) / numpoints; | |||||
| } | |||||
| } | |||||
| } | |||||
| void *BKE_curves_add(Main *bmain, const char *name) | void *BKE_curves_add(Main *bmain, const char *name) | ||||
| { | { | ||||
| Curves *curves = static_cast<Curves *>(BKE_id_new(bmain, ID_CV, name)); | Curves *curves = static_cast<Curves *>(BKE_id_new(bmain, ID_CV, name)); | ||||
| return curves; | return curves; | ||||
| } | } | ||||
| BoundBox *BKE_curves_boundbox_get(Object *ob) | BoundBox *BKE_curves_boundbox_get(Object *ob) | ||||
| ▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines | |||||