Import images: add file handler
[blender-addons.git] / add_mesh_geodesic_domes / third_domes_panel_271.py
blob41ede7ebaa1008b943a81f87d81eef5c864c2188
1 # SPDX-FileCopyrightText: 2016-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 import bpy
6 import os
7 from . import vefm_271
8 from . import forms_271
9 from . import geodesic_classes_271
10 from . import add_shape_geodesic
12 from bpy.types import Operator
13 from bpy.props import (
14 EnumProperty,
15 IntProperty,
16 FloatProperty,
17 StringProperty,
18 BoolProperty,
19 FloatVectorProperty,
21 from math import pi
22 from mathutils import (
23 Vector,
24 Matrix,
26 from bpy_extras import object_utils
28 # global #
29 last_generated_object = None
30 last_imported_mesh = None
31 basegeodesic = None
32 imported_hubmesh_to_use = None
33 error_message = ""
34 geodesic_not_yet_called = True
35 # global end #
37 # ###### EIND FOR SHAPEKEYS ######
40 class GenerateGeodesicDome(Operator, object_utils.AddObjectHelper):
41 bl_label = "Modify Geodesic Objects"
42 bl_idname = "mesh.generate_geodesic_dome"
43 bl_description = "Create Geodesic Object Types"
44 bl_options = {'REGISTER', 'UNDO', 'PRESET'}
46 GeodesicDome : BoolProperty(name = "GeodesicDome",
47 default = True,
48 description = "GeodesicDome")
49 change : BoolProperty(name = "Change",
50 default = False,
51 description = "change Geodesic Dome")
53 gd_help_text_width: IntProperty(
54 name="Text Width",
55 description="The width above which the text wraps",
56 default=60,
57 max=180, min=20
59 mainpages: EnumProperty(
60 name="Menu",
61 description="Create Faces, Struts & Hubs",
62 items=[("Main", "Main", "Geodesic objects"),
63 ("Faces", "Faces", "Generate Faces"),
64 ("Struts", "Struts", "Generate Struts"),
65 ("Hubs", "Hubs", "Generate Hubs"),
66 ("Help", "Help", "Not implemented"),
68 default='Main'
70 # for Faces
71 facetype_menu: EnumProperty(
72 name="Faces",
73 description="choose a facetype",
74 items=[("0", "strip", "strip"),
75 ("1", "open vertical", "vertical"),
76 ("2", "open slanted", "slanted"),
77 ("3", "closed point", "closed point"),
78 ("4", "pillow", "pillow"),
79 ("5", "closed vertical", "closed vertical"),
80 ("6", "stepped", "stepped"),
81 ("7", "spikes", "spikes"),
82 ("8", "boxed", "boxed"),
83 ("9", "diamond", "diamond"),
84 # ("10", "bar", "bar"),
86 default='0'
88 facetoggle: BoolProperty(
89 name="Activate: Face Object",
90 description="Activate Faces for Geodesic object",
91 default=True
93 face_use_imported_object: BoolProperty(
94 name="Use: Imported Object",
95 description="Activate faces on your Imported object",
96 default=False
98 facewidth: FloatProperty(
99 name="Face Width",
100 min=-1, soft_min=0.001, max=4,
101 default=.50
103 fwtog: BoolProperty(
104 name="Width tweak",
105 default=False
107 faceheight: FloatProperty(
108 name="Face Height",
109 min=0.001, max=4,
110 default=1
112 fhtog: BoolProperty(
113 name="Height tweak",
114 default=False
116 face_detach: BoolProperty(
117 name="Detach Faces",
118 default=False
120 fmeshname: StringProperty(
121 name="Face Mesh name",
122 default="defaultface"
124 geodesic_types: EnumProperty(
125 name="Objects",
126 description="Choose Geodesic, Grid, Cylinder, Parabola, "
127 "Torus, Sphere, Import your mesh or Superparameters",
128 items=[("Geodesic", "Geodesic", "Generate Geodesic"),
129 ("Grid", "Grid", "Generate Grid"),
130 ("Cylinder", "Cylinder", "Generate Cylinder"),
131 ("Parabola", "Parabola", "Generate Parabola"),
132 ("Torus", "Torus", "Generate Torus"),
133 ("Sphere", "Sphere", "Generate Sphere"),
134 ("Import_your_mesh", "Import your mesh", "Import Your Mesh"),
136 default='Geodesic'
138 import_mesh_name: StringProperty(
139 name="Mesh to import",
140 description="the name has to be the name of a meshobject",
141 default="None"
143 base_type: EnumProperty(
144 name="Hedron",
145 description="Choose between Tetrahedron, Octahedron, Icosahedron ",
146 items=[("Tetrahedron", "Tetrahedron", "Generate Tetrahedron"),
147 ("Octahedron", "Octahedron", "Generate Octahedron"),
148 ("Icosahedron", "Icosahedron", "Generate Icosahedron"),
150 default='Tetrahedron'
152 orientation: EnumProperty(
153 name="Point^",
154 description="Point (Vert), Edge or Face pointing upwards",
155 items=[("PointUp", "PointUp", "Point up"),
156 ("EdgeUp", "EdgeUp", "Edge up"),
157 ("FaceUp", "FaceUp", "Face up"),
159 default='PointUp'
161 geodesic_class: EnumProperty(
162 name="Class",
163 description="Subdivide Basic/Triacon",
164 items=[("Class_1", "Class 1", "class one"),
165 ("Class_2", "Class 2", "class two"),
167 default='Class_1'
169 tri_hex_star: EnumProperty(
170 name="Shape",
171 description="Choose between tri hex star face types",
172 items=[("tri", "tri", "tri faces"),
173 ("hex", "hex", "hex faces(by tri)"),
174 ("star", "star", "star faces(by tri)"),
176 default='tri'
178 spherical_flat: EnumProperty(
179 name="Round",
180 description="Choose between spherical or flat ",
181 items=[("spherical", "spherical", "Generate spherical"),
182 ("flat", "flat", "Generate flat"),
184 default='spherical'
186 use_imported_mesh: BoolProperty(
187 name="use import",
188 description="Use an imported mesh",
189 default=False
191 # Cylinder
192 cyxres: IntProperty(
193 name="Resolution x/y",
194 min=3, #max=32,
195 description="Number of faces around x/y",
196 default=5
198 cyyres: IntProperty(
199 name="Resolution z",
200 min=3, #max=32,
201 description="Number of faces in z direction",
202 default=5
204 cyxsz: FloatProperty(
205 name="Scale x/y",
206 min=0.01, #max=10,
207 description="Scale in x/y direction",
208 default=1
210 cyysz: FloatProperty(
211 name="Scale z",
212 min=0.01, #max=10,
213 description="Scale in z direction",
214 default=1
216 cyxell: FloatProperty(
217 name="Stretch x",
218 min=0.001, #max=4,
219 description="Stretch in x direction",
220 default=1
222 cygap: FloatProperty(
223 name="Gap",
224 min=-2, #max=2,
225 description="Shrink in % around radius",
226 default=1
228 cygphase: FloatProperty(
229 name="Phase", min=-4, #max=4,
230 description="Rotate around pivot x/y",
231 default=0
233 # Parabola
234 paxres: IntProperty(
235 name="Resolution x/y",
236 min=3, #max=32,
237 description="Number of faces around x/y",
238 default=5
240 payres: IntProperty(
241 name="Resolution z",
242 min=3, #max=32,
243 description="Number of faces in z direction",
244 default=5
246 paxsz: FloatProperty(
247 name="Scale x/y",
248 min=0.001, #max=10,
249 description="scale in x/y direction",
250 default=0.30
252 paysz: FloatProperty(
253 name="Scale z",
254 min=0.001, #max=10,
255 description="Scale in z direction",
256 default=1
258 paxell: FloatProperty(
259 name="Stretch x",
260 min=0.001, #max=4,
261 description="Stretch in x direction",
262 default=1
264 pagap: FloatProperty(
265 name="Gap",
266 min=-2, #max=2,
267 description="Shrink in % around radius",
268 default=1
270 pagphase: FloatProperty(
271 name="Phase",
272 min=-4, #max=4,
273 description="Rotate around pivot x/y",
274 default=0
276 # Torus
277 ures: IntProperty(
278 name="Resolution x/y",
279 min=3, #max=32,
280 description="Number of faces around x/y",
281 default=8)
282 vres: IntProperty(
283 name="Resolution z",
284 min=3, #max=32,
285 description="Number of faces in z direction",
286 default=8)
287 urad: FloatProperty(
288 name="Radius x/y",
289 min=0.001, #max=10,
290 description="Radius in x/y plane",
291 default=1
293 vrad: FloatProperty(
294 name="Radius z",
295 min=0.001, #max=10,
296 description="Radius in z plane",
297 default=0.250
299 uellipse: FloatProperty(
300 name="Stretch x",
301 min=0.001, #max=10,
302 description="Number of faces in z direction",
303 default=1
305 vellipse: FloatProperty(
306 name="Stretch z",
307 min=0.001, #max=10,
308 description="Number of faces in z direction",
309 default=1
311 upart: FloatProperty(
312 name="Gap x/y",
313 min=-4,# max=4,
314 description="Shrink faces around x/y",
315 default=1
317 vpart: FloatProperty(
318 name="Gap z",
319 min=-4, #max=4,
320 description="Shrink faces in z direction",
321 default=1
323 ugap: FloatProperty(
324 name="Phase x/y",
325 min=-4, #max=4,
326 description="Rotate around pivot x/y",
327 default=0
329 vgap: FloatProperty(
330 name="Phase z",
331 min=-4, #max=4,
332 description="Rotate around pivot z",
333 default=0
335 uphase: FloatProperty(
336 name="uphase",
337 min=-4, #max=4,
338 description="Number of faces in z direction",
339 default=0
341 vphase: FloatProperty(
342 name="vphase",
343 min=-4, #max=4,
344 description="Number of faces in z direction",
345 default=0
347 uexp: FloatProperty(
348 name="uexp",
349 min=-4, #max=4,
350 description="Number of faces in z direction",
351 default=0
353 vexp: FloatProperty(
354 name="vexp",
355 min=-4, #max=4,
356 description="Number of faces in z direction",
357 default=0
359 usuper: FloatProperty(
360 name="usuper",
361 min=-4, #max=4,
362 description="First set of superform parameters",
363 default=2
365 vsuper: FloatProperty(
366 name="vsuper",
367 min=-4, #max=4,
368 description="Second set of superform parameters",
369 default=2
371 utwist: FloatProperty(
372 name="Twist x/y",
373 min=-4, #max=4,
374 description="Use with superformular u",
375 default=0
377 vtwist: FloatProperty(
378 name="Twist z",
379 min=-4, #max=4,
380 description="Use with superformular v",
381 default=0
383 # Sphere
384 bures: IntProperty(
385 name="Resolution x/y",
386 min=3, #max=32,
387 description="Number of faces around x/y",
388 default=8
390 bvres: IntProperty(
391 name="Resolution z",
392 min=3, #max=32,
393 description="Number of faces in z direction",
394 default=8
396 burad: FloatProperty(
397 name="Radius",
398 min=-4, #max=4,
399 description="overall radius",
400 default=1
402 bupart: FloatProperty(
403 name="Gap x/y",
404 min=-4, #max=4,
405 description="Shrink faces around x/y",
406 default=1
408 bvpart: FloatProperty(
409 name="Gap z",
410 min=-4, #max=4,
411 description="Shrink faces in z direction",
412 default=1
414 buphase: FloatProperty(
415 name="Phase x/y",
416 min=-4, #max=4,
417 description="Rotate around pivot x/y",
418 default=0
420 bvphase: FloatProperty(
421 name="Phase z",
422 min=-4, #max=4,
423 description="Rotate around pivot z",
424 default=0
426 buellipse: FloatProperty(
427 name="Stretch x",
428 min=0.001, #max=4,
429 description="Stretch in the x direction",
430 default=1
432 bvellipse: FloatProperty(
433 name="Stretch z",
434 min=0.001, #max=4,
435 description="Stretch in the z direction",
436 default=1
438 # Grid
439 grxres: IntProperty(
440 name="Resolution x",
441 min=2, #soft_max=10, max=20,
442 description="Number of faces in x direction",
443 default=5
445 gryres: IntProperty(
446 name="Resolution z",
447 min=2, soft_min=2,
448 #soft_max=10, max=20,
449 description="Number of faces in x direction",
450 default=2
452 grxsz: FloatProperty(
453 name="X size",
454 min=1, soft_min=0.01,
455 #soft_max=5, max=10,
456 description="X size",
457 default=2.0
459 grysz: FloatProperty(
460 name="Y size",
461 min=1, soft_min=0.01,
462 #soft_max=5, max=10,
463 description="Y size",
464 default=1.0
467 # PKHG_TODO_??? what means cart
468 cart: IntProperty(
469 name="cart",
470 min=0, #max=2,
471 default=0
473 frequency: IntProperty(
474 name="Frequency",
475 min=1, #max=8,
476 description="Subdivide base triangles",
477 default=1
479 eccentricity: FloatProperty(
480 name="Eccentricity",
481 min=0.01, #max=4,
482 description="Scaling in x/y dimension",
483 default=1
485 squish: FloatProperty(
486 name="Squish",
487 min=0.01,
488 #soft_max=4, max=10,
489 description="Scaling in z dimension",
490 default=1
492 radius: FloatProperty(
493 name="Radius",
494 min=0.01,
495 #soft_max=4, max=10,
496 description="Overall radius",
497 default=1
499 squareness: FloatProperty(
500 name="Square x/y",
501 min=0.1, #max=5,
502 description="Superelipse action in x/y",
503 default=2
505 squarez: FloatProperty(
506 name="Square z",
507 min=0.1, #soft_max=5, max=10,
508 description="Superelipse action in z",
509 default=2
511 baselevel: IntProperty(
512 name="baselevel",
513 default=5
515 dual: BoolProperty(
516 name="Dual",
517 description="Faces become verts, "
518 "verts become faces, edges flip",
519 default=False
521 rotxy: FloatProperty(
522 name="Rotate x/y",
523 min=-4, #max=4,
524 description="Rotate superelipse action in x/y",
525 default=0
527 rotz: FloatProperty(
528 name="Rotate z",
529 min=-4, #max=4,
530 description="Rotate superelipse action in z",
531 default=0
534 # for choice of superformula
535 uact: BoolProperty(
536 name="Superformula u (x/y)",
537 description="Activate superformula u parameters",
538 default=False
540 vact: BoolProperty(
541 name="Superformula v (z)",
542 description="Activate superformula v parameters",
543 default=False
545 um: FloatProperty(
546 name="Pinch x/y",
547 min=0, soft_min=0.1,
548 #soft_max=5, max=10,
549 description="Pinch the mesh on x/y",
550 default=3
552 un1: FloatProperty(
553 name="Squash x/y",
554 min=0, soft_min=0.1,
555 #soft_max=5, max=20,
556 description="Squash the mesh x/y",
557 default=1
559 un2: FloatProperty(
560 name="Inflate x/y",
561 min=0, soft_min=0.1,
562 #soft_max=5, max=10,
563 description="Inflate the mesh x/y",
564 default=1
566 un3: FloatProperty(
567 name="Roundify x/y",
568 min=0, soft_min=0.1,
569 #soft_max=5, max=10,
570 description="Roundify x/y",
571 default=1
573 ua: FloatProperty(
574 name="Shrink",
575 min=0, soft_min=0.1,
576 #soft_max=5, max=10,
577 description="Shrink",
578 default=1.0
580 ub: FloatProperty(
581 name="Shrink x/y",
582 min=0, soft_min=0.1,
583 #soft_max=5, max=10,
584 description="Shrink y/x",
585 default=4.0
587 vm: FloatProperty(
588 name="Scale Z Base",
589 min=0, soft_min=0.1,
590 #soft_max=5, max=10,
591 description="Scale Z Base",
592 default=1
594 vn1: FloatProperty(
595 name="Scale lock Top Z",
596 min=0, soft_min=0.1,
597 #soft_max=5, max=10,
598 description="Scale lock Top Z",
599 default=1
601 vn2: FloatProperty(
602 name="Inflate Base",
603 min=0, soft_min=0.1,
604 #soft_max=5, max=10,
605 description="Inflate Base",
606 default=1
608 vn3: FloatProperty(
609 name="Inflate",
610 min=0, soft_min=0.1,
611 #soft_max=5, max=10,
612 description="Inflate",
613 default=1
615 va: FloatProperty(
616 name="Scale 1",
617 min=0, soft_min=0.1,
618 #soft_max=5, max=10,
619 description="Scale 1",
620 default=1
622 vb: FloatProperty(
623 name="Scale 2",
624 min=0, soft_min=0.1,
625 #soft_max=5, max=10,
626 description="Scale 2",
627 default=1
630 uturn: FloatProperty(
631 name="x/y Vert cycle",
632 min=0, soft_min=0.1,
633 #soft_max=5, max=10,
634 description="x/y Vert cycle",
635 default=0
637 vturn: FloatProperty(
638 name="z Vert cycle",
639 min=0, soft_min=0.1,
640 #soft_max=5, max=10,
641 description="z Vert cycle",
642 default=0
644 utwist: FloatProperty(
645 name="x/y Twist cycle",
646 min=0, soft_min=0.1,
647 #soft_max=5, max=10,
648 description="x/y Twist cycle",
649 default=0
651 vtwist: FloatProperty(
652 name="z Twist cycle",
653 min=0, soft_min=0.1,
654 #soft_max=5, max=10,
655 description="z Twist cycle",
656 default=0
658 # Strut
659 struttype: IntProperty(
660 name="Strut type",
661 default=0
663 struttoggle: BoolProperty(
664 name="Use Struts",
665 default=False
667 strutimporttoggle: BoolProperty(
668 name="Strut import toggle",
669 default=False
671 strutimpmesh: StringProperty(
672 name="Strut import mesh",
673 default="None"
675 strutwidth: FloatProperty(
676 name="Strut width",
677 min=-10, soft_min=5,
678 #soft_max=5, max=10,
679 default=1
681 swtog: BoolProperty(
682 name="Width enable",
683 default=False
685 strutheight: FloatProperty(
686 name="Strut height",
687 min=-5, soft_min=-1,
688 #soft_max=5, max=10,
689 default=1
691 shtog: BoolProperty(
692 name="Height tweak",
693 default=False
695 strutshrink: FloatProperty(
696 name="Strut shrink",
697 min=0.001, #max=4,
698 default=1
700 sstog: BoolProperty(
701 name="Shrink tweak",
702 default=False
704 stretch: FloatProperty(
705 name="Stretch",
706 min=-4, #max=4,
707 default=1.0
709 lift: FloatProperty(
710 name="Lift",
711 min=0.001, #max=10,
712 default=0
714 smeshname: StringProperty(
715 name="Strut mesh name",
716 default="defaultstrut"
718 # Hubs
719 hubtype: BoolProperty(
720 name="Hub type",
721 description="not used",
722 default=True
724 hubtoggle: BoolProperty(
725 name="Use Hubs",
726 default=False
728 hubimporttoggle: BoolProperty(
729 name="New import",
730 description="Import a mesh",
731 default=False
733 hubimpmesh: StringProperty(
734 name="Hub mesh import",
735 description="Name of mesh to import",
736 default="None"
738 hubwidth: FloatProperty(
739 name="Hub width",
740 min=0.01, #max=10,
741 default=1
743 hwtog: BoolProperty(
744 name="Width tweak",
745 default=False
747 hubheight: FloatProperty(
748 name="Hub height",
749 min=0.01, #max=10,
750 default=1
752 hhtog: BoolProperty(
753 name="Height tweak",
754 default=False
756 hublength: FloatProperty(
757 name="Hub length",
758 min=0.1, #max=10,
759 default=1
761 hstog: BoolProperty(
762 name="Hub s tweak",
763 default=False
765 hmeshname: StringProperty(
766 name="Hub mesh name",
767 description="Name of an existing mesh needed!",
768 default="None"
770 name_list = [
771 'facetype_menu', 'facetoggle', 'face_use_imported_object',
772 'facewidth', 'fwtog', 'faceheight', 'fhtog',
773 'face_detach', 'fmeshname', 'geodesic_types', 'import_mesh_name',
774 'base_type', 'orientation', 'geodesic_class', 'tri_hex_star',
775 'spherical_flat', 'use_imported_mesh', 'cyxres', 'cyyres',
776 'cyxsz', 'cyysz', 'cyxell', 'cygap',
777 'cygphase', 'paxres', 'payres', 'paxsz',
778 'paysz', 'paxell', 'pagap', 'pagphase',
779 'ures', 'vres', 'urad', 'vrad',
780 'uellipse', 'vellipse', 'upart', 'vpart',
781 'ugap', 'vgap', 'uphase', 'vphase',
782 'uexp', 'vexp', 'usuper', 'vsuper',
783 'utwist', 'vtwist', 'bures', 'bvres',
784 'burad', 'bupart', 'bvpart', 'buphase',
785 'bvphase', 'buellipse', 'bvellipse', 'grxres',
786 'gryres', 'grxsz', 'grysz',
787 'cart', 'frequency', 'eccentricity', 'squish',
788 'radius', 'squareness', 'squarez', 'baselevel',
789 'dual', 'rotxy', 'rotz',
790 'uact', 'vact', 'um', 'un1',
791 'un2', 'un3', 'ua', 'ub',
792 'vm', 'vn1', 'vn2', 'vn3',
793 'va', 'vb', 'uturn', 'vturn',
794 'utwist', 'vtwist', 'struttype', 'struttoggle',
795 'strutimporttoggle', 'strutimpmesh', 'strutwidth', 'swtog',
796 'strutheight', 'shtog', 'strutshrink', 'sstog',
797 'stretch', 'lift', 'smeshname', 'hubtype',
798 'hubtoggle', 'hubimporttoggle', 'hubimpmesh', 'hubwidth',
799 'hwtog', 'hubheight', 'hhtog', 'hublength',
800 'hstog', 'hmeshname'
803 def write_params(self, filename):
804 file = open(filename, "w", encoding="utf8", newline="\n")
805 fw = file.write
806 # for Faces!
807 for el in self.name_list:
808 fw(el + ", ")
809 fw(repr(getattr(self, el)))
810 fw(", \n")
811 file.close()
813 def read_file(self, filename):
814 file = open(filename, "r", newline="\n")
815 result = []
816 line = file.readline()
817 while(line):
818 tmp = line.split(", ")
819 result.append(eval(tmp[1]))
820 line = file.readline()
821 return result
823 def draw(self, context):
824 layout = self.layout
825 row = layout.row()
826 col = layout.column()
827 col.prop(self, "mainpages")
828 which_mainpages = self.mainpages
829 if which_mainpages == 'Main':
830 col = layout.column()
831 col.prop(self, "geodesic_types")
832 tmp = self.geodesic_types
833 if tmp == "Geodesic":
834 col.label(text="Geodesic Object Types:")
835 col.prop(self, "geodesic_class")
836 col.prop(self, "base_type")
837 col.prop(self, "orientation")
838 col.prop(self, "tri_hex_star")
839 col.prop(self, "spherical_flat")
840 col.label(text="Geodesic Object Parameters:")
841 row = layout.row()
842 row.prop(self, "frequency")
843 row = layout.row()
844 row.prop(self, "radius")
845 row = layout.row()
846 row.prop(self, "eccentricity")
847 row = layout.row()
848 row.prop(self, "squish")
849 row = layout.row()
850 row.prop(self, "squareness")
851 row = layout.row()
852 row.prop(self, "squarez")
853 row = layout.row()
854 row.prop(self, "rotxy")
855 row = layout.row()
856 row.prop(self, "rotz")
857 row = layout.row()
858 row.prop(self, "dual")
859 elif tmp == 'Torus':
860 col.label(text="Torus Parameters")
861 row = layout.row()
862 row.prop(self, "ures")
863 row = layout.row()
864 row.prop(self, "vres")
865 row = layout.row()
866 row.prop(self, "urad")
867 row = layout.row()
868 row.prop(self, "vrad")
869 row = layout.row()
870 row.prop(self, "uellipse")
871 row = layout.row()
872 row.prop(self, "vellipse")
873 row = layout.row()
874 row.prop(self, "upart")
875 row = layout.row()
876 row.prop(self, "vpart")
877 row = layout.row()
878 row.prop(self, "ugap")
879 row.prop(self, "vgap")
880 row = layout.row()
882 elif tmp == 'Sphere':
883 col.label(text="Sphere Parameters")
884 row = layout.row()
885 row.prop(self, "bures")
886 row = layout.row()
887 row.prop(self, "bvres")
888 row = layout.row()
889 row.prop(self, "burad")
890 row = layout.row()
891 row.prop(self, "bupart")
892 row = layout.row()
893 row.prop(self, "buphase")
894 row = layout.row()
895 row.prop(self, "bvpart")
896 row = layout.row()
897 row.prop(self, "bvphase")
898 row = layout.row()
899 row.prop(self, "buellipse")
900 row = layout.row()
901 row.prop(self, "bvellipse")
902 elif tmp == 'Parabola':
903 col.label(text="Parabola Parameters")
904 row = layout.row()
905 row.prop(self, "paxres")
906 row = layout.row()
907 row.prop(self, "payres")
908 row = layout.row()
909 row.prop(self, "paxsz")
910 row = layout.row()
911 row.prop(self, "paysz")
912 row = layout.row()
913 row.prop(self, "paxell")
914 row = layout.row()
915 row.prop(self, "pagap")
916 row = layout.row()
917 row.prop(self, "pagphase")
918 elif tmp == 'Cylinder':
919 col.label(text="Cylinder Parameters")
920 col.prop(self, "cyxres")
921 col.prop(self, "cyyres")
922 col.prop(self, "cyxsz")
923 col.prop(self, "cyysz")
924 col.prop(self, "cyxell")
925 col.prop(self, "cygap")
926 col.prop(self, "cygphase")
927 elif tmp == 'Grid':
928 col.label(text="Grid Parameters")
929 row = layout.row()
930 row.prop(self, "grxres")
931 row = layout.row()
932 row.prop(self, "gryres")
933 row = layout.row()
934 row.prop(self, "grxsz")
935 row = layout.row()
936 row.prop(self, "grysz")
937 elif tmp == 'Import_your_mesh':
938 col.prop(self, "use_imported_mesh")
939 col.prop(self, "import_mesh_name")
940 # superform parameters only where possible
941 row = layout.row()
942 row.prop(self, "uact")
943 row = layout.row()
944 row.prop(self, "vact")
945 row = layout.row()
946 if tmp != 'Import_your_mesh':
947 if (self.uact is False) and (self.vact is False):
948 row.label(text="No checkbox active", icon="INFO")
949 else:
950 row.label(text="Superform Parameters")
951 if self.uact:
952 row = layout.row()
953 row.prop(self, "um")
954 row = layout.row()
955 row.prop(self, "un1")
956 row = layout.row()
957 row.prop(self, "un2")
958 row = layout.row()
959 row.prop(self, "un3")
960 row = layout.row()
961 row.prop(self, "ua")
962 row = layout.row()
963 row.prop(self, "ub")
964 row = layout.row()
965 row.prop(self, "uturn")
966 row = layout.row()
967 row.prop(self, "utwist")
968 if self.vact:
969 row = layout.row()
970 row.prop(self, "vm")
971 row = layout.row()
972 row.prop(self, "vn1")
973 row = layout.row()
974 row.prop(self, "vn2")
975 row = layout.row()
976 row.prop(self, "vn3")
977 row = layout.row()
978 row.prop(self, "va")
979 row = layout.row()
980 row.prop(self, "vb")
981 row = layout.row()
982 row.prop(self, "vturn")
983 row = layout.row()
984 row.prop(self, "vtwist")
985 box = layout.box()
986 if self.change == False:
987 col = layout.column(align=True)
988 col.prop(self, 'align', expand=True)
989 col = layout.column(align=True)
990 col.prop(self, 'location', expand=True)
991 col = layout.column(align=True)
992 col.prop(self, 'rotation', expand=True)
993 # einde superform
994 elif which_mainpages == "Hubs":
995 row = layout.row()
996 row.prop(self, "hubtoggle")
997 row = layout.row()
998 if self.hubimpmesh == "None":
999 row = layout.row()
1000 row.label(text="Name of a hub to use")
1001 row = layout.row()
1002 row.prop(self, "hubimpmesh")
1003 row = layout.row()
1004 if self.hmeshname == "None":
1005 row = layout.row()
1006 row.label(text="Name of mesh to be filled in")
1007 row = layout.row()
1008 row.prop(self, "hmeshname")
1009 row = layout.row()
1010 row.prop(self, "hwtog")
1011 if self.hwtog:
1012 row.prop(self, "hubwidth")
1013 row = layout.row()
1014 row.prop(self, "hhtog")
1015 if self.hhtog:
1016 row.prop(self, "hubheight")
1017 row = layout.row()
1018 row.prop(self, "hublength")
1019 elif which_mainpages == "Struts":
1020 row = layout.row()
1021 row.prop(self, "struttype")
1022 row.prop(self, "struttoggle")
1024 row = layout.row()
1025 row.prop(self, "strutimpmesh")
1026 row = layout.row()
1027 row.prop(self, "swtog")
1028 if self.swtog:
1029 row.prop(self, "strutwidth")
1030 row = layout.row()
1031 row.prop(self, "shtog")
1032 if self.shtog:
1033 row.prop(self, "strutheight")
1034 row = layout.row()
1035 row.prop(self, "sstog")
1036 if self.sstog:
1037 row.prop(self, "strutshrink")
1038 row = layout.row()
1039 row.prop(self, "stretch")
1040 row = layout.row()
1041 row.prop(self, "lift")
1042 row = layout.row()
1043 row.prop(self, "smeshname")
1044 elif which_mainpages == "Faces":
1045 row = layout.row()
1046 row.prop(self, "facetoggle")
1047 row = layout.row()
1048 row.prop(self, "face_use_imported_object")
1049 row = layout.row()
1050 row.prop(self, "facetype_menu")
1051 row = layout.row()
1052 row.prop(self, "fwtog")
1053 if self.fwtog:
1054 row.prop(self, "facewidth")
1055 row = layout.row()
1056 row.prop(self, "fhtog")
1057 if self.fhtog:
1058 row.prop(self, "faceheight")
1059 row = layout.row()
1060 row.prop(self, "face_detach")
1061 row = layout.row()
1062 row.prop(self, "fmeshname")
1063 row = layout.row()
1065 # help menu GUI
1066 elif which_mainpages == "Help":
1067 import textwrap
1069 # a function that allows for multiple labels with text that wraps
1070 # you can allow the user to set where the text wraps with the
1071 # text_width parameter
1072 # other parameters are ui : here you usually pass layout
1073 # text: is a list with each index representing a line of text
1075 def multi_label(text, ui, text_width=120):
1076 for x in range(0, len(text)):
1077 el = textwrap.wrap(text[x], width=text_width)
1079 for y in range(0, len(el)):
1080 ui.label(text=el[y])
1082 box = layout.box()
1083 help_text = ["To Use",
1084 "If normals look inverted:",
1085 "Once mesh is finished,",
1086 "You may recalc normals outside.",
1087 "--------",
1088 "To use your own mesh with the:",
1089 "Faces:",
1090 "Import your mesh in the:",
1091 "Objects: Geodesic menu.",
1092 "You must type in the name",
1093 "Of your custom object first.",
1094 "--------",
1095 "To use your own mesh with the: ",
1096 "Struts/Hubs:",
1097 "You must type in the name",
1098 "Of your custom object/s first,"]
1099 text_width = self.gd_help_text_width
1100 box.prop(self, "gd_help_text_width", slider=True)
1101 multi_label(help_text, box, text_width)
1103 def execute(self, context):
1105 global last_generated_object, last_imported_mesh, basegeodesic, imported_hubmesh_to_use, error_message
1106 # default superformparam = [3, 10, 10, 10, 1, 1, 4, 10, 10, 10, 1, 1, 0, 0, 0.0, 0.0, 0, 0]]
1107 superformparam = [self.um, self.un1, self.un2, self.un3, self.ua,
1108 self.ub, self.vm, self.vn1, self.vn2, self.vn3,
1109 self.va, self.vb, self.uact, self.vact,
1110 self.uturn * pi, self.vturn * pi,
1111 self.utwist, self.vtwist]
1112 error_message = ""
1113 mesh = None
1114 if self.mainpages == 'Main':
1115 if self.geodesic_types == "Geodesic":
1116 tmp_fs = self.tri_hex_star
1117 faceshape = 0 # tri!
1118 if tmp_fs == "hex":
1119 faceshape = 1
1120 elif tmp_fs == "star":
1121 faceshape = 2
1122 tmp_cl = self.geodesic_class
1123 klass = 0
1124 if tmp_cl == "Class_2":
1125 klass = 1
1126 shape = 0
1127 parameters = [self.frequency, self.eccentricity, self.squish,
1128 self.radius, self.squareness, self.squarez, 0,
1129 shape, self.baselevel, faceshape, self.dual,
1130 self.rotxy, self.rotz, klass, superformparam]
1132 basegeodesic = creategeo(self.base_type, self.orientation, parameters)
1133 basegeodesic.makegeodesic()
1134 basegeodesic.connectivity()
1135 basemesh = vefm_271.mesh()
1136 vefm_271.finalfill(basegeodesic, basemesh) # always! for hexifiy etc. necessary!!!
1137 mesh = vefm_271.vefm_add_object(basegeodesic)
1138 elif self.geodesic_types == 'Grid':
1139 basegeodesic = forms_271.grid(self.grxres, self.gryres,
1140 self.grxsz, self.grysz, 1.0, 1.0, 0, 0, 0,
1141 0, 1.0, 1.0, superformparam)
1142 mesh = vefm_271.vefm_add_object(basegeodesic)
1143 elif self.geodesic_types == "Cylinder":
1144 basegeodesic = forms_271.cylinder(
1145 self.cyxres, self.cyyres,
1146 self.cyxsz, self.cyysz, self.cygap,
1147 1.0, self.cygphase, 0, 0, 0, self.cyxell,
1148 1.0, superformparam
1150 mesh = vefm_271.vefm_add_object(basegeodesic)
1151 elif self.geodesic_types == "Parabola":
1152 basegeodesic = forms_271.parabola(
1153 self.paxres, self.payres,
1154 self.paxsz, self.paysz, self.pagap, 1.0, self.pagphase,
1155 0, 0, 0, self.paxell, 1.0, superformparam
1157 mesh = vefm_271.vefm_add_object(basegeodesic)
1158 elif self.geodesic_types == "Torus":
1159 basegeodesic = forms_271.torus(
1160 self.ures, self.vres,
1161 self.vrad, self.urad, self.upart, self.vpart,
1162 self.ugap, self.vgap, 0, 0, self.uellipse,
1163 self.vellipse, superformparam
1165 mesh = vefm_271.vefm_add_object(basegeodesic)
1166 elif self.geodesic_types == "Sphere":
1167 basegeodesic = forms_271.sphere(
1168 self.bures, self.bvres,
1169 self.burad, 1.0, self.bupart, self.bvpart,
1170 self.buphase, self.bvphase, 0, 0, self.buellipse,
1171 self.bvellipse, superformparam
1173 mesh = vefm_271.vefm_add_object(basegeodesic)
1174 elif self.geodesic_types == "Import_your_mesh":
1175 obj_name = self.import_mesh_name
1176 if obj_name == "None":
1177 message = "Fill in a name \nof an existing mesh\nto be imported"
1178 error_message = message
1179 self.report({"INFO"}, message)
1180 print("***INFO*** You have to fill in the name of an existing mesh")
1181 else:
1182 names = [el.name for el in context.scene.objects]
1183 if obj_name in names and context.scene.objects[obj_name].type == "MESH":
1184 obj = context.scene.objects[obj_name]
1185 your_obj = vefm_271.importmesh(obj.name, False)
1186 last_imported_mesh = your_obj
1187 mesh = vefm_271.vefm_add_object(your_obj)
1188 else:
1189 message = obj_name + " does not exist \nor is not a Mesh"
1190 error_message = message
1191 self.report({'ERROR'}, message)
1192 print("***ERROR***" + obj_name + " does not exist or is not a Mesh")
1193 elif self.mainpages == "Hubs":
1194 hubtype = self.hubtype
1195 hubtoggle = self.hubtoggle
1196 hubimporttoggle = self.hubimporttoggle
1197 hubimpmesh = self.hubimpmesh
1198 hubwidth = self.hubwidth
1199 hwtog = self.hwtog
1200 hubheight = self.hubheight
1201 hhtog = self.hhtog
1202 hublength = self.hublength
1203 hstog = self.hstog
1204 hmeshname = self.hmeshname
1206 if not (hmeshname == "None") and not (hubimpmesh == "None") and hubtoggle:
1207 try:
1208 hub_obj = vefm_271.importmesh(hmeshname, 0)
1210 hub = vefm_271.hub(
1211 hub_obj, True,
1212 hubwidth, hubheight, hublength,
1213 hwtog, hhtog, hstog, hubimpmesh
1215 hubmesh = vefm_271.mesh("test")
1216 vefm_271.finalfill(hub, hubmesh)
1217 mesh = vefm_271.vefm_add_object(hubmesh)
1218 except:
1219 message = "***ERROR*** \nEither no mesh for hub\nor " + \
1220 hmeshname + " available"
1221 error_message = message
1222 print(message)
1223 mesh = vefm_271.vefm_add_object(basegeodesic)
1224 else:
1225 message = "***INFO***\nEnable Hubs first"
1226 error_message = message
1227 print("\n***INFO*** Enable Hubs first")
1228 mesh = vefm_271.vefm_add_object(basegeodesic)
1229 elif self.mainpages == "Struts":
1230 struttype = self.struttype
1231 struttoggle = self.struttoggle
1232 strutimporttoggle = self.strutimporttoggle
1233 strutimpmesh = self.strutimpmesh
1234 strutwidth = self.strutwidth
1235 swtog = self.swtog
1236 strutheight = self.strutheight
1237 shtog = self.shtog
1238 strutshrink = self.strutshrink
1239 sstog = self.sstog
1240 stretch = self.stretch
1241 lift = self.lift
1242 smeshname = self.smeshname
1243 if not (strutimpmesh == "None") and struttoggle:
1244 names = [el.name for el in context.scene.objects]
1245 if strutimpmesh in names and context.scene.objects[strutimpmesh].type == "MESH":
1246 strut = vefm_271.strut(
1247 basegeodesic, struttype, strutwidth,
1248 strutheight, stretch, swtog, shtog, swtog,
1249 strutimpmesh, sstog, lift
1251 strutmesh = vefm_271.mesh()
1252 vefm_271.finalfill(strut, strutmesh)
1253 mesh = vefm_271.vefm_add_object(strutmesh)
1254 else:
1255 message = "***ERROR***\nStrut object " + strutimpmesh + "\nis not a Mesh"
1256 error_message = message
1257 print("***ERROR*** Strut object is not a Mesh")
1258 else:
1259 mesh = vefm_271.vefm_add_object(basegeodesic)
1260 elif self.mainpages == "Faces":
1261 if self.facetoggle:
1262 faceparams = [[self.face_detach, 0, [[0.5, 0.0]]], # 0 strip
1263 [self.face_detach, 0, [[0.0, 0.5]]], # 1 vertical
1264 [self.face_detach, 0, [[0.5, 0.5]]], # 2 slanted
1265 [self.face_detach, 1, [[0.25, 0.25], [0.5, 0.5]]], # 3 closed point
1266 [self.face_detach, 1, [[0.1, 0.03], [0.33, 0.06], [0.0, 0.1]]], # 4 pillow
1267 [self.face_detach, 2, [[0.0, 0.5]]], # 5 closed vertical
1268 [self.face_detach, 2, [[0.0, 0.25], [0.25, 0.25], [0.25, 0.5]]], # 6 stepped
1269 [self.face_detach, 1, [[0.2, 0.1], [0.4, 0.2], [0.0, 1.0]]], # 7 spikes
1270 [self.face_detach, 3, [[0.25, 0.0], [0.25, 0.5], [0.0, 0.5]]], # 8 boxed
1271 [self.face_detach, 3, [[0.25, 0.5], [0.5, 0.0], [0.25, -0.5]]], # 9 diamond
1272 [self.face_detach, 4, [[0.5, 0.0], [0.5, 0.5], [0.0, 0.5]]], ] # 10 bar
1273 facedata = faceparams[int(self.facetype_menu)]
1274 if not self.face_use_imported_object:
1275 faceobject = vefm_271.facetype(
1276 basegeodesic, facedata, self.facewidth,
1277 self.faceheight, self.fwtog
1279 else:
1280 if last_imported_mesh:
1281 faceobject = vefm_271.facetype(
1282 last_imported_mesh, facedata,
1283 self.facewidth, self.faceheight, self.fwtog
1285 else:
1286 message = "***ERROR***\nNo imported message available\n" + "last geodesic used"
1287 error_message = message
1288 print("\n***ERROR*** No imported mesh available \nLast geodesic used!")
1289 faceobject = vefm_271.facetype(
1290 basegeodesic, facedata,
1291 self.facewidth, self.faceheight, self.fwtog
1293 facemesh = vefm_271.mesh()
1294 finalfill(faceobject, facemesh)
1295 mesh = vefm_271.vefm_add_object(facemesh)
1297 if mesh != None:
1298 if bpy.context.mode == "OBJECT":
1299 if context.selected_objects != [] and context.active_object and \
1300 (context.active_object.data is not None) and \
1301 ('GeodesicDome' in context.active_object.data.keys()) and (self.change == True):
1302 obj = context.active_object
1303 oldmesh = obj.data
1304 oldmeshname = obj.data.name
1305 obj.data = mesh
1306 for material in oldmesh.materials:
1307 obj.data.materials.append(material)
1308 bpy.data.meshes.remove(oldmesh)
1309 obj.data.name = oldmeshname
1310 else:
1311 obj = object_utils.object_data_add(context, mesh, operator=self)
1313 obj.data["GeodesicDome"] = True
1314 obj.data["change"] = False
1315 for prm in GeodesicDomeParameters():
1316 obj.data[prm] = getattr(self, prm)
1318 if bpy.context.mode == "EDIT_MESH":
1319 active_object = context.active_object
1320 name_active_object = active_object.name
1321 bpy.ops.object.mode_set(mode='OBJECT')
1322 obj = object_utils.object_data_add(context, mesh, operator=self)
1323 obj.select_set(True)
1324 active_object.select_set(True)
1325 bpy.ops.object.join()
1326 context.active_object.name = name_active_object
1327 bpy.ops.object.mode_set(mode='EDIT')
1329 return {'FINISHED'}
1331 def invoke(self, context, event):
1332 global basegeodesic, geodesic_not_yet_called
1333 if geodesic_not_yet_called:
1334 geodesic_not_yet_called = False
1335 bpy.context.view_layer.update()
1336 self.execute(context)
1338 return {'FINISHED'}
1341 def creategeo(polytype, orientation, parameters):
1342 geo = None
1343 if polytype == "Tetrahedron":
1344 if orientation == "PointUp":
1345 geo = geodesic_classes_271.tetrahedron(parameters)
1346 elif orientation == "EdgeUp":
1347 geo = geodesic_classes_271.tetraedge(parameters)
1348 elif orientation == "FaceUp":
1349 geo = geodesic_classes_271.tetraface(parameters)
1350 elif polytype == "Octahedron":
1351 if orientation == "PointUp":
1352 geo = geodesic_classes_271.octahedron(parameters)
1353 elif orientation == "EdgeUp":
1354 geo = geodesic_classes_271.octaedge(parameters)
1355 elif orientation == "FaceUp":
1356 geo = geodesic_classes_271.octaface(parameters)
1357 elif polytype == "Icosahedron":
1358 if orientation == "PointUp":
1359 geo = geodesic_classes_271.icosahedron(parameters)
1360 elif orientation == "EdgeUp":
1361 geo = geodesic_classes_271.icoedge(parameters)
1362 elif orientation == "FaceUp":
1363 geo = geodesic_classes_271.icoface(parameters)
1364 return geo
1367 basegeodesic, fmeshname, smeshname, hmeshname, outputmeshname, strutimpmesh, hubimpmesh = [None] * 7
1370 def finalfill(source, target):
1371 count = 0
1372 for point in source.verts:
1373 newvert = vefm_271.vertex(point.vector)
1374 target.verts.append(newvert)
1375 point.index = count
1376 count += 1
1377 for facey in source.faces:
1378 row = len(facey.vertices)
1379 if row >= 5:
1380 newvert = vefm_271.average(facey.vertices).centroid()
1381 centre = vefm_271.vertex(newvert.vector)
1382 target.verts.append(centre)
1383 for i in range(row):
1384 if i == row - 1:
1385 a = target.verts[facey.vertices[-1].index]
1386 b = target.verts[facey.vertices[0].index]
1387 else:
1388 a = target.verts[facey.vertices[i].index]
1389 b = target.verts[facey.vertices[i + 1].index]
1390 c = centre
1391 f = [a, b, c]
1392 target.faces.append(f)
1393 else:
1394 f = []
1395 for j in range(len(facey.vertices)):
1397 a = facey.vertices[j]
1398 f.append(target.verts[a.index])
1399 target.faces.append(f)
1402 # for error messages
1403 class DialogOperator(Operator):
1404 bl_idname = "object.dialog_operator"
1405 bl_label = "INFO"
1407 def draw(self, context):
1408 layout = self.layout
1409 message = error_message
1410 col = layout.column()
1411 tmp = message.split("\n")
1412 for el in tmp:
1413 col.label(text = "")
1415 def execute(self, context):
1416 return {'FINISHED'}
1418 def invoke(self, context, event):
1419 wm = context.window_manager
1420 return wm.invoke_props_dialog(self)
1423 def GeodesicDomeParameters():
1424 GeodesicDomeParameters = [
1425 "gd_help_text_width",
1426 "mainpages",
1427 "facetype_menu",
1428 "facetoggle",
1429 "face_use_imported_object",
1430 "facewidth",
1431 "fwtog",
1432 "faceheight",
1433 "fhtog",
1434 "face_detach",
1435 "fmeshname",
1436 "geodesic_types",
1437 "import_mesh_name",
1438 "base_type",
1439 "orientation",
1440 "geodesic_class",
1441 "tri_hex_star",
1442 "spherical_flat",
1443 "use_imported_mesh",
1444 "cyxres",
1445 "cyyres",
1446 "cyxsz",
1447 "cyysz",
1448 "cyxell",
1449 "cygap",
1450 "cygphase",
1451 "paxres",
1452 "payres",
1453 "paxsz",
1454 "paysz",
1455 "paxell",
1456 "pagap",
1457 "pagphase",
1458 "ures",
1459 "vres",
1460 "urad",
1461 "vrad",
1462 "uellipse",
1463 "vellipse",
1464 "upart",
1465 "vpart",
1466 "ugap",
1467 "vgap",
1468 "uphase",
1469 "vphase",
1470 "uexp",
1471 "vexp",
1472 "usuper",
1473 "vsuper",
1474 "utwist",
1475 "vtwist",
1476 "bures",
1477 "bvres",
1478 "burad",
1479 "bupart",
1480 "bvpart",
1481 "buphase",
1482 "bvphase",
1483 "buellipse",
1484 "bvellipse",
1485 "grxres",
1486 "gryres",
1487 "grxsz",
1488 "grysz",
1489 "cart",
1490 "frequency",
1491 "eccentricity",
1492 "squish",
1493 "radius",
1494 "squareness",
1495 "squarez",
1496 "baselevel",
1497 "dual",
1498 "rotxy",
1499 "rotz",
1500 "uact",
1501 "vact",
1502 "um",
1503 "un1",
1504 "un2",
1505 "un3",
1506 "ua",
1507 "ub",
1508 "vm",
1509 "vn1",
1510 "vn2",
1511 "vn3",
1512 "va",
1513 "vb",
1514 "uturn",
1515 "vturn",
1516 "utwist",
1517 "vtwist",
1518 "struttype",
1519 "struttoggle",
1520 "strutimporttoggle",
1521 "strutimpmesh",
1522 "strutwidth",
1523 "swtog",
1524 "strutheight",
1525 "shtog",
1526 "strutshrink",
1527 "sstog",
1528 "stretch",
1529 "lift",
1530 "smeshname",
1531 "hubtype",
1532 "hubtoggle",
1533 "hubimporttoggle",
1534 "hubimpmesh",
1535 "hubwidth",
1536 "hwtog",
1537 "hubheight",
1538 "hhtog",
1539 "hublength",
1540 "hstog",
1541 "hmeshname",
1543 return GeodesicDomeParameters