2016-10-04 20:00:46 +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
|
2018-04-22 08:44:23 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2016-10-04 20:00:46 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spview3d
|
2016-10-04 20:00:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
#include "DNA_armature_types.h"
|
|
|
|
|
#include "DNA_camera_types.h"
|
2018-08-29 15:32:50 +02:00
|
|
|
#include "DNA_collection_types.h"
|
2016-10-04 20:00:46 +00:00
|
|
|
#include "DNA_customdata_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_key_types.h"
|
2019-02-27 12:34:56 +11:00
|
|
|
#include "DNA_light_types.h"
|
2016-10-04 20:00:46 +00:00
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_world_types.h"
|
|
|
|
|
#include "DNA_brush_types.h"
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
#include "BLI_endian_switch.h"
|
|
|
|
|
#include "BLI_threads.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_anim.h"
|
|
|
|
|
#include "BKE_camera.h"
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
|
#include "BKE_customdata.h"
|
|
|
|
|
#include "BKE_image.h"
|
|
|
|
|
#include "BKE_key.h"
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
#include "BKE_layer.h"
|
2016-10-04 20:00:46 +00:00
|
|
|
#include "BKE_object.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_paint.h"
|
|
|
|
|
#include "BKE_scene.h"
|
|
|
|
|
#include "BKE_unit.h"
|
|
|
|
|
#include "BKE_movieclip.h"
|
|
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-04-06 12:07:27 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2017-07-21 11:53:13 +02:00
|
|
|
|
2016-10-04 20:00:46 +00:00
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
#include "IMB_colormanagement.h"
|
|
|
|
|
|
|
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
2017-04-07 00:35:57 +10:00
|
|
|
#include "WM_types.h"
|
2016-10-04 20:00:46 +00:00
|
|
|
|
|
|
|
|
#include "BLF_api.h"
|
|
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
|
|
|
|
#include "ED_armature.h"
|
|
|
|
|
#include "ED_keyframing.h"
|
|
|
|
|
#include "ED_gpencil.h"
|
2019-05-16 09:26:33 +10:00
|
|
|
#include "ED_mesh.h"
|
2016-10-04 20:00:46 +00:00
|
|
|
#include "ED_screen.h"
|
|
|
|
|
#include "ED_space_api.h"
|
|
|
|
|
#include "ED_screen_types.h"
|
|
|
|
|
#include "ED_transform.h"
|
2019-04-11 18:28:20 +02:00
|
|
|
#include "ED_view3d.h"
|
2016-10-04 20:00:46 +00:00
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_interface_icons.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
|
|
#include "GPU_draw.h"
|
|
|
|
|
#include "GPU_framebuffer.h"
|
|
|
|
|
#include "GPU_material.h"
|
|
|
|
|
#include "GPU_extensions.h"
|
|
|
|
|
#include "GPU_immediate.h"
|
2017-04-05 18:30:14 +10:00
|
|
|
#include "GPU_immediate_util.h"
|
2017-03-10 06:16:15 +11:00
|
|
|
#include "GPU_select.h"
|
2017-03-21 02:51:02 -04:00
|
|
|
#include "GPU_matrix.h"
|
2018-06-27 19:07:23 -06:00
|
|
|
#include "GPU_state.h"
|
2019-03-27 10:52:13 -03:00
|
|
|
#include "GPU_viewport.h"
|
2016-10-04 20:00:46 +00:00
|
|
|
|
2017-05-03 02:50:29 +10:00
|
|
|
#include "RE_engine.h"
|
|
|
|
|
|
|
|
|
|
#include "DRW_engine.h"
|
2019-08-07 12:43:04 -03:00
|
|
|
#include "DRW_select_buffer.h"
|
2017-05-03 02:50:29 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
#include "view3d_intern.h" /* own include */
|
2016-10-04 20:00:46 +00:00
|
|
|
|
|
|
|
|
/* ********* custom clipping *********** */
|
|
|
|
|
|
2019-02-06 10:33:14 +11:00
|
|
|
/* Legacy 2.7x, now use shaders that use clip distance instead.
|
|
|
|
|
* Remove once clipping is working properly. */
|
|
|
|
|
#define USE_CLIP_PLANES
|
|
|
|
|
|
2016-10-04 20:00:46 +00:00
|
|
|
void ED_view3d_clipping_set(RegionView3D *rv3d)
|
|
|
|
|
{
|
2019-02-06 10:33:14 +11:00
|
|
|
#ifdef USE_CLIP_PLANES
|
2019-04-17 06:17:24 +02:00
|
|
|
double plane[4];
|
|
|
|
|
const uint tot = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6;
|
|
|
|
|
|
|
|
|
|
for (unsigned a = 0; a < tot; a++) {
|
|
|
|
|
copy_v4db_v4fl(plane, rv3d->clip[a]);
|
|
|
|
|
glClipPlane(GL_CLIP_PLANE0 + a, plane);
|
|
|
|
|
glEnable(GL_CLIP_PLANE0 + a);
|
|
|
|
|
glEnable(GL_CLIP_DISTANCE0 + a);
|
|
|
|
|
}
|
2019-02-06 10:33:14 +11:00
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
for (unsigned a = 0; a < 6; a++) {
|
|
|
|
|
glEnable(GL_CLIP_DISTANCE0 + a);
|
|
|
|
|
}
|
2019-02-06 10:33:14 +11:00
|
|
|
#endif
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* use these to temp disable/enable clipping when 'rv3d->rflag & RV3D_CLIPPING' is set */
|
|
|
|
|
void ED_view3d_clipping_disable(void)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
for (unsigned a = 0; a < 6; a++) {
|
2019-02-06 10:33:14 +11:00
|
|
|
#ifdef USE_CLIP_PLANES
|
2019-04-17 06:17:24 +02:00
|
|
|
glDisable(GL_CLIP_PLANE0 + a);
|
2019-02-06 10:33:14 +11:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
glDisable(GL_CLIP_DISTANCE0 + a);
|
|
|
|
|
}
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
void ED_view3d_clipping_enable(void)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
for (unsigned a = 0; a < 6; a++) {
|
2019-02-06 10:33:14 +11:00
|
|
|
#ifdef USE_CLIP_PLANES
|
2019-04-17 06:17:24 +02:00
|
|
|
glEnable(GL_CLIP_PLANE0 + a);
|
2019-02-06 10:33:14 +11:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
glEnable(GL_CLIP_DISTANCE0 + a);
|
|
|
|
|
}
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* *********************** backdraw for selection *************** */
|
|
|
|
|
|
2019-05-20 12:39:01 +10:00
|
|
|
/**
|
|
|
|
|
* \note Only use in object mode.
|
|
|
|
|
*/
|
2019-08-02 12:04:59 +10:00
|
|
|
static void validate_object_select_id(
|
|
|
|
|
struct Depsgraph *depsgraph, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Object *obact)
|
2016-10-04 20:00:46 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact);
|
|
|
|
|
|
|
|
|
|
BLI_assert(ar->regiontype == RGN_TYPE_WINDOW);
|
2019-08-16 12:44:06 +02:00
|
|
|
UNUSED_VARS_NDEBUG(ar);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
if (obact_eval && (obact_eval->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT) ||
|
|
|
|
|
BKE_paint_select_face_test(obact_eval))) {
|
|
|
|
|
/* do nothing */
|
|
|
|
|
}
|
|
|
|
|
/* texture paint mode sampling */
|
|
|
|
|
else if (obact_eval && (obact_eval->mode & OB_MODE_TEXTURE_PAINT) &&
|
|
|
|
|
(v3d->shading.type > OB_WIRE)) {
|
|
|
|
|
/* do nothing */
|
|
|
|
|
}
|
|
|
|
|
else if ((obact_eval && (obact_eval->mode & OB_MODE_PARTICLE_EDIT)) && !XRAY_ENABLED(v3d)) {
|
|
|
|
|
/* do nothing */
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
v3d->flag &= ~V3D_INVALID_BACKBUF;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(v3d->flag & V3D_INVALID_BACKBUF)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-04 20:00:46 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLE) != 0)) {
|
2019-08-15 10:31:54 -03:00
|
|
|
Base *base = BKE_view_layer_base_find(view_layer, obact);
|
|
|
|
|
DRW_select_buffer_context_create(&base, 1, -1);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-03-08 17:42:06 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO: Create a flag in `DRW_manager` because the drawing is no longer
|
|
|
|
|
* made on the backbuffer in this case. */
|
|
|
|
|
v3d->flag &= ~V3D_INVALID_BACKBUF;
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-27 10:52:13 -03:00
|
|
|
/* TODO: Creating, attaching texture, and destroying a framebuffer is quite slow.
|
|
|
|
|
* Calling this function should be avoided during interactive drawing. */
|
|
|
|
|
static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data)
|
2019-03-26 15:06:29 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
DefaultTextureList *dtxl = (DefaultTextureList *)GPU_viewport_texture_list_get(viewport);
|
2019-03-27 10:52:13 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPUFrameBuffer *tmp_fb = GPU_framebuffer_create();
|
|
|
|
|
GPU_framebuffer_texture_attach(tmp_fb, dtxl->depth, 0, 0);
|
|
|
|
|
GPU_framebuffer_bind(tmp_fb);
|
2019-03-27 10:52:13 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
glReadPixels(rect->xmin,
|
|
|
|
|
rect->ymin,
|
|
|
|
|
BLI_rcti_size_x(rect),
|
|
|
|
|
BLI_rcti_size_y(rect),
|
|
|
|
|
GL_DEPTH_COMPONENT,
|
|
|
|
|
GL_FLOAT,
|
|
|
|
|
data);
|
2019-03-27 10:52:13 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_framebuffer_restore();
|
|
|
|
|
GPU_framebuffer_free(tmp_fb);
|
2019-03-26 15:06:29 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 12:39:01 +10:00
|
|
|
void ED_view3d_select_id_validate(ViewContext *vc)
|
2019-03-15 16:02:55 -03:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO: Create a flag in `DRW_manager` because the drawing is no longer
|
|
|
|
|
* made on the backbuffer in this case. */
|
|
|
|
|
if (vc->v3d->flag & V3D_INVALID_BACKBUF) {
|
2019-08-02 12:04:59 +10:00
|
|
|
validate_object_select_id(vc->depsgraph, vc->view_layer, vc->ar, vc->v3d, vc->obact);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-15 16:02:55 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ED_view3d_backbuf_depth_validate(ViewContext *vc)
|
2016-10-04 20:00:46 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (vc->v3d->flag & V3D_INVALID_BACKBUF) {
|
|
|
|
|
ARegion *ar = vc->ar;
|
|
|
|
|
Object *obact_eval = DEG_get_evaluated_object(vc->depsgraph, vc->obact);
|
2019-03-15 16:02:55 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLE) != 0)) {
|
2019-04-19 11:49:17 -03:00
|
|
|
GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0);
|
2019-04-20 09:15:06 +02:00
|
|
|
DRW_draw_depth_object(vc->ar, viewport, obact_eval);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-15 16:02:55 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
vc->v3d->flag &= ~V3D_INVALID_BACKBUF;
|
|
|
|
|
}
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* allow for small values [0.5 - 2.5],
|
|
|
|
|
* and large values, FLT_MAX by clamping by the area size
|
|
|
|
|
*/
|
|
|
|
|
int ED_view3d_backbuf_sample_size_clamp(ARegion *ar, const float dist)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (int)min_ff(ceilf(dist), (float)max_ii(ar->winx, ar->winx));
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* *********************** */
|
|
|
|
|
|
|
|
|
|
void view3d_update_depths_rect(ARegion *ar, ViewDepths *d, rcti *rect)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* clamp rect by region */
|
|
|
|
|
rcti r = {
|
|
|
|
|
.xmin = 0,
|
|
|
|
|
.xmax = ar->winx - 1,
|
|
|
|
|
.ymin = 0,
|
|
|
|
|
.ymax = ar->winy - 1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Constrain rect to depth bounds */
|
|
|
|
|
BLI_rcti_isect(&r, rect, rect);
|
|
|
|
|
|
|
|
|
|
/* assign values to compare with the ViewDepths */
|
|
|
|
|
int x = rect->xmin;
|
|
|
|
|
int y = rect->ymin;
|
|
|
|
|
|
|
|
|
|
int w = BLI_rcti_size_x(rect);
|
|
|
|
|
int h = BLI_rcti_size_y(rect);
|
|
|
|
|
|
|
|
|
|
if (w <= 0 || h <= 0) {
|
|
|
|
|
if (d->depths) {
|
|
|
|
|
MEM_freeN(d->depths);
|
|
|
|
|
}
|
|
|
|
|
d->depths = NULL;
|
|
|
|
|
|
|
|
|
|
d->damaged = false;
|
|
|
|
|
}
|
|
|
|
|
else if (d->w != w || d->h != h || d->x != x || d->y != y || d->depths == NULL) {
|
|
|
|
|
d->x = x;
|
|
|
|
|
d->y = y;
|
|
|
|
|
d->w = w;
|
|
|
|
|
d->h = h;
|
|
|
|
|
|
|
|
|
|
if (d->depths) {
|
|
|
|
|
MEM_freeN(d->depths);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths Subset");
|
|
|
|
|
|
|
|
|
|
d->damaged = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d->damaged) {
|
|
|
|
|
GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0);
|
|
|
|
|
view3d_opengl_read_Z_pixels(viewport, rect, d->depths);
|
|
|
|
|
glGetDoublev(GL_DEPTH_RANGE, d->depth_range);
|
|
|
|
|
d->damaged = false;
|
|
|
|
|
}
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-26 15:06:29 +01:00
|
|
|
/* note, with nouveau drivers the glReadPixels() is very slow. [#24339] */
|
2016-10-04 20:00:46 +00:00
|
|
|
void ED_view3d_depth_update(ARegion *ar)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
|
|
|
|
|
|
|
|
|
/* Create storage for, and, if necessary, copy depth buffer */
|
|
|
|
|
if (!rv3d->depths) {
|
|
|
|
|
rv3d->depths = MEM_callocN(sizeof(ViewDepths), "ViewDepths");
|
|
|
|
|
}
|
|
|
|
|
if (rv3d->depths) {
|
|
|
|
|
ViewDepths *d = rv3d->depths;
|
|
|
|
|
if (d->w != ar->winx || d->h != ar->winy || !d->depths) {
|
|
|
|
|
d->w = ar->winx;
|
|
|
|
|
d->h = ar->winy;
|
|
|
|
|
if (d->depths) {
|
|
|
|
|
MEM_freeN(d->depths);
|
|
|
|
|
}
|
|
|
|
|
d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths");
|
|
|
|
|
d->damaged = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d->damaged) {
|
2019-04-19 11:49:17 -03:00
|
|
|
GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0);
|
|
|
|
|
rcti r = {
|
|
|
|
|
.xmin = 0,
|
|
|
|
|
.xmax = d->w,
|
|
|
|
|
.ymin = 0,
|
|
|
|
|
.ymax = d->h,
|
|
|
|
|
};
|
|
|
|
|
view3d_opengl_read_Z_pixels(viewport, &r, d->depths);
|
2019-04-17 06:17:24 +02:00
|
|
|
glGetDoublev(GL_DEPTH_RANGE, d->depth_range);
|
|
|
|
|
d->damaged = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* utility function to find the closest Z value, use for autodepth */
|
|
|
|
|
float view3d_depth_near(ViewDepths *d)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* convert to float for comparisons */
|
|
|
|
|
const float near = (float)d->depth_range[0];
|
|
|
|
|
const float far_real = (float)d->depth_range[1];
|
|
|
|
|
float far = far_real;
|
|
|
|
|
|
|
|
|
|
const float *depths = d->depths;
|
|
|
|
|
float depth = FLT_MAX;
|
|
|
|
|
int i = (int)d->w * (int)d->h; /* cast to avoid short overflow */
|
|
|
|
|
|
|
|
|
|
/* far is both the starting 'far' value
|
|
|
|
|
* and the closest value found. */
|
|
|
|
|
while (i--) {
|
|
|
|
|
depth = *depths++;
|
|
|
|
|
if ((depth < far) && (depth > near)) {
|
|
|
|
|
far = depth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return far == far_real ? FLT_MAX : far;
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void ED_view3d_draw_depth_gpencil(Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d)
|
2016-10-04 20:00:46 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Setup view matrix. */
|
|
|
|
|
ED_view3d_draw_setup_view(NULL, depsgraph, scene, ar, v3d, NULL, NULL, NULL);
|
2016-10-04 20:00:46 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_clear(GPU_DEPTH_BIT);
|
2016-10-04 20:00:46 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_depth_test(true);
|
2016-10-04 20:00:46 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0);
|
|
|
|
|
DRW_draw_depth_loop_gpencil(depsgraph, ar, v3d, viewport);
|
2017-03-23 16:27:57 -04:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_depth_test(false);
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* *********************** customdata **************** */
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void ED_view3d_datamask(const bContext *C,
|
|
|
|
|
const Scene *UNUSED(scene),
|
|
|
|
|
const View3D *v3d,
|
|
|
|
|
CustomData_MeshMasks *r_cddata_masks)
|
2016-10-04 20:00:46 +00:00
|
|
|
{
|
2019-06-13 19:56:25 +02:00
|
|
|
if (ELEM(v3d->shading.type, OB_TEXTURE, OB_MATERIAL, OB_RENDER)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_cddata_masks->lmask |= CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL;
|
2019-06-13 19:56:25 +02:00
|
|
|
r_cddata_masks->vmask |= CD_MASK_ORCO;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-10-04 20:00:46 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((CTX_data_mode_enum(C) == CTX_MODE_EDIT_MESH) &&
|
|
|
|
|
(v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_WEIGHT)) {
|
|
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
|
|
|
|
}
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* goes over all modes and view3d settings */
|
2019-04-17 06:17:24 +02:00
|
|
|
void ED_view3d_screen_datamask(const bContext *C,
|
|
|
|
|
const Scene *scene,
|
|
|
|
|
const bScreen *screen,
|
|
|
|
|
CustomData_MeshMasks *r_cddata_masks)
|
2016-10-04 20:00:46 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
CustomData_MeshMasks_update(r_cddata_masks, &CD_MASK_BAREMESH);
|
|
|
|
|
|
|
|
|
|
/* check if we need tfaces & mcols due to view mode */
|
|
|
|
|
for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
|
|
|
|
|
if (sa->spacetype == SPACE_VIEW3D) {
|
|
|
|
|
ED_view3d_datamask(C, scene, sa->spacedata.first, r_cddata_masks);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store values from #RegionView3D, set when drawing.
|
2019-04-22 00:18:34 +10:00
|
|
|
* This is needed when we draw with to a viewport using a different matrix
|
|
|
|
|
* (offscreen drawing for example).
|
2016-10-04 20:00:46 +00:00
|
|
|
*
|
|
|
|
|
* Values set by #ED_view3d_update_viewmat should be handled here.
|
|
|
|
|
*/
|
|
|
|
|
struct RV3DMatrixStore {
|
2019-04-17 06:17:24 +02:00
|
|
|
float winmat[4][4];
|
|
|
|
|
float viewmat[4][4];
|
|
|
|
|
float viewinv[4][4];
|
|
|
|
|
float persmat[4][4];
|
|
|
|
|
float persinv[4][4];
|
|
|
|
|
float viewcamtexcofac[4];
|
|
|
|
|
float pixsize;
|
2016-10-04 20:00:46 +00:00
|
|
|
};
|
|
|
|
|
|
2017-03-06 13:00:46 +01:00
|
|
|
struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d)
|
2016-10-04 20:00:46 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
struct RV3DMatrixStore *rv3dmat = MEM_mallocN(sizeof(*rv3dmat), __func__);
|
|
|
|
|
copy_m4_m4(rv3dmat->winmat, rv3d->winmat);
|
|
|
|
|
copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat);
|
|
|
|
|
copy_m4_m4(rv3dmat->persmat, rv3d->persmat);
|
|
|
|
|
copy_m4_m4(rv3dmat->persinv, rv3d->persinv);
|
|
|
|
|
copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv);
|
|
|
|
|
copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac);
|
|
|
|
|
rv3dmat->pixsize = rv3d->pixsize;
|
|
|
|
|
return (void *)rv3dmat;
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-06 13:00:46 +01:00
|
|
|
void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat_pt)
|
2016-10-04 20:00:46 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
struct RV3DMatrixStore *rv3dmat = rv3dmat_pt;
|
|
|
|
|
copy_m4_m4(rv3d->winmat, rv3dmat->winmat);
|
|
|
|
|
copy_m4_m4(rv3d->viewmat, rv3dmat->viewmat);
|
|
|
|
|
copy_m4_m4(rv3d->persmat, rv3dmat->persmat);
|
|
|
|
|
copy_m4_m4(rv3d->persinv, rv3dmat->persinv);
|
|
|
|
|
copy_m4_m4(rv3d->viewinv, rv3dmat->viewinv);
|
|
|
|
|
copy_v4_v4(rv3d->viewcamtexcofac, rv3dmat->viewcamtexcofac);
|
|
|
|
|
rv3d->pixsize = rv3dmat->pixsize;
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \note The info that this uses is updated in #ED_refresh_viewport_fps,
|
|
|
|
|
* which currently gets called during #SCREEN_OT_animation_step.
|
|
|
|
|
*/
|
2018-10-25 11:47:37 +02:00
|
|
|
void ED_scene_draw_fps(Scene *scene, int xoffset, int *yoffset)
|
2016-10-04 20:00:46 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ScreenFrameRateInfo *fpsi = scene->fps_info;
|
|
|
|
|
char printable[16];
|
2018-04-22 08:44:23 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!fpsi || !fpsi->lredrawtime || !fpsi->redrawtime) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-22 08:44:23 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
printable[0] = '\0';
|
2018-04-22 08:44:23 +02:00
|
|
|
|
2016-10-04 20:00:46 +00:00
|
|
|
#if 0
|
2019-04-17 06:17:24 +02:00
|
|
|
/* this is too simple, better do an average */
|
|
|
|
|
fps = (float)(1.0 / (fpsi->lredrawtime - fpsi->redrawtime))
|
2016-10-04 20:00:46 +00:00
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
fpsi->redrawtimes_fps[fpsi->redrawtime_index] = (float)(1.0 /
|
|
|
|
|
(fpsi->lredrawtime - fpsi->redrawtime));
|
|
|
|
|
|
|
|
|
|
float fps = 0.0f;
|
|
|
|
|
int tot = 0;
|
|
|
|
|
for (int i = 0; i < REDRAW_FRAME_AVERAGE; i++) {
|
|
|
|
|
if (fpsi->redrawtimes_fps[i]) {
|
|
|
|
|
fps += fpsi->redrawtimes_fps[i];
|
|
|
|
|
tot++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (tot) {
|
|
|
|
|
fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_FRAME_AVERAGE;
|
|
|
|
|
|
2019-05-01 11:09:22 +10:00
|
|
|
// fpsi->redrawtime_index++;
|
|
|
|
|
// if (fpsi->redrawtime >= REDRAW_FRAME_AVERAGE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
// fpsi->redrawtime = 0;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
fps = fps / tot;
|
|
|
|
|
}
|
2016-10-04 20:00:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
const int font_id = BLF_default();
|
2017-02-05 00:54:21 -05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* is this more than half a frame behind? */
|
|
|
|
|
if (fps + 0.5f < (float)(FPS)) {
|
|
|
|
|
UI_FontThemeColor(font_id, TH_REDALERT);
|
|
|
|
|
BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %.2f"), fps);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
UI_FontThemeColor(font_id, TH_TEXT_HI);
|
|
|
|
|
BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %i"), (int)(fps + 0.5f));
|
|
|
|
|
}
|
2016-10-04 20:00:46 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLF_enable(font_id, BLF_SHADOW);
|
|
|
|
|
BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f});
|
|
|
|
|
BLF_shadow_offset(font_id, 1, -1);
|
2018-10-25 11:47:37 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
*yoffset -= U.widget_unit;
|
2018-10-25 11:47:37 +02:00
|
|
|
|
2016-10-04 20:00:46 +00:00
|
|
|
#ifdef WITH_INTERNATIONAL
|
2019-04-17 06:17:24 +02:00
|
|
|
BLF_draw_default(xoffset, *yoffset, 0.0f, printable, sizeof(printable));
|
2016-10-04 20:00:46 +00:00
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
BLF_draw_default_ascii(xoffset, *yoffset, 0.0f, printable, sizeof(printable));
|
2016-10-04 20:00:46 +00:00
|
|
|
#endif
|
2018-10-25 11:47:37 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLF_disable(font_id, BLF_SHADOW);
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
static bool view3d_main_region_do_render_draw(const Scene *scene)
|
2016-10-04 20:00:46 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RenderEngineType *type = RE_engines_find(scene->r.engine);
|
|
|
|
|
return (type && type->view_update && type->view_draw);
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool ED_view3d_calc_render_border(
|
|
|
|
|
const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *ar, rcti *rect)
|
2016-10-04 20:00:46 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
|
|
|
|
bool use_border;
|
|
|
|
|
|
|
|
|
|
/* test if there is a 3d view rendering */
|
|
|
|
|
if (v3d->shading.type != OB_RENDER || !view3d_main_region_do_render_draw(scene)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* test if there is a border render */
|
|
|
|
|
if (rv3d->persp == RV3D_CAMOB) {
|
|
|
|
|
use_border = (scene->r.mode & R_BORDER) != 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
use_border = (v3d->flag2 & V3D_RENDER_BORDER) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!use_border) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* compute border */
|
|
|
|
|
if (rv3d->persp == RV3D_CAMOB) {
|
|
|
|
|
rctf viewborder;
|
|
|
|
|
ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &viewborder, false);
|
|
|
|
|
|
|
|
|
|
rect->xmin = viewborder.xmin + scene->r.border.xmin * BLI_rctf_size_x(&viewborder);
|
|
|
|
|
rect->ymin = viewborder.ymin + scene->r.border.ymin * BLI_rctf_size_y(&viewborder);
|
|
|
|
|
rect->xmax = viewborder.xmin + scene->r.border.xmax * BLI_rctf_size_x(&viewborder);
|
|
|
|
|
rect->ymax = viewborder.ymin + scene->r.border.ymax * BLI_rctf_size_y(&viewborder);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
rect->xmin = v3d->render_border.xmin * ar->winx;
|
|
|
|
|
rect->xmax = v3d->render_border.xmax * ar->winx;
|
|
|
|
|
rect->ymin = v3d->render_border.ymin * ar->winy;
|
|
|
|
|
rect->ymax = v3d->render_border.ymax * ar->winy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_rcti_translate(rect, ar->winrct.xmin, ar->winrct.ymin);
|
|
|
|
|
BLI_rcti_isect(&ar->winrct, rect, rect);
|
|
|
|
|
|
|
|
|
|
return true;
|
2016-10-04 20:00:46 +00:00
|
|
|
}
|