1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
6 from bpy
.types
import Operator
, AddonPreferences
7 from bpy_extras
.io_utils
import ImportHelper
, ExportHelper
8 from bpy
.props
import (
16 from io_mesh_atomic
.xyz_import
import import_xyz
17 from io_mesh_atomic
.xyz_import
import ALL_FRAMES
18 from io_mesh_atomic
.xyz_import
import ELEMENTS
19 from io_mesh_atomic
.xyz_import
import STRUCTURE
20 from io_mesh_atomic
.xyz_import
import build_frames
21 from io_mesh_atomic
.xyz_export
import export_xyz
23 # -----------------------------------------------------------------------------
26 # This is the class for the file dialog.
27 class IMPORT_OT_xyz(Operator
, ImportHelper
):
28 bl_idname
= "import_mesh.xyz"
29 bl_label
= "Import XYZ (*.xyz)"
30 bl_options
= {'PRESET', 'UNDO'}
33 filter_glob
: StringProperty(default
="*.xyz", options
={'HIDDEN'},)
35 use_camera
: BoolProperty(
36 name
="Camera", default
=False,
37 description
="Do you need a camera?")
38 use_lamp
: BoolProperty(
39 name
="Lamp", default
=False,
40 description
= "Do you need a lamp?")
43 description
="Choose ball",
44 items
=(('0', "NURBS", "NURBS balls"),
45 ('1', "Mesh" , "Mesh balls"),
46 ('2', "Meta" , "Metaballs")),
48 mesh_azimuth
: IntProperty(
49 name
= "Azimuth", default
=32, min=1,
50 description
= "Number of sectors (azimuth)")
51 mesh_zenith
: IntProperty(
52 name
= "Zenith", default
=32, min=1,
53 description
= "Number of sectors (zenith)")
54 scale_ballradius
: FloatProperty(
55 name
= "Balls", default
=1.0, min=0.0001,
56 description
= "Scale factor for all atom radii")
57 scale_distances
: FloatProperty (
58 name
= "Distances", default
=1.0, min=0.0001,
59 description
= "Scale factor for all distances")
60 atomradius
: EnumProperty(
61 name
="Type of radius",
62 description
="Choose type of atom radius",
63 items
=(('0', "Pre-defined", "Use pre-defined radius"),
64 ('1', "Atomic", "Use atomic radius"),
65 ('2', "van der Waals", "Use van der Waals radius")),
67 use_center
: BoolProperty(
68 name
= "Object to origin (first frames)", default
=False,
69 description
= "Put the object into the global origin, the first frame only")
70 use_center_all
: BoolProperty(
71 name
= "Object to origin (all frames)", default
=True,
72 description
= "Put the object into the global origin, all frames")
73 datafile
: StringProperty(
74 name
= "", description
="Path to your custom data file",
75 maxlen
= 256, default
= "", subtype
='FILE_PATH')
76 use_frames
: BoolProperty(
77 name
= "Load all frames?", default
=False,
78 description
= "Do you want to load all frames?")
79 skip_frames
: IntProperty(
80 name
="", default
=0, min=0,
81 description
="Number of frames you want to skip")
82 images_per_key
: IntProperty(
83 name
="", default
=1, min=1,
84 description
="Choose the number of images between 2 keys")
86 # This thing here just guarantees that the menu entry is not active when the
87 # check box in the addon preferences is not activated! See __init__.py
89 def poll(cls
, context
):
90 pref
= context
.preferences
91 return pref
.addons
[__package__
].preferences
.bool_xyz
93 def draw(self
, context
):
96 row
.prop(self
, "use_camera")
97 row
.prop(self
, "use_lamp")
99 row
.prop(self
, "use_center")
101 row
.prop(self
, "use_center_all")
105 row
.label(text
="Balls / atoms")
108 col
.prop(self
, "ball")
110 row
.active
= (self
.ball
== "1")
111 col
= row
.column(align
=True)
112 col
.prop(self
, "mesh_azimuth")
113 col
.prop(self
, "mesh_zenith")
116 col
.label(text
="Scaling factors")
117 col
= row
.column(align
=True)
118 col
.prop(self
, "scale_ballradius")
119 col
.prop(self
, "scale_distances")
121 row
.prop(self
, "atomradius")
125 row
.label(text
="Frames")
127 row
.prop(self
, "use_frames")
129 row
.active
= self
.use_frames
131 col
.label(text
="Skip frames")
133 col
.prop(self
, "skip_frames")
135 row
.active
= self
.use_frames
137 col
.label(text
="Frames/key")
139 col
.prop(self
, "images_per_key")
141 def execute(self
, context
):
142 # Switch to 'OBJECT' mode when in 'EDIT' mode.
143 if bpy
.context
.mode
== 'EDIT_MESH':
144 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
150 # This is to determine the path.
151 filepath_xyz
= bpy
.path
.abspath(self
.filepath
)
153 # Execute main routine
154 import_xyz(self
.ball
,
157 self
.scale_ballradius
,
159 self
.scale_distances
,
167 if len(ALL_FRAMES
) > 1 and self
.use_frames
:
169 build_frames(self
.images_per_key
, self
.skip_frames
)
174 # This is the class for the file dialog of the exporter.
175 class EXPORT_OT_xyz(Operator
, ExportHelper
):
176 bl_idname
= "export_mesh.xyz"
177 bl_label
= "Export XYZ (*.xyz)"
178 filename_ext
= ".xyz"
180 filter_glob
: StringProperty(
181 default
="*.xyz", options
={'HIDDEN'},)
183 atom_xyz_export_type
: EnumProperty(
184 name
="Type of Objects",
185 description
="Choose type of objects",
186 items
=(('0', "All", "Export all active objects"),
187 ('1', "Elements", "Export only those active objects which have"
188 " a proper element name")),
191 # This thing here just guarantees that the menu entry is not active when the
192 # check box in the addon preferences is not activated! See __init__.py
194 def poll(cls
, context
):
195 pref
= context
.preferences
196 return pref
.addons
[__package__
].preferences
.bool_xyz
198 def draw(self
, context
):
201 row
.prop(self
, "atom_xyz_export_type")
203 def execute(self
, context
):
204 export_xyz(self
.atom_xyz_export_type
, bpy
.path
.abspath(self
.filepath
))