Skip to content

Commit

Permalink
added mesh grading plugin (original commit hziegelwanger 2016-07-25)
Browse files Browse the repository at this point in the history
  • Loading branch information
f-brinkmann committed Sep 23, 2020
1 parent 56f24bb commit f108864
Show file tree
Hide file tree
Showing 12 changed files with 2,135 additions and 466 deletions.
83 changes: 41 additions & 42 deletions Mesh2Input/Source/export_evaluationgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@
# Copyright (C) 2015 by Harald Ziegelwanger,
# Acoustics Research Institute, Austrian Academy of Sciences
# mesh2hrtf.sourceforge.net
#
#
# Mesh2HRTF is licensed under the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# Mesh2HRTF 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 Lesser General Public License for more details.
# You should have received a copy of the GNU LesserGeneral Public License along with Mesh2HRTF. If not, see <http://www.gnu.org/licenses/lgpl.html>.
#
#
# If you use Mesh2HRTF:
# - Provide credits:
# "Mesh2HRTF, H. Ziegelwanger, ARI, OEAW (mesh2hrtf.sourceforge.net)"
# - In your publication, cite both articles:
# [1] Ziegelwanger, H., Kreuzer, W., and Majdak, P. (2015). "Mesh2HRTF: Open-source software package for the numerical calculation of head-related transfer functions," in Proceedings of the 22nd ICSV, Florence, IT.
# [2] Ziegelwanger, H., Majdak, P., and Kreuzer, W. (2015). "Numerical calculation of listener-specific head-related transfer functions and sound localization: Microphone model and mesh discretization," The Journal of the Acoustical Society of America, 138, 208-222.

import os
import bpy
from bpy.props import StringProperty, EnumProperty, IntProperty
from bpy_extras.io_utils import ExportHelper

bl_info = {
"name": "Export Evaluation Grid",
"author": "Harald Ziegelwanger",
"version": (0, 1, 3),
"blender": (2, 72),
"blender": (2, 76),
"location": "File > Import-Export",
"description": "Export evaluation grid",
"warning": "",
Expand All @@ -27,14 +32,6 @@
"support": "COMMUNITY",
"category": "Import-Export"}

import os
import bpy
import datetime
import math
import shutil
from math import pi
from bpy.props import CollectionProperty, StringProperty, BoolProperty, EnumProperty, IntProperty
from bpy_extras.io_utils import ImportHelper, ExportHelper

class ExportEvaluationgrid(bpy.types.Operator, ExportHelper):
'''Export a single object as an evaluation grid'''
Expand All @@ -45,30 +42,29 @@ class ExportEvaluationgrid(bpy.types.Operator, ExportHelper):
filter_glob = StringProperty(default="*.txt", options={'HIDDEN'})

offset = IntProperty(
name = "Offset",
name="Offset",
description="Node and element index offset",
default=0,
min=0,
max=10000000,
)
suffix = StringProperty(
name = "Element suffix",
name="Element suffix",
description="Element suffix",
default=" 2 0 1",
)
unit = EnumProperty(
name = "Unit",
name="Unit",
description="Unit of the evaluation grid",
items=[('m','m','Meter'),('mm','mm','Millimeter')],
items=[('m', 'm', 'Meter'), ('mm', 'mm', 'Millimeter')],
default='mm',
)

@classmethod
def poll(cls, context):
return context.active_object != None
return context.active_object is not None

def execute(self, context):
# DialogPanel.draw(self, context)
filepath = self.filepath
filepath = bpy.path.ensure_ext(filepath, self.filename_ext)
keywords = self.as_keywords(ignore=("check_existing", "filter_glob"))
Expand All @@ -85,67 +81,70 @@ def draw(self, context):
row.prop(self, "unit")

def save(operator,
context,
filepath="",
offset=0,
suffix=" 2 0 1",
unit='mm',
):
context,
filepath="",
offset=0,
suffix=" 2 0 1",
unit='mm',
):

def rvec3d(v):
return round(v[0], 6), round(v[1], 6), round(v[2], 6)

def rvec2d(v):
return round(v[0], 6), round(v[1], 6)

#------------------------ Initialize constants -------------------------------------------
# ----------------------- Initialize constants -------------------------------------------
obj = context.active_object

if not obj:
raise Exception("Error, Select 1 active object")
obj_data=obj.data

unitFactor=1
if unit=='mm':
unitFactor=0.001
(filepath,filename) = os.path.split(filepath)
#------------------------ Write object data ----------------------------------------------
obj_data=obj.data

obj_data = obj.data

unitFactor = 1
if unit == 'mm':
unitFactor = 0.001

(filepath, filename) = os.path.split(filepath)

# ----------------------- Write object data ----------------------------------------------
obj_data = obj.data
file = open(("%s/Nodes.txt" % filepath), "w", encoding="utf8", newline="\n")
fw = file.write
fw("%i\n" % len(obj_data.vertices[:]))
for ii in range(len(obj_data.vertices[:])):
fw("%i " % (ii+offset))
fw("%.6f %.6f %.6f\n" % (obj_data.vertices[ii].co[0]*unitFactor,obj_data.vertices[ii].co[1]*unitFactor,obj_data.vertices[ii].co[2]*unitFactor))
fw("%.6f %.6f %.6f\n" % (obj_data.vertices[ii].co[0]*unitFactor, obj_data.vertices[ii].co[1]*unitFactor, obj_data.vertices[ii].co[2]*unitFactor))
file.close

file = open(("%s/Elements.txt" % filepath), "w", encoding="utf8", newline="\n")
fw = file.write
fw = file.write
fw("%i\n" % len(obj_data.polygons[:]))
if len(obj_data.polygons[0].vertices[:]) == 3:
for ii in range(len(obj_data.polygons[:])):
fw("%i " % (ii+offset))
fw("%d %d %d" % (obj_data.polygons[ii].vertices[0]+offset,obj_data.polygons[ii].vertices[1]+offset,obj_data.polygons[ii].vertices[2]+offset))
fw("%d %d %d" % (obj_data.polygons[ii].vertices[0]+offset, obj_data.polygons[ii].vertices[1]+offset, obj_data.polygons[ii].vertices[2]+offset))
fw("%s\n" % suffix)
else:
for ii in range(len(obj_data.polygons[:])):
fw("%i " % (ii+offset))
fw("%d %d %d %d" % (obj_data.polygons[ii].vertices[0]+offset,obj_data.polygons[ii].vertices[1]+offset,obj_data.polygons[ii].vertices[2]+offset,obj_data.polygons[ii].vertices[3]+offset))
fw("%d %d %d %d" % (obj_data.polygons[ii].vertices[0]+offset, obj_data.polygons[ii].vertices[1]+offset, obj_data.polygons[ii].vertices[2]+offset, obj_data.polygons[ii].vertices[3]+offset))
fw("%s\n" % suffix)
file.close

return {'FINISHED'}


def menu_func_export(self, context):
self.layout.operator(ExportEvaluationgrid.bl_idname, text="Evaluation grid (.txt)")


def register():
bpy.utils.register_class(ExportEvaluationgrid)
bpy.types.INFO_MT_file_export.append(menu_func_export)


def unregister():
bpy.utils.unregister_class(ExportEvaluationgrid)
bpy.types.INFO_MT_file_export.remove(menu_func_export)
bpy.types.INFO_MT_file_export.remove(menu_func_export)
Loading

0 comments on commit f108864

Please sign in to comment.