2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-11-10 19:13:05 +00:00
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-11-10 19:13:05 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
2012-03-25 15:56:17 +00:00
|
|
|
*
|
2009-11-10 19:13:05 +00:00
|
|
|
* The Original Code is: some of this file.
|
|
|
|
|
*
|
|
|
|
|
* */
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bli
|
2011-02-27 20:37:56 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-02-25 09:02:05 +00:00
|
|
|
#ifndef __MATH_VECTOR_INLINE_C__
|
|
|
|
|
#define __MATH_VECTOR_INLINE_C__
|
2009-11-10 19:13:05 +00:00
|
|
|
|
2012-11-23 15:12:13 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
|
|
2009-11-10 19:13:05 +00:00
|
|
|
/********************************** Init *************************************/
|
|
|
|
|
|
|
|
|
|
MINLINE void zero_v2(float r[2])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = 0.0f;
|
|
|
|
|
r[1] = 0.0f;
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void zero_v3(float r[3])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = 0.0f;
|
|
|
|
|
r[1] = 0.0f;
|
|
|
|
|
r[2] = 0.0f;
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-22 11:10:24 +00:00
|
|
|
MINLINE void zero_v4(float r[4])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = 0.0f;
|
|
|
|
|
r[1] = 0.0f;
|
|
|
|
|
r[2] = 0.0f;
|
|
|
|
|
r[3] = 0.0f;
|
2010-01-22 11:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-27 01:32:58 +00:00
|
|
|
MINLINE void copy_v2_v2(float r[2], const float a[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-27 01:32:58 +00:00
|
|
|
MINLINE void copy_v3_v3(float r[3], const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-20 16:22:55 +01:00
|
|
|
MINLINE void copy_v3fl_v3s(float r[3], const short a[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = (float)a[0];
|
|
|
|
|
r[1] = (float)a[1];
|
|
|
|
|
r[2] = (float)a[2];
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void copy_v4_v4(float r[4], const float a[4])
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
|
|
|
|
r[3] = a[3];
|
2010-01-22 11:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-29 04:17:26 +00:00
|
|
|
MINLINE void copy_v2_fl(float r[2], float f)
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = f;
|
|
|
|
|
r[1] = f;
|
2012-02-29 04:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v3_fl(float r[3], float f)
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = f;
|
|
|
|
|
r[1] = f;
|
|
|
|
|
r[2] = f;
|
2012-02-29 04:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v4_fl(float r[4], float f)
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = f;
|
|
|
|
|
r[1] = f;
|
|
|
|
|
r[2] = f;
|
|
|
|
|
r[3] = f;
|
2012-02-29 04:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-11 01:44:47 +02:00
|
|
|
/* unsigned char */
|
|
|
|
|
MINLINE void copy_v2_v2_uchar(unsigned char r[2], const unsigned char a[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v3_v3_uchar(unsigned char r[3], const unsigned char a[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
|
|
|
|
r[3] = a[3];
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-01 14:58:58 +10:00
|
|
|
MINLINE void copy_v2_uchar(unsigned char r[2], const unsigned char a)
|
|
|
|
|
{
|
|
|
|
|
r[0] = a;
|
|
|
|
|
r[1] = a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v3_uchar(unsigned char r[3], const unsigned char a)
|
|
|
|
|
{
|
|
|
|
|
r[0] = a;
|
|
|
|
|
r[1] = a;
|
|
|
|
|
r[2] = a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v4_uchar(unsigned char r[4], const unsigned char a)
|
|
|
|
|
{
|
|
|
|
|
r[0] = a;
|
|
|
|
|
r[1] = a;
|
|
|
|
|
r[2] = a;
|
|
|
|
|
r[3] = a;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-11 01:44:47 +02:00
|
|
|
/* char */
|
2011-11-07 01:38:32 +00:00
|
|
|
MINLINE void copy_v2_v2_char(char r[2], const char a[2])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
2011-11-07 01:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v3_v3_char(char r[3], const char a[3])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
2011-11-07 01:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v4_v4_char(char r[4], const char a[4])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
|
|
|
|
r[3] = a[3];
|
2011-11-07 01:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-12 04:14:12 +00:00
|
|
|
/* short */
|
2012-10-10 13:18:07 +00:00
|
|
|
|
2011-09-12 04:14:12 +00:00
|
|
|
MINLINE void copy_v2_v2_short(short r[2], const short a[2])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
2011-09-12 04:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v3_v3_short(short r[3], const short a[3])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
2011-09-12 04:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v4_v4_short(short r[4], const short a[4])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
|
|
|
|
r[3] = a[3];
|
2011-09-12 04:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-07 01:38:32 +00:00
|
|
|
/* int */
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
MINLINE void zero_v2_int(int r[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = 0;
|
|
|
|
|
r[1] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-17 15:41:27 +01:00
|
|
|
MINLINE void zero_v3_int(int r[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = 0;
|
|
|
|
|
r[1] = 0;
|
|
|
|
|
r[2] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 01:38:32 +00:00
|
|
|
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
2011-11-07 01:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
2011-11-07 01:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v4_v4_int(int r[4], const int a[4])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
|
|
|
|
r[3] = a[3];
|
2011-11-07 01:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-17 15:41:27 +01:00
|
|
|
/* double */
|
|
|
|
|
MINLINE void zero_v3_db(double r[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = 0.0;
|
|
|
|
|
r[1] = 0.0;
|
|
|
|
|
r[2] = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v2_v2_db(double r[2], const double a[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v3_v3_db(double r[3], const double a[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v4_v4_db(double r[4], const double a[4])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0];
|
|
|
|
|
r[1] = a[1];
|
|
|
|
|
r[2] = a[2];
|
|
|
|
|
r[3] = a[3];
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
/* int <-> float */
|
|
|
|
|
MINLINE void round_v2i_v2fl(int r[2], const float a[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = (int)roundf(a[0]);
|
|
|
|
|
r[1] = (int)roundf(a[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v2fl_v2i(float r[2], const int a[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = (float)a[0];
|
|
|
|
|
r[1] = (float)a[1];
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-09 06:04:17 +00:00
|
|
|
/* double -> float */
|
|
|
|
|
MINLINE void copy_v2fl_v2db(float r[2], const double a[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = (float)a[0];
|
|
|
|
|
r[1] = (float)a[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v3fl_v3db(float r[3], const double a[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = (float)a[0];
|
|
|
|
|
r[1] = (float)a[1];
|
|
|
|
|
r[2] = (float)a[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v4fl_v4db(float r[4], const double a[4])
|
|
|
|
|
{
|
|
|
|
|
r[0] = (float)a[0];
|
|
|
|
|
r[1] = (float)a[1];
|
|
|
|
|
r[2] = (float)a[2];
|
|
|
|
|
r[3] = (float)a[3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* float -> double */
|
|
|
|
|
MINLINE void copy_v2db_v2fl(double r[2], const float a[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = (double)a[0];
|
|
|
|
|
r[1] = (double)a[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v3db_v3fl(double r[3], const float a[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = (double)a[0];
|
|
|
|
|
r[1] = (double)a[1];
|
|
|
|
|
r[2] = (double)a[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void copy_v4db_v4fl(double r[4], const float a[4])
|
|
|
|
|
{
|
|
|
|
|
r[0] = (double)a[0];
|
|
|
|
|
r[1] = (double)a[1];
|
|
|
|
|
r[2] = (double)a[2];
|
|
|
|
|
r[3] = (double)a[3];
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-28 13:11:41 +00:00
|
|
|
MINLINE void swap_v2_v2(float a[2], float b[2])
|
|
|
|
|
{
|
|
|
|
|
SWAP(float, a[0], b[0]);
|
|
|
|
|
SWAP(float, a[1], b[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void swap_v3_v3(float a[3], float b[3])
|
|
|
|
|
{
|
|
|
|
|
SWAP(float, a[0], b[0]);
|
|
|
|
|
SWAP(float, a[1], b[1]);
|
|
|
|
|
SWAP(float, a[2], b[2]);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-22 11:10:24 +00:00
|
|
|
MINLINE void swap_v4_v4(float a[4], float b[4])
|
|
|
|
|
{
|
|
|
|
|
SWAP(float, a[0], b[0]);
|
|
|
|
|
SWAP(float, a[1], b[1]);
|
|
|
|
|
SWAP(float, a[2], b[2]);
|
|
|
|
|
SWAP(float, a[3], b[3]);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 03:31:21 +00:00
|
|
|
/* float args -> vec */
|
2013-11-26 20:53:26 +11:00
|
|
|
MINLINE void copy_v2_fl2(float v[2], float x, float y)
|
|
|
|
|
{
|
|
|
|
|
v[0] = x;
|
|
|
|
|
v[1] = y;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 23:38:51 +00:00
|
|
|
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
|
|
|
|
|
{
|
|
|
|
|
v[0] = x;
|
|
|
|
|
v[1] = y;
|
|
|
|
|
v[2] = z;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 03:31:21 +00:00
|
|
|
MINLINE void copy_v4_fl4(float v[4], float x, float y, float z, float w)
|
|
|
|
|
{
|
|
|
|
|
v[0] = x;
|
|
|
|
|
v[1] = y;
|
|
|
|
|
v[2] = z;
|
|
|
|
|
v[3] = w;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-10 19:13:05 +00:00
|
|
|
/********************************* Arithmetic ********************************/
|
|
|
|
|
|
2012-09-05 23:22:47 +00:00
|
|
|
MINLINE void add_v2_fl(float r[2], float f)
|
|
|
|
|
{
|
|
|
|
|
r[0] += f;
|
|
|
|
|
r[1] += f;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-06 22:10:05 +00:00
|
|
|
MINLINE void add_v3_fl(float r[3], float f)
|
|
|
|
|
{
|
|
|
|
|
r[0] += f;
|
|
|
|
|
r[1] += f;
|
|
|
|
|
r[2] += f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void add_v4_fl(float r[4], float f)
|
|
|
|
|
{
|
|
|
|
|
r[0] += f;
|
|
|
|
|
r[1] += f;
|
|
|
|
|
r[2] += f;
|
|
|
|
|
r[3] += f;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 16:28:52 +00:00
|
|
|
MINLINE void add_v2_v2(float r[2], const float a[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
|
r[0] += a[0];
|
|
|
|
|
r[1] += a[1];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-28 18:33:24 -06:00
|
|
|
MINLINE void add_v2_v2_db(double r[2], const double a[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] += a[0];
|
|
|
|
|
r[1] += a[1];
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 16:28:52 +00:00
|
|
|
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0] + b[0];
|
|
|
|
|
r[1] = a[1] + b[1];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-16 23:16:21 +01:00
|
|
|
MINLINE void add_v2_v2_int(int r[2], const int a[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = r[0] + a[0];
|
|
|
|
|
r[1] = r[1] + a[1];
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-31 00:38:50 +00:00
|
|
|
MINLINE void add_v2_v2v2_int(int r[2], const int a[2], const int b[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] + b[0];
|
|
|
|
|
r[1] = a[1] + b[1];
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 16:28:52 +00:00
|
|
|
MINLINE void add_v3_v3(float r[3], const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
|
r[0] += a[0];
|
|
|
|
|
r[1] += a[1];
|
2009-11-28 13:11:41 +00:00
|
|
|
r[2] += a[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-20 21:09:55 +08:00
|
|
|
MINLINE void add_v3_v3_db(double r[3], const double a[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] += a[0];
|
|
|
|
|
r[1] += a[1];
|
|
|
|
|
r[2] += a[2];
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0] + b[0];
|
|
|
|
|
r[1] = a[1] + b[1];
|
|
|
|
|
r[2] = a[2] + b[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-20 16:22:55 +01:00
|
|
|
MINLINE void add_v3fl_v3fl_v3i(float r[3], const float a[3], const int b[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] + (float)b[0];
|
|
|
|
|
r[1] = a[1] + (float)b[1];
|
|
|
|
|
r[2] = a[2] + (float)b[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void add_v3fl_v3fl_v3s(float r[3], const float a[3], const short b[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] + (float)b[0];
|
|
|
|
|
r[1] = a[1] + (float)b[1];
|
|
|
|
|
r[2] = a[2] + (float)b[2];
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 20:04:55 +00:00
|
|
|
MINLINE void add_v4_v4(float r[4], const float a[4])
|
|
|
|
|
{
|
|
|
|
|
r[0] += a[0];
|
|
|
|
|
r[1] += a[1];
|
|
|
|
|
r[2] += a[2];
|
|
|
|
|
r[3] += a[3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void add_v4_v4v4(float r[4], const float a[4], const float b[4])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] + b[0];
|
|
|
|
|
r[1] = a[1] + b[1];
|
|
|
|
|
r[2] = a[2] + b[2];
|
|
|
|
|
r[3] = a[3] + b[3];
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void sub_v2_v2(float r[2], const float a[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
|
r[0] -= a[0];
|
|
|
|
|
r[1] -= a[1];
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0] - b[0];
|
|
|
|
|
r[1] = a[1] - b[1];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-28 18:33:24 -06:00
|
|
|
MINLINE void sub_v2_v2v2_db(double r[2], const double a[2], const double b[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] - b[0];
|
|
|
|
|
r[1] = a[1] - b[1];
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-31 00:38:50 +00:00
|
|
|
MINLINE void sub_v2_v2v2_int(int r[2], const int a[2], const int b[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] - b[0];
|
|
|
|
|
r[1] = a[1] - b[1];
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void sub_v3_v3(float r[3], const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
|
r[0] -= a[0];
|
|
|
|
|
r[1] -= a[1];
|
2009-11-28 13:11:41 +00:00
|
|
|
r[2] -= a[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-27 01:32:58 +00:00
|
|
|
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0] - b[0];
|
|
|
|
|
r[1] = a[1] - b[1];
|
|
|
|
|
r[2] = a[2] - b[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-20 16:22:55 +01:00
|
|
|
MINLINE void sub_v3_v3v3_int(int r[3], const int a[3], const int b[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] - b[0];
|
|
|
|
|
r[1] = a[1] - b[1];
|
|
|
|
|
r[2] = a[2] - b[2];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-20 21:09:55 +08:00
|
|
|
MINLINE void sub_v3_v3v3_db(double r[3], const double a[3], const double b[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] - b[0];
|
|
|
|
|
r[1] = a[1] - b[1];
|
|
|
|
|
r[2] = a[2] - b[2];
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 09:29:38 -03:00
|
|
|
MINLINE void sub_v2db_v2fl_v2fl(double r[2], const float a[2], const float b[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = (double)a[0] - (double)b[0];
|
|
|
|
|
r[1] = (double)a[1] - (double)b[1];
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 16:22:55 +01:00
|
|
|
MINLINE void sub_v3db_v3fl_v3fl(double r[3], const float a[3], const float b[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = (double)a[0] - (double)b[0];
|
|
|
|
|
r[1] = (double)a[1] - (double)b[1];
|
|
|
|
|
r[2] = (double)a[2] - (double)b[2];
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-12 11:16:04 +00:00
|
|
|
MINLINE void sub_v4_v4(float r[4], const float a[4])
|
|
|
|
|
{
|
|
|
|
|
r[0] -= a[0];
|
|
|
|
|
r[1] -= a[1];
|
|
|
|
|
r[2] -= a[2];
|
|
|
|
|
r[3] -= a[3];
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4])
|
2010-11-12 11:16:04 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0] - b[0];
|
|
|
|
|
r[1] = a[1] - b[1];
|
|
|
|
|
r[2] = a[2] - b[2];
|
|
|
|
|
r[3] = a[3] - b[3];
|
2010-11-12 11:16:04 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void mul_v2_fl(float r[2], float f)
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] *= f;
|
|
|
|
|
r[1] *= f;
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-12 19:47:54 +00:00
|
|
|
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0] * f;
|
|
|
|
|
r[1] = a[1] * f;
|
2010-01-12 19:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
2009-11-10 19:13:05 +00:00
|
|
|
MINLINE void mul_v3_fl(float r[3], float f)
|
|
|
|
|
{
|
|
|
|
|
r[0] *= f;
|
|
|
|
|
r[1] *= f;
|
|
|
|
|
r[2] *= f;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-20 21:09:55 +08:00
|
|
|
MINLINE void mul_v3db_db(double r[3], double f)
|
|
|
|
|
{
|
|
|
|
|
r[0] *= f;
|
|
|
|
|
r[1] *= f;
|
|
|
|
|
r[2] *= f;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-12 19:47:54 +00:00
|
|
|
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0] * f;
|
|
|
|
|
r[1] = a[1] * f;
|
|
|
|
|
r[2] = a[2] * f;
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-28 10:56:44 -04:00
|
|
|
MINLINE void mul_v3_v3db_db(double r[3], const double a[3], double f)
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] * f;
|
|
|
|
|
r[1] = a[1] * f;
|
|
|
|
|
r[2] = a[2] * f;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:41:07 +00:00
|
|
|
MINLINE void mul_v2_v2(float r[2], const float a[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] *= a[0];
|
|
|
|
|
r[1] *= a[1];
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void mul_v3_v3(float r[3], const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
|
r[0] *= a[0];
|
|
|
|
|
r[1] *= a[1];
|
|
|
|
|
r[2] *= a[2];
|
|
|
|
|
}
|
|
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
MINLINE void mul_v4_fl(float r[4], float f)
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] *= f;
|
|
|
|
|
r[1] *= f;
|
|
|
|
|
r[2] *= f;
|
|
|
|
|
r[3] *= f;
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
2018-09-27 18:25:50 +02:00
|
|
|
MINLINE void mul_v4_v4(float r[4], const float a[4])
|
|
|
|
|
{
|
|
|
|
|
r[0] *= a[0];
|
|
|
|
|
r[1] *= a[1];
|
|
|
|
|
r[2] *= a[2];
|
|
|
|
|
r[3] *= a[3];
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 20:04:55 +00:00
|
|
|
MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f)
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] * f;
|
|
|
|
|
r[1] = a[1] * f;
|
|
|
|
|
r[2] = a[2] * f;
|
|
|
|
|
r[3] = a[3] * f;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-03 21:47:03 +11:00
|
|
|
/**
|
|
|
|
|
* Avoid doing:
|
|
|
|
|
*
|
|
|
|
|
* angle = atan2f(dvec[0], dvec[1]);
|
|
|
|
|
* angle_to_mat2(mat, angle);
|
|
|
|
|
*
|
|
|
|
|
* instead use a vector as a matrix.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
MINLINE void mul_v2_v2_cw(float r[2], const float mat[2], const float vec[2])
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(r != vec);
|
|
|
|
|
|
|
|
|
|
r[0] = mat[0] * vec[0] + (+mat[1]) * vec[1];
|
|
|
|
|
r[1] = mat[1] * vec[0] + (-mat[0]) * vec[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void mul_v2_v2_ccw(float r[2], const float mat[2], const float vec[2])
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(r != vec);
|
|
|
|
|
|
|
|
|
|
r[0] = mat[0] * vec[0] + (-mat[1]) * vec[1];
|
|
|
|
|
r[1] = mat[1] * vec[0] + (+mat[0]) * vec[1];
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-28 15:35:59 +11:00
|
|
|
/**
|
|
|
|
|
* Convenience function to get the projected depth of a position.
|
|
|
|
|
* This avoids creating a temporary 4D vector and multiplying it - only for the 4th component.
|
|
|
|
|
*
|
|
|
|
|
* Matches logic for:
|
|
|
|
|
*
|
|
|
|
|
* \code{.c}
|
|
|
|
|
* float co_4d[4] = {co[0], co[1], co[2], 1.0};
|
|
|
|
|
* mul_m4_v4(mat, co_4d);
|
|
|
|
|
* return co_4d[3];
|
|
|
|
|
* \endcode
|
|
|
|
|
*/
|
2017-01-20 17:42:55 +01:00
|
|
|
MINLINE float mul_project_m4_v3_zfac(const float mat[4][4], const float co[3])
|
2013-03-09 15:39:24 +00:00
|
|
|
{
|
|
|
|
|
return (mat[0][3] * co[0]) + (mat[1][3] * co[1]) + (mat[2][3] * co[2]) + mat[3][3];
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 10:58:36 +00:00
|
|
|
/**
|
2014-08-17 12:50:48 +10:00
|
|
|
* Has the effect of #mul_m3_v3(), on a single axis.
|
2013-07-30 10:58:36 +00:00
|
|
|
*/
|
2018-05-14 23:12:51 +02:00
|
|
|
MINLINE float dot_m3_v3_row_x(const float M[3][3], const float a[3])
|
2013-07-28 19:46:33 +00:00
|
|
|
{
|
|
|
|
|
return M[0][0] * a[0] + M[1][0] * a[1] + M[2][0] * a[2];
|
|
|
|
|
}
|
2018-05-14 23:12:51 +02:00
|
|
|
MINLINE float dot_m3_v3_row_y(const float M[3][3], const float a[3])
|
2013-07-28 19:46:33 +00:00
|
|
|
{
|
|
|
|
|
return M[0][1] * a[0] + M[1][1] * a[1] + M[2][1] * a[2];
|
|
|
|
|
}
|
2018-05-14 23:12:51 +02:00
|
|
|
MINLINE float dot_m3_v3_row_z(const float M[3][3], const float a[3])
|
2013-07-28 19:46:33 +00:00
|
|
|
{
|
|
|
|
|
return M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2];
|
|
|
|
|
}
|
2013-03-09 15:39:24 +00:00
|
|
|
|
2013-11-20 11:46:22 +11:00
|
|
|
/**
|
2014-08-17 12:50:48 +10:00
|
|
|
* Has the effect of #mul_mat3_m4_v3(), on a single axis.
|
|
|
|
|
* (no adding translation)
|
2013-11-20 11:46:22 +11:00
|
|
|
*/
|
2018-05-14 23:12:51 +02:00
|
|
|
MINLINE float dot_m4_v3_row_x(const float M[4][4], const float a[3])
|
2013-11-20 11:46:22 +11:00
|
|
|
{
|
|
|
|
|
return M[0][0] * a[0] + M[1][0] * a[1] + M[2][0] * a[2];
|
|
|
|
|
}
|
2018-05-14 23:12:51 +02:00
|
|
|
MINLINE float dot_m4_v3_row_y(const float M[4][4], const float a[3])
|
2013-11-20 11:46:22 +11:00
|
|
|
{
|
|
|
|
|
return M[0][1] * a[0] + M[1][1] * a[1] + M[2][1] * a[2];
|
|
|
|
|
}
|
2018-05-14 23:12:51 +02:00
|
|
|
MINLINE float dot_m4_v3_row_z(const float M[4][4], const float a[3])
|
2013-11-20 11:46:22 +11:00
|
|
|
{
|
|
|
|
|
return M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2];
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-15 10:28:32 +00:00
|
|
|
MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] += a[0] * f;
|
|
|
|
|
r[1] += a[1] * f;
|
2010-04-15 10:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] += a[0] * f;
|
|
|
|
|
r[1] += a[1] * f;
|
|
|
|
|
r[2] += a[2] * f;
|
2009-11-28 13:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3])
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] += a[0] * b[0];
|
|
|
|
|
r[1] += a[1] * b[1];
|
|
|
|
|
r[2] += a[2] * b[2];
|
2009-11-28 13:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
|
2010-01-07 12:41:07 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0] + b[0] * f;
|
|
|
|
|
r[1] = a[1] + b[1] * f;
|
2010-01-07 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0] + b[0] * f;
|
|
|
|
|
r[1] = a[1] + b[1] * f;
|
|
|
|
|
r[2] = a[2] + b[2] * f;
|
2009-11-28 13:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3])
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[0] + b[0] * c[0];
|
|
|
|
|
r[1] = a[1] + b[1] * c[1];
|
|
|
|
|
r[2] = a[2] + b[2] * c[2];
|
2009-11-28 13:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-20 16:22:55 +01:00
|
|
|
MINLINE void madd_v3fl_v3fl_v3fl_v3i(float r[3],
|
|
|
|
|
const float a[3],
|
|
|
|
|
const float b[3],
|
|
|
|
|
const int c[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] + b[0] * (float)c[0];
|
|
|
|
|
r[1] = a[1] + b[1] * (float)c[1];
|
|
|
|
|
r[2] = a[2] + b[2] * (float)c[2];
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-15 10:28:32 +00:00
|
|
|
MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] += a[0] * f;
|
|
|
|
|
r[1] += a[1] * f;
|
|
|
|
|
r[2] += a[2] * f;
|
|
|
|
|
r[3] += a[3] * f;
|
2010-04-15 10:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-12 20:04:55 +00:00
|
|
|
MINLINE void madd_v4_v4v4(float r[4], const float a[4], const float b[4])
|
|
|
|
|
{
|
|
|
|
|
r[0] += a[0] * b[0];
|
|
|
|
|
r[1] += a[1] * b[1];
|
|
|
|
|
r[2] += a[2] * b[2];
|
|
|
|
|
r[3] += a[3] * b[3];
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void mul_v3_v3v3(float r[3], const float v1[3], const float v2[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2011-08-26 22:37:20 +00:00
|
|
|
r[0] = v1[0] * v2[0];
|
|
|
|
|
r[1] = v1[1] * v2[1];
|
|
|
|
|
r[2] = v1[2] * v2[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2018-09-29 17:54:13 +02:00
|
|
|
MINLINE void mul_v2_v2v2(float r[2], const float a[2], const float b[2])
|
|
|
|
|
{
|
|
|
|
|
r[0] = a[0] * b[0];
|
|
|
|
|
r[1] = a[1] * b[1];
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-23 16:09:26 +00:00
|
|
|
MINLINE void negate_v2(float r[2])
|
2011-10-23 17:52:20 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = -r[0];
|
|
|
|
|
r[1] = -r[1];
|
2011-10-23 17:52:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void negate_v2_v2(float r[2], const float a[2])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = -a[0];
|
|
|
|
|
r[1] = -a[1];
|
2011-10-23 17:52:20 +00:00
|
|
|
}
|
|
|
|
|
|
2009-11-10 19:13:05 +00:00
|
|
|
MINLINE void negate_v3(float r[3])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = -r[0];
|
|
|
|
|
r[1] = -r[1];
|
|
|
|
|
r[2] = -r[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE void negate_v3_v3(float r[3], const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = -a[0];
|
|
|
|
|
r[1] = -a[1];
|
|
|
|
|
r[2] = -a[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-02 00:40:55 +00:00
|
|
|
MINLINE void negate_v4(float r[4])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = -r[0];
|
|
|
|
|
r[1] = -r[1];
|
|
|
|
|
r[2] = -r[2];
|
|
|
|
|
r[3] = -r[3];
|
2011-02-02 00:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-08 03:37:49 +00:00
|
|
|
MINLINE void negate_v4_v4(float r[4], const float a[4])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = -a[0];
|
|
|
|
|
r[1] = -a[1];
|
|
|
|
|
r[2] = -a[2];
|
|
|
|
|
r[3] = -a[3];
|
2011-02-08 03:37:49 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-13 11:05:52 +00:00
|
|
|
/* could add more... */
|
|
|
|
|
MINLINE void negate_v3_short(short r[3])
|
|
|
|
|
{
|
2013-12-06 03:46:27 +11:00
|
|
|
r[0] = (short)-r[0];
|
|
|
|
|
r[1] = (short)-r[1];
|
|
|
|
|
r[2] = (short)-r[2];
|
2012-05-13 11:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-14 16:43:14 +10:00
|
|
|
MINLINE void negate_v3_db(double r[3])
|
|
|
|
|
{
|
|
|
|
|
r[0] = -r[0];
|
|
|
|
|
r[1] = -r[1];
|
|
|
|
|
r[2] = -r[2];
|
|
|
|
|
}
|
|
|
|
|
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
MINLINE void invert_v2(float r[2])
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(!ELEM(0.0f, r[0], r[1]));
|
|
|
|
|
r[0] = 1.0f / r[0];
|
|
|
|
|
r[1] = 1.0f / r[1];
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-15 16:12:51 +02:00
|
|
|
MINLINE void invert_v3(float r[3])
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(!ELEM(0.0f, r[0], r[1], r[2]));
|
|
|
|
|
r[0] = 1.0f / r[0];
|
|
|
|
|
r[1] = 1.0f / r[1];
|
|
|
|
|
r[2] = 1.0f / r[2];
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 18:13:35 +01:00
|
|
|
MINLINE void abs_v2(float r[2])
|
|
|
|
|
{
|
2015-03-19 06:13:50 +11:00
|
|
|
r[0] = fabsf(r[0]);
|
|
|
|
|
r[1] = fabsf(r[1]);
|
2015-03-17 18:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void abs_v2_v2(float r[2], const float a[2])
|
|
|
|
|
{
|
2015-03-19 06:13:50 +11:00
|
|
|
r[0] = fabsf(a[0]);
|
|
|
|
|
r[1] = fabsf(a[1]);
|
2015-03-17 18:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void abs_v3(float r[3])
|
|
|
|
|
{
|
2015-03-19 06:13:50 +11:00
|
|
|
r[0] = fabsf(r[0]);
|
|
|
|
|
r[1] = fabsf(r[1]);
|
|
|
|
|
r[2] = fabsf(r[2]);
|
2015-03-17 18:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void abs_v3_v3(float r[3], const float a[3])
|
|
|
|
|
{
|
2015-03-19 06:13:50 +11:00
|
|
|
r[0] = fabsf(a[0]);
|
|
|
|
|
r[1] = fabsf(a[1]);
|
|
|
|
|
r[2] = fabsf(a[2]);
|
2015-03-17 18:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void abs_v4(float r[4])
|
|
|
|
|
{
|
2015-03-19 06:13:50 +11:00
|
|
|
r[0] = fabsf(r[0]);
|
|
|
|
|
r[1] = fabsf(r[1]);
|
|
|
|
|
r[2] = fabsf(r[2]);
|
|
|
|
|
r[3] = fabsf(r[3]);
|
2015-03-17 18:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void abs_v4_v4(float r[4], const float a[4])
|
|
|
|
|
{
|
2015-03-19 06:13:50 +11:00
|
|
|
r[0] = fabsf(a[0]);
|
|
|
|
|
r[1] = fabsf(a[1]);
|
|
|
|
|
r[2] = fabsf(a[2]);
|
|
|
|
|
r[3] = fabsf(a[3]);
|
2015-03-17 18:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float dot_v2v2(const float a[2], const float b[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
return a[0] * b[0] + a[1] * b[1];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-28 18:33:24 -06:00
|
|
|
MINLINE double dot_v2v2_db(const double a[2], const double b[2])
|
|
|
|
|
{
|
|
|
|
|
return a[0] * b[0] + a[1] * b[1];
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float dot_v3v3(const float a[3], const float b[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-09 12:23:34 +01:00
|
|
|
MINLINE float dot_v3v3v3(const float p[3], const float a[3], const float b[3])
|
|
|
|
|
{
|
|
|
|
|
float vec1[3], vec2[3];
|
|
|
|
|
|
|
|
|
|
sub_v3_v3v3(vec1, a, p);
|
|
|
|
|
sub_v3_v3v3(vec2, b, p);
|
|
|
|
|
if (is_zero_v3(vec1) || is_zero_v3(vec2)) {
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
return dot_v3v3(vec1, vec2);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-04 09:23:29 +11:00
|
|
|
MINLINE float dot_v4v4(const float a[4], const float b[4])
|
|
|
|
|
{
|
|
|
|
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 20:59:08 +10:00
|
|
|
MINLINE double dot_v3db_v3fl(const double a[3], const float b[3])
|
|
|
|
|
{
|
|
|
|
|
return a[0] * (double)b[0] + a[1] * (double)b[1] + a[2] * (double)b[2];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-20 21:09:55 +08:00
|
|
|
MINLINE double dot_v3v3_db(const double a[3], const double b[3])
|
|
|
|
|
{
|
|
|
|
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float cross_v2v2(const float a[2], const float b[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
return a[0] * b[1] - a[1] * b[0];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-28 09:29:38 -03:00
|
|
|
MINLINE double cross_v2v2_db(const double a[2], const double b[2])
|
|
|
|
|
{
|
|
|
|
|
return a[0] * b[1] - a[1] * b[0];
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-27 01:32:58 +00:00
|
|
|
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2013-01-29 05:18:30 +00:00
|
|
|
BLI_assert(r != a && r != b);
|
2012-03-25 12:41:58 +00:00
|
|
|
r[0] = a[1] * b[2] - a[2] * b[1];
|
|
|
|
|
r[1] = a[2] * b[0] - a[0] * b[2];
|
|
|
|
|
r[2] = a[0] * b[1] - a[1] * b[0];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-07 23:21:20 +03:00
|
|
|
/* cross product suffers from severe precision loss when vectors are
|
|
|
|
|
* nearly parallel or opposite; doing the computation in double helps a lot */
|
|
|
|
|
MINLINE void cross_v3_v3v3_hi_prec(float r[3], const float a[3], const float b[3])
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(r != a && r != b);
|
|
|
|
|
r[0] = (float)((double)a[1] * (double)b[2] - (double)a[2] * (double)b[1]);
|
|
|
|
|
r[1] = (float)((double)a[2] * (double)b[0] - (double)a[0] * (double)b[2]);
|
|
|
|
|
r[2] = (float)((double)a[0] * (double)b[1] - (double)a[1] * (double)b[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-20 21:09:55 +08:00
|
|
|
MINLINE void cross_v3_v3v3_db(double r[3], const double a[3], const double b[3])
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(r != a && r != b);
|
|
|
|
|
r[0] = a[1] * b[2] - a[2] * b[1];
|
|
|
|
|
r[1] = a[2] * b[0] - a[0] * b[2];
|
|
|
|
|
r[2] = a[0] * b[1] - a[1] * b[0];
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-16 16:49:37 +00:00
|
|
|
/* Newell's Method */
|
2012-07-16 23:23:33 +00:00
|
|
|
/* excuse this fairly specific function,
|
2012-04-16 16:49:37 +00:00
|
|
|
* its used for polygon normals all over the place
|
|
|
|
|
* could use a better name */
|
|
|
|
|
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
|
|
|
|
|
{
|
|
|
|
|
n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
|
|
|
|
|
n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
|
|
|
|
|
n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-11 14:29:01 +00:00
|
|
|
MINLINE void star_m3_v3(float rmat[3][3], float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
rmat[0][0] = rmat[1][1] = rmat[2][2] = 0.0;
|
|
|
|
|
rmat[0][1] = -a[2];
|
|
|
|
|
rmat[0][2] = a[1];
|
|
|
|
|
rmat[1][0] = a[2];
|
|
|
|
|
rmat[1][2] = -a[0];
|
|
|
|
|
rmat[2][0] = -a[1];
|
|
|
|
|
rmat[2][1] = a[0];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*********************************** Length **********************************/
|
|
|
|
|
|
2012-01-17 16:31:13 +00:00
|
|
|
MINLINE float len_squared_v2(const float v[2])
|
|
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
return v[0] * v[0] + v[1] * v[1];
|
2012-01-17 16:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 19:02:28 +00:00
|
|
|
MINLINE float len_squared_v3(const float v[3])
|
|
|
|
|
{
|
|
|
|
|
return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 10:56:44 -04:00
|
|
|
MINLINE double len_squared_v3_db(const double v[3])
|
|
|
|
|
{
|
|
|
|
|
return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-10 01:22:19 +00:00
|
|
|
MINLINE float len_manhattan_v2(const float v[2])
|
|
|
|
|
{
|
|
|
|
|
return fabsf(v[0]) + fabsf(v[1]);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-13 17:11:09 +00:00
|
|
|
MINLINE int len_manhattan_v2_int(const int v[2])
|
2013-04-11 02:23:45 +00:00
|
|
|
{
|
2013-12-06 03:46:27 +11:00
|
|
|
return abs(v[0]) + abs(v[1]);
|
2013-04-11 02:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-10 01:22:19 +00:00
|
|
|
MINLINE float len_manhattan_v3(const float v[3])
|
|
|
|
|
{
|
|
|
|
|
return fabsf(v[0]) + fabsf(v[1]) + fabsf(v[2]);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float len_v2(const float v[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-04-16 16:49:37 +00:00
|
|
|
return sqrtf(v[0] * v[0] + v[1] * v[1]);
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-28 09:29:38 -03:00
|
|
|
MINLINE double len_v2_db(const double v[2])
|
|
|
|
|
{
|
|
|
|
|
return sqrt(v[0] * v[0] + v[1] * v[1]);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float len_v2v2(const float v1[2], const float v2[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
|
float x, y;
|
|
|
|
|
|
2012-03-25 12:41:58 +00:00
|
|
|
x = v1[0] - v2[0];
|
|
|
|
|
y = v1[1] - v2[1];
|
2012-04-16 16:49:37 +00:00
|
|
|
return sqrtf(x * x + y * y);
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-28 18:33:24 -06:00
|
|
|
MINLINE double len_v2v2_db(const double v1[2], const double v2[2])
|
|
|
|
|
{
|
|
|
|
|
double x, y;
|
|
|
|
|
|
|
|
|
|
x = v1[0] - v2[0];
|
|
|
|
|
y = v1[1] - v2[1];
|
|
|
|
|
return sqrt(x * x + y * y);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-28 15:02:57 +11:00
|
|
|
MINLINE float len_v2v2_int(const int v1[2], const int v2[2])
|
|
|
|
|
{
|
|
|
|
|
float x, y;
|
|
|
|
|
|
|
|
|
|
x = (float)(v1[0] - v2[0]);
|
|
|
|
|
y = (float)(v1[1] - v2[1]);
|
|
|
|
|
return sqrtf(x * x + y * y);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float len_v3(const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
|
return sqrtf(dot_v3v3(a, a));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 10:56:44 -04:00
|
|
|
MINLINE double len_v3_db(const double a[3])
|
|
|
|
|
{
|
|
|
|
|
return sqrt(dot_v3v3_db(a, a));
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-17 16:31:13 +00:00
|
|
|
MINLINE float len_squared_v2v2(const float a[2], const float b[2])
|
2010-10-03 14:16:27 +00:00
|
|
|
{
|
|
|
|
|
float d[2];
|
|
|
|
|
|
|
|
|
|
sub_v2_v2v2(d, b, a);
|
|
|
|
|
return dot_v2v2(d, d);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-28 18:33:24 -06:00
|
|
|
MINLINE double len_squared_v2v2_db(const double a[2], const double b[2])
|
|
|
|
|
{
|
|
|
|
|
double d[2];
|
|
|
|
|
|
|
|
|
|
sub_v2_v2v2_db(d, b, a);
|
|
|
|
|
return dot_v2v2_db(d, d);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-10 01:22:19 +00:00
|
|
|
MINLINE float len_squared_v3v3(const float a[3], const float b[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
|
float d[3];
|
|
|
|
|
|
|
|
|
|
sub_v3_v3v3(d, b, a);
|
2012-10-10 01:22:19 +00:00
|
|
|
return dot_v3v3(d, d);
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-19 00:35:24 +11:00
|
|
|
MINLINE float len_squared_v4v4(const float a[4], const float b[4])
|
|
|
|
|
{
|
|
|
|
|
float d[4];
|
|
|
|
|
|
|
|
|
|
sub_v4_v4v4(d, b, a);
|
|
|
|
|
return dot_v4v4(d, d);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-10 01:22:19 +00:00
|
|
|
MINLINE float len_manhattan_v2v2(const float a[2], const float b[2])
|
|
|
|
|
{
|
|
|
|
|
float d[2];
|
|
|
|
|
|
|
|
|
|
sub_v2_v2v2(d, b, a);
|
|
|
|
|
return len_manhattan_v2(d);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-13 17:11:09 +00:00
|
|
|
MINLINE int len_manhattan_v2v2_int(const int a[2], const int b[2])
|
2013-04-11 02:23:45 +00:00
|
|
|
{
|
|
|
|
|
int d[2];
|
|
|
|
|
|
|
|
|
|
sub_v2_v2v2_int(d, b, a);
|
|
|
|
|
return len_manhattan_v2_int(d);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-10 01:22:19 +00:00
|
|
|
MINLINE float len_manhattan_v3v3(const float a[3], const float b[3])
|
2010-04-15 10:28:32 +00:00
|
|
|
{
|
|
|
|
|
float d[3];
|
|
|
|
|
|
|
|
|
|
sub_v3_v3v3(d, b, a);
|
2012-10-10 01:22:19 +00:00
|
|
|
return len_manhattan_v3(d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE float len_v3v3(const float a[3], const float b[3])
|
|
|
|
|
{
|
|
|
|
|
float d[3];
|
|
|
|
|
|
|
|
|
|
sub_v3_v3v3(d, b, a);
|
|
|
|
|
return len_v3(d);
|
2010-04-15 10:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-08 09:52:29 +10:00
|
|
|
MINLINE float normalize_v2_v2_length(float r[2], const float a[2], const float unit_length)
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
float d = dot_v2v2(a, a);
|
2009-11-10 19:13:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (d > 1.0e-35f) {
|
2012-03-25 12:41:58 +00:00
|
|
|
d = sqrtf(d);
|
2016-07-08 09:52:29 +10:00
|
|
|
mul_v2_v2fl(r, a, unit_length / d);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2010-01-12 19:47:54 +00:00
|
|
|
zero_v2(r);
|
2012-03-25 12:41:58 +00:00
|
|
|
d = 0.0f;
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
2010-01-12 19:47:54 +00:00
|
|
|
|
2009-11-10 19:13:05 +00:00
|
|
|
return d;
|
|
|
|
|
}
|
2016-07-08 09:52:29 +10:00
|
|
|
MINLINE float normalize_v2_v2(float r[2], const float a[2])
|
|
|
|
|
{
|
|
|
|
|
return normalize_v2_v2_length(r, a, 1.0f);
|
|
|
|
|
}
|
2009-11-10 19:13:05 +00:00
|
|
|
|
2010-01-12 19:47:54 +00:00
|
|
|
MINLINE float normalize_v2(float n[2])
|
|
|
|
|
{
|
|
|
|
|
return normalize_v2_v2(n, n);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-08 09:52:29 +10:00
|
|
|
MINLINE float normalize_v2_length(float n[2], const float unit_length)
|
|
|
|
|
{
|
|
|
|
|
return normalize_v2_v2_length(n, n, unit_length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE float normalize_v3_v3_length(float r[3], const float a[3], const float unit_length)
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
float d = dot_v3v3(a, a);
|
2009-11-10 19:13:05 +00:00
|
|
|
|
|
|
|
|
/* a larger value causes normalize errors in a
|
2013-02-11 00:49:00 +00:00
|
|
|
* scaled down models with camera extreme close */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (d > 1.0e-35f) {
|
2012-03-25 12:41:58 +00:00
|
|
|
d = sqrtf(d);
|
2016-07-08 09:52:29 +10:00
|
|
|
mul_v3_v3fl(r, a, unit_length / d);
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2010-01-12 19:47:54 +00:00
|
|
|
zero_v3(r);
|
2012-03-25 12:41:58 +00:00
|
|
|
d = 0.0f;
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return d;
|
|
|
|
|
}
|
2016-07-08 09:52:29 +10:00
|
|
|
MINLINE float normalize_v3_v3(float r[3], const float a[3])
|
|
|
|
|
{
|
|
|
|
|
return normalize_v3_v3_length(r, a, 1.0f);
|
|
|
|
|
}
|
2009-11-10 19:13:05 +00:00
|
|
|
|
2020-09-04 17:01:32 +02:00
|
|
|
MINLINE double normalize_v3_v3_length_db(double r[3], const double a[3], double const unit_length)
|
2020-08-28 10:56:44 -04:00
|
|
|
{
|
|
|
|
|
double d = dot_v3v3_db(a, a);
|
|
|
|
|
|
|
|
|
|
/* a larger value causes normalize errors in a
|
|
|
|
|
* scaled down models with camera extreme close */
|
|
|
|
|
if (d > 1.0e-70) {
|
|
|
|
|
d = sqrt(d);
|
|
|
|
|
mul_v3_v3db_db(r, a, unit_length / d);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
zero_v3_db(r);
|
|
|
|
|
d = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
MINLINE double normalize_v3_v3_db(double r[3], const double a[3])
|
|
|
|
|
{
|
|
|
|
|
return normalize_v3_v3_length_db(r, a, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE double normalize_v3_length_db(double n[3], const double unit_length)
|
2012-01-20 02:24:01 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
double d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
|
2012-01-20 02:24:01 +00:00
|
|
|
|
|
|
|
|
/* a larger value causes normalize errors in a
|
2013-02-11 00:49:00 +00:00
|
|
|
* scaled down models with camera extreme close */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (d > 1.0e-35) {
|
2012-01-20 02:24:01 +00:00
|
|
|
double mul;
|
|
|
|
|
|
2012-03-25 12:41:58 +00:00
|
|
|
d = sqrt(d);
|
2016-07-08 09:52:29 +10:00
|
|
|
mul = unit_length / d;
|
2012-01-20 02:24:01 +00:00
|
|
|
|
|
|
|
|
n[0] *= mul;
|
|
|
|
|
n[1] *= mul;
|
|
|
|
|
n[2] *= mul;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-01-20 02:24:01 +00:00
|
|
|
n[0] = n[1] = n[2] = 0;
|
2012-03-25 12:41:58 +00:00
|
|
|
d = 0.0;
|
2012-01-20 02:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return d;
|
|
|
|
|
}
|
2020-08-28 10:56:44 -04:00
|
|
|
MINLINE double normalize_v3_db(double n[3])
|
2016-07-08 09:52:29 +10:00
|
|
|
{
|
2020-08-28 10:56:44 -04:00
|
|
|
return normalize_v3_length_db(n, 1.0);
|
2016-07-08 09:52:29 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE float normalize_v3_length(float n[3], const float unit_length)
|
|
|
|
|
{
|
|
|
|
|
return normalize_v3_v3_length(n, n, unit_length);
|
|
|
|
|
}
|
2012-01-20 02:24:01 +00:00
|
|
|
|
2010-01-12 19:47:54 +00:00
|
|
|
MINLINE float normalize_v3(float n[3])
|
|
|
|
|
{
|
|
|
|
|
return normalize_v3_v3(n, n);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-14 16:13:00 +02:00
|
|
|
MINLINE void normal_float_to_short_v2(short out[2], const float in[2])
|
|
|
|
|
{
|
|
|
|
|
out[0] = (short)(in[0] * 32767.0f);
|
|
|
|
|
out[1] = (short)(in[1] * 32767.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 04:57:57 +00:00
|
|
|
MINLINE void normal_short_to_float_v3(float out[3], const short in[3])
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
out[0] = in[0] * (1.0f / 32767.0f);
|
|
|
|
|
out[1] = in[1] * (1.0f / 32767.0f);
|
|
|
|
|
out[2] = in[2] * (1.0f / 32767.0f);
|
2009-11-28 13:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-27 04:57:57 +00:00
|
|
|
MINLINE void normal_float_to_short_v3(short out[3], const float in[3])
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
out[0] = (short)(in[0] * 32767.0f);
|
|
|
|
|
out[1] = (short)(in[1] * 32767.0f);
|
|
|
|
|
out[2] = (short)(in[2] * 32767.0f);
|
2009-11-28 13:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-17 14:45:59 +01:00
|
|
|
MINLINE void normal_float_to_short_v4(short out[4], const float in[4])
|
|
|
|
|
{
|
|
|
|
|
out[0] = (short)(in[0] * 32767.0f);
|
|
|
|
|
out[1] = (short)(in[1] * 32767.0f);
|
|
|
|
|
out[2] = (short)(in[2] * 32767.0f);
|
|
|
|
|
out[3] = (short)(in[3] * 32767.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-22 11:10:24 +00:00
|
|
|
/********************************* Comparison ********************************/
|
|
|
|
|
|
2013-08-20 09:34:52 +00:00
|
|
|
MINLINE bool is_zero_v2(const float v[2])
|
2012-03-14 06:14:15 +00:00
|
|
|
{
|
2014-07-30 11:00:59 +02:00
|
|
|
return (v[0] == 0.0f && v[1] == 0.0f);
|
2012-03-14 06:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-20 09:34:52 +00:00
|
|
|
MINLINE bool is_zero_v3(const float v[3])
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
2014-07-30 11:00:59 +02:00
|
|
|
return (v[0] == 0.0f && v[1] == 0.0f && v[2] == 0.0f);
|
2010-01-22 11:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-20 09:34:52 +00:00
|
|
|
MINLINE bool is_zero_v4(const float v[4])
|
2011-02-06 09:01:01 +00:00
|
|
|
{
|
2014-07-30 11:00:59 +02:00
|
|
|
return (v[0] == 0.0f && v[1] == 0.0f && v[2] == 0.0f && v[3] == 0.0f);
|
2011-02-06 09:01:01 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-20 09:34:52 +00:00
|
|
|
MINLINE bool is_one_v3(const float v[3])
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
2014-07-30 11:00:59 +02:00
|
|
|
return (v[0] == 1.0f && v[1] == 1.0f && v[2] == 1.0f);
|
2010-01-22 11:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-27 21:32:09 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
2014-07-14 11:33:19 +10:00
|
|
|
/** \name Vector Comparison
|
|
|
|
|
*
|
|
|
|
|
* \note use ``value <= limit``, so a limit of zero doesn't fail on an exact match.
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2013-08-20 09:34:52 +00:00
|
|
|
MINLINE bool equals_v2v2(const float v1[2], const float v2[2])
|
2010-12-11 21:27:39 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
|
2010-12-11 21:27:39 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-20 09:34:52 +00:00
|
|
|
MINLINE bool equals_v3v3(const float v1[3], const float v2[3])
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
|
2010-01-22 11:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-20 09:34:52 +00:00
|
|
|
MINLINE bool equals_v4v4(const float v1[4], const float v2[4])
|
2010-07-27 04:56:24 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]) && (v1[3] == v2[3]));
|
2010-07-27 04:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
MINLINE bool equals_v2v2_int(const int v1[2], const int v2[2])
|
|
|
|
|
{
|
|
|
|
|
return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 21:07:26 +02:00
|
|
|
MINLINE bool equals_v3v3_int(const int v1[3], const int v2[3])
|
|
|
|
|
{
|
|
|
|
|
return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-29 15:16:37 +02:00
|
|
|
MINLINE bool equals_v4v4_int(const int v1[4], const int v2[4])
|
|
|
|
|
{
|
|
|
|
|
return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]) && (v1[3] == v2[3]));
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-20 09:34:52 +00:00
|
|
|
MINLINE bool compare_v2v2(const float v1[2], const float v2[2], const float limit)
|
2012-09-19 04:48:34 +00:00
|
|
|
{
|
2015-07-10 14:32:35 +02:00
|
|
|
return (compare_ff(v1[0], v2[0], limit) && compare_ff(v1[1], v2[1], limit));
|
2012-09-19 04:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-20 09:34:52 +00:00
|
|
|
MINLINE bool compare_v3v3(const float v1[3], const float v2[3], const float limit)
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
2015-07-10 14:32:35 +02:00
|
|
|
return (compare_ff(v1[0], v2[0], limit) && compare_ff(v1[1], v2[1], limit) &&
|
|
|
|
|
compare_ff(v1[2], v2[2], limit));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE bool compare_v4v4(const float v1[4], const float v2[4], const float limit)
|
|
|
|
|
{
|
|
|
|
|
return (compare_ff(v1[0], v2[0], limit) && compare_ff(v1[1], v2[1], limit) &&
|
|
|
|
|
compare_ff(v1[2], v2[2], limit) && compare_ff(v1[3], v2[3], limit));
|
|
|
|
|
}
|
2010-01-22 11:10:24 +00:00
|
|
|
|
2015-07-10 14:32:35 +02:00
|
|
|
MINLINE bool compare_v2v2_relative(const float v1[2],
|
|
|
|
|
const float v2[2],
|
|
|
|
|
const float limit,
|
|
|
|
|
const int max_ulps)
|
|
|
|
|
{
|
|
|
|
|
return (compare_ff_relative(v1[0], v2[0], limit, max_ulps) &&
|
|
|
|
|
compare_ff_relative(v1[1], v2[1], limit, max_ulps));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE bool compare_v3v3_relative(const float v1[3],
|
|
|
|
|
const float v2[3],
|
|
|
|
|
const float limit,
|
|
|
|
|
const int max_ulps)
|
|
|
|
|
{
|
|
|
|
|
return (compare_ff_relative(v1[0], v2[0], limit, max_ulps) &&
|
|
|
|
|
compare_ff_relative(v1[1], v2[1], limit, max_ulps) &&
|
|
|
|
|
compare_ff_relative(v1[2], v2[2], limit, max_ulps));
|
2010-01-22 11:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-10 14:32:35 +02:00
|
|
|
MINLINE bool compare_v4v4_relative(const float v1[4],
|
|
|
|
|
const float v2[4],
|
|
|
|
|
const float limit,
|
|
|
|
|
const int max_ulps)
|
|
|
|
|
{
|
|
|
|
|
return (compare_ff_relative(v1[0], v2[0], limit, max_ulps) &&
|
|
|
|
|
compare_ff_relative(v1[1], v2[1], limit, max_ulps) &&
|
|
|
|
|
compare_ff_relative(v1[2], v2[2], limit, max_ulps) &&
|
|
|
|
|
compare_ff_relative(v1[3], v2[3], limit, max_ulps));
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-20 09:34:52 +00:00
|
|
|
MINLINE bool compare_len_v3v3(const float v1[3], const float v2[3], const float limit)
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
2018-11-01 12:06:04 +01:00
|
|
|
float d[3];
|
|
|
|
|
sub_v3_v3v3(d, v1, v2);
|
|
|
|
|
return (dot_v3v3(d, d) <= (limit * limit));
|
2010-01-22 11:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-02 14:14:47 +02:00
|
|
|
MINLINE bool compare_size_v3v3(const float v1[3], const float v2[3], const float limit)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
if (v2[i] == 0.0f) {
|
|
|
|
|
/* Catch division by zero. */
|
|
|
|
|
if (v1[i] != v2[i]) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (fabsf(v1[i] / v2[i] - 1.0f) > limit) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 21:32:09 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
2020-03-04 11:23:00 +11:00
|
|
|
/** \name Vector Clamping
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
MINLINE void clamp_v2(float vec[2], const float min, const float max)
|
|
|
|
|
{
|
|
|
|
|
CLAMP(vec[0], min, max);
|
|
|
|
|
CLAMP(vec[1], min, max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void clamp_v3(float vec[3], const float min, const float max)
|
|
|
|
|
{
|
|
|
|
|
CLAMP(vec[0], min, max);
|
|
|
|
|
CLAMP(vec[1], min, max);
|
|
|
|
|
CLAMP(vec[2], min, max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void clamp_v4(float vec[4], const float min, const float max)
|
|
|
|
|
{
|
|
|
|
|
CLAMP(vec[0], min, max);
|
|
|
|
|
CLAMP(vec[1], min, max);
|
|
|
|
|
CLAMP(vec[2], min, max);
|
|
|
|
|
CLAMP(vec[3], min, max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void clamp_v2_v2v2(float vec[2], const float min[2], const float max[2])
|
|
|
|
|
{
|
|
|
|
|
CLAMP(vec[0], min[0], max[0]);
|
|
|
|
|
CLAMP(vec[1], min[1], max[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void clamp_v3_v3v3(float vec[3], const float min[3], const float max[3])
|
|
|
|
|
{
|
|
|
|
|
CLAMP(vec[0], min[0], max[0]);
|
|
|
|
|
CLAMP(vec[1], min[1], max[1]);
|
|
|
|
|
CLAMP(vec[2], min[2], max[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MINLINE void clamp_v4_v4v4(float vec[4], const float min[4], const float max[4])
|
|
|
|
|
{
|
|
|
|
|
CLAMP(vec[0], min[0], max[0]);
|
|
|
|
|
CLAMP(vec[1], min[1], max[1]);
|
|
|
|
|
CLAMP(vec[2], min[2], max[2]);
|
|
|
|
|
CLAMP(vec[3], min[3], max[3]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
2014-09-28 14:39:38 +10:00
|
|
|
/**
|
|
|
|
|
* <pre>
|
|
|
|
|
* + l1
|
|
|
|
|
* |
|
|
|
|
|
* neg <- | -> pos
|
|
|
|
|
* |
|
|
|
|
|
* + l2
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* \return Positive value when 'pt' is left-of-line
|
|
|
|
|
* (looking from 'l1' -> 'l2').
|
|
|
|
|
*/
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2])
|
2010-10-15 05:18:45 +00:00
|
|
|
{
|
2012-03-25 12:41:58 +00:00
|
|
|
return (((l1[0] - pt[0]) * (l2[1] - pt[1])) - ((l2[0] - pt[0]) * (l1[1] - pt[1])));
|
2010-10-15 05:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-14 11:33:19 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
2012-02-25 09:02:05 +00:00
|
|
|
#endif /* __MATH_VECTOR_INLINE_C__ */
|