-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.py
More file actions
88 lines (66 loc) · 2.37 KB
/
plugin.py
File metadata and controls
88 lines (66 loc) · 2.37 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import bpy
bl_info = {
"name": "WFC Tile Generator",
"blender": (3, 5, 0),
"category": "Collection",
}
class OperatorAdjacencyFromGeo(bpy.types.Operator):
bl_idname = "wfc.geo_adjacency"
bl_label = "Adjacency From Geometry"
def execute(self, context):
if not bpy.context.scene.wfc_source_tiles:
self.report({"ERROR"}, "must set source tiles")
return {"FINISHED"}
try:
from wfc.adjacency import compute_adjacency
compute_adjacency(bpy.context.scene.wfc_source_tiles)
except Exception as e:
self.report({"ERROR"}, e)
return {"FINISHED"}
class OperatorGenerateRandom(bpy.types.Operator):
bl_idname = "wfc.generate_random"
bl_label = "Generate Random"
def execute(self, context):
if not bpy.context.scene.wfc_source_tiles:
self.report({"ERROR"}, "must set source tiles")
return {"FINISHED"}
try:
from wfc.solver import test_with_retry
test_with_retry(iterations=1000)
except Exception as e:
self.report({"ERROR"}, e)
return {"FINISHED"}
class WFCPanel(bpy.types.Panel):
bl_label = "WFC Tile Generator"
bl_category = "WFC"
bl_idname = "COLLECTION_PT_wfc"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
# bl_space_type = 'PROPERTIES'
# bl_region_type = 'WINDOW'
# bl_context = "collection"
def draw(self, context):
self.layout.prop(context.scene, "wfc_source_tiles")
self.layout.prop(context.scene, "wfc_prototypes_path")
self.layout.operator(OperatorAdjacencyFromGeo.bl_idname)
self.layout.operator(OperatorGenerateRandom.bl_idname)
def register():
bpy.types.Scene.wfc_prototypes_path = bpy.props.StringProperty(
name="Prototypes JSON"
)
bpy.types.Scene.wfc_source_tiles = bpy.props.PointerProperty(
name="Source Tiles", type=bpy.types.Collection
)
bpy.utils.register_class(OperatorAdjacencyFromGeo)
bpy.utils.register_class(OperatorGenerateRandom)
bpy.utils.register_class(WFCPanel)
def unregister():
bpy.utils.unregister_class(OperatorAdjacencyFromGeo)
bpy.utils.unregister_class(OperatorGenerateRandom)
bpy.utils.unregister_class(WFCPanel)
if __name__ == "__main__":
# for local dev
import os
import sys
sys.path.append(os.getcwd())
register()