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:
Diffstat (limited to 'doc/python_api/examples')
-rw-r--r--doc/python_api/examples/bpy.props.4.py4
-rw-r--r--doc/python_api/examples/bpy.props.5.py4
-rw-r--r--doc/python_api/examples/bpy.props.py9
-rw-r--r--doc/python_api/examples/bpy.types.Menu.4.py31
-rw-r--r--doc/python_api/examples/bpy.types.Operator.5.py2
-rw-r--r--doc/python_api/examples/gpu.10.py50
-rw-r--r--doc/python_api/examples/gpu.2.py52
-rw-r--r--doc/python_api/examples/gpu.7.py54
8 files changed, 108 insertions, 98 deletions
diff --git a/doc/python_api/examples/bpy.props.4.py b/doc/python_api/examples/bpy.props.4.py
index daab18c8986..93e4a9fda62 100644
--- a/doc/python_api/examples/bpy.props.4.py
+++ b/doc/python_api/examples/bpy.props.4.py
@@ -6,6 +6,10 @@ It can be useful to perform an action when a property is changed and can be
used to update other properties or synchronize with external data.
All properties define update functions except for CollectionProperty.
+
+.. warning::
+ Remember that these callbacks may be executed in threaded context.
+
"""
import bpy
diff --git a/doc/python_api/examples/bpy.props.5.py b/doc/python_api/examples/bpy.props.5.py
index c428b4743f8..49853168661 100644
--- a/doc/python_api/examples/bpy.props.5.py
+++ b/doc/python_api/examples/bpy.props.5.py
@@ -6,6 +6,10 @@ Getter/setter functions can be used for boolean, int, float, string and enum pro
If these callbacks are defined the property will not be stored in the ID properties
automatically. Instead, the `get` and `set` functions will be called when the property
is respectively read or written from the API.
+
+.. warning::
+ Remember that these callbacks may be executed in threaded context.
+
"""
import bpy
diff --git a/doc/python_api/examples/bpy.props.py b/doc/python_api/examples/bpy.props.py
index d19b57b13a5..a2a51addc65 100644
--- a/doc/python_api/examples/bpy.props.py
+++ b/doc/python_api/examples/bpy.props.py
@@ -7,6 +7,15 @@ Custom properties can be added to any subclass of an :class:`ID`,
These properties can be animated, accessed by the user interface and python
like Blender's existing properties.
+
+.. warning::
+
+ Access to these properties might happen in threaded context, on a per-data-block level.
+ This has to be carefully considered when using accessors or update callbacks.
+
+ Typically, these callbacks should not affect any other data that the one owned by their data-block.
+ When accessing external non-Blender data, thread safety mechanisms should be considered.
+
"""
import bpy
diff --git a/doc/python_api/examples/bpy.types.Menu.4.py b/doc/python_api/examples/bpy.types.Menu.4.py
index 869def8bfe0..4d1ae2d4a19 100644
--- a/doc/python_api/examples/bpy.types.Menu.4.py
+++ b/doc/python_api/examples/bpy.types.Menu.4.py
@@ -3,8 +3,8 @@ Extending the Button Context Menu
+++++++++++++++++++++++++++++++++
This example enables you to insert your own menu entry into the common
-right click menu that you get while hovering over a value field,
-color, string, etc.
+right click menu that you get while hovering over a UI button (e.g. operator,
+value field, color, string, etc.)
To make the example work, you have to first select an object
then right click on an user interface element (maybe a color in the
@@ -14,7 +14,6 @@ Executing the operator will then print all values.
"""
import bpy
-from bpy.types import Menu
def dump(obj, text):
@@ -47,36 +46,20 @@ class WM_OT_button_context_test(bpy.types.Operator):
return {'FINISHED'}
-# This class has to be exactly named like that to insert an entry in the right click menu
-class WM_MT_button_context(Menu):
- bl_label = "Unused"
-
- def draw(self, context):
- pass
-
-
-def menu_func(self, context):
+def draw_menu(self, context):
layout = self.layout
layout.separator()
layout.operator(WM_OT_button_context_test.bl_idname)
-classes = (
- WM_OT_button_context_test,
- WM_MT_button_context,
-)
-
-
def register():
- for cls in classes:
- bpy.utils.register_class(cls)
- bpy.types.WM_MT_button_context.append(menu_func)
+ bpy.utils.register_class(WM_OT_button_context_test)
+ bpy.types.UI_MT_button_context_menu.append(draw_menu)
def unregister():
- for cls in classes:
- bpy.utils.unregister_class(cls)
- bpy.types.WM_MT_button_context.remove(menu_func)
+ bpy.types.UI_MT_button_context_menu.remove(draw_menu)
+ bpy.utils.unregister_class(WM_OT_button_context_test)
if __name__ == "__main__":
diff --git a/doc/python_api/examples/bpy.types.Operator.5.py b/doc/python_api/examples/bpy.types.Operator.5.py
index 90c899f222e..0b6035fc3da 100644
--- a/doc/python_api/examples/bpy.types.Operator.5.py
+++ b/doc/python_api/examples/bpy.types.Operator.5.py
@@ -1,4 +1,6 @@
"""
+.. _modal_operator:
+
Modal Execution
+++++++++++++++
diff --git a/doc/python_api/examples/gpu.10.py b/doc/python_api/examples/gpu.10.py
index 8e354dd09a8..b47ff732e2b 100644
--- a/doc/python_api/examples/gpu.10.py
+++ b/doc/python_api/examples/gpu.10.py
@@ -14,33 +14,36 @@ from random import random
from mathutils import Vector
from gpu_extras.batch import batch_for_shader
-vertex_shader = '''
- uniform mat4 u_ViewProjectionMatrix;
+vert_out = gpu.types.GPUStageInterfaceInfo("my_interface")
+vert_out.smooth('FLOAT', "v_ArcLength")
- in vec3 position;
- in float arcLength;
+shader_info = gpu.types.GPUShaderCreateInfo()
+shader_info.push_constant('MAT4', "u_ViewProjectionMatrix")
+shader_info.push_constant('FLOAT', "u_Scale")
+shader_info.vertex_in(0, 'VEC3', "position")
+shader_info.vertex_in(1, 'FLOAT', "arcLength")
+shader_info.vertex_out(vert_out)
+shader_info.fragment_out(0, 'VEC4', "FragColor")
- out float v_ArcLength;
-
- void main()
- {
- v_ArcLength = arcLength;
- gl_Position = u_ViewProjectionMatrix * vec4(position, 1.0f);
- }
-'''
-
-fragment_shader = '''
- uniform float u_Scale;
+shader_info.vertex_source(
+ "void main()"
+ "{"
+ " v_ArcLength = arcLength;"
+ " gl_Position = u_ViewProjectionMatrix * vec4(position, 1.0f);"
+ "}"
+)
- in float v_ArcLength;
- out vec4 FragColor;
+shader_info.fragment_source(
+ "void main()"
+ "{"
+ " if (step(sin(v_ArcLength * u_Scale), 0.5) == 1) discard;"
+ " FragColor = vec4(1.0);"
+ "}"
+)
- void main()
- {
- if (step(sin(v_ArcLength * u_Scale), 0.5) == 1) discard;
- FragColor = vec4(1.0);
- }
-'''
+shader = gpu.shader.create_from_info(shader_info)
+del vert_out
+del shader_info
coords = [Vector((random(), random(), random())) * 5 for _ in range(5)]
@@ -48,7 +51,6 @@ arc_lengths = [0]
for a, b in zip(coords[:-1], coords[1:]):
arc_lengths.append(arc_lengths[-1] + (a - b).length)
-shader = gpu.types.GPUShader(vertex_shader, fragment_shader)
batch = batch_for_shader(
shader, 'LINE_STRIP',
{"position": coords, "arcLength": arc_lengths},
diff --git a/doc/python_api/examples/gpu.2.py b/doc/python_api/examples/gpu.2.py
index 565ec5d5d0c..2a46e833752 100644
--- a/doc/python_api/examples/gpu.2.py
+++ b/doc/python_api/examples/gpu.2.py
@@ -6,33 +6,37 @@ import bpy
import gpu
from gpu_extras.batch import batch_for_shader
-vertex_shader = '''
- uniform mat4 viewProjectionMatrix;
- in vec3 position;
- out vec3 pos;
-
- void main()
- {
- pos = position;
- gl_Position = viewProjectionMatrix * vec4(position, 1.0f);
- }
-'''
-
-fragment_shader = '''
- uniform float brightness;
-
- in vec3 pos;
- out vec4 FragColor;
-
- void main()
- {
- FragColor = vec4(pos * brightness, 1.0);
- }
-'''
+vert_out = gpu.types.GPUStageInterfaceInfo("my_interface")
+vert_out.smooth('VEC3', "pos")
+
+shader_info = gpu.types.GPUShaderCreateInfo()
+shader_info.push_constant('MAT4', "viewProjectionMatrix")
+shader_info.push_constant('FLOAT', "brightness")
+shader_info.vertex_in(0, 'VEC3', "position")
+shader_info.vertex_out(vert_out)
+shader_info.fragment_out(0, 'VEC4', "FragColor")
+
+shader_info.vertex_source(
+ "void main()"
+ "{"
+ " pos = position;"
+ " gl_Position = viewProjectionMatrix * vec4(position, 1.0f);"
+ "}"
+)
+
+shader_info.fragment_source(
+ "void main()"
+ "{"
+ " FragColor = vec4(pos * brightness, 1.0);"
+ "}"
+)
+
+shader = gpu.shader.create_from_info(shader_info)
+del vert_out
+del shader_info
coords = [(1, 1, 1), (2, 0, 0), (-2, -1, 3)]
-shader = gpu.types.GPUShader(vertex_shader, fragment_shader)
batch = batch_for_shader(shader, 'TRIS', {"position": coords})
diff --git a/doc/python_api/examples/gpu.7.py b/doc/python_api/examples/gpu.7.py
index 9d881831c21..e3bfbd14e34 100644
--- a/doc/python_api/examples/gpu.7.py
+++ b/doc/python_api/examples/gpu.7.py
@@ -35,35 +35,37 @@ with offscreen.bind():
# Drawing the generated texture in 3D space
#############################################
-vertex_shader = '''
- uniform mat4 modelMatrix;
- uniform mat4 viewProjectionMatrix;
-
- in vec2 position;
- in vec2 uv;
-
- out vec2 uvInterp;
-
- void main()
- {
- uvInterp = uv;
- gl_Position = viewProjectionMatrix * modelMatrix * vec4(position, 0.0, 1.0);
- }
-'''
-
-fragment_shader = '''
- uniform sampler2D image;
+vert_out = gpu.types.GPUStageInterfaceInfo("my_interface")
+vert_out.smooth('VEC2', "uvInterp")
+
+shader_info = gpu.types.GPUShaderCreateInfo()
+shader_info.push_constant('MAT4', "viewProjectionMatrix")
+shader_info.push_constant('MAT4', "modelMatrix")
+shader_info.sampler(0, 'FLOAT_2D', "image")
+shader_info.vertex_in(0, 'VEC2', "position")
+shader_info.vertex_in(1, 'VEC2', "uv")
+shader_info.vertex_out(vert_out)
+shader_info.fragment_out(0, 'VEC4', "FragColor")
+
+shader_info.vertex_source(
+ "void main()"
+ "{"
+ " uvInterp = uv;"
+ " gl_Position = viewProjectionMatrix * modelMatrix * vec4(position, 0.0, 1.0);"
+ "}"
+)
- in vec2 uvInterp;
- out vec4 FragColor;
+shader_info.fragment_source(
+ "void main()"
+ "{"
+ " FragColor = texture(image, uvInterp);"
+ "}"
+)
- void main()
- {
- FragColor = texture(image, uvInterp);
- }
-'''
+shader = gpu.shader.create_from_info(shader_info)
+del vert_out
+del shader_info
-shader = gpu.types.GPUShader(vertex_shader, fragment_shader)
batch = batch_for_shader(
shader, 'TRI_FAN',
{