File: properties_physics_geometry_nodes.py

package info (click to toggle)
blender 4.3.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 309,564 kB
  • sloc: cpp: 2,385,210; python: 330,236; ansic: 280,972; xml: 2,446; sh: 972; javascript: 317; makefile: 170
file content (64 lines) | stat: -rw-r--r-- 1,898 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# SPDX-FileCopyrightText: 2023 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later

from bpy.types import (
    Panel,
)
from bpy.app.translations import (
    pgettext_iface as iface_,
    contexts as i18n_contexts,
)


class PHYSICS_PT_geometry_nodes(Panel):
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "physics"
    bl_label = "Simulation Nodes"
    bl_options = {'DEFAULT_CLOSED'}

    @classmethod
    def geometry_nodes_objects(cls, context):
        for ob in context.selected_editable_objects:
            if any([modifier.type == 'NODES' for modifier in ob.modifiers]):
                yield ob

    @classmethod
    def poll(cls, context):
        return any(cls.geometry_nodes_objects(context))

    def draw(self, context):
        layout = self.layout

        if len(context.selected_editable_objects) > 1:
            calc_text = iface_("Calculate Selected to Frame")
            bake_text = iface_("Bake Selected")
        else:
            calc_text = iface_("Calculate to Frame")
            bake_text = iface_("Bake")

        layout.operator(
            "object.simulation_nodes_cache_calculate_to_frame",
            text=calc_text, translate=False,
        ).selected = True

        row = layout.row(align=True)
        row.operator("object.simulation_nodes_cache_bake", text=bake_text, translate=False).selected = True
        row.operator("object.simulation_nodes_cache_delete", text="", icon='TRASH').selected = True

        layout.use_property_split = True
        layout.use_property_decorate = False
        ob = context.object
        layout.prop(ob, "use_simulation_cache", text="Cache", text_ctxt=i18n_contexts.id_simulation)


classes = (
    PHYSICS_PT_geometry_nodes,
)


if __name__ == "__main__":  # only for live edit.
    from bpy.utils import register_class
    for cls in classes:
        register_class(cls)