2023-08-16 00:20:26 +10:00
|
|
|
# SPDX-FileCopyrightText: 2010-2023 Blender Authors
|
2023-06-15 13:09:04 +10:00
|
|
|
#
|
2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2023-06-15 13:09:04 +10:00
|
|
|
|
2021-02-21 21:21:18 +11:00
|
|
|
from __future__ import annotations
|
2010-05-23 12:14:07 +00:00
|
|
|
|
2011-05-28 07:47:58 +00:00
|
|
|
__all__ = (
|
|
|
|
"add_object_align_init",
|
|
|
|
"object_data_add",
|
2012-03-15 03:50:52 +00:00
|
|
|
"AddObjectHelper",
|
2013-05-28 23:07:16 +00:00
|
|
|
"object_add_grid_scale",
|
|
|
|
"object_add_grid_scale_apply_operator",
|
2013-06-16 14:35:15 +00:00
|
|
|
"world_to_camera_view",
|
2024-01-19 19:01:25 +01:00
|
|
|
"object_report_if_active_shape_key_is_locked",
|
2018-07-03 06:27:53 +02:00
|
|
|
)
|
2011-05-28 07:47:58 +00:00
|
|
|
|
|
|
|
|
2010-05-23 12:14:07 +00:00
|
|
|
import bpy
|
2010-05-23 12:38:49 +00:00
|
|
|
|
2015-05-17 17:17:31 +10:00
|
|
|
from bpy.props import (
|
2017-11-29 18:00:41 +11:00
|
|
|
FloatVectorProperty,
|
2019-05-15 16:56:22 +02:00
|
|
|
EnumProperty,
|
2017-11-29 18:00:41 +11:00
|
|
|
)
|
2012-03-14 08:55:57 +00:00
|
|
|
|
2010-06-09 19:12:03 +00:00
|
|
|
|
2010-05-30 17:18:16 +00:00
|
|
|
def add_object_align_init(context, operator):
|
2011-05-28 09:34:45 +00:00
|
|
|
"""
|
|
|
|
Return a matrix using the operator settings and view context.
|
|
|
|
|
|
|
|
:arg context: The context to use.
|
2011-08-26 18:48:48 +00:00
|
|
|
:type context: :class:`bpy.types.Context`
|
2011-05-28 09:34:45 +00:00
|
|
|
:arg operator: The operator, checked for location and rotation properties.
|
2011-08-26 18:48:48 +00:00
|
|
|
:type operator: :class:`bpy.types.Operator`
|
2011-05-28 09:34:45 +00:00
|
|
|
:return: the matrix from the context and settings.
|
2011-08-26 18:48:48 +00:00
|
|
|
:rtype: :class:`mathutils.Matrix`
|
2011-05-28 09:34:45 +00:00
|
|
|
"""
|
2011-07-31 03:15:37 +00:00
|
|
|
|
2021-03-06 19:24:07 +11:00
|
|
|
from mathutils import Matrix, Vector
|
2011-07-31 12:46:34 +00:00
|
|
|
properties = operator.properties if operator is not None else None
|
2011-07-31 03:15:37 +00:00
|
|
|
|
2011-01-12 15:45:00 +00:00
|
|
|
space_data = context.space_data
|
2012-02-02 05:11:42 +00:00
|
|
|
if space_data and space_data.type != 'VIEW_3D':
|
2011-01-12 15:45:00 +00:00
|
|
|
space_data = None
|
2010-05-23 12:38:49 +00:00
|
|
|
|
2011-01-12 15:45:00 +00:00
|
|
|
# location
|
2011-07-31 03:15:37 +00:00
|
|
|
if operator and properties.is_property_set("location"):
|
|
|
|
location = Matrix.Translation(Vector(properties.location))
|
2010-05-23 12:38:49 +00:00
|
|
|
else:
|
2019-03-01 12:35:48 +11:00
|
|
|
location = Matrix.Translation(context.scene.cursor.location)
|
2011-01-12 15:45:00 +00:00
|
|
|
|
|
|
|
if operator:
|
2011-07-31 03:15:37 +00:00
|
|
|
properties.location = location.to_translation()
|
2010-05-23 12:38:49 +00:00
|
|
|
|
2011-01-12 15:45:00 +00:00
|
|
|
# rotation
|
2019-05-15 16:56:22 +02:00
|
|
|
add_align_preference = context.preferences.edit.object_align
|
2011-01-12 15:45:00 +00:00
|
|
|
if operator:
|
2019-05-15 16:56:22 +02:00
|
|
|
if not properties.is_property_set("rotation"):
|
|
|
|
# So one of "align" and "rotation" will be set
|
|
|
|
properties.align = add_align_preference
|
|
|
|
|
|
|
|
if properties.align == 'WORLD':
|
|
|
|
rotation = properties.rotation.to_matrix().to_4x4()
|
|
|
|
elif properties.align == 'VIEW':
|
|
|
|
rotation = space_data.region_3d.view_matrix.to_3x3().inverted()
|
|
|
|
rotation.resize_4x4()
|
|
|
|
properties.rotation = rotation.to_euler()
|
|
|
|
elif properties.align == 'CURSOR':
|
2019-05-16 13:48:23 +10:00
|
|
|
rotation = context.scene.cursor.matrix
|
|
|
|
rotation.col[3][0:3] = 0.0, 0.0, 0.0
|
2019-05-15 16:56:22 +02:00
|
|
|
properties.rotation = rotation.to_euler()
|
2011-01-12 15:45:00 +00:00
|
|
|
else:
|
2019-05-15 16:56:22 +02:00
|
|
|
rotation = properties.rotation.to_matrix().to_4x4()
|
2011-01-12 15:45:00 +00:00
|
|
|
else:
|
2019-05-15 16:56:22 +02:00
|
|
|
if (add_align_preference == 'VIEW') and space_data:
|
2011-07-31 03:15:37 +00:00
|
|
|
rotation = space_data.region_3d.view_matrix.to_3x3().inverted()
|
|
|
|
rotation.resize_4x4()
|
2019-05-15 16:56:22 +02:00
|
|
|
elif add_align_preference == 'CURSOR':
|
|
|
|
rotation = context.scene.cursor.rotation_euler.to_matrix().to_4x4()
|
2010-05-30 17:18:16 +00:00
|
|
|
else:
|
2013-01-02 16:15:45 +00:00
|
|
|
rotation = Matrix()
|
2010-05-23 12:38:49 +00:00
|
|
|
|
2018-08-12 15:01:26 +10:00
|
|
|
return location @ rotation
|
2010-05-23 12:14:07 +00:00
|
|
|
|
2010-05-30 17:18:16 +00:00
|
|
|
|
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
|
|
|
def object_data_add(context, obdata, operator=None, name=None):
|
2011-05-28 09:34:45 +00:00
|
|
|
"""
|
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
|
|
|
Add an object using the view context and preference to initialize the
|
2011-05-28 09:34:45 +00:00
|
|
|
location, rotation and layer.
|
|
|
|
|
|
|
|
:arg context: The context to use.
|
2011-08-26 18:48:48 +00:00
|
|
|
:type context: :class:`bpy.types.Context`
|
2024-11-03 15:42:19 +11:00
|
|
|
:arg obdata: Valid object data to used for the new object or None.
|
|
|
|
:type obdata: :class:`bpy.types.ID` | None
|
2011-05-28 09:34:45 +00:00
|
|
|
:arg operator: The operator, checked for location and rotation properties.
|
2011-08-26 18:48:48 +00:00
|
|
|
:type operator: :class:`bpy.types.Operator`
|
2014-12-10 17:22:26 +01:00
|
|
|
:arg name: Optional name
|
2024-11-03 15:42:19 +11:00
|
|
|
:type name: str
|
2011-05-28 09:34:45 +00:00
|
|
|
:return: the newly created object in the scene.
|
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
|
|
|
:rtype: :class:`bpy.types.Object`
|
2011-05-28 09:34:45 +00:00
|
|
|
"""
|
2017-11-22 10:52:39 -02:00
|
|
|
layer = context.view_layer
|
2018-11-06 17:20:49 +01:00
|
|
|
layer_collection = context.layer_collection or layer.active_layer_collection
|
|
|
|
scene_collection = layer_collection.collection
|
2017-02-23 12:35:14 +01:00
|
|
|
|
2017-05-19 15:33:50 +02:00
|
|
|
for ob in layer.objects:
|
2018-11-11 11:22:38 +01:00
|
|
|
ob.select_set(False)
|
2017-05-19 15:33:50 +02:00
|
|
|
|
2014-12-10 17:22:26 +01:00
|
|
|
if name is None:
|
|
|
|
name = "Object" if obdata is None else obdata.name
|
|
|
|
|
2017-05-19 15:33:50 +02:00
|
|
|
obj_act = layer.objects.active
|
2014-12-10 17:22:26 +01:00
|
|
|
obj_new = bpy.data.objects.new(name, obdata)
|
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
|
|
|
scene_collection.objects.link(obj_new)
|
2018-11-11 11:22:38 +01:00
|
|
|
obj_new.select_set(True)
|
2010-07-03 17:39:29 +00:00
|
|
|
obj_new.matrix_world = add_object_align_init(context, operator)
|
2010-05-23 12:14:07 +00:00
|
|
|
|
2019-03-13 10:41:12 +11:00
|
|
|
space_data = context.space_data
|
2019-12-11 16:13:44 +11:00
|
|
|
if space_data and space_data.type != 'VIEW_3D':
|
|
|
|
space_data = None
|
|
|
|
|
|
|
|
if space_data:
|
2019-03-13 10:41:12 +11:00
|
|
|
if space_data.local_view:
|
|
|
|
obj_new.local_view_set(space_data, True)
|
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
if obj_act and obj_act.mode == 'EDIT' and obj_act.type == obj_new.type:
|
2011-01-12 15:45:00 +00:00
|
|
|
bpy.ops.mesh.select_all(action='DESELECT')
|
2018-11-11 11:22:38 +01:00
|
|
|
obj_act.select_set(True)
|
2010-05-23 12:14:07 +00:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
|
|
|
|
2018-11-11 11:22:38 +01:00
|
|
|
obj_act.select_set(True)
|
2019-05-17 11:51:38 +02:00
|
|
|
layer.update() # apply location
|
2018-07-24 11:18:45 +02:00
|
|
|
# layer.objects.active = obj_new
|
2010-05-23 12:14:07 +00:00
|
|
|
|
2023-01-10 14:49:51 -05:00
|
|
|
# Match up UV layers, this is needed so adding an object with UVs
|
2019-07-31 14:25:09 +02:00
|
|
|
# doesn't create new layers when there happens to be a naming mismatch.
|
2016-11-19 06:57:55 +11:00
|
|
|
uv_new = obdata.uv_layers.active
|
|
|
|
if uv_new is not None:
|
|
|
|
uv_act = obj_act.data.uv_layers.active
|
|
|
|
if uv_act is not None:
|
|
|
|
uv_new.name = uv_act.name
|
|
|
|
|
2010-09-07 15:17:42 +00:00
|
|
|
bpy.ops.object.join() # join into the active.
|
2014-12-10 17:22:26 +01:00
|
|
|
if obdata:
|
|
|
|
bpy.data.meshes.remove(obdata)
|
2010-05-23 12:14:07 +00:00
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
else:
|
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
|
|
|
layer.objects.active = obj_new
|
2022-10-06 12:59:26 +11:00
|
|
|
if context.preferences.edit.use_enter_edit_mode:
|
|
|
|
if obdata and obdata.library is None:
|
|
|
|
obtype = obj_new.type
|
|
|
|
mode = None
|
|
|
|
if obtype in {'ARMATURE', 'CURVE', 'CURVES', 'FONT', 'LATTICE', 'MESH', 'META', 'SURFACE'}:
|
|
|
|
mode = 'EDIT'
|
|
|
|
elif obtype == 'GPENCIL':
|
|
|
|
mode = 'EDIT_GPENCIL'
|
|
|
|
|
|
|
|
if mode is not None:
|
|
|
|
bpy.ops.object.mode_set(mode=mode)
|
2010-05-23 12:38:49 +00:00
|
|
|
|
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
|
|
|
return obj_new
|
2012-03-14 08:55:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AddObjectHelper:
|
2019-05-15 16:56:22 +02:00
|
|
|
def align_update_callback(self, _context):
|
|
|
|
if self.align == 'WORLD':
|
2012-03-14 08:55:57 +00:00
|
|
|
self.rotation.zero()
|
|
|
|
|
2019-05-15 16:56:22 +02:00
|
|
|
align: EnumProperty(
|
|
|
|
name="Align",
|
2021-02-21 19:48:11 +11:00
|
|
|
items=(
|
|
|
|
('WORLD', "World", "Align the new object to the world"),
|
|
|
|
('VIEW', "View", "Align the new object to the view"),
|
|
|
|
('CURSOR', "3D Cursor", "Use the 3D cursor orientation for the new object"),
|
|
|
|
),
|
2019-05-15 16:56:22 +02:00
|
|
|
default='WORLD',
|
2021-02-21 21:21:18 +11:00
|
|
|
update=AddObjectHelper.align_update_callback,
|
2018-07-03 07:13:27 +02:00
|
|
|
)
|
2018-07-11 22:18:09 +02:00
|
|
|
location: FloatVectorProperty(
|
2018-07-03 07:13:27 +02:00
|
|
|
name="Location",
|
|
|
|
subtype='TRANSLATION',
|
|
|
|
)
|
2018-07-11 22:18:09 +02:00
|
|
|
rotation: FloatVectorProperty(
|
2018-07-03 07:13:27 +02:00
|
|
|
name="Rotation",
|
|
|
|
subtype='EULER',
|
|
|
|
)
|
2012-10-19 12:53:03 +00:00
|
|
|
|
2013-11-07 08:40:47 +00:00
|
|
|
@classmethod
|
2019-04-19 07:36:07 +02:00
|
|
|
def poll(cls, context):
|
2013-11-07 08:40:47 +00:00
|
|
|
return context.scene.library is None
|
|
|
|
|
2012-10-19 12:53:03 +00:00
|
|
|
|
|
|
|
def object_add_grid_scale(context):
|
|
|
|
"""
|
2013-04-07 01:38:03 +00:00
|
|
|
Return scale which should be applied on object
|
|
|
|
data to align it to grid scale
|
2012-10-19 12:53:03 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
space_data = context.space_data
|
|
|
|
|
|
|
|
if space_data and space_data.type == 'VIEW_3D':
|
2018-05-05 10:45:15 +02:00
|
|
|
return space_data.overlay.grid_scale_unit
|
2012-10-19 12:53:03 +00:00
|
|
|
|
|
|
|
return 1.0
|
2013-04-10 11:43:25 +00:00
|
|
|
|
|
|
|
|
2013-05-28 23:07:16 +00:00
|
|
|
def object_add_grid_scale_apply_operator(operator, context):
|
|
|
|
"""
|
|
|
|
Scale an operators distance values by the grid size.
|
|
|
|
"""
|
2025-03-26 17:11:39 +11:00
|
|
|
# This is a Python version of the C++ function `WM_operator_view3d_unit_defaults`.
|
2013-05-28 23:07:16 +00:00
|
|
|
grid_scale = object_add_grid_scale(context)
|
|
|
|
|
|
|
|
properties = operator.properties
|
|
|
|
properties_def = properties.bl_rna.properties
|
|
|
|
for prop_id in properties_def.keys():
|
2020-11-04 18:06:38 +11:00
|
|
|
if not properties.is_property_set(prop_id, ghost=False):
|
2013-05-28 23:07:16 +00:00
|
|
|
prop_def = properties_def[prop_id]
|
|
|
|
if prop_def.unit == 'LENGTH' and prop_def.subtype == 'DISTANCE':
|
2014-02-13 08:51:33 +11:00
|
|
|
setattr(operator, prop_id,
|
|
|
|
getattr(operator, prop_id) * grid_scale)
|
2013-05-28 23:07:16 +00:00
|
|
|
|
|
|
|
|
2013-06-16 14:35:15 +00:00
|
|
|
def world_to_camera_view(scene, obj, coord):
|
2013-06-13 13:51:01 +00:00
|
|
|
"""
|
2013-06-16 14:35:15 +00:00
|
|
|
Returns the camera space coords for a 3d point.
|
|
|
|
(also known as: normalized device coordinates - NDC).
|
2013-06-13 13:51:01 +00:00
|
|
|
|
2015-05-17 17:17:31 +10:00
|
|
|
Where (0, 0) is the bottom left and (1, 1)
|
2015-06-18 07:52:52 +10:00
|
|
|
is the top right of the camera frame.
|
2013-06-13 13:51:01 +00:00
|
|
|
values outside 0-1 are also supported.
|
2013-06-16 14:35:15 +00:00
|
|
|
A negative 'z' value means the point is behind the camera.
|
2013-06-13 13:51:01 +00:00
|
|
|
|
|
|
|
Takes shift-x/y, lens angle and sensor size into account
|
|
|
|
as well as perspective/ortho projections.
|
|
|
|
|
|
|
|
:arg scene: Scene to use for frame size.
|
|
|
|
:type scene: :class:`bpy.types.Scene`
|
|
|
|
:arg obj: Camera object.
|
|
|
|
:type obj: :class:`bpy.types.Object`
|
|
|
|
:arg coord: World space location.
|
|
|
|
:type coord: :class:`mathutils.Vector`
|
2015-05-17 17:17:31 +10:00
|
|
|
:return: a vector where X and Y map to the view plane and
|
|
|
|
Z is the depth on the view axis.
|
2013-06-13 13:51:01 +00:00
|
|
|
:rtype: :class:`mathutils.Vector`
|
|
|
|
"""
|
2013-06-13 14:07:36 +00:00
|
|
|
from mathutils import Vector
|
2013-06-13 13:51:01 +00:00
|
|
|
|
2018-09-10 18:03:40 +02:00
|
|
|
co_local = obj.matrix_world.normalized().inverted() @ coord
|
2013-06-13 14:07:36 +00:00
|
|
|
z = -co_local.z
|
2013-06-13 13:51:01 +00:00
|
|
|
|
|
|
|
camera = obj.data
|
2020-05-19 16:23:44 +02:00
|
|
|
frame = [v for v in camera.view_frame(scene=scene)[:3]]
|
2013-06-13 13:51:01 +00:00
|
|
|
if camera.type != 'ORTHO':
|
2013-06-13 14:07:36 +00:00
|
|
|
if z == 0.0:
|
|
|
|
return Vector((0.5, 0.5, 0.0))
|
|
|
|
else:
|
2020-05-19 16:23:44 +02:00
|
|
|
frame = [-(v / (v.z / z)) for v in frame]
|
2013-06-13 13:51:01 +00:00
|
|
|
|
2020-05-19 16:23:44 +02:00
|
|
|
min_x, max_x = frame[2].x, frame[1].x
|
|
|
|
min_y, max_y = frame[1].y, frame[0].y
|
2013-06-13 13:51:01 +00:00
|
|
|
|
|
|
|
x = (co_local.x - min_x) / (max_x - min_x)
|
|
|
|
y = (co_local.y - min_y) / (max_y - min_y)
|
|
|
|
|
2013-06-13 14:07:36 +00:00
|
|
|
return Vector((x, y, z))
|
2023-07-14 20:57:28 +03:00
|
|
|
|
|
|
|
|
|
|
|
def object_report_if_active_shape_key_is_locked(obj, operator):
|
|
|
|
"""
|
|
|
|
Checks if the active shape key of the specified object is locked, and reports an error if so.
|
|
|
|
|
|
|
|
If the object has no shape keys, there is nothing to lock, and the function returns False.
|
|
|
|
|
|
|
|
:arg obj: Object to check.
|
|
|
|
:type obj: :class:`bpy.types.Object`
|
|
|
|
:arg operator: Currently running operator to report the error through. Use None to suppress emitting the message.
|
|
|
|
:type operator: :class:`bpy.types.Operator`
|
|
|
|
:return: True if the shape key was locked.
|
|
|
|
"""
|
|
|
|
key = obj.active_shape_key
|
|
|
|
|
|
|
|
if key and key.lock_shape:
|
|
|
|
if operator:
|
2024-04-27 16:06:51 +10:00
|
|
|
operator.report({'ERROR'}, "The active shape key of {:s} is locked".format(obj.name))
|
2023-07-14 20:57:28 +03:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|