Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-01-30 05:31:39 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-01-30 05:31:39 +0300
commit4c1b7f311da58269654655359a8bddf439cc8ce9 (patch)
tree432bcc4ecb1932ee0a4e21a61b50fb0a922635f1
parent002b1835062b9ae213828b202c02059212bdef2e (diff)
parent7a27f64ecb5ac4c6cac3a27436d7b25037e62054 (diff)
Merge branch 'blender-v2.82-release'
-rw-r--r--source/blender/blenkernel/BKE_displist_tangent.h26
-rw-r--r--source/blender/blenkernel/CMakeLists.txt2
-rw-r--r--source/blender/blenkernel/intern/displist_tangent.c146
-rw-r--r--source/blender/draw/intern/draw_cache_impl_displist.c10
-rw-r--r--source/blender/makesrna/intern/rna_object.c35
5 files changed, 201 insertions, 18 deletions
diff --git a/source/blender/blenkernel/BKE_displist_tangent.h b/source/blender/blenkernel/BKE_displist_tangent.h
new file mode 100644
index 00000000000..3af7c513f67
--- /dev/null
+++ b/source/blender/blenkernel/BKE_displist_tangent.h
@@ -0,0 +1,26 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __BKE_DISPLIST_TANGENT_H__
+#define __BKE_DISPLIST_TANGENT_H__
+
+/** \file
+ * \ingroup bke
+ */
+
+void BKE_displist_tangent_calc(const DispList *dl, float (*fnormals)[3], float (**r_tangent)[4]);
+
+#endif /* __BKE_DISPLIST_TANGENT_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 61aeb51a197..0aa4f0fe677 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -105,6 +105,7 @@ set(SRC
intern/data_transfer.c
intern/deform.c
intern/displist.c
+ intern/displist_tangent.c
intern/dynamicpaint.c
intern/editlattice.c
intern/editmesh.c
@@ -271,6 +272,7 @@ set(SRC
BKE_data_transfer.h
BKE_deform.h
BKE_displist.h
+ BKE_displist_tangent.h
BKE_dynamicpaint.h
BKE_editlattice.h
BKE_editmesh.h
diff --git a/source/blender/blenkernel/intern/displist_tangent.c b/source/blender/blenkernel/intern/displist_tangent.c
new file mode 100644
index 00000000000..754aa78c0ac
--- /dev/null
+++ b/source/blender/blenkernel/intern/displist_tangent.c
@@ -0,0 +1,146 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup bke
+ */
+
+#include "BLI_math.h"
+#include "BLI_task.h"
+
+#include "BKE_displist.h"
+#include "BKE_displist_tangent.h"
+
+#include "MEM_guardedalloc.h"
+
+/* interface */
+#include "mikktspace.h"
+
+/** \name Tangent Space Calculation
+ * \{ */
+
+/* Necessary complexity to handle looptri's as quads for correct tangents */
+#define USE_LOOPTRI_DETECT_QUADS
+
+typedef struct {
+ const DispList *dl;
+ float (*tangent)[4]; /* destination */
+} SGLSLDisplistToTangent;
+
+static int dl3_ts_GetNumFaces(const SMikkTSpaceContext *pContext)
+{
+ SGLSLDisplistToTangent *dlt = pContext->m_pUserData;
+
+ return dlt->dl->parts;
+}
+
+static int dl3_ts_GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num)
+{
+ UNUSED_VARS(pContext, face_num);
+
+ return 3;
+}
+
+static void dl3_ts_GetPosition(const SMikkTSpaceContext *pContext,
+ float r_co[3],
+ const int face_num,
+ const int vert_index)
+{
+ SGLSLDisplistToTangent *dlt = pContext->m_pUserData;
+ const float(*verts)[3] = (float(*)[3])dlt->dl->verts;
+ const int(*idx)[3] = (int(*)[3])dlt->dl->index;
+
+ copy_v3_v3(r_co, verts[idx[face_num][vert_index]]);
+}
+
+static void dl3_ts_GetTextureCoordinate(const SMikkTSpaceContext *pContext,
+ float r_uv[2],
+ const int face_num,
+ const int vert_index)
+{
+ SGLSLDisplistToTangent *dlt = pContext->m_pUserData;
+ const int(*idx)[3] = (int(*)[3])dlt->dl->index;
+
+ r_uv[0] = idx[face_num][vert_index] / (float)(dlt->dl->nr - 1);
+ r_uv[1] = 0.0f;
+}
+
+static void dl3_ts_GetNormal(const SMikkTSpaceContext *pContext,
+ float r_no[3],
+ const int face_num,
+ const int vert_index)
+{
+ SGLSLDisplistToTangent *dlt = pContext->m_pUserData;
+ UNUSED_VARS(face_num, vert_index);
+
+ copy_v3_v3(r_no, dlt->dl->nors);
+}
+
+static void dl3_ts_SetTSpace(const SMikkTSpaceContext *pContext,
+ const float fvTangent[3],
+ const float fSign,
+ const int face_num,
+ const int vert_index)
+{
+ SGLSLDisplistToTangent *dlt = pContext->m_pUserData;
+ UNUSED_VARS(face_num, vert_index);
+
+ copy_v3_v3(dlt->tangent[0], fvTangent);
+ dlt->tangent[0][3] = fSign;
+}
+
+void BKE_displist_tangent_calc(const DispList *dl, float (*fnormals)[3], float (**r_tangent)[4])
+{
+ UNUSED_VARS(fnormals);
+
+ if (dl->type == DL_INDEX3) {
+ /* INDEX3 have only one tangent so we don't need actual allocation. */
+ BLI_assert(*r_tangent != NULL);
+
+ SGLSLDisplistToTangent mesh2tangent = {
+ .tangent = *r_tangent,
+ .dl = dl,
+ };
+ SMikkTSpaceContext sContext = {NULL};
+ SMikkTSpaceInterface sInterface = {NULL};
+ sContext.m_pUserData = &mesh2tangent;
+ sContext.m_pInterface = &sInterface;
+ sInterface.m_getNumFaces = dl3_ts_GetNumFaces;
+ sInterface.m_getNumVerticesOfFace = dl3_ts_GetNumVertsOfFace;
+ sInterface.m_getPosition = dl3_ts_GetPosition;
+ sInterface.m_getTexCoord = dl3_ts_GetTextureCoordinate;
+ sInterface.m_getNormal = dl3_ts_GetNormal;
+ sInterface.m_setTSpaceBasic = dl3_ts_SetTSpace;
+ /* 0 if failed */
+ genTangSpaceDefault(&sContext);
+ }
+ else if (dl->type == DL_SURF) {
+#if 0
+ int vert_len = dl->parts * dl->nr;
+ if (*r_tangent == NULL) {
+ *r_tangent = MEM_mallocN(sizeof(float[4]) * vert_len, "displist tangents");
+ }
+#endif
+ /* TODO */
+ BLI_assert(0);
+ }
+ else {
+ /* Unsupported. */
+ BLI_assert(0);
+ }
+}
+
+/** \} */
diff --git a/source/blender/draw/intern/draw_cache_impl_displist.c b/source/blender/draw/intern/draw_cache_impl_displist.c
index ad2495aa0d1..10f4b7ddbb6 100644
--- a/source/blender/draw/intern/draw_cache_impl_displist.c
+++ b/source/blender/draw/intern/draw_cache_impl_displist.c
@@ -33,6 +33,7 @@
#include "DNA_curve_types.h"
#include "BKE_displist.h"
+#include "BKE_displist_tangent.h"
#include "GPU_batch.h"
#include "GPU_extensions.h"
@@ -495,11 +496,12 @@ void DRW_displist_vertbuf_create_loop_pos_and_nor_and_uv_and_tan(ListBase *lb,
GPUPackedNormal ptan = {0, 0, 0, 1};
if (tan_step.size != 0) {
- float tan[3];
- /* We consider the surface flat so the vector is already ortogonal to the normal. */
- sub_v3_v3v3(tan, verts[idx[0]], verts[idx[2]]);
- normalize_v3(tan);
+ float tan[4];
+ float(*tan_ptr)[4] = &tan;
+ BKE_displist_tangent_calc(dl, NULL, &tan_ptr);
+
ptan = GPU_normal_convert_i10_v3(tan);
+ ptan.w = (tan[3] > 0.0) ? 1 : -2;
}
const float x_max = (float)(dl->nr - 1);
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 04d56921ca6..70192198e14 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -383,36 +383,44 @@ static void rna_Object_matrix_basis_set(PointerRNA *ptr, const float values[16])
BKE_object_apply_mat4(ob, (float(*)[4])values, false, false);
}
-void rna_Object_internal_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+void rna_Object_internal_update_data_impl(PointerRNA *ptr)
{
DEG_id_tag_update(ptr->owner_id, ID_RECALC_GEOMETRY);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, ptr->owner_id);
}
-void rna_Object_internal_update_data_dependency(Main *bmain, Scene *scene, PointerRNA *ptr)
+void rna_Object_internal_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+ rna_Object_internal_update_data_impl(ptr);
+}
+
+void rna_Object_internal_update_data_dependency(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
DEG_relations_tag_update(bmain);
- rna_Object_internal_update_data(bmain, scene, ptr);
+ rna_Object_internal_update_data_impl(ptr);
}
-static void rna_Object_active_shape_update(bContext *C, PointerRNA *ptr)
+static void rna_Object_active_shape_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
Object *ob = (Object *)ptr->owner_id;
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- if (CTX_data_edit_object(C) == ob) {
+ if (BKE_object_is_in_editmode(ob)) {
/* exit/enter editmode to get new shape */
switch (ob->type) {
- case OB_MESH:
+ case OB_MESH: {
+ Mesh *me = ob->data;
+ BMEditMesh *em = me->edit_mesh;
+ int select_mode = em->selectmode;
EDBM_mesh_load(bmain, ob);
- EDBM_mesh_make(ob, scene->toolsettings->selectmode, true);
+ EDBM_mesh_make(ob, select_mode, true);
+ em = me->edit_mesh;
- DEG_id_tag_update(ob->data, 0);
+ DEG_id_tag_update(&me->id, 0);
- EDBM_mesh_normals_update(((Mesh *)ob->data)->edit_mesh);
- BKE_editmesh_looptri_calc(((Mesh *)ob->data)->edit_mesh);
+ EDBM_mesh_normals_update(em);
+ BKE_editmesh_looptri_calc(em);
break;
+ }
case OB_CURVE:
case OB_SURF:
ED_curve_editnurb_load(bmain, ob);
@@ -425,7 +433,7 @@ static void rna_Object_active_shape_update(bContext *C, PointerRNA *ptr)
}
}
- rna_Object_internal_update_data(bmain, scene, ptr);
+ rna_Object_internal_update_data_impl(ptr);
}
static void rna_Object_dependency_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
@@ -3105,7 +3113,6 @@ static void rna_def_object(BlenderRNA *brna)
prop = RNA_def_property(srna, "active_shape_key_index", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "shapenr");
- RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); /* XXX this is really unpredictable... */
RNA_def_property_int_funcs(prop,
"rna_Object_active_shape_key_index_get",