Blender V5.3
mathutils_noise.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12/************************/
13/* Blender Noise Module */
14/************************/
15#include <ctime>
16
17#include <Python.h>
18
19#include "BLI_math_vector_c.hh"
20#include "BLI_noise_c.hh"
21#include "BLI_utildefines.hh"
22
23#include "DNA_texture_types.h"
24
26
27#include "mathutils.hh"
28#include "mathutils_noise.hh"
29
30namespace blender {
31
32/*-----------------------------------------*/
33/* 'mersenne twister' random number generator */
34
35/* A C-program for MT19937, with initialization improved 2002/2/10.
36 * Coded by Takuji Nishimura and Makoto Matsumoto.
37 * This is a faster version by taking Shawn Cokus's optimization,
38 * Matthe Bellew's simplification, Isaku Wada's real version.
39 *
40 * Before using, initialize the state by using
41 * `init_genrand(seed)` or `init_by_array(init_key, key_length)`.
42 *
43 * SPDX-License-Identifier: BSD-3-Clause
44 * Copyright 1997-2002 Makoto Matsumoto and Takuji Nishimura, All rights reserved.
45 *
46 * Any feedback is very welcome.
47 * http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
48 * email: `m-mat @ math.sci.hiroshima-u.ac.jp` (remove space). */
49
50/* Period parameters */
51#define N 624
52#define M 397
53#define MATRIX_A 0x9908b0dfUL /* constant vector a */
54#define UMASK 0x80000000UL /* most significant w-r bits */
55#define LMASK 0x7fffffffUL /* least significant r bits */
56#define MIXBITS(u, v) (((u) & UMASK) | ((v) & LMASK))
57#define TWIST(u, v) ((MIXBITS(u, v) >> 1) ^ ((v) & 1UL ? MATRIX_A : 0UL))
58
59static ulong state[N]; /* The array for the state vector. */
60static int left = 1;
61static int initf = 0;
62static ulong *next;
63static float state_offset_vector[3 * 3];
64
65/* initializes state[N] with a seed */
66static void init_genrand(ulong s)
67{
68 int j;
69 state[0] = s & 0xffffffffUL;
70 for (j = 1; j < N; j++) {
71 state[j] = (1812433253UL * (state[j - 1] ^ (state[j - 1] >> 30)) + j);
72 /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier.
73 * In the previous versions, MSBs of the seed affect
74 * only MSBs of the array state[].
75 * 2002/01/09 modified by Makoto Matsumoto. */
76 state[j] &= 0xffffffffUL; /* for >32 bit machines */
77 }
78 left = 1;
79 initf = 1;
80
81 /* update vector offset */
82 {
83 const ulong *state_offset = &state[N - ARRAY_SIZE(state_offset_vector)];
84 const float range = 32; /* range in both pos/neg direction */
85 for (j = 0; j < ARRAY_SIZE(state_offset_vector); j++, state_offset++) {
86 /* overflow is fine here */
87 state_offset_vector[j] = float(int(*state_offset)) * (1.0f / (float(INT_MAX) / range));
88 }
89 }
90}
91
92static void next_state()
93{
94 ulong *p = state;
95 int j;
96
97 /* If init_genrand() has not been called, a default initial seed is used. */
98 if (initf == 0) {
99 init_genrand(5489UL);
100 }
101
102 left = N;
103 next = state;
104
105 for (j = N - M + 1; --j; p++) {
106 *p = p[M] ^ TWIST(p[0], p[1]);
107 }
108
109 for (j = M; --j; p++) {
110 *p = p[M - N] ^ TWIST(p[0], p[1]);
111 }
112
113 *p = p[M - N] ^ TWIST(p[0], state[0]);
114}
115
116/*------------------------------------------------------------*/
117
118static void setRndSeed(int seed)
119{
120 if (seed == 0) {
121 init_genrand(time(nullptr));
122 }
123 else {
124 init_genrand(seed);
125 }
126}
127
128/* Float number in range [0, 1) using the mersenne twister random number generator. */
129static float frand()
130{
131 ulong y;
132
133 if (--left == 0) {
134 next_state();
135 }
136 y = *next++;
137
138 /* Tempering */
139 y ^= (y >> 11);
140 y ^= (y << 7) & 0x9d2c5680UL;
141 y ^= (y << 15) & 0xefc60000UL;
142 y ^= (y >> 18);
143
144 return float(y) / 4294967296.0f;
145}
146
147/*------------------------------------------------------------*/
148/* Utility Functions */
149/*------------------------------------------------------------*/
150
151#define BPY_NOISE_BASIS_ENUM_DOC \
152 " :param noise_basis: A noise basis string.\n" \
153 " :type noise_basis: Literal['BLENDER', 'PERLIN_ORIGINAL', 'PERLIN_NEW', " \
154 "'VORONOI_F1', 'VORONOI_F2', " \
155 "'VORONOI_F3', 'VORONOI_F4', 'VORONOI_F2F1', 'VORONOI_CRACKLE', " \
156 "'CELLNOISE']\n"
157
158#define BPY_NOISE_METRIC_ENUM_DOC \
159 " :param distance_metric: A distance metric string.\n" \
160 " :type distance_metric: Literal['DISTANCE', 'DISTANCE_SQUARED', 'MANHATTAN', " \
161 "'CHEBYCHEV', " \
162 "'MINKOVSKY', 'MINKOVSKY_HALF', 'MINKOVSKY_FOUR']\n"
163
164/* Noise basis enum */
165#define DEFAULT_NOISE_TYPE TEX_STDPERLIN
166
168 {TEX_BLENDER, "BLENDER"},
169 {TEX_STDPERLIN, "PERLIN_ORIGINAL"},
170 {TEX_NEWPERLIN, "PERLIN_NEW"},
171 {TEX_VORONOI_F1, "VORONOI_F1"},
172 {TEX_VORONOI_F2, "VORONOI_F2"},
173 {TEX_VORONOI_F3, "VORONOI_F3"},
174 {TEX_VORONOI_F4, "VORONOI_F4"},
175 {TEX_VORONOI_F2F1, "VORONOI_F2F1"},
176 {TEX_VORONOI_CRACKLE, "VORONOI_CRACKLE"},
177 {TEX_CELLNOISE, "CELLNOISE"},
178 {0, nullptr},
179};
180
181/* Metric basis enum */
182#define DEFAULT_METRIC_TYPE TEX_DISTANCE
183
185 {TEX_DISTANCE, "DISTANCE"},
186 {TEX_DISTANCE_SQUARED, "DISTANCE_SQUARED"},
187 {TEX_MANHATTAN, "MANHATTAN"},
188 {TEX_CHEBYCHEV, "CHEBYCHEV"},
189 {TEX_MINKOVSKY, "MINKOVSKY"},
190 {TEX_MINKOVSKY_HALF, "MINKOVSKY_HALF"},
191 {TEX_MINKOVSKY_FOUR, "MINKOVSKY_FOUR"},
192 {0, nullptr},
193};
194
195/* Fills an array of length size with random numbers in the range (-1, 1). */
196static void rand_vn(float *array_tar, const int size)
197{
198 float *array_pt = array_tar + (size - 1);
199 int i = size;
200 while (i--) {
201 *(array_pt--) = 2.0f * frand() - 1.0f;
202 }
203}
204
205/* Fills an array of length 3 with noise values */
206static void noise_vector(float x, float y, float z, int nb, float v[3])
207{
208 /* Simply evaluate noise at 3 different positions */
209 const float *ofs = state_offset_vector;
210 for (int j = 0; j < 3; j++) {
211 v[j] = (2.0f * BLI_noise_generic_noise(1.0f, x + ofs[0], y + ofs[1], z + ofs[2], false, nb) -
212 1.0f);
213 ofs += 3;
214 }
215}
216
217/* Returns a turbulence value for a given position (x, y, z) */
218static float turb(
219 float x, float y, float z, int oct, int hard, int nb, float ampscale, float freqscale)
220{
221 float amp, out, t;
222 int i;
223 amp = 1.0f;
224 out = (2.0f * BLI_noise_generic_noise(1.0f, x, y, z, false, nb) - 1.0f);
225 if (hard) {
226 out = fabsf(out);
227 }
228 for (i = 1; i < oct; i++) {
229 amp *= ampscale;
230 x *= freqscale;
231 y *= freqscale;
232 z *= freqscale;
233 t = (amp * (2.0f * BLI_noise_generic_noise(1.0f, x, y, z, false, nb) - 1.0f));
234 if (hard) {
235 t = fabsf(t);
236 }
237 out += t;
238 }
239 return out;
240}
241
242/* Fills an array of length 3 with the turbulence vector for a given
243 * position (x, y, z) */
244static void vTurb(float x,
245 float y,
246 float z,
247 int oct,
248 int hard,
249 int nb,
250 float ampscale,
251 float freqscale,
252 float v[3])
253{
254 float amp, t[3];
255 int i;
256 amp = 1.0f;
257 noise_vector(x, y, z, nb, v);
258 if (hard) {
259 v[0] = fabsf(v[0]);
260 v[1] = fabsf(v[1]);
261 v[2] = fabsf(v[2]);
262 }
263 for (i = 1; i < oct; i++) {
264 amp *= ampscale;
265 x *= freqscale;
266 y *= freqscale;
267 z *= freqscale;
268 noise_vector(x, y, z, nb, t);
269 if (hard) {
270 t[0] = fabsf(t[0]);
271 t[1] = fabsf(t[1]);
272 t[2] = fabsf(t[2]);
273 }
274 v[0] += amp * t[0];
275 v[1] += amp * t[1];
276 v[2] += amp * t[2];
277 }
278}
279
280/*------------------------------------------------------------*/
281/* Python Functions */
282/*------------------------------------------------------------*/
283
285 /* Wrap. */
286 M_Noise_random_doc,
287 ".. function:: random()\n"
288 "\n"
289 " Returns a random number in the range [0, 1).\n"
290 "\n"
291 " :return: The random number.\n"
292 " :rtype: float\n");
293static PyObject *M_Noise_random(PyObject * /*self*/)
294{
295 return PyFloat_FromDouble(frand());
296}
297
299 /* Wrap. */
300 M_Noise_random_unit_vector_doc,
301 ".. function:: random_unit_vector(*, size=3)\n"
302 "\n"
303 " Returns a unit vector with random entries.\n"
304 "\n"
305 " :param size: The size of the vector to be produced, in the range [2, 4].\n"
306 " :type size: int\n"
307 " :return: The random unit vector.\n"
308 " :rtype: :class:`mathutils.Vector`\n");
309static PyObject *M_Noise_random_unit_vector(PyObject * /*self*/, PyObject *args, PyObject *kw)
310{
311 static const char *kwlist[] = {"size", nullptr};
312 float vec[4] = {0.0f, 0.0f, 0.0f, 0.0f};
313 float norm = 2.0f;
314 int vec_num = 3;
315
316 if (!PyArg_ParseTupleAndKeywords(args,
317 kw,
318 "|$" /* Optional, keyword only arguments. */
319 "i" /* `size` */
320 ":random_unit_vector",
321 const_cast<char **>(kwlist),
322 &vec_num))
323 {
324 return nullptr;
325 }
326
327 if (vec_num > 4 || vec_num < 2) {
328 PyErr_SetString(PyExc_ValueError, "Vector(): invalid size");
329 return nullptr;
330 }
331
332 while (norm == 0.0f || norm > 1.0f) {
333 rand_vn(vec, vec_num);
334 norm = normalize_vn(vec, vec_num);
335 }
336
337 return Vector_CreatePyObject(vec, vec_num, nullptr);
338}
339
341 /* Wrap. */
342 M_Noise_random_vector_doc,
343 ".. function:: random_vector(*, size=3)\n"
344 "\n"
345 " Returns a vector with random entries in the range (-1, 1).\n"
346 "\n"
347 " :param size: The size of the vector to be produced, must be 2 or greater.\n"
348 " :type size: int\n"
349 " :return: The random vector.\n"
350 " :rtype: :class:`mathutils.Vector`\n");
351static PyObject *M_Noise_random_vector(PyObject * /*self*/, PyObject *args, PyObject *kw)
352{
353 static const char *kwlist[] = {"size", nullptr};
354 float *vec = nullptr;
355 int vec_num = 3;
356
357 if (!PyArg_ParseTupleAndKeywords(args,
358 kw,
359 "|$" /* Optional, keyword only arguments. */
360 "i" /* `size` */
361 ":random_vector",
362 const_cast<char **>(kwlist),
363 &vec_num))
364 {
365 return nullptr;
366 }
367
368 if (vec_num < 2) {
369 PyErr_SetString(PyExc_ValueError, "Vector(): invalid size");
370 return nullptr;
371 }
372
373 vec = PyMem_New(float, vec_num);
374
375 rand_vn(vec, vec_num);
376
377 return Vector_CreatePyObject_alloc(vec, vec_num, nullptr);
378}
379
381 /* Wrap. */
382 M_Noise_seed_set_doc,
383 ".. function:: seed_set(seed, /)\n"
384 "\n"
385 " Sets the random seed used for random_unit_vector, random_vector, and random.\n"
386 "\n"
387 " :param seed: Seed used for the random generator.\n"
388 " When seed is zero, the current time will be used instead.\n"
389 " :type seed: int\n");
390static PyObject *M_Noise_seed_set(PyObject * /*self*/, PyObject *args)
391{
392 int s;
393 if (!PyArg_ParseTuple(args,
394 "i" /* `seed` */
395 ":seed_set",
396 &s))
397 {
398 return nullptr;
399 }
400 setRndSeed(s);
401 Py_RETURN_NONE;
402}
403
405 /* Wrap. */
406 M_Noise_noise_doc,
407 ".. function:: noise(position, /, *, noise_basis='PERLIN_ORIGINAL')\n"
408 "\n"
409 " Returns noise value from the noise basis at the position specified.\n"
410 "\n"
411 " :param position: The position to evaluate the selected noise function.\n"
412 " :type position: :class:`mathutils.Vector`\n" BPY_NOISE_BASIS_ENUM_DOC
413 " :return: The noise value.\n"
414 " :rtype: float\n");
415static PyObject *M_Noise_noise(PyObject * /*self*/, PyObject *args, PyObject *kw)
416{
417 static const char *kwlist[] = {"", "noise_basis", nullptr};
418 PyObject *value;
419 float vec[3];
420 const char *noise_basis_str = nullptr;
421 int noise_basis_enum = DEFAULT_NOISE_TYPE;
422
423 if (!PyArg_ParseTupleAndKeywords(args,
424 kw,
425 "O" /* `position` */
426 "|$" /* Optional, keyword only arguments. */
427 "s" /* `noise_basis` */
428 ":noise",
429 const_cast<char **>(kwlist),
430 &value,
431 &noise_basis_str))
432 {
433 return nullptr;
434 }
435
436 if (!noise_basis_str) {
437 /* pass through */
438 }
439 else if (PyC_FlagSet_ValueFromID(bpy_noise_types, noise_basis_str, &noise_basis_enum, "noise") ==
440 -1)
441 {
442 return nullptr;
443 }
444
445 if (mathutils_array_parse(vec, 3, 3, value, "noise: invalid 'position' arg") == -1) {
446 return nullptr;
447 }
448
449 return PyFloat_FromDouble(
450 (2.0f * BLI_noise_generic_noise(1.0f, vec[0], vec[1], vec[2], false, noise_basis_enum) -
451 1.0f));
452}
453
455 /* Wrap. */
456 M_Noise_noise_vector_doc,
457 ".. function:: noise_vector(position, /, *, noise_basis='PERLIN_ORIGINAL')\n"
458 "\n"
459 " Returns the noise vector from the noise basis at the specified position.\n"
460 "\n"
461 " :param position: The position to evaluate the selected noise function.\n"
462 " :type position: :class:`mathutils.Vector`\n" BPY_NOISE_BASIS_ENUM_DOC
463 " :return: The noise vector.\n"
464 " :rtype: :class:`mathutils.Vector`\n");
465static PyObject *M_Noise_noise_vector(PyObject * /*self*/, PyObject *args, PyObject *kw)
466{
467 static const char *kwlist[] = {"", "noise_basis", nullptr};
468 PyObject *value;
469 float vec[3], r_vec[3];
470 const char *noise_basis_str = nullptr;
471 int noise_basis_enum = DEFAULT_NOISE_TYPE;
472
473 if (!PyArg_ParseTupleAndKeywords(args,
474 kw,
475 "O" /* `position` */
476 "|$" /* Optional, keyword only arguments. */
477 "s" /* `noise_basis` */
478 ":noise_vector",
479 const_cast<char **>(kwlist),
480 &value,
481 &noise_basis_str))
482 {
483 return nullptr;
484 }
485
486 if (!noise_basis_str) {
487 /* pass through */
488 }
490 bpy_noise_types, noise_basis_str, &noise_basis_enum, "noise_vector") == -1)
491 {
492 return nullptr;
493 }
494
495 if (mathutils_array_parse(vec, 3, 3, value, "noise_vector: invalid 'position' arg") == -1) {
496 return nullptr;
497 }
498
499 noise_vector(vec[0], vec[1], vec[2], noise_basis_enum, r_vec);
500
501 return Vector_CreatePyObject(r_vec, 3, nullptr);
502}
503
505 /* Wrap. */
506 M_Noise_turbulence_doc,
507 ".. function:: turbulence(position, octaves, hard, /, *, "
508 "noise_basis='PERLIN_ORIGINAL', amplitude_scale=0.5, frequency_scale=2.0)\n"
509 "\n"
510 " Returns the turbulence value from the noise basis at the specified position.\n"
511 "\n"
512 " :param position: The position to evaluate the selected noise function.\n"
513 " :type position: :class:`mathutils.Vector`\n"
514 " :param octaves: The number of different noise frequencies used.\n"
515 " :type octaves: int\n"
516 " :param hard: Specifies whether returned turbulence is hard (sharp transitions) or "
517 "soft (smooth transitions).\n"
518 " :type hard: bool\n" BPY_NOISE_BASIS_ENUM_DOC
519 " :param amplitude_scale: The amplitude scaling factor.\n"
520 " :type amplitude_scale: float\n"
521 " :param frequency_scale: The frequency scaling factor.\n"
522 " :type frequency_scale: float\n"
523 " :return: The turbulence value.\n"
524 " :rtype: float\n");
525static PyObject *M_Noise_turbulence(PyObject * /*self*/, PyObject *args, PyObject *kw)
526{
527 static const char *kwlist[] = {
528 "", "", "", "noise_basis", "amplitude_scale", "frequency_scale", nullptr};
529 PyObject *value;
530 float vec[3];
531 const char *noise_basis_str = nullptr;
532 int oct, hd, noise_basis_enum = DEFAULT_NOISE_TYPE;
533 float as = 0.5f, fs = 2.0f;
534
535 if (!PyArg_ParseTupleAndKeywords(args,
536 kw,
537 "O" /* `position` */
538 "i" /* `octaves` */
539 "i" /* `hard` */
540 "|$" /* Optional, keyword only arguments. */
541 "s" /* `noise_basis` */
542 "f" /* `amplitude_scale` */
543 "f" /* `frequency_scale` */
544 ":turbulence",
545 const_cast<char **>(kwlist),
546 &value,
547 &oct,
548 &hd,
549 &noise_basis_str,
550 &as,
551 &fs))
552 {
553 return nullptr;
554 }
555
556 if (!noise_basis_str) {
557 /* pass through */
558 }
560 bpy_noise_types, noise_basis_str, &noise_basis_enum, "turbulence") == -1)
561 {
562 return nullptr;
563 }
564
565 if (mathutils_array_parse(vec, 3, 3, value, "turbulence: invalid 'position' arg") == -1) {
566 return nullptr;
567 }
568
569 return PyFloat_FromDouble(turb(vec[0], vec[1], vec[2], oct, hd, noise_basis_enum, as, fs));
570}
571
573 /* Wrap. */
574 M_Noise_turbulence_vector_doc,
575 ".. function:: turbulence_vector(position, octaves, hard, /, *, "
576 "noise_basis='PERLIN_ORIGINAL', amplitude_scale=0.5, frequency_scale=2.0)\n"
577 "\n"
578 " Returns the turbulence vector from the noise basis at the specified position.\n"
579 "\n"
580 " :param position: The position to evaluate the selected noise function.\n"
581 " :type position: :class:`mathutils.Vector`\n"
582 " :param octaves: The number of different noise frequencies used.\n"
583 " :type octaves: int\n"
584 " :param hard: Specifies whether returned turbulence is hard (sharp transitions) or "
585 "soft (smooth transitions).\n"
586 " :type hard: bool\n" BPY_NOISE_BASIS_ENUM_DOC
587 " :param amplitude_scale: The amplitude scaling factor.\n"
588 " :type amplitude_scale: float\n"
589 " :param frequency_scale: The frequency scaling factor.\n"
590 " :type frequency_scale: float\n"
591 " :return: The turbulence vector.\n"
592 " :rtype: :class:`mathutils.Vector`\n");
593static PyObject *M_Noise_turbulence_vector(PyObject * /*self*/, PyObject *args, PyObject *kw)
594{
595 static const char *kwlist[] = {
596 "", "", "", "noise_basis", "amplitude_scale", "frequency_scale", nullptr};
597 PyObject *value;
598 float vec[3], r_vec[3];
599 const char *noise_basis_str = nullptr;
600 int oct, hd, noise_basis_enum = DEFAULT_NOISE_TYPE;
601 float as = 0.5f, fs = 2.0f;
602
603 if (!PyArg_ParseTupleAndKeywords(args,
604 kw,
605 "O" /* `position` */
606 "i" /* `octaves` */
607 "i" /* `hard` */
608 "|$" /* Optional, keyword only arguments. */
609 "s" /* `noise_basis` */
610 "f" /* `amplitude_scale` */
611 "f" /* `frequency_scale` */
612 ":turbulence_vector",
613 const_cast<char **>(kwlist),
614 &value,
615 &oct,
616 &hd,
617 &noise_basis_str,
618 &as,
619 &fs))
620 {
621 return nullptr;
622 }
623
624 if (!noise_basis_str) {
625 /* pass through */
626 }
628 bpy_noise_types, noise_basis_str, &noise_basis_enum, "turbulence_vector") == -1)
629 {
630 return nullptr;
631 }
632
633 if (mathutils_array_parse(vec, 3, 3, value, "turbulence_vector: invalid 'position' arg") == -1) {
634 return nullptr;
635 }
636
637 vTurb(vec[0], vec[1], vec[2], oct, hd, noise_basis_enum, as, fs, r_vec);
638
639 return Vector_CreatePyObject(r_vec, 3, nullptr);
640}
641
642/* F. Kenton Musgrave's fractal functions */
644 /* Wrap. */
645 M_Noise_fractal_doc,
646 ".. function:: fractal(position, H, lacunarity, octaves, /, *, "
647 "noise_basis='PERLIN_ORIGINAL')\n"
648 "\n"
649 " Returns the fractal Brownian motion (fBm) noise value from the noise basis at the "
650 "specified position.\n"
651 "\n"
652 " :param position: The position to evaluate the selected noise function.\n"
653 " :type position: :class:`mathutils.Vector`\n"
654 " :param H: The fractal increment parameter.\n"
655 " :type H: float\n"
656 " :param lacunarity: The gap between successive frequencies.\n"
657 " :type lacunarity: float\n"
658 " :param octaves: The number of different noise frequencies used.\n"
659 " :type octaves: float\n" BPY_NOISE_BASIS_ENUM_DOC
660 " :return: The fractal Brownian motion noise value.\n"
661 " :rtype: float\n");
662static PyObject *M_Noise_fractal(PyObject * /*self*/, PyObject *args, PyObject *kw)
663{
664 static const char *kwlist[] = {"", "", "", "", "noise_basis", nullptr};
665 PyObject *value;
666 float vec[3];
667 const char *noise_basis_str = nullptr;
668 float H, lac, oct;
669 int noise_basis_enum = DEFAULT_NOISE_TYPE;
670
671 if (!PyArg_ParseTupleAndKeywords(args,
672 kw,
673 "O" /* `position` */
674 "f" /* `H` */
675 "f" /* `lacunarity` */
676 "f" /* `octaves` */
677 "|$" /* Optional, keyword only arguments. */
678 "s" /* `noise_basis` */
679 ":fractal",
680 const_cast<char **>(kwlist),
681 &value,
682 &H,
683 &lac,
684 &oct,
685 &noise_basis_str))
686 {
687 return nullptr;
688 }
689
690 if (!noise_basis_str) {
691 /* pass through */
692 }
694 bpy_noise_types, noise_basis_str, &noise_basis_enum, "fractal") == -1)
695 {
696 return nullptr;
697 }
698
699 if (mathutils_array_parse(vec, 3, 3, value, "fractal: invalid 'position' arg") == -1) {
700 return nullptr;
701 }
702
703 return PyFloat_FromDouble(
704 BLI_noise_mg_fbm(vec[0], vec[1], vec[2], H, lac, oct, noise_basis_enum));
705}
706
708 /* Wrap. */
709 M_Noise_multi_fractal_doc,
710 ".. function:: multi_fractal(position, H, lacunarity, octaves, /, *, "
711 "noise_basis='PERLIN_ORIGINAL')\n"
712 "\n"
713 " Returns multifractal noise value from the noise basis at the specified position.\n"
714 "\n"
715 " :param position: The position to evaluate the selected noise function.\n"
716 " :type position: :class:`mathutils.Vector`\n"
717 " :param H: Determines the highest fractal dimension.\n"
718 " :type H: float\n"
719 " :param lacunarity: The gap between successive frequencies.\n"
720 " :type lacunarity: float\n"
721 " :param octaves: The number of different noise frequencies used.\n"
722 " :type octaves: float\n" BPY_NOISE_BASIS_ENUM_DOC
723 " :return: The multifractal noise value.\n"
724 " :rtype: float\n");
725static PyObject *M_Noise_multi_fractal(PyObject * /*self*/, PyObject *args, PyObject *kw)
726{
727 static const char *kwlist[] = {"", "", "", "", "noise_basis", nullptr};
728 PyObject *value;
729 float vec[3];
730 const char *noise_basis_str = nullptr;
731 float H, lac, oct;
732 int noise_basis_enum = DEFAULT_NOISE_TYPE;
733
734 if (!PyArg_ParseTupleAndKeywords(args,
735 kw,
736 "O" /* `position` */
737 "f" /* `H` */
738 "f" /* `lacunarity` */
739 "f" /* `octaves` */
740 "|$" /* Optional, keyword only arguments. */
741 "s" /* `noise_basis` */
742 ":multi_fractal",
743 const_cast<char **>(kwlist),
744 &value,
745 &H,
746 &lac,
747 &oct,
748 &noise_basis_str))
749 {
750 return nullptr;
751 }
752
753 if (!noise_basis_str) {
754 /* pass through */
755 }
757 bpy_noise_types, noise_basis_str, &noise_basis_enum, "multi_fractal") == -1)
758 {
759 return nullptr;
760 }
761
762 if (mathutils_array_parse(vec, 3, 3, value, "multi_fractal: invalid 'position' arg") == -1) {
763 return nullptr;
764 }
765
766 return PyFloat_FromDouble(
767 BLI_noise_mg_multi_fractal(vec[0], vec[1], vec[2], H, lac, oct, noise_basis_enum));
768}
769
771 /* Wrap. */
772 M_Noise_variable_lacunarity_doc,
773 ".. function:: variable_lacunarity(position, distortion, /, *, "
774 "noise_type1='PERLIN_ORIGINAL', noise_type2='PERLIN_ORIGINAL')\n"
775 "\n"
776 " Returns variable lacunarity noise value, a distorted variety of noise, from "
777 "noise type 1 distorted by noise type 2 at the specified position.\n"
778 "\n"
779 " :param position: The position to evaluate the selected noise function.\n"
780 " :type position: :class:`mathutils.Vector`\n"
781 " :param distortion: The amount of distortion.\n"
782 " :type distortion: float\n"
783 " :param noise_type1: A noise type string.\n"
784 " :type noise_type1: Literal['BLENDER', 'PERLIN_ORIGINAL', 'PERLIN_NEW', "
785 "'VORONOI_F1', 'VORONOI_F2', "
786 "'VORONOI_F3', 'VORONOI_F4', 'VORONOI_F2F1', 'VORONOI_CRACKLE', "
787 "'CELLNOISE']\n"
788 " :param noise_type2: A noise type string.\n"
789 " :type noise_type2: Literal['BLENDER', 'PERLIN_ORIGINAL', 'PERLIN_NEW', "
790 "'VORONOI_F1', 'VORONOI_F2', "
791 "'VORONOI_F3', 'VORONOI_F4', 'VORONOI_F2F1', 'VORONOI_CRACKLE', "
792 "'CELLNOISE']\n"
793 " :return: The variable lacunarity noise value.\n"
794 " :rtype: float\n");
795static PyObject *M_Noise_variable_lacunarity(PyObject * /*self*/, PyObject *args, PyObject *kw)
796{
797 static const char *kwlist[] = {"", "", "noise_type1", "noise_type2", nullptr};
798 PyObject *value;
799 float vec[3];
800 const char *noise_type1_str = nullptr, *noise_type2_str = nullptr;
801 float d;
802 int noise_type1_enum = DEFAULT_NOISE_TYPE, noise_type2_enum = DEFAULT_NOISE_TYPE;
803
804 if (!PyArg_ParseTupleAndKeywords(args,
805 kw,
806 "O" /* `position` */
807 "f" /* `distortion` */
808 "|$" /* Optional, keyword only arguments. */
809 "s" /* `noise_type1` */
810 "s" /* `noise_type2` */
811 ":variable_lacunarity",
812 const_cast<char **>(kwlist),
813 &value,
814 &d,
815 &noise_type1_str,
816 &noise_type2_str))
817 {
818 return nullptr;
819 }
820
821 if (!noise_type1_str) {
822 /* pass through */
823 }
825 bpy_noise_types, noise_type1_str, &noise_type1_enum, "variable_lacunarity") == -1)
826 {
827 return nullptr;
828 }
829
830 if (!noise_type2_str) {
831 /* pass through */
832 }
834 bpy_noise_types, noise_type2_str, &noise_type2_enum, "variable_lacunarity") == -1)
835 {
836 return nullptr;
837 }
838
839 if (mathutils_array_parse(vec, 3, 3, value, "variable_lacunarity: invalid 'position' arg") == -1)
840 {
841 return nullptr;
842 }
843
844 return PyFloat_FromDouble(BLI_noise_mg_variable_lacunarity(
845 vec[0], vec[1], vec[2], d, noise_type1_enum, noise_type2_enum));
846}
847
849 /* Wrap. */
850 M_Noise_hetero_terrain_doc,
851 ".. function:: hetero_terrain(position, H, lacunarity, octaves, offset, /, *, "
852 "noise_basis='PERLIN_ORIGINAL')\n"
853 "\n"
854 " Returns the heterogeneous terrain value from the noise basis at the specified position.\n"
855 "\n"
856 " :param position: The position to evaluate the selected noise function.\n"
857 " :type position: :class:`mathutils.Vector`\n"
858 " :param H: The fractal dimension of the roughest areas.\n"
859 " :type H: float\n"
860 " :param lacunarity: The gap between successive frequencies.\n"
861 " :type lacunarity: float\n"
862 " :param octaves: The number of different noise frequencies used.\n"
863 " :type octaves: float\n"
864 " :param offset: The height of the terrain above 'sea level'.\n"
865 " :type offset: float\n" BPY_NOISE_BASIS_ENUM_DOC
866 " :return: The heterogeneous terrain value.\n"
867 " :rtype: float\n");
868static PyObject *M_Noise_hetero_terrain(PyObject * /*self*/, PyObject *args, PyObject *kw)
869{
870 static const char *kwlist[] = {"", "", "", "", "", "noise_basis", nullptr};
871 PyObject *value;
872 float vec[3];
873 const char *noise_basis_str = nullptr;
874 float H, lac, oct, ofs;
875 int noise_basis_enum = DEFAULT_NOISE_TYPE;
876
877 if (!PyArg_ParseTupleAndKeywords(args,
878 kw,
879 "O" /* `position` */
880 "f" /* `H` */
881 "f" /* `lacunarity` */
882 "f" /* `octaves` */
883 "f" /* `offset` */
884 "|$" /* Optional, keyword only arguments. */
885 "s" /* `noise_basis` */
886 ":hetero_terrain",
887 const_cast<char **>(kwlist),
888 &value,
889 &H,
890 &lac,
891 &oct,
892 &ofs,
893 &noise_basis_str))
894 {
895 return nullptr;
896 }
897
898 if (!noise_basis_str) {
899 /* pass through */
900 }
902 bpy_noise_types, noise_basis_str, &noise_basis_enum, "hetero_terrain") == -1)
903 {
904 return nullptr;
905 }
906
907 if (mathutils_array_parse(vec, 3, 3, value, "hetero_terrain: invalid 'position' arg") == -1) {
908 return nullptr;
909 }
910
911 return PyFloat_FromDouble(
912 BLI_noise_mg_hetero_terrain(vec[0], vec[1], vec[2], H, lac, oct, ofs, noise_basis_enum));
913}
914
916 /* Wrap. */
917 M_Noise_hybrid_multi_fractal_doc,
918 ".. function:: hybrid_multi_fractal(position, H, lacunarity, octaves, offset, gain, /, *, "
919 "noise_basis='PERLIN_ORIGINAL')\n"
920 "\n"
921 " Returns hybrid multifractal value from the noise basis at the specified position.\n"
922 "\n"
923 " :param position: The position to evaluate the selected noise function.\n"
924 " :type position: :class:`mathutils.Vector`\n"
925 " :param H: The fractal dimension of the roughest areas.\n"
926 " :type H: float\n"
927 " :param lacunarity: The gap between successive frequencies.\n"
928 " :type lacunarity: float\n"
929 " :param octaves: The number of different noise frequencies used.\n"
930 " :type octaves: float\n"
931 " :param offset: The height of the terrain above 'sea level'.\n"
932 " :type offset: float\n"
933 " :param gain: Scaling applied to the values.\n"
934 " :type gain: float\n" BPY_NOISE_BASIS_ENUM_DOC
935 " :return: The hybrid multifractal value.\n"
936 " :rtype: float\n");
937static PyObject *M_Noise_hybrid_multi_fractal(PyObject * /*self*/, PyObject *args, PyObject *kw)
938{
939 static const char *kwlist[] = {"", "", "", "", "", "", "noise_basis", nullptr};
940 PyObject *value;
941 float vec[3];
942 const char *noise_basis_str = nullptr;
943 float H, lac, oct, ofs, gn;
944 int noise_basis_enum = DEFAULT_NOISE_TYPE;
945
946 if (!PyArg_ParseTupleAndKeywords(args,
947 kw,
948 "O" /* `position` */
949 "f" /* `H` */
950 "f" /* `lacunarity` */
951 "f" /* `octaves` */
952 "f" /* `offset` */
953 "f" /* `gain` */
954 "|$" /* Optional, keyword only arguments. */
955 "s" /* `noise_basis` */
956 ":hybrid_multi_fractal",
957 const_cast<char **>(kwlist),
958 &value,
959 &H,
960 &lac,
961 &oct,
962 &ofs,
963 &gn,
964 &noise_basis_str))
965 {
966 return nullptr;
967 }
968
969 if (!noise_basis_str) {
970 /* pass through */
971 }
973 bpy_noise_types, noise_basis_str, &noise_basis_enum, "hybrid_multi_fractal") == -1)
974 {
975 return nullptr;
976 }
977
978 if (mathutils_array_parse(vec, 3, 3, value, "hybrid_multi_fractal: invalid 'position' arg") ==
979 -1)
980 {
981 return nullptr;
982 }
983
984 return PyFloat_FromDouble(BLI_noise_mg_hybrid_multi_fractal(
985 vec[0], vec[1], vec[2], H, lac, oct, ofs, gn, noise_basis_enum));
986}
987
989 /* Wrap. */
990 M_Noise_ridged_multi_fractal_doc,
991 ".. function:: ridged_multi_fractal(position, H, lacunarity, octaves, offset, gain, /, *, "
992 "noise_basis='PERLIN_ORIGINAL')\n"
993 "\n"
994 " Returns ridged multifractal value from the noise basis at the specified position.\n"
995 "\n"
996 " :param position: The position to evaluate the selected noise function.\n"
997 " :type position: :class:`mathutils.Vector`\n"
998 " :param H: The fractal dimension of the roughest areas.\n"
999 " :type H: float\n"
1000 " :param lacunarity: The gap between successive frequencies.\n"
1001 " :type lacunarity: float\n"
1002 " :param octaves: The number of different noise frequencies used.\n"
1003 " :type octaves: float\n"
1004 " :param offset: The height of the terrain above 'sea level'.\n"
1005 " :type offset: float\n"
1006 " :param gain: Scaling applied to the values.\n"
1007 " :type gain: float\n" BPY_NOISE_BASIS_ENUM_DOC
1008 " :return: The ridged multifractal value.\n"
1009 " :rtype: float\n");
1010static PyObject *M_Noise_ridged_multi_fractal(PyObject * /*self*/, PyObject *args, PyObject *kw)
1011{
1012 static const char *kwlist[] = {"", "", "", "", "", "", "noise_basis", nullptr};
1013 PyObject *value;
1014 float vec[3];
1015 const char *noise_basis_str = nullptr;
1016 float H, lac, oct, ofs, gn;
1017 int noise_basis_enum = DEFAULT_NOISE_TYPE;
1018
1019 if (!PyArg_ParseTupleAndKeywords(args,
1020 kw,
1021 "O" /* `position` */
1022 "f" /* `H` */
1023 "f" /* `lacunarity` */
1024 "f" /* `octaves` */
1025 "f" /* `offset` */
1026 "f" /* `gain` */
1027 "|$" /* Optional, keyword only arguments. */
1028 "s" /* `noise_basis` */
1029 ":ridged_multi_fractal",
1030 const_cast<char **>(kwlist),
1031 &value,
1032 &H,
1033 &lac,
1034 &oct,
1035 &ofs,
1036 &gn,
1037 &noise_basis_str))
1038 {
1039 return nullptr;
1040 }
1041
1042 if (!noise_basis_str) {
1043 /* pass through */
1044 }
1045 else if (PyC_FlagSet_ValueFromID(
1046 bpy_noise_types, noise_basis_str, &noise_basis_enum, "ridged_multi_fractal") == -1)
1047 {
1048 return nullptr;
1049 }
1050
1051 if (mathutils_array_parse(vec, 3, 3, value, "ridged_multi_fractal: invalid 'position' arg") ==
1052 -1)
1053 {
1054 return nullptr;
1055 }
1056
1057 return PyFloat_FromDouble(BLI_noise_mg_ridged_multi_fractal(
1058 vec[0], vec[1], vec[2], H, lac, oct, ofs, gn, noise_basis_enum));
1059}
1060
1062 /* Wrap. */
1063 M_Noise_voronoi_doc,
1064 ".. function:: voronoi(position, /, *, distance_metric='DISTANCE', exponent=2.5)\n"
1065 "\n"
1066 " Returns a list of distances to the four closest features and their locations.\n"
1067 "\n"
1068 " :param position: The position to evaluate the selected noise function.\n"
1069 " :type position: :class:`mathutils.Vector`\n" BPY_NOISE_METRIC_ENUM_DOC
1070 " :param exponent: The exponent for Minkowski distance metric.\n"
1071 " :type exponent: float\n"
1072 " :return: A list of distances to the four closest features and their locations.\n"
1073 " :rtype: list[list[float] | list[:class:`mathutils.Vector`]]\n");
1074static PyObject *M_Noise_voronoi(PyObject * /*self*/, PyObject *args, PyObject *kw)
1075{
1076 static const char *kwlist[] = {"", "distance_metric", "exponent", nullptr};
1077 PyObject *value;
1078 PyObject *list;
1079 PyObject *ret;
1080 float vec[3];
1081 const char *metric_str = nullptr;
1082 float da[4], pa[12];
1083 int metric_enum = DEFAULT_METRIC_TYPE;
1084 float me = 2.5f; /* default minkowski exponent */
1085
1086 int i;
1087
1088 if (!PyArg_ParseTupleAndKeywords(args,
1089 kw,
1090 "O" /* `position` */
1091 "|$" /* Optional, keyword only arguments. */
1092 "s" /* `distance_metric` */
1093 "f" /* `exponent` */
1094 ":voronoi",
1095 const_cast<char **>(kwlist),
1096 &value,
1097 &metric_str,
1098 &me))
1099 {
1100 return nullptr;
1101 }
1102
1103 if (!metric_str) {
1104 /* pass through */
1105 }
1106 else if (PyC_FlagSet_ValueFromID(bpy_noise_metrics, metric_str, &metric_enum, "voronoi") == -1) {
1107 return nullptr;
1108 }
1109
1110 if (mathutils_array_parse(vec, 3, 3, value, "voronoi: invalid 'position' arg") == -1) {
1111 return nullptr;
1112 }
1113
1114 list = PyList_New(4);
1115
1116 BLI_noise_voronoi(vec[0], vec[1], vec[2], da, pa, me, metric_enum);
1117
1118 for (i = 0; i < 4; i++) {
1119 PyObject *v = Vector_CreatePyObject(pa + 3 * i, 3, nullptr);
1120 PyList_SET_ITEM(list, i, v);
1121 }
1122
1123 ret = Py_BuildValue("[[ffff]O]", da[0], da[1], da[2], da[3], list);
1124 Py_DECREF(list);
1125 return ret;
1126}
1127
1129 /* Wrap. */
1130 M_Noise_cell_doc,
1131 ".. function:: cell(position, /)\n"
1132 "\n"
1133 " Returns cell noise value at the specified position.\n"
1134 "\n"
1135 " :param position: The position to evaluate the cell noise at.\n"
1136 " :type position: :class:`mathutils.Vector`\n"
1137 " :return: The cell noise value.\n"
1138 " :rtype: float\n");
1139static PyObject *M_Noise_cell(PyObject * /*self*/, PyObject *args)
1140{
1141 PyObject *value;
1142 float vec[3];
1143
1144 if (!PyArg_ParseTuple(args,
1145 "O" /* `position` */
1146 ":cell",
1147 &value))
1148 {
1149 return nullptr;
1150 }
1151
1152 if (mathutils_array_parse(vec, 3, 3, value, "cell: invalid 'position' arg") == -1) {
1153 return nullptr;
1154 }
1155
1156 return PyFloat_FromDouble(BLI_noise_cell(vec[0], vec[1], vec[2]));
1157}
1158
1160 /* Wrap. */
1161 M_Noise_cell_vector_doc,
1162 ".. function:: cell_vector(position, /)\n"
1163 "\n"
1164 " Returns cell noise vector at the specified position.\n"
1165 "\n"
1166 " :param position: The position to evaluate the cell noise at.\n"
1167 " :type position: :class:`mathutils.Vector`\n"
1168 " :return: The cell noise vector.\n"
1169 " :rtype: :class:`mathutils.Vector`\n");
1170static PyObject *M_Noise_cell_vector(PyObject * /*self*/, PyObject *args)
1171{
1172 PyObject *value;
1173 float vec[3], r_vec[3];
1174
1175 if (!PyArg_ParseTuple(args,
1176 "O" /* `position` */
1177 ":cell_vector",
1178 &value))
1179 {
1180 return nullptr;
1181 }
1182
1183 if (mathutils_array_parse(vec, 3, 3, value, "cell_vector: invalid 'position' arg") == -1) {
1184 return nullptr;
1185 }
1186
1187 BLI_noise_cell_v3(vec[0], vec[1], vec[2], r_vec);
1188 return Vector_CreatePyObject(r_vec, 3, nullptr);
1189}
1190
1191#ifdef __GNUC__
1192# ifdef __clang__
1193# pragma clang diagnostic push
1194# pragma clang diagnostic ignored "-Wcast-function-type"
1195# else
1196# pragma GCC diagnostic push
1197# pragma GCC diagnostic ignored "-Wcast-function-type"
1198# endif
1199#endif
1200
1201static PyMethodDef M_Noise_methods[] = {
1202 {"seed_set", static_cast<PyCFunction>(M_Noise_seed_set), METH_VARARGS, M_Noise_seed_set_doc},
1203 {"random", reinterpret_cast<PyCFunction>(M_Noise_random), METH_NOARGS, M_Noise_random_doc},
1204 {"random_unit_vector",
1205 reinterpret_cast<PyCFunction>(M_Noise_random_unit_vector),
1206 METH_VARARGS | METH_KEYWORDS,
1207 M_Noise_random_unit_vector_doc},
1208 {"random_vector",
1209 reinterpret_cast<PyCFunction>(M_Noise_random_vector),
1210 METH_VARARGS | METH_KEYWORDS,
1211 M_Noise_random_vector_doc},
1212 {"noise",
1213 reinterpret_cast<PyCFunction>(M_Noise_noise),
1214 METH_VARARGS | METH_KEYWORDS,
1215 M_Noise_noise_doc},
1216 {"noise_vector",
1217 reinterpret_cast<PyCFunction>(M_Noise_noise_vector),
1218 METH_VARARGS | METH_KEYWORDS,
1219 M_Noise_noise_vector_doc},
1220 {"turbulence",
1221 reinterpret_cast<PyCFunction>(M_Noise_turbulence),
1222 METH_VARARGS | METH_KEYWORDS,
1223 M_Noise_turbulence_doc},
1224 {"turbulence_vector",
1225 reinterpret_cast<PyCFunction>(M_Noise_turbulence_vector),
1226 METH_VARARGS | METH_KEYWORDS,
1227 M_Noise_turbulence_vector_doc},
1228 {"fractal",
1229 reinterpret_cast<PyCFunction>(M_Noise_fractal),
1230 METH_VARARGS | METH_KEYWORDS,
1231 M_Noise_fractal_doc},
1232 {"multi_fractal",
1233 reinterpret_cast<PyCFunction>(M_Noise_multi_fractal),
1234 METH_VARARGS | METH_KEYWORDS,
1235 M_Noise_multi_fractal_doc},
1236 {"variable_lacunarity",
1237 reinterpret_cast<PyCFunction>(M_Noise_variable_lacunarity),
1238 METH_VARARGS | METH_KEYWORDS,
1239 M_Noise_variable_lacunarity_doc},
1240 {"hetero_terrain",
1241 reinterpret_cast<PyCFunction>(M_Noise_hetero_terrain),
1242 METH_VARARGS | METH_KEYWORDS,
1243 M_Noise_hetero_terrain_doc},
1244 {"hybrid_multi_fractal",
1245 reinterpret_cast<PyCFunction>(M_Noise_hybrid_multi_fractal),
1246 METH_VARARGS | METH_KEYWORDS,
1247 M_Noise_hybrid_multi_fractal_doc},
1248 {"ridged_multi_fractal",
1249 reinterpret_cast<PyCFunction>(M_Noise_ridged_multi_fractal),
1250 METH_VARARGS | METH_KEYWORDS,
1251 M_Noise_ridged_multi_fractal_doc},
1252 {"voronoi",
1253 reinterpret_cast<PyCFunction>(M_Noise_voronoi),
1254 METH_VARARGS | METH_KEYWORDS,
1255 M_Noise_voronoi_doc},
1256 {"cell", static_cast<PyCFunction>(M_Noise_cell), METH_VARARGS, M_Noise_cell_doc},
1257 {"cell_vector",
1258 static_cast<PyCFunction>(M_Noise_cell_vector),
1259 METH_VARARGS,
1260 M_Noise_cell_vector_doc},
1261 {nullptr, nullptr, 0, nullptr},
1262};
1263
1264#ifdef __GNUC__
1265# ifdef __clang__
1266# pragma clang diagnostic pop
1267# else
1268# pragma GCC diagnostic pop
1269# endif
1270#endif
1271
1273 /* Wrap. */
1274 M_Noise_doc,
1275 "The Blender noise module.");
1276static PyModuleDef M_Noise_module_def = {
1277 /*m_base*/ PyModuleDef_HEAD_INIT,
1278 /*m_name*/ "mathutils.noise",
1279 /*m_doc*/ M_Noise_doc,
1280 /*m_size*/ 0,
1281 /*m_methods*/ M_Noise_methods,
1282 /*m_slots*/ nullptr,
1283 /*m_traverse*/ nullptr,
1284 /*m_clear*/ nullptr,
1285 /*m_free*/ nullptr,
1286};
1287
1288/*----------------------------MODULE INIT-------------------------*/
1289
1291{
1292 PyObject *submodule = PyModule_Create(&M_Noise_module_def);
1293
1294 /* use current time as seed for random number generator by default */
1295 setRndSeed(0);
1296
1297 return submodule;
1298}
1299
1300} // namespace blender
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Definition btVector3.h:263
#define INT_MAX
const int state
#define TWIST(u, v)
#define BPY_NOISE_BASIS_ENUM_DOC
#define DEFAULT_METRIC_TYPE
#define M
#define BPY_NOISE_METRIC_ENUM_DOC
#define DEFAULT_NOISE_TYPE
#define N
#define H(x, y, z)
BMesh Iterators.
static int left
float BLI_noise_mg_ridged_multi_fractal(float x, float y, float z, float H, float lacunarity, float octaves, float offset, float gain, int noisebasis)
Definition noise_c.cc:1537
PyMODINIT_FUNC PyInit_mathutils_noise()
static void rand_vn(float *array_tar, const int size)
static PyMethodDef M_Noise_methods[]
float normalize_vn(float *array_tar, int size)
static int initf
static PyObject * M_Noise_variable_lacunarity(PyObject *, PyObject *args, PyObject *kw)
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
unsigned long ulong
Definition BKE_text.h:57
static PyObject * M_Noise_multi_fractal(PyObject *, PyObject *args, PyObject *kw)
static PyObject * M_Noise_random_unit_vector(PyObject *, PyObject *args, PyObject *kw)
float BLI_noise_generic_noise(float noisesize, float x, float y, float z, bool hard, int noisebasis)
Definition noise_c.cc:1155
static float frand()
int PyC_FlagSet_ValueFromID(const PyC_FlagSet *item, const char *identifier, int *r_value, const char *error_prefix)
float BLI_noise_mg_hybrid_multi_fractal(float x, float y, float z, float H, float lacunarity, float octaves, float offset, float gain, int noisebasis)
Definition noise_c.cc:1463
static void noise_vector(float x, float y, float z, int nb, float v[3])
ATTR_WARN_UNUSED_RESULT const BMVert * v
float BLI_noise_mg_multi_fractal(float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis)
Definition noise_c.cc:1334
static PyObject * M_Noise_cell_vector(PyObject *, PyObject *args)
static PyObject * M_Noise_turbulence_vector(PyObject *, PyObject *args, PyObject *kw)
PyObject * Vector_CreatePyObject_alloc(float *vec, const int vec_num, PyTypeObject *base_type)
float BLI_noise_mg_hetero_terrain(float x, float y, float z, float H, float lacunarity, float octaves, float offset, int noisebasis)
Definition noise_c.cc:1393
static PyC_FlagSet bpy_noise_metrics[]
static PyC_FlagSet bpy_noise_types[]
static PyObject * M_Noise_noise(PyObject *, PyObject *args, PyObject *kw)
static PyObject * M_Noise_ridged_multi_fractal(PyObject *, PyObject *args, PyObject *kw)
static void init_genrand(ulong s)
PyObject * Vector_CreatePyObject(const float *vec, const int vec_num, PyTypeObject *base_type)
static void vTurb(float x, float y, float z, int oct, int hard, int nb, float ampscale, float freqscale, float v[3])
void BLI_noise_voronoi(float x, float y, float z, float *da, float *pa, float me, int dtype)
Definition noise_c.cc:917
float BLI_noise_mg_fbm(float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis)
Definition noise_c.cc:1274
static PyObject * M_Noise_voronoi(PyObject *, PyObject *args, PyObject *kw)
static PyObject * M_Noise_noise_vector(PyObject *, PyObject *args, PyObject *kw)
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
Definition mathutils.cc:97
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
static void setRndSeed(int seed)
float BLI_noise_mg_variable_lacunarity(float x, float y, float z, float distortion, int nbas1, int nbas2)
Definition noise_c.cc:1608
static PyObject * M_Noise_hybrid_multi_fractal(PyObject *, PyObject *args, PyObject *kw)
static float state_offset_vector[3 *3]
float BLI_noise_cell(float x, float y, float z)
Definition noise_c.cc:1128
static ulong * next
static PyObject * M_Noise_random_vector(PyObject *, PyObject *args, PyObject *kw)
void BLI_noise_cell_v3(float x, float y, float z, float r_ca[3])
Definition noise_c.cc:1133
static PyObject * M_Noise_random(PyObject *)
static void next_state()
static float turb(float x, float y, float z, int oct, int hard, int nb, float ampscale, float freqscale)
static PyObject * M_Noise_cell(PyObject *, PyObject *args)
static PyObject * M_Noise_hetero_terrain(PyObject *, PyObject *args, PyObject *kw)
static PyObject * M_Noise_fractal(PyObject *, PyObject *args, PyObject *kw)
static PyModuleDef M_Noise_module_def
static PyObject * M_Noise_turbulence(PyObject *, PyObject *args, PyObject *kw)
static PyObject * M_Noise_seed_set(PyObject *, PyObject *args)
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float