-
Notifications
You must be signed in to change notification settings - Fork 50
/
archipack_wall.py
157 lines (130 loc) · 5.4 KB
/
archipack_wall.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# -*- coding:utf-8 -*-
# ##### BEGIN GPL LICENSE BLOCK #####
#
# 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
# of the License, or (at your option) any later version.
#
# 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.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
# ----------------------------------------------------------
# Author: Stephen Leger (s-leger)
#
# ----------------------------------------------------------
import bpy
import bmesh
from bpy.types import Operator, PropertyGroup, Mesh, Panel
from bpy.props import FloatProperty, CollectionProperty
from .archipack_object import ArchipackObject, ArchipackCreateTool
from .archipack_dimension import DimensionProvider
def update_wall(self, context):
self.update(context)
class archipack_wall(ArchipackObject, DimensionProvider, PropertyGroup):
z = FloatProperty(
name='height',
min=0.1, max=10000,
default=2.7, precision=2,
description='height', update=update_wall,
)
def update(self, context):
# update height via bmesh to avoid loosing material ids
# this should be the rule for other simple objects
# as long as there is no topologic changes
o = context.active_object
if archipack_wall.datablock(o) != self:
return
# bpy.ops.object.mode_set(mode='EDIT')
me = o.data
for v in me.vertices:
self.add_dimension_point(v.index, v.co)
# bm = bmesh.from_edit_mesh(me)
# bm.verts.ensure_lookup_table()
# bm.faces.ensure_lookup_table()
new_z = self.z
# use "Top" vertex group
# create vertex group lookup dictionary for names
vgroup_names = {vgroup.index: vgroup.name for vgroup in o.vertex_groups}
# create dictionary of vertex group assignments per vertex
if len(vgroup_names) > 0:
vertex_groups = [[vgroup_names[g.group] for g in v.groups] for v in me.vertices]
last_z = [me.vertices[i].co.z for i, g in enumerate(vertex_groups) if 'Top' in g]
if len(last_z) > 0:
max_z = max(last_z)
for i, g in enumerate(vertex_groups):
if 'Top' in g:
me.vertices[i].co.z = new_z
self.update_dimensions(context, o)
# bpy.ops.object.mode_set(mode='OBJECT')
class ARCHIPACK_PT_wall(Panel):
bl_idname = "ARCHIPACK_PT_wall"
bl_label = "Wall"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'ArchiPack'
@classmethod
def poll(cls, context):
return archipack_wall.filter(context.active_object)
def draw(self, context):
prop = archipack_wall.datablock(context.active_object)
if prop is None:
return
layout = self.layout
layout.prop(prop, 'z')
# ------------------------------------------------------------------
# Define operator class to create object
# ------------------------------------------------------------------
class ARCHIPACK_OT_wall(Operator, ArchipackCreateTool):
bl_idname = "archipack.wall"
bl_label = "Wall"
bl_description = "Add wall parameters to active object to draw windows and doors and use autoboolean"
bl_category = 'Archipack'
bl_options = {'REGISTER', 'UNDO'}
z = FloatProperty(
name="z",
default=2.7
)
@classmethod
def poll(cls, context):
o = context.active_object
return (o is not None and
o.type == 'MESH' and
"archipack_wall2" not in o.data and
"archipack_custom_hole" not in o)
def draw(self, context):
layout = self.layout
row = layout.row()
row.label("Use Properties panel (N) to define parms", icon='INFO')
def execute(self, context):
if context.mode == "OBJECT":
o = context.active_object
if archipack_wall.filter(o):
return {'CANCELLED'}
d = o.data.archipack_wall.add()
# @TODO: estimate z from mesh,
# using "TOP" vertex group
d.z = self.z
self.add_material(o)
return {'FINISHED'}
else:
self.report({'WARNING'}, "Archipack: Option only valid in Object mode")
return {'CANCELLED'}
def register():
bpy.utils.register_class(archipack_wall)
Mesh.archipack_wall = CollectionProperty(type=archipack_wall)
bpy.utils.register_class(ARCHIPACK_PT_wall)
bpy.utils.register_class(ARCHIPACK_OT_wall)
def unregister():
bpy.utils.unregister_class(archipack_wall)
del Mesh.archipack_wall
bpy.utils.unregister_class(ARCHIPACK_PT_wall)
bpy.utils.unregister_class(ARCHIPACK_OT_wall)