├── help ├── editElem.png ├── createElem.png ├── showFiltering.png ├── index.html └── info.svg ├── README.md ├── plot.py ├── user_defined_common.py ├── ns_node.py ├── __init__.py ├── friction.py ├── database_module.py ├── shape.py ├── driver.py ├── menu.py ├── common.py ├── input_card.py ├── matrix.py ├── user_defined_element.py ├── function.py ├── LICENSE └── simulator.py /help/editElem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdbaldw/BlenderAndMBDyn/HEAD/help/editElem.png -------------------------------------------------------------------------------- /help/createElem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdbaldw/BlenderAndMBDyn/HEAD/help/createElem.png -------------------------------------------------------------------------------- /help/showFiltering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdbaldw/BlenderAndMBDyn/HEAD/help/showFiltering.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlenderAndMBDyn 2 | Combines Blender's graphical interface and rendering capabilities with MBDyn's multi-body dynamics, aerodynamics, and aeroelastics simulation and analysis, for rapid modeling and realistic rendering of physics based multi-body simulations. 3 | 4 | For a very brief video introduction, watch here: https://www.youtube.com/watch?v=Fb4ExUd_mGI 5 | -------------------------------------------------------------------------------- /plot.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | import matplotlib.pyplot as plt 26 | import pandas as pd 27 | import sys 28 | 29 | with sys.stdin as f: 30 | name = f.readline().strip() 31 | pd.read_csv(f, index_col=0).plot() 32 | plt.gcf().canvas.set_window_title(name) 33 | plt.xlabel("Time (in seconds)") 34 | plt.show() 35 | 36 | -------------------------------------------------------------------------------- /user_defined_common.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | from .common import Tree 26 | 27 | collision_tree = Tree([ 28 | ("Collision world", None), 29 | ("Box", 2), 30 | ("Capsule", 2), 31 | ("Cone", 2), 32 | ("Plane", 2), 33 | ("Sphere", 2)]) 34 | 35 | # Each module 36 | tree = Tree([ 37 | ("Module load", None), 38 | ("Sandbox", 2), 39 | ("Collision", collision_tree)]) 40 | 41 | # Types in this list will become MBDyn elements, in order 42 | loadable_element_types = [ 43 | "Sandbox", 44 | "Box", 45 | "Capsule", 46 | "Cone", 47 | "Plane", 48 | "Sphere", 49 | "Collision world"] 50 | 51 | # Types in these lists will become MBDyn nodes 52 | structural_static_types = [] 53 | 54 | structural_dynamic_types = [] 55 | 56 | # Types in this list will be be handled like a Rigid offset 57 | offset_types = ["Box", "Cone", "Capsule", "Plane", "Sphere"] 58 | -------------------------------------------------------------------------------- /ns_node.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | if "bpy" in locals(): 26 | import imp 27 | for x in [base]: 28 | imp.reload(x) 29 | else: 30 | from . import base 31 | from .base import bpy, database, Operator, Entity, Bundle 32 | 33 | types = [ 34 | "Electric", 35 | "Abstract", 36 | "Hydraulic", 37 | "Parameter"] 38 | 39 | tree = ["NS Node", types] 40 | 41 | klasses = dict() 42 | 43 | class Base(Operator): 44 | bl_label = "NS Nodes" 45 | bl_options = {'DEFAULT_CLOSED'} 46 | @classmethod 47 | def poll(cls, context): 48 | return True 49 | @classmethod 50 | def make_list(self, ListItem): 51 | bpy.types.Scene.ns_node_uilist = bpy.props.CollectionProperty(type = ListItem) 52 | bpy.types.Scene.ns_node_index = bpy.props.IntProperty(default=-1) 53 | @classmethod 54 | def delete_list(self): 55 | del bpy.types.Scene.ns_node_uilist 56 | del bpy.types.Scene.ns_node_index 57 | @classmethod 58 | def get_uilist(self, context): 59 | return context.scene.ns_node_index, context.scene.ns_node_uilist 60 | def set_index(self, context, value): 61 | context.scene.ns_node_index = value 62 | 63 | for t in types: 64 | class Tester(Base): 65 | bl_label = t 66 | @classmethod 67 | def poll(cls, context): 68 | return False 69 | def create_entity(self): 70 | return Entity(self.name) 71 | klasses[t] = Tester 72 | 73 | bundle = Bundle(tree, Base, klasses, database.ns_node) 74 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | bl_info = { 26 | "name": "MBDyn Modeling and Simulation", 27 | "author": "G Douglas Baldwin", 28 | "version": (2, 0), 29 | "blender": (2, 7, 2), 30 | "location": "View3D", 31 | "description": "Provides an MBDyn multibody dynamic model design and presentation environment.", 32 | "warning": "", 33 | "wiki_url": "", 34 | "category": "STEM"} 35 | 36 | if "BPY" in locals(): 37 | import imp 38 | for x in [element, constitutive, drive, driver, input_card, friction, function, matrix, 39 | # ns_node, 40 | shape, definition, simulator, base]: 41 | imp.reload(x) 42 | else: 43 | from . import base 44 | from . import element 45 | from . import drive 46 | from . import driver 47 | from . import friction 48 | from . import shape 49 | from . import function 50 | # from . import ns_node 51 | from . import constitutive 52 | from . import matrix 53 | from . import input_card 54 | from . import definition 55 | from . import simulator 56 | from .base import BPY 57 | 58 | modules = [element, constitutive, drive, driver, input_card, friction, function, matrix, 59 | # ns_node, 60 | shape, definition, simulator] 61 | 62 | def register(): 63 | BPY.register() 64 | for module in modules: 65 | module.bundle.register() 66 | 67 | def unregister(): 68 | BPY.unregister() 69 | for module in modules: 70 | module.bundle.unregister() 71 | 72 | if __name__ == "__main__": 73 | register() 74 | -------------------------------------------------------------------------------- /friction.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | if "bpy" in locals(): 26 | import imp 27 | for x in [base, menu]: 28 | imp.reload(x) 29 | else: 30 | from . import base 31 | from . import menu 32 | from .base import bpy, BPY, database, Operator, Entity, Bundle 33 | from .menu import default_klasses, friction_tree 34 | 35 | class Base(Operator): 36 | bl_label = "Frictions" 37 | bl_options = {'DEFAULT_CLOSED'} 38 | @classmethod 39 | def poll(cls, context): 40 | return True 41 | @classmethod 42 | def make_list(self, ListItem): 43 | bpy.types.Scene.friction_uilist = bpy.props.CollectionProperty(type = ListItem) 44 | bpy.types.Scene.friction_index = bpy.props.IntProperty(default=-1) 45 | @classmethod 46 | def delete_list(self): 47 | del bpy.types.Scene.friction_uilist 48 | del bpy.types.Scene.friction_index 49 | @classmethod 50 | def get_uilist(self, context): 51 | return context.scene.friction_index, context.scene.friction_uilist 52 | def set_index(self, context, value): 53 | context.scene.friction_index = value 54 | def prereqs(self, context): 55 | pass 56 | 57 | klasses = default_klasses(friction_tree, Base) 58 | 59 | class Modlugre(Entity): 60 | def string(self): 61 | string = ("modlugre, " + BPY.FORMAT(self.sigma0) + ", " + BPY.FORMAT(self.sigma1) + ", " + BPY.FORMAT(self.sigma2) + ", " + BPY.FORMAT(self.kappa) + ",\n" + 62 | "\t\t\t\"" + self.function.name + "\", ") 63 | if self.radius is not None: 64 | string += "simple plane hinge, " + BPY.FORMAT(self.radius) 65 | else: 66 | string += "simple" 67 | return string 68 | 69 | class ModlugreOperator(Base): 70 | bl_label = "Modlugre" 71 | sigma0 = bpy.props.PointerProperty(type = BPY.Float) 72 | sigma1 = bpy.props.PointerProperty(type = BPY.Float) 73 | sigma2 = bpy.props.PointerProperty(type = BPY.Float) 74 | kappa = bpy.props.PointerProperty(type = BPY.Float) 75 | radius = bpy.props.PointerProperty(type = BPY.Float) 76 | function = bpy.props.PointerProperty(type = BPY.Function) 77 | def prereqs(self, context): 78 | self.sigma0.mandatory = True 79 | self.sigma1.mandatory = True 80 | self.sigma2.mandatory = True 81 | self.kappa.mandatory = True 82 | self.function.mandatory = True 83 | def assign(self, context): 84 | self.sigma0.assign(self.entity.sigma0) 85 | self.sigma1.assign(self.entity.sigma1) 86 | self.sigma2.assign(self.entity.sigma2) 87 | self.kappa.assign(self.entity.kappa) 88 | self.radius.assign(self.entity.radius) 89 | self.function.assign(self.entity.function) 90 | def store(self, context): 91 | self.entity.sigma0 = self.sigma0.store() 92 | self.entity.sigma1 = self.sigma1.store() 93 | self.entity.sigma2 = self.sigma2.store() 94 | self.entity.kappa = self.kappa.store() 95 | self.entity.radius = self.radius.store() 96 | self.entity.function = self.function.store() 97 | def draw(self, context): 98 | layout = self.layout 99 | self.sigma0.draw(layout, "Sigma0") 100 | self.sigma1.draw(layout, "Sigma1") 101 | self.sigma2.draw(layout, "Sigma2") 102 | self.kappa.draw(layout, "Kappa") 103 | self.radius.draw(layout, "Radius") 104 | self.function.draw(layout, "function") 105 | def check(self, context): 106 | return True in [v.check(context) for v in [self.sigma0, self.sigma1, self.sigma2, self.kappa, self.radius, self.function]] 107 | def create_entity(self): 108 | return Modlugre(self.name) 109 | 110 | klasses[ModlugreOperator.bl_label] = ModlugreOperator 111 | 112 | bundle = Bundle(friction_tree, Base, klasses, database.friction) 113 | -------------------------------------------------------------------------------- /database_module.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | import bpy 26 | import gc 27 | from io import BytesIO 28 | import pickle 29 | from base64 import b64encode, b64decode 30 | 31 | class Pickler(pickle.Pickler): 32 | def persistent_id(self, obj): 33 | return repr(obj) if repr(obj).startswith("bpy.data") else None 34 | 35 | class Unpickler(pickle.Unpickler): 36 | def persistent_load(self, pid): 37 | if not pid.startswith("bpy.data") and len(pid.split()) == 1: 38 | raise pickle.UnpicklingError(pid + " is forbidden") 39 | exec("id_data = " + pid) 40 | name = locals()["id_data"].mbdyn_name 41 | exec("id_data = " + pid.split("[")[0] + "[\"" + name + "\"]") 42 | return locals()["id_data"] 43 | def find_class(self, module, name): 44 | if module.startswith("BlenderAndMBDyn"): 45 | module = ".".join((__package__, module.split(".", 1)[1])) 46 | elif module == "builtins" and name in ("exec", "eval"): 47 | raise pickle.UnpicklingError("global " + ".".join((module, name)) + " is forbidden") 48 | return super().find_class(module, name) 49 | 50 | class EntityLookupError(LookupError): 51 | pass 52 | 53 | class Entities(list): 54 | def filter(self, types, obj=None): 55 | if isinstance(types, str): 56 | types = [types,] 57 | return [e for e in self if e.type in types and 58 | (not obj or (hasattr(e, "objects") and e.objects[0] == obj))] 59 | def get_by_name(self, name): 60 | if name != "New": 61 | for e in self: 62 | if e.name == name: 63 | return e 64 | raise EntityLookupError 65 | def move(self, i, j): 66 | self[i], self[j] = self[j], self[i] 67 | 68 | class Database: 69 | def __init__(self): 70 | self.compatibility_stamp = 0 71 | self.element = Entities() 72 | self.drive = Entities() 73 | self.driver = Entities() 74 | self.friction = Entities() 75 | self.shape = Entities() 76 | self.function = Entities() 77 | # self.ns_node = Entities() 78 | self.constitutive = Entities() 79 | self.matrix = Entities() 80 | self.input_card = Entities() 81 | self.definition = Entities() 82 | self.simulator = Entities() 83 | self.node = list() 84 | self.clear() 85 | def clear(self): 86 | self.element.clear() 87 | self.drive.clear() 88 | self.driver.clear() 89 | self.friction.clear() 90 | self.shape.clear() 91 | self.function.clear() 92 | # self.ns_node.clear() 93 | self.constitutive.clear() 94 | self.matrix.clear() 95 | self.input_card.clear() 96 | self.definition.clear() 97 | self.simulator.clear() 98 | self.node.clear() 99 | self.scene = None 100 | def all_entities(self): 101 | return (self.element + self.drive + self.driver + self.friction + self.shape + self.function + 102 | # self.ns_node + 103 | self.constitutive + self.matrix + self.input_card + self.definition + self.simulator) 104 | def entities_using(self, objects): 105 | set_objects = set(objects) 106 | entities = list() 107 | for entity in self.all_entities(): 108 | if hasattr(entity, "objects"): 109 | if not set_objects.isdisjoint(set(entity.objects)): 110 | entities.append(entity) 111 | entities.extend([e for e in self.element if (e.type == 'Driven' and e.element in entities)]) 112 | return entities 113 | def entities_originating_from(self, objects): 114 | entities = list() 115 | for entity in self.all_entities(): 116 | if hasattr(entity, "objects"): 117 | if entity.objects[0] in objects: 118 | entities.append(entity) 119 | entities.extend([e for e in self.element if (e.type == 'Driven' and e.element in entities)]) 120 | return entities 121 | def users_of(self, entity): 122 | ret = list() 123 | for e in self.all_entities(): 124 | if True in [((entity == v) or (isinstance(v, list) and entity in v)) for v in vars(e).values()]: 125 | ret.append(e) 126 | return ret 127 | def pickle(self): 128 | if not self.scene: 129 | self.scene = bpy.context.scene 130 | bpy.context.scene.mbdyn_name = bpy.context.scene.name 131 | for obj in bpy.context.scene.objects: 132 | obj.mbdyn_name = obj.name 133 | with BytesIO() as f: 134 | p = Pickler(f) 135 | p.dump(self) 136 | self.scene.pickled_database = b64encode(f.getvalue()).decode() 137 | del p 138 | gc.collect() 139 | def unpickle(self): 140 | self.clear() 141 | if bpy.context.scene.pickled_database: 142 | with BytesIO(b64decode(bpy.context.scene.pickled_database.encode())) as f: 143 | up = Unpickler(f) 144 | database = up.load() 145 | for k, v in vars(database).items(): 146 | if type(v) in [list, Entities]: 147 | self.__dict__[k].extend(v) 148 | elif type(v) in [dict, set]: 149 | self.__dict__[k].update(v) 150 | else: 151 | self.__dict__[k] = v 152 | del up, database 153 | gc.collect() 154 | def replace(self): 155 | self.pickle() 156 | self.unpickle() 157 | -------------------------------------------------------------------------------- /shape.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | if "bpy" in locals(): 26 | import imp 27 | for x in [base, menu, common]: 28 | imp.reload(x) 29 | else: 30 | from . import base 31 | from . import menu 32 | from . import common 33 | from .base import bpy, BPY, database, Operator, Entity, Bundle 34 | from .common import FORMAT 35 | from .menu import default_klasses, shape_tree 36 | 37 | class Base(Operator): 38 | bl_label = "Shapes" 39 | bl_options = {'DEFAULT_CLOSED'} 40 | @classmethod 41 | def poll(cls, context): 42 | return True 43 | @classmethod 44 | def make_list(self, ListItem): 45 | bpy.types.Scene.shape_uilist = bpy.props.CollectionProperty(type = ListItem) 46 | bpy.types.Scene.shape_index = bpy.props.IntProperty(default=-1) 47 | @classmethod 48 | def delete_list(self): 49 | del bpy.types.Scene.shape_uilist 50 | del bpy.types.Scene.shape_index 51 | @classmethod 52 | def get_uilist(self, context): 53 | return context.scene.shape_index, context.scene.shape_uilist 54 | def set_index(self, context, value): 55 | context.scene.shape_index = value 56 | 57 | klasses = default_klasses(shape_tree, Base) 58 | 59 | class ConstShape(Entity): 60 | def string(self): 61 | return '\t\tconst, '+ BPY.FORMAT(self.constant) 62 | 63 | class ConstShapeOperator(Base): 64 | bl_label = "Const shape" 65 | constant = bpy.props.PointerProperty(type = BPY.Float) 66 | def prereqs(self, context): 67 | self.constant.mandatory = True 68 | def assign(self, context): 69 | self.constant.assign(self.entity.constant) 70 | def store(self, context): 71 | self.entity.constant = self.constant.store() 72 | def draw(self, context): 73 | self.constant.draw(self.layout, "Constant") 74 | def check(self, context): 75 | return self.constant.check(context) 76 | def create_entity(self): 77 | return ConstShape(self.name) 78 | 79 | klasses[ConstShapeOperator.bl_label] = ConstShapeOperator 80 | 81 | class PiecewiseConstShape(Entity): 82 | def string(self): 83 | ret += "\t\tpiecewise const, " + BPY.FORMAT(self.N) 84 | for i in range(self.N): 85 | ret += ",\n\t\t\t" + BPY.FORMAT(self.X[i]) + ", " + BPY.FORMAT(self.Y[i]) 86 | return ret 87 | 88 | class Multiple(Base): 89 | N = bpy.props.IntProperty(name="Number of points", min=2, max=50, description="", default=2) 90 | X = bpy.props.CollectionProperty(type = BPY.Float) 91 | Y = bpy.props.CollectionProperty(type = BPY.Float) 92 | def prereqs(self, context): 93 | self.X.clear() 94 | self.Y.clear() 95 | for i in range(50): 96 | x = self.X.add() 97 | x.mandatory = True 98 | y = self.Y.add() 99 | y.mandatory = True 100 | def assign(self, context): 101 | self.N = self.entity.N 102 | for i, x in enumerate(self.entity.X): 103 | self.X[i].assign(x) 104 | for i, y in enumerate(self.entity.Y): 105 | self.Y[i].assign(y) 106 | def store(self, context): 107 | self.entity.N = self.N 108 | self.entity.X = [x.store() for x in self.X][:self.entity.N] 109 | self.entity.Y = [y.store() for y in self.Y][:self.entity.N] 110 | def draw(self, context): 111 | self.basis = self.N 112 | layout = self.layout 113 | layout.prop(self, "N") 114 | row = layout.row() 115 | row.label("Abscissa") 116 | row.label("Value") 117 | for i in range(self.N): 118 | row = layout.row() 119 | self.X[i].draw(row, "") 120 | self.Y[i].draw(row, "") 121 | def check(self, context): 122 | return (self.basis != self.N) or True in [x.check(context) for x in self.X] + [y.check(context) for y in self.Y] 123 | 124 | class PiecewiseConstShapeOperator(Multiple): 125 | bl_label = "Piecewise const shape" 126 | def create_entity(self): 127 | return PiecewiseConstShape(self.name) 128 | 129 | klasses[PiecewiseConstShapeOperator.bl_label] = PiecewiseConstShapeOperator 130 | 131 | class LinearShape(Entity): 132 | def string(self): 133 | return '\t\tlinear, ' + ", ".join([BPY.FORMAT(y) for y in [self.y1, self.y2]]) 134 | 135 | class LinearShapeOperator(Base): 136 | bl_label = "Linear shape" 137 | y1 = bpy.props.PointerProperty(type = BPY.Float) 138 | y2 = bpy.props.PointerProperty(type = BPY.Float) 139 | def prereqs(self, context): 140 | self.y1.mandatory = True 141 | self.y2.mandatory = True 142 | def assign(self, context): 143 | self.y1.assign(self.entity.y1) 144 | self.y2.assign(self.entity.y2) 145 | def store(self, context): 146 | self.entity.y1 = self.y1.store() 147 | self.entity.y2 = self.y2.store() 148 | def draw(self, context): 149 | self.y1.draw(self.layout, "y1") 150 | self.y2.draw(self.layout, "y2") 151 | def check(self, context): 152 | return self.y1.check(context) or self.y2.check(context) 153 | def create_entity(self): 154 | return LinearShape(self.name) 155 | 156 | klasses[LinearShapeOperator.bl_label] = LinearShapeOperator 157 | 158 | class PiecewiseLinearShape(Entity): 159 | def string(self): 160 | ret += "\t\tpiecewise linear, " + BPY.FORMAT(self.N) 161 | for i in range(self.N): 162 | ret += ",\n\t\t\t" + BPY.FORMAT(self.X[i]) + ", " + BPY.FORMAT(self.Y[i]) 163 | return ret 164 | 165 | class PiecewiseLinearShapeOperator(Multiple): 166 | bl_label = "Piecewise linear shape" 167 | def create_entity(self): 168 | return PiecewiseLinearShape(self.name) 169 | 170 | klasses[PiecewiseLinearShapeOperator.bl_label] = PiecewiseLinearShapeOperator 171 | 172 | class ParabolicShape(Entity): 173 | def string(self): 174 | return '\t\tparabolic' + ", ".join([BPY.FORMAT(y) for y in [self.y1, self.y2, self.y3]]) 175 | 176 | class ParabolicShapeOperator(Base): 177 | bl_label = "Parabolic shape" 178 | y1 = bpy.props.PointerProperty(type = BPY.Float) 179 | y2 = bpy.props.PointerProperty(type = BPY.Float) 180 | y3 = bpy.props.PointerProperty(type = BPY.Float) 181 | def prereqs(self, context): 182 | self.y1.mandatory = True 183 | self.y2.mandatory = True 184 | self.y3.mandatory = True 185 | def assign(self, context): 186 | self.y1.assign(self.entity.y1) 187 | self.y2.assign(self.entity.y2) 188 | self.y3.assign(self.entity.y3) 189 | def store(self, context): 190 | self.entity.y1 = self.y1.store() 191 | self.entity.y2 = self.y2.store() 192 | self.entity.y3 = self.y3.store() 193 | def draw(self, context): 194 | self.y1.draw(self.layout, "y1 (at x=-1)") 195 | self.y2.draw(self.layout, "y2 (at x=0)") 196 | self.y3.draw(self.layout, "y3 (at x=1)") 197 | def check(self, context): 198 | return self.y1.check(context) or self.y2.check(context) or self.y3.check(context) 199 | def create_entity(self): 200 | return ParabolicShape(self.name) 201 | 202 | klasses[ParabolicShapeOperator.bl_label] = ParabolicShapeOperator 203 | 204 | bundle = Bundle(shape_tree, Base, klasses, database.shape) 205 | -------------------------------------------------------------------------------- /driver.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | if "bpy" in locals(): 26 | import imp 27 | for x in [base, menu]: 28 | imp.reload(x) 29 | else: 30 | from . import base 31 | from . import menu 32 | from .base import bpy, BPY, database, Operator, Entity, Bundle 33 | from .menu import default_klasses, driver_tree 34 | 35 | class Base(Operator): 36 | bl_label = "Drivers" 37 | bl_options = {'DEFAULT_CLOSED'} 38 | @classmethod 39 | def poll(cls, context): 40 | return True 41 | @classmethod 42 | def make_list(self, ListItem): 43 | bpy.types.Scene.driver_uilist = bpy.props.CollectionProperty(type = ListItem) 44 | bpy.types.Scene.driver_index = bpy.props.IntProperty(default=-1) 45 | @classmethod 46 | def delete_list(self): 47 | del bpy.types.Scene.driver_uilist 48 | del bpy.types.Scene.driver_index 49 | @classmethod 50 | def get_uilist(self, context): 51 | return context.scene.driver_index, context.scene.driver_uilist 52 | def set_index(self, context, value): 53 | context.scene.driver_index = value 54 | 55 | klasses = default_klasses(driver_tree, Base) 56 | 57 | class Stream(Entity): 58 | def write(self, f): 59 | columns = database.drive.filter("Event drive") 60 | f.write("\tfile: " + self.safe_name() + ", stream" 61 | ",\n\t\tname, " + BPY.FORMAT(self.stream_name) + 62 | ",\n\t\tcreate, " + ("yes" if self.create else "no")) 63 | if self.path is not None: 64 | f.write(",\n\t\tlocal, ", BPY.FORMAT(self.path)) 65 | else: 66 | f.write((",\n\t\tport, " + BPY.FORMAT(self.port_number) if self.port_number is not None else "") + 67 | (",\n\t\thost, " + BPY.FORMAT(self.host_name) if self.host_name is not None else "")) 68 | f.write(",\n\t\t" + ("" if self.signal else "no ") + "signal" + 69 | ",\n\t\t" + ("" if self.blocking else "non ") + "blocking") 70 | f.write((",\n\t\tinput every, " + BPY.FORMAT(self.steps) if self.steps is not None else "") + 71 | (",\n\t\treceive first, " + ("yes" if self.receive_first else "no")) + 72 | (",\n\t\ttimeout, " + BPY.FORMAT(self.timeout) if self.timeout is not None else "")) 73 | if self.file_name is not None: 74 | f.write(",\n\t\techo, " + BPY.FORMAT(self.file_name) + 75 | (",\n\t\tprecision, " + BPY.FORMAT(self.precision) if self.precision is not None else "") + 76 | (",\n\t\tshift, " + BPY.FORMAT(self.shift) if self.shift is not None else "")) 77 | f.write(",\n\t\t" + str(len(columns)) + 78 | (", initial values, " + ", ".join([str(c.initial_value) for c in columns]) if columns else "")) 79 | f.write(";\n") 80 | 81 | class StreamOperator(Base): 82 | bl_label = "Stream" 83 | stream_name = bpy.props.PointerProperty(type = BPY.Str) 84 | create = bpy.props.BoolProperty(name="Create") 85 | path = bpy.props.PointerProperty(type = BPY.Str) 86 | port_number = bpy.props.PointerProperty(type = BPY.Int) 87 | host_name = bpy.props.PointerProperty(type = BPY.Str) 88 | signal = bpy.props.BoolProperty(name="Signal") 89 | blocking = bpy.props.BoolProperty(name="Blocking") 90 | steps = bpy.props.PointerProperty(type = BPY.Int) 91 | receive_first = bpy.props.BoolProperty(name="Receive first") 92 | timeout = bpy.props.PointerProperty(type = BPY.Float) 93 | file_name = bpy.props.PointerProperty(type = BPY.Str) 94 | precision = bpy.props.PointerProperty(type = BPY.Int) 95 | shift = bpy.props.PointerProperty(type = BPY.Float) 96 | def prereqs(self, context): 97 | self.stream_name.mandatory = True 98 | self.stream_name.value = "MAILIN" 99 | self.port_number.value = 9012 100 | self.port_number.select = True 101 | self.host_name.value = "127.0.0.1" 102 | self.host_name.select = True 103 | self.signal = False 104 | self.blocking = False 105 | self.steps.value = 1 106 | def assign(self, context): 107 | self.stream_name.assign(self.entity.stream_name) 108 | self.create = self.entity.create 109 | self.path.assign(self.entity.path) 110 | self.port_number.assign(self.entity.port_number) 111 | self.host_name.assign(self.entity.host_name) 112 | self.signal = self.entity.signal 113 | self.blocking = self.entity.blocking 114 | self.steps.assign(self.entity.steps) 115 | self.receive_first = self.entity.receive_first 116 | self.timeout.assign(self.entity.timeout) 117 | self.file_name.assign(self.entity.file_name) 118 | self.precision.assign(self.entity.precision) 119 | self.shift.assign(self.entity.shift) 120 | def store(self, context): 121 | self.entity.stream_name = self.stream_name.store() 122 | self.entity.create = self.create 123 | self.entity.path = self.path.store() if not (self.port_number.select or self.host_name.select) else None 124 | self.entity.port_number = self.port_number.store() if not self.path.select else None 125 | self.entity.host_name = self.host_name.store() if not self.path.select else None 126 | self.entity.signal = self.signal 127 | self.entity.blocking = self.blocking 128 | self.entity.steps = self.steps.store() 129 | self.entity.receive_first = self.receive_first 130 | self.entity.timeout = self.timeout.store() 131 | self.entity.file_name = self.file_name.store() 132 | self.entity.precision = self.precision.store() if self.file_name.select else None 133 | self.entity.shift = self.shift.store() if self.file_name.select else None 134 | def draw(self, context): 135 | layout = self.layout 136 | self.stream_name.draw(layout, "Stream name") 137 | layout.prop(self, "create") 138 | if not (self.port_number.select or self.host_name.select): 139 | self.path.draw(layout, "Path") 140 | if not self.path.select: 141 | self.port_number.draw(layout, "Port number") 142 | self.host_name.draw(layout, "Host name") 143 | layout.prop(self, "signal") 144 | layout.prop(self, "blocking") 145 | self.steps.draw(layout, "Steps") 146 | layout.prop(self, "receive_first") 147 | self.timeout.draw(layout, "Timeout") 148 | self.file_name.draw(layout, "File name") 149 | if self.file_name.select: 150 | self.precision.draw(layout, "Precision") 151 | self.shift.draw(layout, "Shift") 152 | def check(self, context): 153 | return True in [x.check(context) for x in (self.stream_name, self.path, self.port_number, self.host_name, self.steps, self.timeout, self.file_name, self.precision, self.shift)] 154 | def create_entity(self): 155 | return Stream(self.name) 156 | 157 | klasses[StreamOperator.bl_label] = StreamOperator 158 | 159 | class EventStream(Stream): 160 | pass 161 | 162 | class EventStreamOperator(StreamOperator): 163 | bl_label = "Event stream" 164 | @classmethod 165 | def poll(cls, context): 166 | return not database.driver.filter(cls.bl_label) 167 | def draw(self, context): 168 | layout = self.layout 169 | self.stream_name.draw(layout, "Stream name") 170 | self.port_number.draw(layout, "Port number") 171 | self.host_name.draw(layout, "Host name") 172 | layout.prop(self, "blocking") 173 | self.steps.draw(layout, "Steps") 174 | layout.prop(self, "receive_first") 175 | self.file_name.draw(layout, "File name") 176 | if self.file_name.select: 177 | self.precision.draw(layout, "Precision") 178 | self.shift.draw(layout, "Shift") 179 | 180 | klasses[EventStreamOperator.bl_label] = EventStreamOperator 181 | 182 | bundle = Bundle(driver_tree, Base, klasses, database.driver) 183 | -------------------------------------------------------------------------------- /menu.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | if "user_defined_common" in locals(): 26 | import imp 27 | for x in [user_defined_common, common]: 28 | imp.reload(x) 29 | else: 30 | from . import user_defined_common 31 | from .common import Tree 32 | from collections import OrderedDict 33 | 34 | def default_klasses(tree, base_klass): 35 | klasses = dict() 36 | def find_leaves(tree): 37 | for key, value in [kv for kv in tree.items()]: 38 | if isinstance(value, OrderedDict): 39 | find_leaves(value) 40 | else: 41 | class Default(base_klass): 42 | bl_label = key 43 | @classmethod 44 | def poll(cls, context): 45 | return False 46 | def create_entity(self): 47 | return Entity(self.name) 48 | klasses[key] = Default 49 | find_leaves(tree) 50 | return klasses 51 | 52 | constitutive = Tree((t, None) for t in [ 53 | "Linear elastic", 54 | "Linear elastic generic", 55 | "Linear elastic generic axial torsion coupling", 56 | "Cubic elastic generic", 57 | "Inverse square elastic", 58 | "Log elastic", 59 | "Linear elastic bistop", 60 | "Double linear elastic", 61 | "Isotropic hardening elastic", 62 | "Scalar function elastic isotropic", 63 | "Scalar function elastic orthotropic", 64 | "Linear viscous", 65 | "Linear viscous generic", 66 | "Linear viscoelastic", 67 | "Linear viscoelastic generic", 68 | "Linear time variant viscoelastic generic", 69 | "Linear viscoelastic generic axial torsion couple", 70 | "Cubic viscoelastic generic", 71 | "Double linear viscoelastic", 72 | "Turbulent viscoelastic", 73 | "Linear viscoelastic bistop", 74 | "Shock absorber", 75 | "Symbolic elastic", 76 | "Symbolic viscous", 77 | "Symbolic viscoelastic", 78 | "ann elastic", 79 | "ann viscoelastic", 80 | "nlsf elastic", 81 | "nlsf viscous", 82 | "nlsf viscoelastic", 83 | "nlp elastic", 84 | "nlp viscous", 85 | "nlp viscoelastic", 86 | ]) 87 | 88 | constitutive_tree = Tree([("Constitutive", constitutive)]) 89 | 90 | method = Tree((t, None) for t in [ 91 | "Crank Nicolson", 92 | "ms", 93 | "Hope", 94 | "Third order", 95 | "bdf", 96 | "Implicit Euler"]) 97 | 98 | nonlinear_solver = Tree((t, None) for t in [ 99 | "Newton Raphston", 100 | "Line search", 101 | "Matrix free"]) 102 | 103 | problem = Tree((t, None) for t in [ 104 | "General data", 105 | "Method", 106 | "Nonlinear solver", 107 | "Eigenanalysis", 108 | "Abort after", 109 | "Linear solver", 110 | "Dummy steps", 111 | "Output data", 112 | "Real time"]) 113 | problem["Method"] = method 114 | problem["Nonlinear solver"] = nonlinear_solver 115 | 116 | control = Tree((t, None) for t in [ 117 | "Assembly", 118 | "Job control", 119 | "Default output", 120 | "Default aerodynamic output", 121 | "Default beam output", 122 | "Default scale", 123 | "Rigid body kinematics"]) 124 | 125 | definition = Tree((t, None) for t in [ 126 | "Problem", 127 | "Control"]) 128 | definition["Problem"] = problem 129 | definition["Control"] = control 130 | 131 | definition_tree = Tree([("Definition", definition)]) 132 | 133 | scalar_drive = Tree((t, None) for t in [ 134 | "Array of scalar drives", 135 | "Constant drive", 136 | "Cosine drive", 137 | "Cubic drive", 138 | "Direct drive", 139 | "Dof drive", 140 | "Double ramp drive", 141 | "Double step drive", 142 | "Drive drive", 143 | "Element drive", 144 | "Event drive", 145 | "Exponential drive", 146 | "File drive", 147 | "Fourier series drive", 148 | "Frequency sweep drive", 149 | "Hints", 150 | "Linear drive", 151 | "Meter drive", 152 | "Mult drive", 153 | "Node drive", 154 | "Null drive", 155 | "Parabolic drive", 156 | "Piecewise linear drive", 157 | "Ramp drive", 158 | "Random drive", 159 | "Sine drive", 160 | "Step drive", 161 | "String drive", 162 | "Tanh drive", 163 | "Time drive", 164 | "Unit drive"]) 165 | 166 | matrix_3x1_drive = Tree((t, None) for t in [ 167 | "Array of 3D drives", 168 | "Template 3D drive"]) 169 | matrix_6x1_drive = Tree((t, None) for t in [ 170 | "Array of 6D drives", 171 | "Template 6D drive"]) 172 | matrix_3x3_drive = Tree((t, None) for t in [ 173 | "Array of 3x3 drives", 174 | "Template 3x3 drive"]) 175 | matrix_6x6_drive = Tree((t, None) for t in [ 176 | "Array of 6x6 drives", 177 | "Template 6x6 drive"]) 178 | 179 | drive = Tree([ 180 | ("Scalar drive", scalar_drive), 181 | ("3D drive", matrix_3x1_drive), 182 | ("6D drive", matrix_6x1_drive), 183 | ("3x3 drive", matrix_3x3_drive), 184 | ("6x6 drive", matrix_6x6_drive)]) 185 | 186 | drive_tree = Tree([("Drive", drive)]) 187 | 188 | file_driver = Tree((t, None) for t in [ 189 | "Fixed step", 190 | "Variable step", 191 | "Socket", 192 | "RTAI input", 193 | "Stream", 194 | "Event stream"]) 195 | 196 | driver = Tree([("File driver", file_driver)]) 197 | 198 | driver_tree = Tree([("Driver", driver)]) 199 | 200 | aerodynamic = Tree([ 201 | ("Aerodynamic body", 1), 202 | ("Aerodynamic beam2", 2), 203 | ("Aerodynamic beam3", None), 204 | ("Generic aerodynamic force", None), 205 | ("Induced velocity", None)]) 206 | 207 | beam = Tree([ 208 | ("Beam segment", 2), 209 | ("Three node beam", None)]) 210 | 211 | force = Tree([ 212 | ("Abstract force", None), 213 | ("Structural force", 1), 214 | ("Structural internal force", 2), 215 | ("Structural couple", 1), 216 | ("Structural internal couple", 2)]) 217 | 218 | genel = Tree([ 219 | ("Swashplate", None)]) 220 | 221 | joint = Tree([ 222 | ("Axial rotation", 2), 223 | ("Clamp", 1), 224 | ("Distance", 2), 225 | ("Deformable displacement joint", 2), 226 | ("Deformable hinge", 2), 227 | ("Deformable joint", 2), 228 | ("In line", 2), 229 | ("In plane", 2), 230 | ("Revolute hinge", 2), 231 | ("Rod", 2), 232 | ("Spherical hinge", 2), 233 | ("Total joint", 2), 234 | ("Viscous body", 1)]) 235 | 236 | output = Tree([ 237 | ("Stream animation", None), 238 | ("Stream output", None)]) 239 | 240 | environment = Tree([ 241 | ("Air properties", None), 242 | ("Gravity", None)]) 243 | 244 | node = Tree([ 245 | ("Rigid offset", 2), 246 | ("Dummy node", 2), 247 | ("Feedback node", 2)]) 248 | 249 | element = Tree([ 250 | ("Aerodynamic", aerodynamic), 251 | ("Beam", beam), 252 | ("Body", 1), 253 | ("Force", force), 254 | ("GENEL", genel), 255 | ("Joint", joint), 256 | ("User defined", user_defined_common.tree), 257 | ("Output", output), 258 | ("Environment", environment), 259 | ("Driven", None), 260 | ("Node", node)]) 261 | 262 | element_tree = Tree([("Element", element)]) 263 | 264 | friction = Tree((t, None) for t in [ 265 | "Modlugre", "Discrete Coulomb"]) 266 | 267 | friction_tree = Tree([("Friction", friction)]) 268 | 269 | function = Tree((t, None) for t in [ 270 | "Const", 271 | "Exp", 272 | "Log", 273 | "Pow", 274 | "Linear", 275 | "Cubic natural spline", 276 | "Multilinear", 277 | "Chebychev", 278 | "Sum", 279 | "Sub", 280 | "Mul", 281 | "Div"]) 282 | 283 | function_tree = Tree([("Function", function)]) 284 | 285 | input_card = Tree((t, None) for t in [ 286 | "c81 data", 287 | "Hydraulic fluid", 288 | "Include", 289 | "Module load", 290 | "Print symbol table", 291 | "Reference frame", 292 | "Remark", 293 | "Set", 294 | "Setenv"]) 295 | 296 | input_card_tree = Tree([("Input Card", input_card)]) 297 | 298 | matrix = Tree((t, None) for t in [ 299 | "3x1", 300 | "6x1", 301 | "3x3", 302 | "6x6", 303 | "6xN"]) 304 | 305 | matrix_tree = Tree([("Matrix", matrix)]) 306 | 307 | shape = Tree((t, None) for t in [ 308 | "Const shape", 309 | "Piecewise const shape", 310 | "Linear shape", 311 | "Piecewise linear shape", 312 | "Parabolic shape"]) 313 | 314 | shape_tree = Tree([("Shape", shape)]) 315 | 316 | simulator = Tree((t, None) for t in [ 317 | "Initial value"]) 318 | 319 | simulator_tree = Tree([("Simulator", simulator)]) 320 | 321 | 322 | -------------------------------------------------------------------------------- /common.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | import bpy 26 | from math import sqrt 27 | import bmesh 28 | from socket import socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR, SHUT_RDWR 29 | from struct import pack, unpack 30 | from threading import Thread 31 | from collections import OrderedDict 32 | from time import sleep 33 | 34 | class Tree(OrderedDict): 35 | def get_leaves(self): 36 | ret = list() 37 | for key, value in self.items(): 38 | if isinstance(value, Tree): 39 | ret.extend(value.get_leaves()) 40 | else: 41 | ret.append(key) 42 | return ret 43 | 44 | FORMAT = "{:.6g}".format 45 | 46 | def safe_name(name): 47 | return "_".join("_".join(name.split(".")).split()) 48 | 49 | def create_stream_socket(host_name, port_number): 50 | with socket(AF_INET, SOCK_STREAM) as sock: 51 | sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) 52 | sock.bind((host_name, port_number)) 53 | sock.listen(5) 54 | sock.settimeout(1.) 55 | try: 56 | streaming_socket, address = sock.accept() 57 | return streaming_socket 58 | except OSError as err: 59 | print(err) 60 | 61 | class StreamSender: 62 | def __init__(self, host_name=None, port_number=None): 63 | self.socket = create_stream_socket(host_name if host_name is not None else "127.0.0.1", port_number if port_number is not None else 9012) 64 | def send(self, floats): 65 | self.socket.send(pack('d'*len(floats), *floats)) 66 | def close(self): 67 | try: 68 | self.socket.shutdown(SHUT_RDWR) 69 | except OSError as err: 70 | if err.errno != 107: 71 | print(err) 72 | self.socket.close() 73 | del self.socket 74 | 75 | class StreamReceiver(Thread): 76 | def __init__(self, fmt, initial_data=None, host_name=None, port_number=None): 77 | Thread.__init__(self) 78 | self.daemon = True 79 | self.fmt = fmt 80 | self.packed_data = pack(self.fmt, *initial_data) 81 | self.recv_size = len(self.packed_data) 82 | self.receiving = True 83 | self.socket = create_stream_socket(host_name if host_name is not None else "127.0.0.1", port_number if port_number is not None else 9011) 84 | def run(self): 85 | try: 86 | while self.receiving: 87 | self.packed_data += self.socket.recv(self.recv_size) 88 | self.packed_data = self.packed_data[( (len(self.packed_data) // self.recv_size) - 1) * self.recv_size : ] 89 | except Exception as e: 90 | sleep(1) 91 | if self.receiving: 92 | raise Exception(e) 93 | try: 94 | self.socket.shutdown(SHUT_RDWR) 95 | except OSError as err: 96 | if err.errno != 107: 97 | print(err) 98 | self.socket.close() 99 | del self.socket 100 | def get_data(self): 101 | return unpack(self.fmt, self.packed_data[:self.recv_size]) 102 | def close(self): 103 | self.receiving = False 104 | 105 | def write_vector(f, v, prepend=True): 106 | f.write((", " if prepend else "") + ", ".join([FORMAT(round(x, 6) if round(x, 6) != -0. else 0) for x in v])) 107 | 108 | def write_orientation(f, m, pad=""): 109 | f.write(",\n" + pad + "euler") 110 | write_vector(f, m.to_euler('ZYX')) 111 | #f.write(",\n" + pad +"matr,\n" + ",\n\t".join([pad + ", ".join(FORMAT(round(x, 6) if round(x, 6) != -0. else 0) for x in r) for r in m])) 112 | 113 | def subsurf(obj): 114 | subsurf = [m for m in obj.modifiers if m.type == 'SUBSURF'] 115 | subsurf = subsurf[0] if subsurf else obj.modifiers.new("Subsurf", 'SUBSURF') 116 | subsurf.levels = 3 117 | 118 | def Ellipsoid(obj, mass, mat): 119 | def v_or_1(value): 120 | return value if isinstance(value, (int, float)) else 1.0 121 | diag, scale = 3*[1.0], 1.0 122 | if mat is not None: 123 | if mat.subtype != "eye": 124 | diag = [v_or_1(mat.floats[4*i]) for i in range(3)] 125 | scale = v_or_1(mat.scale) 126 | s = [0.5*sqrt(x*scale/v_or_1(mass)) for x in diag] 127 | bm = bmesh.new() 128 | for v in [(x*s[0],y*s[1],z*s[2]) for z in [-1., 1.] for y in [-1., 1.] for x in [-1., 1.]]: 129 | bm.verts.new(v) 130 | if hasattr(bm.verts, "ensure_lookup_table"): 131 | bm.verts.ensure_lookup_table() 132 | for f in [(1,0,2,3),(4,5,7,6),(0,1,5,4),(1,3,7,5),(3,2,6,7),(2,0,4,6)]: 133 | bm.faces.new([bm.verts[i] for i in f]) 134 | crease = bm.edges.layers.crease.new() 135 | for e in bm.edges: 136 | e[crease] = 0.184 137 | bm.to_mesh(obj.data) 138 | subsurf(obj) 139 | bm.free() 140 | 141 | def Sphere(obj): 142 | bm = bmesh.new() 143 | for v in [(x, y, z) for z in [-0.5, 0.5] for y in [-0.5, 0.5] for x in [-0.5, 0.5]]: 144 | bm.verts.new(v) 145 | if hasattr(bm.verts, "ensure_lookup_table"): 146 | bm.verts.ensure_lookup_table() 147 | for f in [(1,0,2,3),(4,5,7,6),(0,1,5,4),(1,3,7,5),(3,2,6,7),(2,0,4,6)]: 148 | bm.faces.new([bm.verts[i] for i in f]) 149 | bm.to_mesh(obj.data) 150 | subsurf(obj) 151 | bm.free() 152 | 153 | def Cube(obj): 154 | bm = bmesh.new() 155 | for v in [(x, y, z) for z in [-0.5, 0.5] for y in [-0.5, 0.5] for x in [-0.5, 0.5]]: 156 | bm.verts.new(v) 157 | if hasattr(bm.verts, "ensure_lookup_table"): 158 | bm.verts.ensure_lookup_table() 159 | for f in [(1,0,2,3),(4,5,7,6),(0,1,5,4),(1,3,7,5),(3,2,6,7),(2,0,4,6)]: 160 | bm.faces.new([bm.verts[i] for i in f]) 161 | crease = bm.edges.layers.crease.new() 162 | for e in bm.edges: 163 | e[crease] = 1.0 164 | bm.to_mesh(obj.data) 165 | subsurf(obj) 166 | bm.free() 167 | 168 | def RhombicPyramid(obj): 169 | bm = bmesh.new() 170 | for v in [(.333,0.,0.),(0.,.666,0.),(-.333,0.,0.),(0.,-.666,0.),(0.,0.,1.)]: 171 | bm.verts.new(v) 172 | if hasattr(bm.verts, "ensure_lookup_table"): 173 | bm.verts.ensure_lookup_table() 174 | for f in [(3,2,1,0),(0,1,4),(1,2,4),(2,3,4),(3,0,4)]: 175 | bm.faces.new([bm.verts[i] for i in f]) 176 | crease = bm.edges.layers.crease.new() 177 | for e in bm.edges: 178 | e[crease] = 1.0 179 | bm.to_mesh(obj.data) 180 | subsurf(obj) 181 | bm.free() 182 | 183 | def TriPyramid(obj): 184 | bm = bmesh.new() 185 | for v in [(0.,0.,0.),(.333,0.,0.),(0.,.666,0.),(0.,0.,1.)]: 186 | bm.verts.new(v) 187 | if hasattr(bm.verts, "ensure_lookup_table"): 188 | bm.verts.ensure_lookup_table() 189 | for f in [(0,1,2),(0,1,3),(0,2,3),(1,2,3)]: 190 | bm.faces.new([bm.verts[i] for i in f]) 191 | crease = bm.edges.layers.crease.new() 192 | for e in bm.edges: 193 | e[crease] = 1.0 194 | bm.to_mesh(obj.data) 195 | subsurf(obj) 196 | bm.free() 197 | 198 | def Octahedron(obj): 199 | bm = bmesh.new() 200 | for v in [(.5,0.,0.),(0.,.5,0.),(-.5,0.,0.),(0.,-.5,0.),(0.,0.,.5),(0.,0.,-.5)]: 201 | bm.verts.new(v) 202 | if hasattr(bm.verts, "ensure_lookup_table"): 203 | bm.verts.ensure_lookup_table() 204 | for f in [(0,1,4),(1,2,4),(2,3,4),(3,0,4),(0,1,5),(1,2,5),(2,3,5),(3,0,5)]: 205 | bm.faces.new([bm.verts[i] for i in f]) 206 | crease = bm.edges.layers.crease.new() 207 | for e in bm.edges: 208 | e[crease] = 1.0 209 | bm.to_mesh(obj.data) 210 | subsurf(obj) 211 | bm.free() 212 | 213 | def Teardrop(obj): 214 | bm = bmesh.new() 215 | for v in [(x, y, -.5) for y in [-.5, .5] for x in [-.5, .5]] + [(0.,0.,0.)]: 216 | bm.verts.new(v) 217 | if hasattr(bm.verts, "ensure_lookup_table"): 218 | bm.verts.ensure_lookup_table() 219 | for q in [(2,3,1,0),(0,1,4),(1,3,4),(3,2,4),(2,0,4)]: 220 | bm.faces.new([bm.verts[i] for i in q]) 221 | crease = bm.edges.layers.crease.new() 222 | if hasattr(bm.edges, "ensure_lookup_table"): 223 | bm.edges.ensure_lookup_table() 224 | for i in range(4,8): 225 | bm.edges[i][crease] = 1.0 226 | bm.to_mesh(obj.data) 227 | bm.free() 228 | subsurf(obj) 229 | 230 | def Cylinder(obj): 231 | bm = bmesh.new() 232 | scale = .5 233 | for z in [-1., 1.]: 234 | for y in [-1., 1.]: 235 | for x in [-1., 1.]: 236 | bm.verts.new((scale*x,scale*y,scale*z)) 237 | if hasattr(bm.verts, "ensure_lookup_table"): 238 | bm.verts.ensure_lookup_table() 239 | for q in [(1,0,2,3),(4,5,7,6),(0,1,5,4),(1,3,7,5),(3,2,6,7),(2,0,4,6)]: 240 | bm.faces.new([bm.verts[i] for i in q]) 241 | crease = bm.edges.layers.crease.new() 242 | for v0, v1 in ([(0,1),(0,2),(2,3),(3,1),(4,5),(4,6),(6,7),(7,5)]): 243 | bm.edges.get((bm.verts[v0], bm.verts[v1]))[crease] = 1.0 244 | bm.to_mesh(obj.data) 245 | bm.free() 246 | subsurf(obj) 247 | 248 | def RectangularCuboid(obj): 249 | bm = bmesh.new() 250 | for v in [(x, y, z) for z in [-0.2, 0.2] for y in [-0.1, 0.1] for x in [-0.3, 0.3]]: 251 | bm.verts.new(v) 252 | if hasattr(bm.verts, "ensure_lookup_table"): 253 | bm.verts.ensure_lookup_table() 254 | for f in [(1,0,2,3),(4,5,7,6),(0,1,5,4),(1,3,7,5),(3,2,6,7),(2,0,4,6)]: 255 | bm.faces.new([bm.verts[i] for i in f]) 256 | crease = bm.edges.layers.crease.new() 257 | for e in bm.edges: 258 | e[crease] = 1.0 259 | bm.to_mesh(obj.data) 260 | subsurf(obj) 261 | bm.free() 262 | -------------------------------------------------------------------------------- /input_card.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | if "bpy" in locals(): 26 | import imp 27 | for x in [base, menu, common]: 28 | imp.reload(x) 29 | else: 30 | from . import base 31 | from . import menu 32 | from . import common 33 | from .base import bpy, BPY, root_dot, database, Operator, Entity, Bundle, SelectedObjects 34 | from .menu import default_klasses, input_card_tree 35 | from .common import RhombicPyramid, write_vector, write_orientation 36 | from mathutils import Vector 37 | from copy import copy 38 | import os, shutil 39 | 40 | class Base(Operator): 41 | bl_label = "Input Cards" 42 | bl_options = {'DEFAULT_CLOSED'} 43 | @classmethod 44 | def poll(cls, context): 45 | return True 46 | @classmethod 47 | def make_list(self, ListItem): 48 | bpy.types.Scene.input_card_uilist = bpy.props.CollectionProperty(type = ListItem) 49 | def select_and_activate(self, context): 50 | if database.input_card and self.input_card_index < len(database.input_card) and hasattr(database.input_card[self.input_card_index], "objects"): 51 | bpy.ops.object.select_all(action='DESELECT') 52 | input_card = database.input_card[self.input_card_index] 53 | for ob in input_card.objects: 54 | ob.select = True 55 | context.scene.objects.active = input_card.objects[0] 56 | input_card.remesh() 57 | bpy.types.Scene.input_card_index = bpy.props.IntProperty(default=-1, update=select_and_activate) 58 | @classmethod 59 | def delete_list(self): 60 | del bpy.types.Scene.input_card_uilist 61 | del bpy.types.Scene.input_card_index 62 | @classmethod 63 | def get_uilist(self, context): 64 | return context.scene.input_card_index, context.scene.input_card_uilist 65 | def set_index(self, context, value): 66 | context.scene.input_card_index = value 67 | 68 | klasses = default_klasses(input_card_tree, Base) 69 | 70 | class ReferenceFrame(Entity): 71 | def write(self, f, parent): 72 | parent_label = parent.safe_name() if parent else "global" 73 | vectors = list() 74 | for r in [self.linear_rate, self.angular_rate]: 75 | vectors.append(Vector([0., 0., r if r is not None else 0.])) 76 | location = self.objects[0].matrix_world.translation - (parent.objects[0].matrix_world.translation if parent else Vector([0., 0., 0.])) 77 | rot = self.objects[0].matrix_world.to_quaternion().to_matrix() 78 | rot_parent = parent.objects[0].matrix_world.to_quaternion().to_matrix() if parent else rot 79 | orientation = rot_parent.transposed()*rot if parent else rot 80 | f.write("\treference: " + self.safe_name() + ",\n\t\treference, " + parent_label) 81 | write_vector(f, rot_parent.transposed()*location if parent else location) 82 | f.write(",\n\t\treference, " + parent_label) 83 | write_orientation(f, orientation, "\t\t") 84 | f.write(",\n\t\treference, " + parent_label) 85 | write_vector(f, orientation*vectors[0]) 86 | f.write(",\n\t\treference, " + parent_label) 87 | write_vector(f, orientation*vectors[1]) 88 | f.write(";\n") 89 | def remesh(self): 90 | RhombicPyramid(self.objects[0]) 91 | 92 | class ReferenceFrameOperator(Base): 93 | bl_label = "Reference frame" 94 | linear_rate = bpy.props.PointerProperty(type = BPY.Float) 95 | angular_rate = bpy.props.PointerProperty(type = BPY.Float) 96 | @classmethod 97 | def poll(self, context): 98 | frames = copy(database.input_card.filter("Reference frame")) 99 | if self.bl_idname.startswith(root_dot + "e_"): 100 | frames.remove(database.input_card[context.scene.input_card_index]) 101 | selected = SelectedObjects(context) 102 | overlapped = False in [set(selected[1:]).isdisjoint(set(f.objects[1:])) for f in frames] 103 | duplicate = True in [selected[0] == f.objects[0] for f in frames if hasattr(f, "objects")] 104 | if len(selected) < 2 or overlapped or duplicate: 105 | return False 106 | frame_objects = [f.objects for f in frames] 107 | head, hold = selected[0], None 108 | while frame_objects and head != hold: 109 | hold = head 110 | for objects in frame_objects: 111 | if head in objects[1:]: 112 | head = objects[0] 113 | frame_objects.remove(objects) 114 | return head not in selected[1:] 115 | def assign(self, context): 116 | self.linear_rate.assign(self.entity.linear_rate) 117 | self.angular_rate.assign(self.entity.angular_rate) 118 | def store(self, context): 119 | self.entity.linear_rate = self.linear_rate.store() 120 | self.entity.angular_rate = self.angular_rate.store() 121 | self.entity.objects = SelectedObjects(context) 122 | def draw(self, context): 123 | layout = self.layout 124 | self.linear_rate.draw(layout, "Linear rate", "Set") 125 | self.angular_rate.draw(layout, "Angular rate", "Set") 126 | def check(self, context): 127 | return True in [v.check(context) for v in [self.linear_rate, self.angular_rate]] 128 | def create_entity(self): 129 | return ReferenceFrame(self.name) 130 | 131 | klasses[ReferenceFrameOperator.bl_label] = ReferenceFrameOperator 132 | 133 | class Set(Entity): 134 | def write(self, f): 135 | value = ("\"" + self.value + "\"") if self.value_type == "string" else self.value 136 | f.write("\tset: " + 137 | ("ifndef " if self.ifndef else "") + 138 | ("const " if self.const else "") + 139 | self.value_type + " " + self.safe_name() + ((" = " + value) if self.value else "") + ";\n") 140 | 141 | class SetOperator(Base): 142 | bl_label = "Set" 143 | ifndef = bpy.props.BoolProperty(name="If not defined", description="Define only if not already defined", default=False) 144 | const = bpy.props.BoolProperty(name="Constant", description="Constant value", default=False) 145 | value_type = bpy.props.EnumProperty(items=[("bool", "Boolean", ""), ("integer", "Integer", ""), ("real", "Real", ""), ("string", "String", "")], name="Type", default="real") 146 | value = bpy.props.StringProperty(name="Value", description="Set value", default="") 147 | def assign(self, context): 148 | self.ifndef = self.entity.ifndef 149 | self.const = self.entity.const 150 | self.value_type = self.entity.value_type 151 | self.value = self.entity.value 152 | def store(self, context): 153 | self.entity.ifndef = self.ifndef 154 | self.entity.const = self.const 155 | self.entity.value_type = self.value_type 156 | self.entity.value = self.value 157 | def draw(self, context): 158 | layout = self.layout 159 | layout.prop(self, "value") 160 | row = layout.row() 161 | row.prop(self, "value_type", text="") 162 | row.prop(self, "const") 163 | row.prop(self, "ifndef") 164 | def create_entity(self): 165 | return Set(self.name) 166 | 167 | klasses[SetOperator.bl_label] = SetOperator 168 | 169 | class ModuleLoad(Entity): 170 | def write(self, f): 171 | f.write("\tmodule load: " + BPY.FORMAT(self.value_type)) 172 | if self.args: 173 | f.write(",\n\t\t" + self.args) 174 | f.write(";\n") 175 | 176 | def enum_loadable_module(self, context): 177 | sim = database.simulator[context.scene.simulator_index] if database.simulator else None 178 | head, tail = os.path.split(os.path.realpath(shutil.which(sim.mbdyn_path if sim is not None and sim.mbdyn_path is not None else "mbdyn"))) 179 | head = os.path.split(head)[0] if head else None 180 | if head and os.path.exists(os.path.join(head, "libexec")): 181 | return [(base, base, "") for base, ext in [os.path.splitext(fn) for fn in os.listdir(os.path.join(head, "libexec"))] if ext == ".la" and 182 | base not in [x.value_type for x in database.input_card.filter("Module load")]] 183 | else: 184 | return list() 185 | 186 | class ModuleLoadOperator(Base): 187 | bl_label = "Module load" 188 | loadable_module = bpy.props.EnumProperty(items=enum_loadable_module, name="File name", description="Select from the list of available loadable modules") 189 | args = bpy.props.StringProperty() 190 | @classmethod 191 | def poll(cls, context): 192 | return enum_loadable_module(cls, context) or cls.bl_idname.endswith("e_module_load") 193 | def prereqs(self, context): 194 | if self.bl_idname.endswith("c_module_load"): 195 | self.loadable_module = enum_loadable_module(self, context)[0][0] 196 | def assign(self, context): 197 | self.args = self.entity.args 198 | def store(self, context): 199 | if self.bl_idname.endswith("c_module_load"): 200 | self.entity.value_type = self.loadable_module 201 | self.entity.args = self.args 202 | def draw(self, context): 203 | layout = self.layout 204 | if self.bl_idname.endswith("c_module_load"): 205 | layout.prop(self, "loadable_module") 206 | else: 207 | layout.label("Module: " + self.entity.value_type) 208 | layout.prop(self, "args") 209 | def create_entity(self): 210 | return ModuleLoad(self.name) 211 | 212 | klasses[ModuleLoadOperator.bl_label] = ModuleLoadOperator 213 | 214 | bundle = Bundle(input_card_tree, Base, klasses, database.input_card) 215 | -------------------------------------------------------------------------------- /matrix.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | if "bpy" in locals(): 26 | import imp 27 | for x in [base, menu, common]: 28 | imp.reload(x) 29 | else: 30 | from . import base 31 | from . import menu 32 | from . import common 33 | from .base import bpy, BPY, database, Operator, Entity, Bundle 34 | from .common import FORMAT 35 | from .menu import default_klasses, matrix_tree 36 | 37 | class Base(Operator): 38 | bl_label = "Matrices" 39 | bl_options = {'DEFAULT_CLOSED'} 40 | @classmethod 41 | def poll(cls, context): 42 | return True 43 | @classmethod 44 | def make_list(self, ListItem): 45 | bpy.types.Scene.matrix_uilist = bpy.props.CollectionProperty(type = ListItem) 46 | bpy.types.Scene.matrix_index = bpy.props.IntProperty(default=-1) 47 | @classmethod 48 | def delete_list(self): 49 | del bpy.types.Scene.matrix_uilist 50 | del bpy.types.Scene.matrix_index 51 | @classmethod 52 | def get_uilist(self, context): 53 | return context.scene.matrix_index, context.scene.matrix_uilist 54 | def set_index(self, context, value): 55 | context.scene.matrix_index = value 56 | 57 | klasses = default_klasses(matrix_tree, Base) 58 | 59 | class MatrixBase(Base): 60 | N = None 61 | subtype = None 62 | ordinals = {} 63 | floats = bpy.props.CollectionProperty(type = BPY.Float) 64 | scale = bpy.props.PointerProperty(type = BPY.Float) 65 | def prereqs(self, context): 66 | self.floats.clear() 67 | for i in range(self.N): 68 | f = self.floats.add() 69 | f.mandatory = True 70 | def assign(self, context): 71 | self.subtype = self.entity.subtype 72 | for i, f in enumerate(self.entity.floats): 73 | self.floats[i].assign(f) 74 | self.scale.assign(self.entity.scale) 75 | def store(self, context): 76 | self.entity.subtype = self.subtype 77 | self.entity.floats = [f.store() if i in self.ordinals[self.subtype] else 0 for i, f in enumerate(self.floats)] 78 | self.entity.scale = self.scale.store() 79 | def check(self, context): 80 | return (self.basis != self.subtype) or self.scale.check(context) or True in [f.check(context) for f in self.floats] 81 | 82 | class Matrix3x1(Entity): 83 | def string(self): 84 | if self.subtype == "null": 85 | ret = "\n\t\t\tnull" 86 | elif self.subtype == "default": 87 | ret = "\n\t\t\tdefault" 88 | else: 89 | ret = "\n\t\t\t" + ", ".join([BPY.FORMAT(prop) for prop in self.floats]) 90 | if self.scale is not None: 91 | ret += ", scale, " + BPY.FORMAT(self.scale) 92 | return ret 93 | 94 | class Matrix3x1Operator(MatrixBase): 95 | N = 3 96 | bl_label = "3x1" 97 | subtype = bpy.props.EnumProperty(items=[ 98 | ("matr", "General", ""), 99 | ("null", "Null", ""), 100 | ("default", "Default", "")], 101 | name="Subtype") 102 | ordinals = { 103 | "matr": [i for i in range(3)], 104 | "null": [], 105 | "default": []} 106 | def draw(self, context): 107 | self.basis = self.subtype 108 | layout = self.layout 109 | layout.prop(self, "subtype") 110 | if self.subtype not in "null default".split(): 111 | self.scale.draw(layout, "Scale") 112 | for i in range(self.N): 113 | self.floats[i].draw(layout, "x" + str(i+1)) 114 | def create_entity(self): 115 | return Matrix3x1(self.name) 116 | 117 | 118 | klasses[Matrix3x1Operator.bl_label] = Matrix3x1Operator 119 | 120 | class Matrix6x1(Matrix3x1): 121 | pass 122 | 123 | class Matrix6x1Operator(Matrix3x1Operator): 124 | N = 6 125 | bl_label = "6x1" 126 | ordinals = { 127 | "matr": [i for i in range(6)], 128 | "null": [], 129 | "default": []} 130 | def create_entity(self): 131 | return Matrix6x1(self.name) 132 | 133 | klasses[Matrix6x1Operator.bl_label] = Matrix6x1Operator 134 | 135 | class Matrix3x3(Entity): 136 | def string(self): 137 | if self.subtype == "matr": 138 | ret = ("\n\t\t\tmatr,\n" + 139 | "\t"*4 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[0:3]]) + ",\n" + 140 | "\t"*4 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[3:6]]) + ",\n" + 141 | "\t"*4 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[6:9]])) 142 | elif self.subtype == "sym": 143 | ret = ("\n\t\t\tsym,\n" + 144 | "\t"*4 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[0:3]]) + ",\n" + 145 | "\t"*5 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[4:6]]) + ",\n" + 146 | "\t"*6 + BPY.FORMAT(self.floats[8])) 147 | elif self.subtype == "skew": 148 | ret = "\n\t\t\tskew, " + ", ".join([BPY.FORMAT(self.floats[i]) for i in [7, 2, 3]]) 149 | elif self.subtype == "diag": 150 | ret = "\n\t\t\tdiag, " + ", ".join([BPY.FORMAT(self.floats[i]) for i in [0, 4, 8]]) 151 | elif self.subtype == "eye": 152 | ret = "\n\t\t\teye" 153 | elif self.subtype == "null": 154 | ret = "\n\t\t\tnull" 155 | ret += (", scale, " + BPY.FORMAT(self.scale)) if self.scale is not None else "" 156 | return ret 157 | 158 | class Matrix3x3Operator(MatrixBase): 159 | N = 9 160 | bl_label = "3x3" 161 | subtype = bpy.props.EnumProperty(items=[ 162 | ("matr", "General", "General matrix"), 163 | ("null", "Null", "Null matrix"), 164 | ("sym", "Symmetric", "Symmetric matrix"), 165 | ("skew", "Skew symmetric", "Skew symmetric matrix"), 166 | ("diag", "Diagonal", "Diagonal matrix"), 167 | ("eye", "Identity", "Identity matrix"), 168 | ], name="Subtype", default="eye") 169 | ordinals = { 170 | "matr": [i for i in range(9)], 171 | "null": [], 172 | "sym": [0,1,2,4,5,8], 173 | "skew": [2,3,7], 174 | "diag": [0,4,8], 175 | "eye": []} 176 | def draw(self, context): 177 | self.basis = self.subtype 178 | layout = self.layout 179 | layout.prop(self, "subtype") 180 | if self.subtype != "null": 181 | self.scale.draw(layout, "Scale") 182 | if self.subtype != "eye": 183 | for i in range(3): 184 | row = layout.row() 185 | for j in range(3): 186 | k = 3*i+j 187 | if k in self.ordinals[self.subtype]: 188 | self.floats[k].draw(row, "") 189 | else: 190 | row.label() 191 | def create_entity(self): 192 | return Matrix3x3(self.name) 193 | 194 | klasses[Matrix3x3Operator.bl_label] = Matrix3x3Operator 195 | 196 | class Matrix6x6(Entity): 197 | def string(self): 198 | if self.subtype == "matr": 199 | ret = ("\n\t\t\tmatr,\n" + 200 | "\t"*4 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[0:6]]) + ",\n" + 201 | "\t"*4 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[6:12]]) + ",\n" + 202 | "\t"*4 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[12:18]]) + ",\n" + 203 | "\t"*4 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[18:24]]) + ",\n" + 204 | "\t"*4 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[24:30]]) + ",\n" + 205 | "\t"*4 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[30:36]])) 206 | elif self.subtype == "sym": 207 | ret = ("\n\t\t\tsym,\n" + 208 | "\t"*4 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[0:6]]) + ",\n" + 209 | "\t"*5 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[7:12]]) + ",\n" + 210 | "\t"*6 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[14:18]]) + ",\n" + 211 | "\t"*7 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[21:24]]) + ",\n" + 212 | "\t"*8 + ", ".join([BPY.FORMAT(prop) for prop in self.floats[28:30]]) + ",\n" + 213 | "\t"*9 + BPY.FORMAT(self.floats[35])) 214 | elif self.subtype == "diag": 215 | ret = "\n\t\t\tdiag, " + ", ".join([BPY.FORMAT(self.floats[i]) for i in [0,7,14,21,28,35]]) 216 | elif self.subtype == "eye": 217 | ret = "\n\t\t\teye" 218 | elif self.subtype == "null": 219 | ret = "\n\t\t\tnull" 220 | if self.scale is not None: 221 | ret += ", scale, " + BPY.FORMAT(self.scale) 222 | return ret 223 | 224 | class Matrix6x6Operator(MatrixBase): 225 | N = 36 226 | bl_label = "6x6" 227 | subtype = bpy.props.EnumProperty(items=[ 228 | ("matr", "General", "General matrix"), 229 | ("null", "Null", "Null matrix"), 230 | ("sym", "Symmetric", "Symmetric matrix"), 231 | ("diag", "Diagonal", "Diagonal matrix"), 232 | ("eye", "Identity", "Identity matrix"), 233 | ], name="Subtype", default="eye") 234 | ordinals = { 235 | "matr": [i for i in range(36)], 236 | "null": [], 237 | "sym": [0,1,2,3,4,5,7,8,9,10,11,14,15,16,17,21,22,23,28,29,35], 238 | "diag": [0,7,14,21,28,35], 239 | "eye": []} 240 | show_column = bpy.props.IntProperty(min=1, max=4, name="Show column", default=1) 241 | def draw(self, context): 242 | self.basis = (self.subtype, self.show_column) 243 | layout = self.layout 244 | layout.prop(self, "subtype") 245 | if self.subtype != "null": 246 | self.scale.draw(layout, "Scale") 247 | if self.subtype != "eye": 248 | row = layout.row() 249 | row.prop(self, "show_column") 250 | row.label("to column: " + str(self.show_column +2)) 251 | row = layout.row() 252 | for i in range(3): 253 | row.label(str(self.show_column + i)) 254 | for i in range(6): 255 | row = layout.row() 256 | for j in range(self.show_column - 1, self.show_column + 2): 257 | k = 6*i+j 258 | if k in self.ordinals[self.subtype]: 259 | self.floats[k].draw(row, "") 260 | else: 261 | row.label() 262 | def check(self, context): 263 | return self.basis != (self.subtype, self.show_column) or self.scale.check(context) or True in [f.check(context) for f in self.floats] 264 | def create_entity(self): 265 | return Matrix6x6(self.name) 266 | 267 | klasses[Matrix6x6Operator.bl_label] = Matrix6x6Operator 268 | 269 | class Matrix6xN(Entity): 270 | ... 271 | 272 | class Matrix6xNOperator(MatrixBase): 273 | N = 30 274 | bl_label = "6xN" 275 | @classmethod 276 | def poll(cls, context): 277 | return False 278 | 279 | klasses[Matrix6xNOperator.bl_label] = Matrix6xNOperator 280 | 281 | bundle = Bundle(matrix_tree, Base, klasses, database.matrix) 282 | -------------------------------------------------------------------------------- /user_defined_element.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | if "bpy" in locals(): 26 | import imp 27 | for x in [common, base]: 28 | imp.reload(x) 29 | else: 30 | from . import common 31 | from . import base 32 | from .common import safe_name, Teardrop 33 | from .base import bpy, BPY, root_dot, database, Entity, SelectedObjects 34 | import bmesh, mathutils, math 35 | 36 | klass_list = list() 37 | 38 | class Sandbox(Entity): 39 | def write(self, f): 40 | f.write( 41 | "\tuser defined: " + self.safe_name() + ", sandbox") 42 | f.write(";\n") 43 | 44 | class Constitutive: 45 | constitutive = bpy.props.PointerProperty(type = BPY.Constitutive) 46 | def prereqs(self, context): 47 | self.constitutive.mandatory = True 48 | self.constitutive.dimension = "3D" 49 | def assign(self, context): 50 | self.constitutive.assign(self.entity.constitutive) 51 | def store(self, context): 52 | self.entity.constitutive = self.constitutive.store() 53 | self.entity.objects = self.sufficient_objects(context) 54 | def draw(self, context): 55 | self.constitutive.draw(self.layout, text="Constitutive") 56 | def check(self, context): 57 | return self.constitutive.check(context) 58 | 59 | class SandboxOperator: 60 | bl_label = "Sandbox" 61 | @classmethod 62 | def poll(cls, context): 63 | return super().poll(context) and "libmodule-sandbox" in [x.value_type for x in database.input_card.filter("Module load")] 64 | def create_entity(self): 65 | return Sandbox(self.name) 66 | 67 | klass_list.append((Sandbox, SandboxOperator)) 68 | 69 | class CollisionWorld(Entity): 70 | file_ext = "usr" 71 | labels = "Node1 Node2 f1x f1y f1z f2x f2y f2z Ftx Fty Ftz Fn".split() 72 | def write(self, f): 73 | f.write("\tuser defined: " + self.safe_name() + ", collision world,\n\t\tmaterial pairs, " + str(len(self.first))) 74 | for i, x in enumerate(self.first): 75 | f.write(",\n\t\t\t" + ", ".join([BPY.FORMAT(x), BPY.FORMAT(self.second[i]), "reference, " + self.constitutive[i].safe_name()])) 76 | f.write((",\n\t\t\t\tfriction function, \"" + self.function[i].name + "\",\n\t\t\t\tpenetration ratio, " + BPY.FORMAT(self.penetration[i])) if self.function[i] else "") 77 | f.write(",\n\t\tcollision objects, " + str(len(self.collision_objects))) 78 | for co in self.collision_objects: 79 | f.write(",\n\t\t\t" + BPY.FORMAT(co)) 80 | f.write(";\n") 81 | 82 | class CollisionWorldOperator: 83 | bl_label = "Collision world" 84 | exclusive = True 85 | N_objects = 0 86 | first = bpy.props.CollectionProperty(type=BPY.Str) 87 | second = bpy.props.CollectionProperty(type=BPY.Str) 88 | constitutive = bpy.props.CollectionProperty(type=BPY.Constitutive) 89 | penetration = bpy.props.CollectionProperty(type=BPY.Float) 90 | function = bpy.props.CollectionProperty(type=BPY.Function) 91 | N_pairs = bpy.props.IntProperty(min=1, max=50, name="Material pairs", default=1) 92 | @classmethod 93 | def poll(cls, context): 94 | ob_set = set([e.objects[0] for e in database.element.filter(["Box", "Capsule", "Cone", "Plane", "Sphere"])]) 95 | return set([o for o in context.selected_objects if o.type == 'MESH']) <= ob_set 96 | def prereqs(self, context): 97 | super().prereqs(context) 98 | for collection in [self.first, self.second, self.penetration]: 99 | collection.clear() 100 | for i in range(50): 101 | c = collection.add() 102 | c.mandatory = True 103 | self.constitutive.clear() 104 | self.function.clear() 105 | for i in range(50): 106 | c = self.constitutive.add() 107 | c.mandatory = True 108 | c.dimension = "1D" 109 | self.function.add() 110 | def assign(self, context): 111 | super().assign(context) 112 | self.N_pairs = len(self.entity.first) 113 | for i, value in enumerate(self.entity.first): 114 | self.first[i].assign(value) 115 | for i, value in enumerate(self.entity.second): 116 | self.second[i].assign(value) 117 | for i, value in enumerate(self.entity.constitutive): 118 | self.constitutive[i].assign(value) 119 | if hasattr(self.entity, "penetration"): 120 | for i, value in enumerate(self.entity.penetration): 121 | self.penetration[i].assign(value) 122 | for i, value in enumerate(self.entity.function): 123 | self.function[i].assign(value) 124 | def store(self, context): 125 | self.entity.first = [x.store() for x in self.first][:self.N_pairs] 126 | self.entity.second = [x.store() for x in self.second][:self.N_pairs] 127 | self.entity.constitutive = [x.store() for x in self.constitutive][:self.N_pairs] 128 | self.entity.penetration = [x.store() for x in self.penetration][:self.N_pairs] 129 | self.entity.function = [x.store() for x in self.function][:self.N_pairs] 130 | self.entity.collision_objects = [e for e in database.element.filter(["Box", "Capsule", "Cone", "Plane", "Sphere"]) 131 | if e.objects[0] in [o for o in context.selected_objects if o.type == 'MESH']] 132 | self.entity.objects = [e.objects[0] for e in self.entity.collision_objects] 133 | self.entity.labels = list() 134 | for i in range(4 * int(((len(self.entity.objects) - 1) * len(self.entity.objects)) / 2)): 135 | for x in CollisionWorld.labels: 136 | self.entity.labels.append("_".join([x, str(i + 1)])) 137 | def draw(self, context): 138 | super().draw(context) 139 | self.basis = self.N_pairs 140 | layout = self.layout 141 | layout.prop(self, "N_pairs") 142 | for i in range(self.N_pairs): 143 | layout.label("Pair-" + str(i + 1) + ":") 144 | self.first[i].draw(layout, "") 145 | self.second[i].draw(layout, "") 146 | self.constitutive[i].draw(layout, "") 147 | self.function[i].draw(layout, "Friction") 148 | if self.function[i].select: 149 | self.penetration[i].draw(layout, "Penetration ratio") 150 | def check(self, context): 151 | return (self.basis != self.N_pairs) or True in [(True in [x.check(context) for x in X]) for X in [self.first, self.second, self.constitutive, self.penetration, self.function]] 152 | def create_entity(self): 153 | return CollisionWorld(self.name) 154 | 155 | klass_list.append((CollisionWorld, CollisionWorldOperator)) 156 | 157 | class CollisionObject(Entity): 158 | group = "Collision object" 159 | def write(self, f): 160 | f.write("\tuser defined: " + self.safe_name() + ", collision object") 161 | self.write_node(f, 0, node=True, position=True, orientation=True) 162 | f.write(",\n\t\t" + BPY.FORMAT(self.material)) 163 | 164 | class Collision: 165 | material = bpy.props.PointerProperty(type=BPY.Str) 166 | @classmethod 167 | def poll(cls, context): 168 | return super().poll(context) and "libmodule-collision" in [x.value_type for x in database.input_card.filter("Module load")] 169 | def prereqs(self, context): 170 | self.material.mandatory = True 171 | self.material.is_card = True 172 | def assign(self, context): 173 | self.material.assign(self.entity.material) 174 | def store(self, context): 175 | super().store(context) 176 | self.entity.objects[0].parent = self.entity.objects[1] 177 | self.entity.objects[0].matrix_parent_inverse = self.entity.objects[1].matrix_basis.inverted() 178 | self.entity.material = self.material.store() 179 | self.entity.objects = self.sufficient_objects(context) 180 | def draw(self, context): 181 | self.material.draw(self.layout, "Material", "Set") 182 | def check(self, context): 183 | return self.material.check(context) 184 | 185 | class Box(CollisionObject): 186 | def write(self, f): 187 | super().write(f) 188 | f.write(", box, " + ", ".join([BPY.FORMAT(x) for x in [self.x, self.y, self.z,]]) + ";\n") 189 | def remesh(self): 190 | bm = bmesh.new() 191 | bmesh.ops.create_cube(bm, size=2.0*self.x) 192 | for v in bm.verts: 193 | v.co[1] = math.copysign(self.y, v.co[1]) 194 | v.co[2] = math.copysign(self.z, v.co[2]) 195 | bm.to_mesh(self.objects[0].data) 196 | bm.free() 197 | 198 | class BoxOperator(Collision): 199 | bl_label = "Box" 200 | x = bpy.props.FloatProperty(precision=6, min=0.0, default=1.0, name="x") 201 | y = bpy.props.FloatProperty(precision=6, min=0.0, default=1.0, name="y") 202 | z = bpy.props.FloatProperty(precision=6, min=0.0, default=1.0, name="z") 203 | def assign(self, context): 204 | self.x = self.entity.x 205 | self.y = self.entity.y 206 | self.z = self.entity.z 207 | super().assign(context) 208 | def store(self, context): 209 | self.entity.x = self.x 210 | self.entity.y = self.y 211 | self.entity.z = self.z 212 | super().store(context) 213 | def draw(self, context): 214 | layout = self.layout 215 | layout.label("Half extents:") 216 | layout.prop(self, "x") 217 | layout.prop(self, "y") 218 | layout.prop(self, "z") 219 | super().draw(context) 220 | def create_entity(self): 221 | return Box(self.name) 222 | 223 | #klass_list.append((Box, BoxOperator)) 224 | 225 | class Capsule(CollisionObject): 226 | def write(self, f): 227 | super().write(f) 228 | f.write(", capsule, " + ", ".join([BPY.FORMAT(x) for x in [self.radius, self.height]]) + ";\n") 229 | def remesh(self): 230 | bm = bmesh.new() 231 | bmesh.ops.create_uvsphere(bm, u_segments=16, v_segments=32, diameter=self.radius) 232 | for v in bm.verts: 233 | if 0.0 < v.co[2]: 234 | bm.verts.remove(v) 235 | hold = bm.verts[:] + bm.edges[:] + bm.faces[:] 236 | loop = list() 237 | for e in bm.edges: 238 | if not [v for v in e.verts if v.co[2] < -1e-5*self.radius]: 239 | loop.append(e) 240 | geom = bmesh.ops.extrude_edge_only(bm, edges=loop)["geom"] 241 | verts = [ele for ele in geom if isinstance(ele, bmesh.types.BMVert)] 242 | bmesh.ops.translate(bm, verts=verts, vec=(0.0, 0.0, self.height)) 243 | geom = bmesh.ops.duplicate(bm, geom=hold)["geom"] 244 | verts = [ele for ele in geom if isinstance(ele, bmesh.types.BMVert)] 245 | bmesh.ops.rotate(bm, verts=verts, cent=(0.0, 0.0, 0.0), matrix=mathutils.Matrix.Rotation(math.radians(180.0), 3, 'X')) 246 | bmesh.ops.translate(bm, verts=verts, vec=(0.0, 0.0, self.height)) 247 | bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=1e-5*self.radius) 248 | bmesh.ops.translate(bm, verts=bm.verts, vec=(0.0, 0.0, -0.5*self.height)) 249 | bmesh.ops.rotate(bm, verts=bm.verts, cent=(0.0, 0.0, 0.0), matrix=mathutils.Matrix.Rotation(math.radians(-90.0), 3, 'X')) 250 | bm.to_mesh(self.objects[0].data) 251 | bm.free() 252 | 253 | class CapsuleOperator(Collision): 254 | bl_label = "Capsule" 255 | radius = bpy.props.FloatProperty(precision=6, min=0.0, default=1.0, name="Radius") 256 | height = bpy.props.FloatProperty(precision=6, min=0.0, default=1.0, name="Height") 257 | def assign(self, context): 258 | self.radius = self.entity.radius 259 | self.height = self.entity.height 260 | super().assign(context) 261 | def store(self, context): 262 | self.entity.radius = self.radius 263 | self.entity.height = self.height 264 | super().store(context) 265 | def draw(self, context): 266 | layout = self.layout 267 | layout.prop(self, "radius") 268 | layout.prop(self, "height") 269 | super().draw(context) 270 | def create_entity(self): 271 | return Capsule(self.name) 272 | 273 | #klass_list.append((Capsule, CapsuleOperator)) 274 | 275 | class Cone(CollisionObject): 276 | def write(self, f): 277 | super().write(f) 278 | f.write(", cone, " + ", ".join([BPY.FORMAT(x) for x in [self.radius, self.height]]) + ";\n") 279 | def remesh(self): 280 | bm = bmesh.new() 281 | bmesh.ops.create_cone(bm, diameter1=self.radius, diameter2=0, segments=32, depth=self.height) 282 | geom = bm.verts[:] + bm.edges[:] + bm.faces[:] 283 | geom = bmesh.ops.duplicate(bm, geom=geom)["geom"] 284 | verts = [ele for ele in geom if isinstance(ele, bmesh.types.BMVert)] 285 | bmesh.ops.rotate(bm, verts=verts, cent=(0.0, 0.0, 0.0), matrix=mathutils.Matrix.Rotation(math.radians(180.0), 3, 'X')) 286 | for v in verts: 287 | v.co[2] = -0.5*self.height 288 | bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=1e-5*self.height) 289 | bmesh.ops.rotate(bm, verts=bm.verts, cent=(0.0, 0.0, 0.0), matrix=mathutils.Matrix.Rotation(math.radians(-90.0), 3, 'X')) 290 | bm.to_mesh(self.objects[0].data) 291 | bm.free() 292 | 293 | class ConeOperator(CapsuleOperator): 294 | bl_label = "Cone" 295 | def create_entity(self): 296 | return Cone(self.name) 297 | 298 | #klass_list.append((Cone, ConeOperator)) 299 | 300 | class Sphere(CollisionObject): 301 | def write(self, f): 302 | super().write(f) 303 | f.write(", sphere, " + BPY.FORMAT(self.radius) +";\n") 304 | def remesh(self): 305 | bm = bmesh.new() 306 | bmesh.ops.create_icosphere(bm, subdivisions=3, diameter=self.radius) 307 | bm.to_mesh(self.objects[0].data) 308 | bm.free() 309 | 310 | class SphereOperator(Collision): 311 | bl_label = "Sphere" 312 | radius = bpy.props.FloatProperty(precision=6, min=0.0, default=1.0, name="Radius") 313 | def assign(self, context): 314 | self.radius = self.entity.radius 315 | super().assign(context) 316 | def store(self, context): 317 | self.entity.radius = self.radius 318 | super().store(context) 319 | def draw(self, context): 320 | self.layout.prop(self, "radius") 321 | super().draw(context) 322 | def create_entity(self): 323 | return Sphere(self.name) 324 | 325 | klass_list.append((Sphere, SphereOperator)) 326 | 327 | class Plane(CollisionObject): 328 | def write(self, f): 329 | super().write(f) 330 | f.write(", plane;\n") 331 | def remesh(self): 332 | bm = bmesh.new() 333 | for v in [(10.,10.,0.),(-10.,10.,0.),(-10.,-10.,0.),(10.,-10.,0.)]: 334 | bm.verts.new(v) 335 | if hasattr(bm.verts, "ensure_lookup_table"): 336 | bm.verts.ensure_lookup_table() 337 | bm.faces.new(bm.verts) 338 | bm.to_mesh(self.objects[0].data) 339 | bm.free() 340 | 341 | class PlaneOperator(Collision): 342 | bl_label = "Plane" 343 | def create_entity(self): 344 | return Plane(self.name) 345 | 346 | klass_list.append((Plane, PlaneOperator)) 347 | -------------------------------------------------------------------------------- /function.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | if "bpy" in locals(): 26 | import imp 27 | for x in [base, common, menu]: 28 | imp.reload(x) 29 | else: 30 | from . import base 31 | from . import common 32 | from . import menu 33 | from .base import bpy, database, Operator, Entity, Bundle, BPY 34 | from .common import FORMAT 35 | from .menu import default_klasses, function_tree 36 | 37 | class Base(Operator): 38 | bl_label = "Functions" 39 | bl_options = {'DEFAULT_CLOSED'} 40 | @classmethod 41 | def poll(cls, context): 42 | return True 43 | @classmethod 44 | def make_list(self, ListItem): 45 | bpy.types.Scene.function_uilist = bpy.props.CollectionProperty(type = ListItem) 46 | bpy.types.Scene.function_index = bpy.props.IntProperty(default=-1) 47 | @classmethod 48 | def delete_list(self): 49 | del bpy.types.Scene.function_uilist 50 | del bpy.types.Scene.function_index 51 | @classmethod 52 | def get_uilist(self, context): 53 | return context.scene.function_index, context.scene.function_uilist 54 | def set_index(self, context, value): 55 | context.scene.function_index = value 56 | 57 | klasses = default_klasses(function_tree, Base) 58 | 59 | class Const(Entity): 60 | def write(self, f): 61 | f.write("scalar function: \"" + self.name + "\", const, " + BPY.FORMAT(self.constant) + ";\n") 62 | 63 | class ConstOperator(Base): 64 | bl_label = "Const" 65 | constant = bpy.props.PointerProperty(type = BPY.Float) 66 | def prereqs(self, context): 67 | self.constant.mandatory = True 68 | def assign(self, context): 69 | self.constant.assign(self.entity.constant) 70 | def store(self, context): 71 | self.entity.constant = self.constant.store() 72 | def draw(self, context): 73 | self.constant.draw(self.layout, "Constant") 74 | def check(self, context): 75 | return self.constant.check(context) 76 | def create_entity(self): 77 | return Const(self.name) 78 | 79 | klasses[ConstOperator.bl_label] = ConstOperator 80 | 81 | class Exp(Entity): 82 | def write(self, f): 83 | f.write("scalar function: \"" + self.name + "\", exp") 84 | if self.base is not None: 85 | f.write(", base, " + BPY.FORMAT(self.base)) 86 | if self.coefficient is not None: 87 | f.write(", coefficient, " + BPYFORMAT(self.coefficient)) 88 | f.write(", " + BPY.FORMAT(self.multiplier) + ";\n") 89 | 90 | class ExpLog(Base): 91 | base = bpy.props.PointerProperty(type = BPY.Float) 92 | coefficient = bpy.props.PointerProperty(type = BPY.Float) 93 | multiplier = bpy.props.PointerProperty(type = BPY.Float) 94 | def prereqs(self, context): 95 | self.multiplier.mandatory = True 96 | def assign(self, context): 97 | self.base.assign(self.entity.base) 98 | self.coefficient.assign(self.entity.coefficient) 99 | self.multiplier.assign(self.entity.multiplier) 100 | def store(self, context): 101 | self.entity.base = self.base.store() 102 | self.entity.coefficient = self.coefficient.store() 103 | self.entity.multiplier = self.multiplier.store() 104 | def draw(self, context): 105 | self.base.draw(self.layout, "Base (else e)") 106 | self.coefficient.draw(self.layout, "Coefficient (else 1)") 107 | self.multiplier.draw(self.layout, "Multiplier") 108 | def check(self, context): 109 | return self.base.check(context) or self.coefficient.check(context) or self.multiplier.check(context) 110 | 111 | class ExpOperator(ExpLog): 112 | bl_label = "Exp" 113 | def create_entity(self): 114 | return Exp(self.name) 115 | 116 | klasses[ExpOperator.bl_label] = ExpOperator 117 | 118 | class Log(Entity): 119 | def write(self, f): 120 | f.write("scalar function: \"" + self.name + "\", log") 121 | if self.base is not None: 122 | f.write(", base, " + BPY.FORMAT(self.base)) 123 | if self.coefficient is not None: 124 | f.write(", coefficient, " + BPY.FORMAT(self.coefficient)) 125 | f.write(", " + FORMAT(self.multiplier) + ";\n") 126 | 127 | class LogOperator(ExpLog): 128 | bl_label = "Log" 129 | def create_entity(self): 130 | return Log(self.name) 131 | 132 | klasses[LogOperator.bl_label] = LogOperator 133 | 134 | class Pow(Entity): 135 | def write(self, f): 136 | f.write("scalar function: \"" + self.name + "\", pow, " + BPY.FORMAT(self.power) + ";\n") 137 | 138 | class PowOperator(Base): 139 | bl_label = "Pow" 140 | power = bpy.props.PointerProperty(type = BPY.Float) 141 | def prereqs(self, context): 142 | self.power.mandatory = True 143 | def assign(self, context): 144 | self.power.assign(self.entity.power) 145 | def store(self, context): 146 | self.entity.power = self.power.store() 147 | def draw(self, context): 148 | self.power.draw(self.layout, "Power") 149 | def check(self, context): 150 | return self.power.check(context) 151 | def create_entity(self): 152 | return Pow(self.name) 153 | 154 | klasses[PowOperator.bl_label] = PowOperator 155 | 156 | class Linear(Entity): 157 | def write(self, f): 158 | f.write("scalar function: \"" + self.name + "\", linear") 159 | f.write(",\n\t\t" + ", ".join([BPY.FORMAT(x) for x in self.X])) 160 | f.write(", " + ", ".join([BPY.FORMAT(x) for x in self.X]) + ";\n") 161 | 162 | class LinearOperator(Base): 163 | bl_label = "Linear" 164 | X = bpy.props.CollectionProperty(type = BPY.Float) 165 | Y = bpy.props.CollectionProperty(type = BPY.Float) 166 | def prereqs(self, context): 167 | self.X.clear() 168 | self.Y.clear() 169 | for i in range(2): 170 | x = self.X.add() 171 | x.mandatory = True 172 | y = self.Y.add() 173 | y.mandatory = True 174 | def assign(self, context): 175 | for i, x in enumerate(self.entity.X): 176 | self.X[i].assign(x) 177 | for i, y in enumerate(self.entity.Y): 178 | self.Y[i].assign(y) 179 | def store(self, context): 180 | self.entity.X = [x.store() for x in self.X] 181 | self.entity.Y = [y.store() for y in self.Y] 182 | def draw(self, context): 183 | layout = self.layout 184 | row = layout.row() 185 | row.label("X") 186 | row.label("Y") 187 | for i in range(2): 188 | row = layout.row() 189 | self.X[i].draw(row, "") 190 | self.Y[i].draw(row, "") 191 | def check(self, context): 192 | return True in [x.check(context) for x in self.X] + [y.check(context) for y in self.Y] 193 | def create_entity(self): 194 | return Linear(self.name) 195 | 196 | klasses[LinearOperator.bl_label] = LinearOperator 197 | 198 | class CubicNaturalSpline(Entity): 199 | def write(self, f): 200 | f.write("scalar function: \"" + self.name + "\", cubicspline") 201 | if not self.extrapolate: 202 | f.write(", do not extrapolate") 203 | for i in range(self.N): 204 | f.write(",\n\t\t" + BPY.FORMAT(self.X[i]) + ", " + BPY.FORMAT(self.Y[i])) 205 | f.write(";\n") 206 | 207 | class Multiple(Base): 208 | extrapolate = bpy.props.BoolProperty(name="Extrapolate", default=True) 209 | N = bpy.props.IntProperty(name="Number of points", min=2, max=50, description="", default=2) 210 | X = bpy.props.CollectionProperty(type = BPY.Float) 211 | Y = bpy.props.CollectionProperty(type = BPY.Float) 212 | def prereqs(self, context): 213 | self.X.clear() 214 | self.Y.clear() 215 | for i in range(50): 216 | x = self.X.add() 217 | x.mandatory = True 218 | y = self.Y.add() 219 | y.mandatory = True 220 | def assign(self, context): 221 | self.extrapolate = self.entity.extrapolate 222 | self.N = self.entity.N 223 | for i, x in enumerate(self.entity.X): 224 | self.X[i].assign(x) 225 | for i, y in enumerate(self.entity.Y): 226 | self.Y[i].assign(y) 227 | def store(self, context): 228 | self.entity.extrapolate = self.extrapolate 229 | self.entity.N = self.N 230 | self.entity.X = [x.store() for x in self.X][:self.entity.N] 231 | self.entity.Y = [y.store() for y in self.Y][:self.entity.N] 232 | def draw(self, context): 233 | self.basis = self.N 234 | layout = self.layout 235 | layout.prop(self, "extrapolate") 236 | layout.prop(self, "N") 237 | row = layout.row() 238 | row.label("X") 239 | row.label("Y") 240 | for i in range(self.N): 241 | row = layout.row() 242 | self.X[i].draw(row, "") 243 | self.Y[i].draw(row, "") 244 | def check(self, context): 245 | return (self.basis != self.N) or True in [x.check(context) for x in self.X] + [y.check(context) for y in self.Y] 246 | 247 | class CubicNaturalSplineOperator(Multiple): 248 | bl_label = "Cubic natural spline" 249 | def create_entity(self): 250 | return CubicNaturalSpline(self.name) 251 | 252 | #klasses[CubicNaturalSplineOperator.bl_label] = CubicNaturalSplineOperator 253 | 254 | class Multilinear(Entity): 255 | def write(self, f): 256 | f.write("scalar function: \"" + self.name + "\", multilinear") 257 | if not self.extrapolate: 258 | f.write(", do not extrapolate") 259 | for i in range(self.N): 260 | f.write(",\n\t\t" + BPY.FORMAT(self.X[i]) + ", " + BPY.FORMAT(self.Y[i])) 261 | f.write(";\n") 262 | 263 | class MultilinearOperator(Multiple): 264 | bl_label = "Multilinear" 265 | def create_entity(self): 266 | return Multilinear(self.name) 267 | 268 | klasses[MultilinearOperator.bl_label] = MultilinearOperator 269 | 270 | class Chebychev(Entity): 271 | def write(self, f): 272 | f.write("scalar function: \"" + self.name + "\", chebychev") 273 | f.write(",\n\t\t" + BPY.FORMAT(self.lower_bound) + ", " + BPY.FORMAT(self.upper_bound)) 274 | if not self.extrapolate: 275 | f.write(", do not extrapolate") 276 | N = int(self.N/4) 277 | for i in range(N): 278 | f.write(",\n\t\t" + ", ".join([BPY.FORMAT(c) for c in self.C[4*i:4*(i+1)]])) 279 | if 4*N == self.N: 280 | f.write(";\n") 281 | else: 282 | f.write(",\n\t\t" + ", ".join([BPY.FORMAT(c) for c in self.C[4*N:self.N]]) + ";\n") 283 | 284 | class ChebychevOperator(Base): 285 | bl_label = "Chebychev" 286 | lower_bound = bpy.props.PointerProperty(type = BPY.Float) 287 | upper_bound = bpy.props.PointerProperty(type = BPY.Float) 288 | extrapolate = bpy.props.BoolProperty(name="Extrapolate", default=True) 289 | N = bpy.props.IntProperty(name="Number of points", min=2, max=50, description="", default=2) 290 | C = bpy.props.CollectionProperty(type = BPY.Float) 291 | def prereqs(self, context): 292 | self.lower_bound.mandatory = True 293 | self.upper_bound.mandatory = True 294 | self.C.clear() 295 | for i in range(50): 296 | c = self.C.add() 297 | c.mandatory = True 298 | def assign(self, context): 299 | self.lower_bound.assign(self.entity.lower_bound) 300 | self.upper_bound.assign(self.entity.upper_bound) 301 | self.extrapolate = self.entity.extrapolate 302 | self.N = len(self.entity.C) 303 | for i, value in enumerate(self.entity.C): 304 | self.C[i].assign(value) 305 | def store(self, context): 306 | self.entity.lower_bound = self.lower_bound.store() 307 | self.entity.upper_bound = self.upper_bound.store() 308 | self.entity.extrapolate = self.extrapolate 309 | self.entity.C = [c.store() for c in self.C][:self.N] 310 | def draw(self, context): 311 | self.basis = self.N 312 | layout = self.layout 313 | self.lower_bound.draw(layout, "Lower bound") 314 | self.upper_bound.draw(layout, "Upper bound") 315 | layout.prop(self, "extrapolate") 316 | layout.prop(self, "N") 317 | layout.label("Coefficients") 318 | for i in range(self.N): 319 | self.C[i].draw(layout, "") 320 | def check(self, context): 321 | return (self.basis != self.N) or self.lower_bound.check(context) or self.upper_bound.check(context) or True in [c.check(context) for c in self.C] 322 | def create_entity(self): 323 | return Chebychev(self.name) 324 | 325 | klasses[ChebychevOperator.bl_label] = ChebychevOperator 326 | 327 | class Sum(Entity): 328 | def write(self, f): 329 | f.write("scalar function: \"" + self.name + "\", sum") 330 | f.write(",\n\t\t\"" + self.functions[0].name + "\", \"" + self.functions[1].name + "\";\n") 331 | 332 | class Binary(Base): 333 | functions = bpy.props.CollectionProperty(type = BPY.Function) 334 | def prereqs(self, context): 335 | self.functions.clear() 336 | for i in range(2): 337 | f = self.functions.add() 338 | f.mandatory = True 339 | def assign(self, context): 340 | for i, f in enumerate(self.entity.functions): 341 | self.functions[i].assign(f) 342 | def store(self, context): 343 | self.entity.functions = [f.store() for f in self.functions] 344 | def draw(self, context): 345 | layout = self.layout 346 | for i in range(2): 347 | self.functions[i].draw(layout, "Function " + str(i+1)) 348 | def check(self, context): 349 | return True in [f.check(context) for f in self.functions] 350 | 351 | class SumOperator(Binary): 352 | bl_label = "Sum" 353 | def create_entity(self): 354 | return Sum(self.name) 355 | 356 | klasses[SumOperator.bl_label] = SumOperator 357 | 358 | class Sub(Entity): 359 | def write(self, f): 360 | f.write("scalar function: \"" + self.name + "\", sub") 361 | f.write(",\n\t\t\"" + self.functions[0].name + "\", \"" + self.functions[1].name + "\";\n") 362 | 363 | class SubOperator(Binary): 364 | bl_label = "Sub" 365 | def create_entity(self): 366 | return Sub(self.name) 367 | 368 | klasses[SubOperator.bl_label] = SubOperator 369 | 370 | class Mul(Entity): 371 | def write(self, f): 372 | f.write("scalar function: \"" + self.name + "\", mul") 373 | f.write(",\n\t\t\"" + self.functions[0].name + "\", \"" + self.functions[1].name + "\";\n") 374 | 375 | class MulOperator(Binary): 376 | bl_label = "Mul" 377 | def create_entity(self): 378 | return Mul(self.name) 379 | 380 | klasses[MulOperator.bl_label] = MulOperator 381 | 382 | class Div(Entity): 383 | def write(self, f): 384 | f.write("scalar function: \"" + self.name + "\", div") 385 | f.write(",\n\t\t\"" + self.functions[0].name + "\", \"" + self.functions[1].name + "\";\n") 386 | 387 | class DivOperator(Binary): 388 | bl_label = "Div" 389 | def create_entity(self): 390 | return Div(self.name) 391 | 392 | klasses[DivOperator.bl_label] = DivOperator 393 | 394 | bundle = Bundle(function_tree, Base, klasses, database.function) 395 | -------------------------------------------------------------------------------- /help/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 16 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 55 | 56 |

Disclaimer:

57 |

This manual was written with the intent of giving a quick reference to the suer who is using BAM v2. It does not pretend to be complete. The descriptions given here come from the MBDyn official input manual, the BAM v2 mailing lists, and the available video tutorials.

58 | 59 | 60 |

Installation:

61 | To install BlenderAndMBDyn v2 (BAM) from the Blender interface go to menu File->User Preferences and at the bottom of the panel which appear click the Install from file button. 62 | The procedure is fairly straightfoward but a few details should be taken into consideration: 63 |
    64 |
  • It is recommmended to use Blender 2.72 or newer and a recent MBDyn version;
  • 65 |
  • Before reinstalling BAM, it should first be uninstalled from Blender which should also be restarted;
  • 66 |
  • The software is still in development and any bug reports are welcomed on the Github page.
  • 67 |
68 | 69 |

Video Tutorials:

70 | The simplest way to learn the basics of the BAM v2 tool is to watch a few of the video tutorials. 71 | The important ones are listed here: 72 |
    73 |
  • Crank and slider; construct, simulate, drive through the keyboard while simulating, animate while simulating, and analyze a Crank and Slider model in MBDyn.
  • 74 |
  • Double pendulum; construct, simulate, and analyze a double pendulum.
  • 75 |
  • Chain; construct, simulate, and analyze a four link chain.
  • 76 |
77 | 78 | 79 |

Elements:

80 |

81 | The elements section is the basis of the BAM software. You may create an element by clicking on the + button and choosing from the list. If you currently have a Blender mesh object selected, it will become that element. Usually, one will start by creating a Body. Another common element which needs to be inserted is the Gravity element. The + button will expand the menu to also show filtering options of the element list. The inverse triangle button will allow one to edit an element or see a list of its users. Double clicking on a name in the list allows to change the said name. In case of a name conflict when creating a new element, a number will be added to the end of the chosen name. 82 |

83 | 84 |

85 | 86 |

Body:

87 |

88 | A body represents a mass in the multibody model. It requires a mass value, which can be set as a variable name by ticking the checkbox. It also requires a 3x3 matrix of inertia. 89 |

90 | If no Blender mesh object is selected when creating a body, a new one will be created at the location of the cursor. Upon accepting the body creation dialog, the user is invited by the "Object specifications" dialog to modify numerically the position and orientation of the body. This is optional and, in any case, any modifications brough by the user to the associated Blender mesh object will be also applied to the body. 91 |

92 | Click to show/hide elaborate explanation 93 |

94 | The body element describes a lumped rigid body connected to a 6 degree of freedom 95 | structural node. The inertia matrix is always referred to the center of mass of the mass that is being added. 96 |
97 |

98 | 99 | 100 | 101 | 102 | 103 | 104 |

Constitutive:

105 |

106 | 107 |

108 | 109 | 110 |

Drive:

111 |

112 | 113 |

114 | 115 | 116 |

Friction:

117 |

118 | 119 |

120 | 121 | 122 | 123 | 124 | 130 | 131 | 132 |

Structural force:

133 |

134 | The structural force element allows to apply a force to the selected element. It can be ither absolute or follower. And absolute force will always have the same position and orientation while the follower force will follow the object to which it is applied. The force value is defined by a driver. 135 |

136 | 137 | 138 |

StructuralInternalForce:

139 |

140 | 141 |

142 | 143 | 144 | 145 | 146 | 147 |

StructuralCouple:

148 |

149 | 150 |

151 | 152 | 153 | 154 | 155 | 156 |

StructuralInternalCouple:

157 |

158 | 159 |

160 | 161 | 162 | 163 | 164 | 165 | 171 | 172 | 173 |

Hinge:

174 |

175 | 176 |

177 | 178 | 179 |

AxialRotation:

180 |

181 | 182 |

183 | 184 | 185 |

Clamp:

186 |

187 | The clamp element is used to rigidly fixed a node in space. Use this element to create a solid ground to which moving ovjects may be attached later on. 188 |

189 | 190 | 191 | 192 |

DeformableDisplacementJoint:

193 |

194 | This joint implements a configuration dependent force that is exchanged between two points associated 195 | to two nodes with an offset. The force may depend, by way of a generic 3D constitutive law, on the 196 | relative position and velocity of the two points, expressed in the reference frame of node 1. 197 | The constitutive law is attached to the reference frame of node 1 (TODO: selected last?), so the sequence of the connections 198 | may matter in case of anisotropic constitutive laws, if the relative orientation of the two nodes changes 199 | during the analysis. 200 | 201 |

202 | 203 | 204 | 205 | 206 | 207 |

DeformableHinge:

208 |

209 | 210 |

211 | 212 | 213 | 214 | 215 | 216 |

DeformableJoint:

217 |

218 | 219 |

220 | 221 | 222 | 223 | 224 | 225 |

Distance:

226 |

227 | 228 |

229 | 230 | 231 | 232 | 233 | 234 |

InLine:

235 |

236 | 237 |

238 | 239 | 240 | 241 | 242 | 243 |

InPlane:

244 |

245 | 246 |

247 | 248 | 249 | 250 | 251 | 252 |

RevoluteHinge:

253 |

254 | 255 |

256 | 257 | 258 | 259 | 260 | 261 |

Rod:

262 |

263 | 264 |

265 | 266 | 267 | 268 | 269 | 270 |

Spherical Hinge:

271 |

272 | This joint constrains the relative position of two nodes; the relative orientation is not constrained. 273 |

274 | 275 | 276 | 281 | 282 | 283 |

Total Joint:

284 |

285 | The total joint allows to arbitrarily impose constraints between two nodes in the form of user chosen drivers. 286 |

287 | 288 | 289 | 290 | 291 | 292 |

ViscousBody:

293 |

294 | 295 |

296 | 297 | 298 | 299 | 300 | 301 |

StreamOutput:

302 |

303 | 304 |

305 | 306 | 307 | 308 | 309 | 310 |

StreamAnimation:

311 |

312 | 313 |

314 | 315 | 316 | 317 | 318 | 319 |

Gravity:

320 |

321 | The Gravity element is used to add a gravity force to the simulation. Many times one will want to define it as a constant drive with a value of 9.81 m/s^2. The gravity element does not get linked with any Blender mesh object. Any type of gravity may be defined by combining the required vector input with a chosen driver. 322 |

323 | 324 | 325 | 326 |

BodyMass:

327 |

328 | 329 |

330 | 331 | 332 | 333 | 334 | 335 |

RigidOffset:

336 |

337 | 338 |

339 | 340 | 341 | 342 | 343 | 344 |

DummyNode:

345 |

346 | The dummy structural node has been added to ease the visualization of the kinematics of arbitrary points 347 | of the system during the simulation. It does not provide any degrees of freedom, and it must be attached 348 | to another node. 349 | 350 |

351 | 352 | 353 | 354 | 355 | 356 |

BeamSegment:

357 |

358 | 359 |

360 | 361 | 362 | 363 | 364 | 365 |

Constitutives:

366 |

367 |

368 | 369 | 378 | 379 | 380 |

file drive:

381 |

382 | The file format is
383 | # an arbitrary number of comment lines starting with '#'
384 | #
385 | # comment lines may provide special parameters
386 | # like "initial time", "time step" as indicated above; for example
387 | #
388 | # initial time: 0
389 | # time step: 0.01
390 | #
391 | # channel #1 channel #2 ... channel #n
392 | 1. 2. ... 100.
393 | ...
394 | Example.
395 | begin: drivers;
396 | file: 100,
397 | fixed step,
398 | 100, # n. steps
399 | 1, # n. channels
400 | 0, # initial_time
401 | 0.01, # time_step
402 | "input.dat";
403 | file: 200,
404 | fixed step,
405 | count, # n. steps
406 | 1, # n. channels
407 | from file, # initial_time
408 | from file, # time_step
409 | "input.dat";
410 | end: drivers; 411 | 412 |

413 | 414 | 415 |

Input card

416 |

417 | This panel allows to create new variables by name. These may then be used throughout the model. 418 |

419 | Click to show/hide elaborate explanation 420 |

421 | The user is encouraged to use such variables to simplify the creation of the model. A typical example would be to define variables of mass, length, height, and depth of a body to then be able to easily change later on the properties of that body. The values can be changed without having to manually edit all the matrices associated to that body. It becomes even more useful when one would want to scale a complete model by a factor. Mathematical operations can be done to create new variables from previously defined ones. 422 |
423 |

424 | 425 |

Frictions:

426 |

427 |

428 | 429 |

Functions:

430 |

431 |

432 | 433 | 434 | 435 | 436 |

Matrices:

437 |

438 |

439 | 440 |

3x1 Matrix:

441 |

442 |

443 | 444 |

3x3 Matrix:

445 |

446 |

447 | 448 |

Shapes:

449 |

450 |

451 | 452 |

Definitions:

453 |

454 |

455 | 456 |

Simulator:

457 |

458 | This tab allows to create a new simulator/simulation. Only one simulation needs to be created. It can be ran multiple times. After having updated the multibody model, one can simply select the desired simulator and click the Run simulation button followed by the Animated objects button to see the new updated results. 459 | 460 |

i: It is recommended to initially chose a high value of steps between objects when importing the animated results because MBDyn typically has a large number of timesteps and importing all of them in Blender may take a long time. 461 |

462 | Click to show/hide elaborate explanation 463 |

464 | In the panel which ... 465 |
466 |

467 | 468 |

Initial Value:

469 |

470 | This panel allows to set the core preferences of MBDyn and the multibody simulation. By ticking the MBDyn path box, one will be able to give the path to the MBDyn executable to be used. 471 | 472 | The General_data, Output_data, and job_control allow to impose settings in a similar fashion as explained in the MBDyn manual. TODO: insert link to manual ? 473 | 474 | The default_output drop-down menu selector allows to create a set of output values that ought to be printed to the output files when the simulation is ran. 475 |

476 | Click to show/hide elaborate explanation 477 |

478 | ... 479 |
480 |

481 | 482 | 483 | 484 | 485 |

Constitutive law:

486 |

487 | This panel allows to define the laws used by the deformable joints. 488 |

489 | Click to show/hide elaborate explanation 490 |

491 | Every time a "deformable" 492 | entity requires a constitutive law, a template constitutive law is read. 493 | The "deformable" elements at present are:
494 | - rod and genel spring and related elements (1D);
495 | - deformable hinge and deformable displacement joint elements (3D);
496 | - deformable joint and beam elements (6D).
497 | Constitutive laws are also used in non-structural components, to allow some degree of generality in 498 | defining input/output relationships. Some constitutive laws are meaningful only when related to some 499 | precise dimensionality. In some special cases, general purpose (genel) elements use 1D constitutive laws 500 | to express an arbitrary dependence of some value on a scalar state of the system. Table 2.7 shows the 501 | availability of each constitutive law.
502 | The meaning of the input and output parameters of a constitutive law is dictated by the entity that 503 | uses it. In general, the user should refer to the element the constitutive law is being instantiated for in 504 | order to understand what the input and the output parameters are supposed to be. 505 |
506 |

507 | 508 | 509 | 510 | 511 | 512 | -------------------------------------------------------------------------------- /help/info.svg: -------------------------------------------------------------------------------- 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 | image/svg+xmlOpenclipartinfo_lightbulb2007-04-09T12:34:48A lightbulb with a green "info" icon superimposed on it. Suitable for use as a "tip" or "info" or "idea" icon.https://openclipart.org/detail/3836/info_lightbulb-by-selanitSelanitbulbiconinforemixtip -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /simulator.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # BlenderAndMBDyn 3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com 4 | # -------------------------------------------------------------------------- 5 | # ***** BEGIN GPL LICENSE BLOCK ***** 6 | # 7 | # This file is part of BlenderAndMBDyn. 8 | # 9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # BlenderAndMBDyn is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with BlenderAndMBDyn. If not, see . 21 | # 22 | # ***** END GPL LICENCE BLOCK ***** 23 | # -------------------------------------------------------------------------- 24 | 25 | if "bpy" in locals(): 26 | import imp 27 | for x in [base, menu, common, user_defined_common]: 28 | imp.reload(x) 29 | else: 30 | from . import base 31 | from . import menu 32 | from . import common 33 | from . import user_defined_common 34 | from .base import bpy, BPY, root_dot, database, Operator, Entity, Bundle 35 | from .common import FORMAT, safe_name, write_vector, write_orientation, StreamSender, StreamReceiver 36 | from .menu import default_klasses, simulator_tree 37 | from mathutils import Matrix 38 | import subprocess 39 | from tempfile import TemporaryFile 40 | import os 41 | from time import sleep 42 | import sys 43 | from signal import SIGTERM 44 | import math 45 | from mathutils import Vector, Euler, Quaternion 46 | 47 | aerodynamic_types = [ 48 | "Aerodynamic body", 49 | "Aerodynamic beam2", 50 | "Aerodynamic beam3", 51 | "Generic aerodynamic force", 52 | "Induced velocity"] 53 | beam_types = [ 54 | "Beam segment", 55 | "Three node beam"] 56 | force_types = [ 57 | "Structural force", 58 | "Structural internal force", 59 | "Structural couple", 60 | "Structural internal couple", 61 | "Total force", 62 | "Total internal force"] 63 | genel_types = [ 64 | "Swashplate"] 65 | joint_types = [ 66 | "Axial rotation", 67 | "Clamp", 68 | "Distance", 69 | "Deformable displacement joint", 70 | "Deformable hinge", 71 | "Deformable joint", 72 | "In line", 73 | "In plane", 74 | "Revolute hinge", 75 | "Rod", 76 | "Spherical hinge", 77 | "Total joint", 78 | "Viscous body"] 79 | output_types = [ 80 | "Stream animation", 81 | "Stream output"] 82 | environment_types = [ 83 | "Air properties", 84 | "Gravity"] 85 | node_types = [ 86 | "Rigid offset", 87 | "Dummy node", 88 | "Feedback node"] 89 | 90 | rigid_body_types = ["Body"] 91 | 92 | structural_static_types = aerodynamic_types + joint_types + ["Rotor"] + beam_types + force_types 93 | 94 | structural_dynamic_types = rigid_body_types 95 | 96 | class Base(Operator): 97 | bl_label = "Simulators" 98 | @classmethod 99 | def poll(cls, context): 100 | return True 101 | @classmethod 102 | def make_list(self, ListItem): 103 | bpy.types.Scene.simulator_uilist = bpy.props.CollectionProperty(type = ListItem) 104 | def update(self, context): 105 | if database.simulator and self.simulator_index < len(database.simulator): 106 | exec("bpy.ops." + root_dot + "save('INVOKE_DEFAULT')") 107 | bpy.types.Scene.simulator_index = bpy.props.IntProperty(default=-1, update=update) 108 | @classmethod 109 | def delete_list(self): 110 | del bpy.types.Scene.simulator_uilist 111 | del bpy.types.Scene.simulator_index 112 | @classmethod 113 | def get_uilist(self, context): 114 | return context.scene.simulator_index, context.scene.simulator_uilist 115 | def set_index(self, context, value): 116 | context.scene.simulator_index = value 117 | def prereqs(self, context): 118 | pass 119 | def draw_panel_post(self, context, layout): 120 | if context.scene.dirty_simulator: 121 | layout.label("Choose a simulator") 122 | else: 123 | layout.operator(root_dot + "simulate") 124 | if context.scene.clean_log: 125 | layout.operator(root_dot + "write_keyframes") 126 | 127 | klasses = default_klasses(simulator_tree, Base) 128 | 129 | class InitialValue(Entity): 130 | def write_input_file(self, context, directory): 131 | def write_structural_node(f, structural_type, node, frame): 132 | f.write("\tstructural: " + ", ".join([safe_name(node.name), structural_type])) 133 | frame_label = frame.safe_name() if frame else "global" 134 | location, orientation = node.matrix_world.translation, node.matrix_world.to_quaternion().to_matrix() 135 | if frame: 136 | orientation = frame.objects[0].matrix_world.to_quaternion().to_matrix().transposed()*orientation 137 | location = orientation * (location - frame.objects[0].matrix_world.translation) 138 | f.write(",\n\t\treference, " + frame_label) 139 | write_vector(f, location) 140 | f.write(",\n\t\treference, " + frame_label) 141 | write_orientation(f, orientation, "\t\t") 142 | f.write(",\n\t\treference, " + frame_label + ", null" + 143 | ",\n\t\treference, " + frame_label + ", null;\n") 144 | with open(os.path.join(directory, context.scene.name + ".mbd"), "w") as f: 145 | f.write("# MBDyn v1.7 input file generated using BlenderAndMBDyn v2.0\n\n") 146 | frame_for, frames, parent_of = dict(), list(), dict() 147 | reference_frames = database.input_card.filter("Reference frame") 148 | for frame in reference_frames: 149 | frame_for.update({ob : frame for ob in frame.objects[1:]}) 150 | frames.append(frame) 151 | parent_of.update({frame : parent for parent in reference_frames if frame.objects[0] in parent.objects[1:]}) 152 | frames_to_write = list() 153 | while frames: 154 | frame = frames.pop() 155 | if frame in parent_of and parent_of[frame] in frames: 156 | frames.appendleft(frame) 157 | else: 158 | frames_to_write.append(frame) 159 | if frames_to_write: 160 | f.write("# Frame labels:\n") 161 | for i, frame in enumerate(sorted(frames_to_write, key=lambda x: x.name)): 162 | f.write("\tset: const integer " + safe_name(frame.name) + " = " + str(i) + ";\n") 163 | else: 164 | f.write("# Frame labels: none\n") 165 | nodes = set() 166 | dummy_dict = dict() 167 | structural_dynamic_nodes = set() 168 | structural_static_nodes = set() 169 | structural_dummy_nodes = set() 170 | database.rigid_dict = {e.objects[0] : e.objects[1] for e in database.element.filter("Rigid offset") + database.element.filter(user_defined_common.offset_types)} 171 | names = [e.name for e in database.all_entities()] 172 | for e in (e for e in database.element + database.drive if hasattr(e, "objects")): 173 | ob = database.rigid_dict[e.objects[0]] if e.objects[0] in database.rigid_dict else e.objects[0] 174 | if ob.name in names: 175 | ob.name = "Node" 176 | nodes |= set([ob]) 177 | if e.type in structural_dynamic_types + user_defined_common.structural_dynamic_types: 178 | structural_dynamic_nodes |= set([ob]) 179 | elif e.type in structural_static_types + user_defined_common.structural_static_types: 180 | structural_static_nodes |= set([ob]) 181 | elif e.type == "Dummy": 182 | structural_dummy_nodes |= set([ob]) 183 | dummy_dict[ob] = e.objects[1] 184 | structural_static_nodes -= structural_dynamic_nodes | structural_dummy_nodes 185 | database.node.clear() 186 | database.node.extend(sorted(nodes, key=lambda x: x.name)) 187 | if database.node: 188 | f.write("\n# Node labels:\n") 189 | for i, node in enumerate(database.node): 190 | f.write("\tset: const integer " + safe_name(node.name) + " = " + str(i) + ";\n") 191 | else: 192 | f.write("\n# Node labels: none\n") 193 | if database.element: 194 | f.write("\n# Element labels:\n") 195 | for i, element in enumerate(sorted(database.element, key=lambda x: x.name)): 196 | f.write("\tset: const integer " + element.safe_name() + " = " + str(i) + ";\n") 197 | else: 198 | f.write("\n# Element labels: none\n") 199 | if database.drive: 200 | f.write("\n# Drive labels:\n") 201 | for i, drive in enumerate(sorted(database.drive, key=lambda x: x.name)): 202 | f.write("\tset: const integer " + drive.safe_name() + " = " + str(i) + ";\n") 203 | else: 204 | f.write("\n# Drive labels: none\n") 205 | if database.driver: 206 | f.write("\n# Driver labels:\n") 207 | for i, driver in enumerate(sorted(database.driver, key=lambda x: x.name)): 208 | f.write("\tset: const integer " + driver.safe_name() + " = " + str(i) + ";\n") 209 | else: 210 | f.write("\n# Driver labels: none\n") 211 | if database.constitutive: 212 | f.write("\n# Constitutive labels:\n") 213 | for i, constitutive in enumerate(sorted(database.constitutive, key=lambda x: x.name)): 214 | f.write("\tset: const integer " + constitutive.safe_name() + " = " + str(i) + ";\n") 215 | else: 216 | f.write("\n# Constitutive labels: none\n") 217 | set_cards = database.input_card.filter("Set") 218 | if set_cards: 219 | f.write("\n# Parameters:\n") 220 | for set_card in set_cards: 221 | set_card.write(f) 222 | else: 223 | f.write("\n# Parameters: none\n") 224 | module_load_cards = database.input_card.filter("Module load") 225 | if module_load_cards: 226 | f.write("\n# Modules:\n") 227 | for module_load_card in module_load_cards: 228 | module_load_card.write(f) 229 | else: 230 | f.write("\n# Modules: none\n") 231 | structural_node_count = len(structural_static_nodes | structural_dynamic_nodes | structural_dummy_nodes) 232 | joint_count = len([e for e in database.element if e.type in joint_types]) 233 | output_count = len([e for e in database.element if e.type in output_types]) 234 | force_count = len([e for e in database.element if e.type in force_types]) 235 | rigid_body_count = len([e for e in database.element if e.type in rigid_body_types]) 236 | aerodynamic_element_count = len([e for e in database.element if e.type in aerodynamic_types]) 237 | rotor_count = len([e for e in database.element if e.type in ["Rotor"]]) 238 | genel_count = len([e for e in database.element if e.type in genel_types]) 239 | beam_count = len([e for e in database.element if e.type in beam_types and not hasattr(e, "consumer")]) 240 | air_properties = bool([e for e in database.element if e.type in ["Air properties"]]) 241 | gravity = bool([e for e in database.element if e.type in ["Gravity"]]) 242 | loadable_element_count = len([e for e in database.element if e.type in user_defined_common.loadable_element_types]) 243 | file_driver_count = len(database.driver) 244 | bailout_upper = False 245 | upper_bailout_time = 0.0 246 | # electric_node_count = len([e for e in database.ns_node if e.type in ["Electric"]]) 247 | # abstract_node_count = len([e for e in database.ns_node if e.type in ["Abstract"]]) 248 | # hydraulic_node_count = len([e for e in database.ns_node if e.type in ["Hydraulic"]]) 249 | # parameter_node_count = len([e for e in database.ns_node if e.type in ["Parameter"]]) 250 | f.write( 251 | "\nbegin: data" + 252 | ";\n\tproblem: initial value" + 253 | ";\nend: data" + 254 | ";\n\nbegin: initial value" + 255 | ";\n\tinitial time: " + (BPY.FORMAT(self.initial_time) if self.initial_time is not None else "0") + 256 | ";\n\tfinal time: " + (BPY.FORMAT(self.final_time) if self.final_time is not None else "forever") + 257 | ";\n") 258 | for a in [self.general_data, self.method, self.nonlinear_solver, self.eigenanalysis, self.abort_after, self.linear_solver, self.dummy_steps, self.output_data, self.real_time]: 259 | if a is not None: 260 | a.write(f) 261 | f.write("end: initial value;\n" + 262 | "\nbegin: control data;\n") 263 | for a in [self.assembly, self.job_control, self.default_output, self.default_aerodynamic_output, self.default_beam_output]: 264 | if a is not None: 265 | a.write(f) 266 | if structural_node_count: 267 | f.write("\tstructural nodes: " + str(structural_node_count) + ";\n") 268 | """ 269 | if electric_node_count: 270 | f.write("\telectric nodes: " + str(electric_node_count) + ";\n") 271 | if abstract_node_count: 272 | f.write("\tabstract nodes: " + str(abstract_node_count) + ";\n") 273 | if hydraulic_node_count: 274 | f.write("\thydraulic nodes: " + str(hydraulic_node_count) + ";\n") 275 | """ 276 | if joint_count: 277 | f.write("\tjoints: " + str(joint_count) + ";\n") 278 | if output_count: 279 | f.write("\toutput elements: " + str(output_count) + ";\n") 280 | if force_count: 281 | f.write("\tforces: " + str(force_count) + ";\n") 282 | if genel_count: 283 | f.write("\tgenels: " + str(genel_count) + ";\n") 284 | if beam_count: 285 | f.write("\tbeams: " + str(beam_count) + ";\n") 286 | if rigid_body_count: 287 | f.write("\trigid bodies: " + str(rigid_body_count) + ";\n") 288 | if air_properties: 289 | f.write("\tair properties;\n") 290 | if gravity: 291 | f.write("\tgravity;\n") 292 | if aerodynamic_element_count: 293 | f.write("\taerodynamic elements: " + str(aerodynamic_element_count) + ";\n") 294 | if rotor_count: 295 | f.write("\trotors: " + str(rotor_count) + ";\n") 296 | if file_driver_count: 297 | f.write("\tfile drivers: " + str(file_driver_count) + ";\n") 298 | if loadable_element_count: 299 | f.write("\tloadable elements: " + str(loadable_element_count) + ";\n") 300 | f.write("end: control data;\n") 301 | if frames_to_write: 302 | f.write("\n# Frames:\n") 303 | for frame in frames_to_write: 304 | frame.write(f, parent_of[frame] if frame in parent_of else None) 305 | if database.node: 306 | f.write("\nbegin: nodes;\n") 307 | for node in structural_static_nodes: 308 | write_structural_node(f, "static", node, frame_for[node] if node in frame_for else None) 309 | for node in structural_dynamic_nodes: 310 | write_structural_node(f, "dynamic", node, frame_for[node] if node in frame_for else None) 311 | for node in structural_dummy_nodes: 312 | base_node = dummy_dict[node] 313 | rot = base_node.matrix_world.to_quaternion().to_matrix() 314 | globalV = node.matrix_world.translation - base_node.matrix_world.translation 315 | localV = rot*globalV 316 | rotT = node.matrix_world.to_quaternion().to_matrix() 317 | f.write("\tstructural: " + str(database.node.index(node)) + ", dummy,\n\t\t" + 318 | str(database.node.index(base_node)) + ", offset,\n\t\t\t") 319 | write_vector(f, localV, prepend=False) 320 | write_orientation(f, rot*rotT, "\t\t\t") 321 | f.write(";\n") 322 | """ 323 | for i, ns_node in enumerate(self.ns_node): 324 | if ns_node.type == "Electric": 325 | f.write("\telectric: " + str(i) + ", value, " + str(ns_node._args[0])) 326 | if ns_node._args[1]: f.write(", derivative, " + str(ns_node._args[2])) 327 | f.write(";\n") 328 | if ns_node.type == "Abstract": 329 | f.write("\tabstract: " + str(i) + ", value, " + str(ns_node._args[0])) 330 | if ns_node._args[1]: f.write(", differential, " + str(ns_node._args[2])) 331 | f.write(";\n") 332 | if ns_node.type == "Hydraulic": 333 | f.write("\thydraulic: " + str(i) + ", value, " + str(ns_node._args[0]) + ";\n") 334 | """ 335 | f.write("end: nodes;\n") 336 | if file_driver_count: 337 | f.write("\nbegin: drivers;\n") 338 | for driver in database.driver: 339 | driver.write(f) 340 | f.write("end: drivers;\n") 341 | if database.function: 342 | f.write("\n# Functions:\n") 343 | for function in sorted(database.function, key=lambda x: x.name): 344 | function.write(f) 345 | if database.drive: 346 | f.write("\n# Drives:\n") 347 | for drive in database.drive: 348 | if drive.dimension == "1D": 349 | f.write("\tdrive caller: " + ", ".join([drive.safe_name(), drive.string()]) + ";\n") 350 | else: 351 | dim_name = {"3D": "\"3\"", "6D": "\"6\"", "3x3": "\"3x3\"", "6x6": "\"6x6\""}[drive.dimension] 352 | f.write("\ttemplate drive caller: " + ", ".join([drive.safe_name(), dim_name, drive.string()]) + ";\n") 353 | if database.constitutive: 354 | f.write("\n# Constitutives:\n") 355 | for constitutive in database.constitutive: 356 | f.write("\tconstitutive law: " + ", ".join([constitutive.safe_name(), constitutive.dimension[0], constitutive.string()]) + ";\n") 357 | if database.element: 358 | f.write("\nbegin: elements;\n") 359 | try: 360 | for element_type in aerodynamic_types + beam_types + ["Body"] + force_types + genel_types + joint_types + ["Rotor"] + environment_types + user_defined_common.loadable_element_types + ["Driven"] + output_types: 361 | for element in database.element: 362 | if element.type == element_type: 363 | element.write(f) 364 | except Exception as e: 365 | print(e) 366 | f.write(str(e) + "\n") 367 | f.write("end: elements;\n") 368 | del database.rigid_dict 369 | del dummy_dict 370 | 371 | class InitialValueOperator(Base): 372 | bl_label = "Initial value" 373 | mbdyn_path = bpy.props.PointerProperty(type=BPY.Str) 374 | initial_time = bpy.props.PointerProperty(type=BPY.Float) 375 | final_time = bpy.props.PointerProperty(type=BPY.Float) 376 | general_data = bpy.props.PointerProperty(type=BPY.Definition) 377 | method = bpy.props.PointerProperty(type=BPY.Definition) 378 | nonlinear_solver = bpy.props.PointerProperty(type=BPY.Definition) 379 | eigenanalysis = bpy.props.PointerProperty(type=BPY.Definition) 380 | abort_after = bpy.props.PointerProperty(type=BPY.Definition) 381 | linear_solver = bpy.props.PointerProperty(type=BPY.Definition) 382 | dummy_steps = bpy.props.PointerProperty(type=BPY.Definition) 383 | output_data = bpy.props.PointerProperty(type=BPY.Definition) 384 | real_time = bpy.props.PointerProperty(type=BPY.Definition) 385 | assembly = bpy.props.PointerProperty(type=BPY.Definition) 386 | job_control = bpy.props.PointerProperty(type=BPY.Definition) 387 | default_output = bpy.props.PointerProperty(type=BPY.Definition) 388 | default_aerodynamic_output = bpy.props.PointerProperty(type=BPY.Definition) 389 | default_beam_output = bpy.props.PointerProperty(type=BPY.Definition) 390 | def prereqs(self, context): 391 | self.mbdyn_path.assign(BPY.mbdyn_path) 392 | self.final_time.select, self.final_time.value = True, 10.0 393 | self.general_data.type = "General data" 394 | self.general_data.mandatory = True 395 | self.general_data_exists(context) 396 | self.method.type = "Method" 397 | self.nonlinear_solver.type = "Nonlinear solver" 398 | self.eigenanalysis.type = "Eigenanalysis" 399 | self.abort_after.type = "Abort after" 400 | self.linear_solver.type = "Linear solver" 401 | self.dummy_steps.type = "Dummy steps" 402 | self.output_data.type = "Output data" 403 | self.output_data.mandatory = True 404 | self.output_data_exists(context) 405 | self.real_time.type = "Real time" 406 | self.assembly.type = "Assembly" 407 | self.job_control.type = "Job control" 408 | self.job_control.mandatory = True 409 | self.job_control_exists(context) 410 | self.default_output.type = "Default output" 411 | self.default_output.mandatory = True 412 | self.default_output_exists(context) 413 | self.default_aerodynamic_output.type = "Default aerodynamic output" 414 | self.default_beam_output.type = "Default beam output" 415 | def assign(self, context): 416 | self.mbdyn_path.assign(self.entity.mbdyn_path) 417 | self.initial_time.assign(self.entity.initial_time) 418 | self.final_time.assign(self.entity.final_time) 419 | self.general_data.assign(self.entity.general_data) 420 | self.method.assign(self.entity.method) 421 | self.nonlinear_solver.assign(self.entity.nonlinear_solver) 422 | self.eigenanalysis.assign(self.entity.eigenanalysis) 423 | self.abort_after.assign(self.entity.abort_after) 424 | self.linear_solver.assign(self.entity.linear_solver) 425 | self.dummy_steps.assign(self.entity.dummy_steps) 426 | self.output_data.assign(self.entity.output_data) 427 | self.real_time.assign(self.entity.real_time) 428 | self.assembly.assign(self.entity.assembly) 429 | self.job_control.assign(self.entity.job_control) 430 | self.default_output.assign(self.entity.default_output) 431 | self.default_aerodynamic_output.assign(self.entity.default_aerodynamic_output) 432 | self.default_beam_output.assign(self.entity.default_beam_output) 433 | def store(self, context): 434 | self.entity.mbdyn_path = BPY.mbdyn_path = self.mbdyn_path.store() 435 | self.entity.initial_time = self.initial_time.store() 436 | self.entity.final_time = self.final_time.store() 437 | self.entity.general_data = self.general_data.store() 438 | self.entity.method = self.method.store() 439 | self.entity.nonlinear_solver = self.nonlinear_solver.store() 440 | self.entity.eigenanalysis = self.eigenanalysis.store() 441 | self.entity.abort_after = self.abort_after.store() 442 | self.entity.linear_solver = self.linear_solver.store() 443 | self.entity.dummy_steps = self.dummy_steps.store() 444 | self.entity.output_data = self.output_data.store() 445 | self.entity.real_time = self.real_time.store() 446 | self.entity.assembly = self.assembly.store() 447 | self.entity.job_control = self.job_control.store() 448 | self.entity.default_output = self.default_output.store() 449 | self.entity.default_aerodynamic_output = self.default_aerodynamic_output.store() 450 | self.entity.default_beam_output = self.default_beam_output.store() 451 | def pre_finished(self, context): 452 | exec("bpy.ops." + root_dot + "save('INVOKE_DEFAULT')") 453 | def draw(self, context): 454 | layout = self.layout 455 | self.mbdyn_path.draw(layout, "MBDyn path", "Set") 456 | self.initial_time.draw(layout, "Initial time") 457 | self.final_time.draw(layout, "Final time") 458 | self.general_data.draw(layout, "General data") 459 | self.method.draw(layout, "Method", "Set") 460 | self.nonlinear_solver.draw(layout, "Nonlinear solver", "Set") 461 | self.eigenanalysis.draw(layout, "Eigenanalysis", "Set") 462 | self.abort_after.draw(layout, "Abort after", "Set") 463 | self.linear_solver.draw(layout, "Linear solver", "Set") 464 | self.dummy_steps.draw(layout, "Dummy steps", "Set") 465 | self.output_data.draw(layout, "Output data", "Set") 466 | self.real_time.draw(layout, "Real time", "Set") 467 | self.assembly.draw(layout, "Assembly", "Set") 468 | self.job_control.draw(layout, "Job control", "Set") 469 | self.default_output.draw(layout, "Default output", "Set") 470 | self.default_aerodynamic_output.draw(layout, "Default aerodynamic output", "Set") 471 | self.default_beam_output.draw(layout, "Default beam output", "Set") 472 | def check(self, context): 473 | return (True in [x.check(context) for x in [self.mbdyn_path, self.initial_time, self.final_time, self.general_data, self.method, self.nonlinear_solver, self.eigenanalysis, self.abort_after, self.linear_solver, self.dummy_steps, self.output_data, self.real_time, self.assembly, self.default_output, self.default_aerodynamic_output, self.default_beam_output]]) 474 | def create_entity(self): 475 | return InitialValue(self.name) 476 | 477 | klasses[InitialValueOperator.bl_label] = InitialValueOperator 478 | 479 | class Save(bpy.types.Operator, Base): 480 | bl_idname = root_dot + "save" 481 | bl_options = {'REGISTER', 'INTERNAL'} 482 | bl_label = "Save Blender File" 483 | filter_glob = bpy.props.StringProperty( 484 | default="*.blend", 485 | options={'HIDDEN'}, 486 | ) 487 | filepath = bpy.props.StringProperty() 488 | def invoke(self, context, event): 489 | if not context.blend_data.filepath: 490 | self.filepath = "untitled.blend" 491 | context.window_manager.fileselect_add(self) 492 | return {'RUNNING_MODAL'} 493 | self.filepath = context.blend_data.filepath 494 | return self.execute(context) 495 | def execute(self, context): 496 | directory = os.path.splitext(self.filepath)[0] 497 | if not os.path.exists(directory): 498 | os.mkdir(directory) 499 | database.simulator[context.scene.simulator_index].write_input_file(context, directory) 500 | bpy.ops.object.select_all(action='DESELECT') 501 | for node in database.node: 502 | node.select = True 503 | bpy.ops.wm.save_mainfile(filepath=self.filepath) 504 | context.scene.dirty_simulator = False 505 | context.scene.clean_log = False 506 | return{'FINISHED'} 507 | BPY.klasses.append(Save) 508 | 509 | class Simulate(bpy.types.Operator, Base): 510 | bl_idname = root_dot + "simulate" 511 | bl_options = {'REGISTER', 'INTERNAL'} 512 | bl_label = "Run simulation" 513 | bl_description = "Run MBDyn for the input file" 514 | def modal(self, context, event): 515 | if not (event.type in ['ESC', 'TIMER'] or (hasattr(self, "channels") and event.type in self.channels)): 516 | return {'PASS_THROUGH'} 517 | if event.type == 'ESC': 518 | return self.close(context) 519 | #self.report({'INFO'}, self.process.stdout.read().decode()) 520 | if hasattr(self, "sender") and event.type in self.channels: 521 | i, dv = self.channels[event.type] 522 | self.values[i] += dv 523 | try: 524 | self.sender.send(self.values) 525 | except BrokenPipeError: 526 | return self.close(context) 527 | if hasattr(self, "receiver"): 528 | data = self.receiver.get_data() 529 | for i, node in enumerate(self.nodes): 530 | node.location = Vector(data[12*i : 12*i+3]) 531 | node.rotation_euler = Matrix([data[12*i+3 : 12*i+6], data[12*i+6 : 12*i+9], data[12*i+9 : 12*i+12]]).to_euler(node.rotation_euler.order) 532 | if self.process.poll() == None: 533 | if self.platform != "win32": 534 | output = subprocess.check_output(("tail", "-n", "1", self.out_file)) 535 | if output and 2 < len(output.split()): 536 | percent = 100.*(1.-(self.t_final - float(output.split()[2]))/self.t_range) 537 | context.window_manager.progress_update(percent) 538 | return {'PASS_THROUGH'} 539 | else: 540 | return self.close(context) 541 | def close(self, context): 542 | wm = context.window_manager 543 | wm.event_timer_remove(self.timer) 544 | if hasattr(self, "nodes"): 545 | for preserved, node in zip(self.preserve, self.nodes): 546 | node.location, node.rotation_euler = preserved 547 | del self.nodes 548 | try: 549 | stdout, stderr = self.process.communicate(timeout=1) 550 | except subprocess.TimeoutExpired: 551 | self.process.terminate() 552 | stdout, stderr = self.process.communicate() 553 | del self.process 554 | if stdout: 555 | self.report({'INFO'}, stdout.decode()) 556 | if stderr: 557 | self.report({'INFO'}, stderr.decode()) 558 | if hasattr(self, "receiver"): 559 | self.receiver.close() 560 | if hasattr(self, "sender"): 561 | self.sender.close() 562 | context.scene.clean_log = True 563 | context.scene.mbdyn_default_orientation = database.simulator[context.scene.simulator_index].job_control.default_orientation 564 | BPY.plot_data.clear() 565 | wm.progress_end() 566 | return {'FINISHED'} 567 | def execute(self, context): 568 | sim = database.simulator[context.scene.simulator_index] 569 | directory = os.path.splitext(context.blend_data.filepath)[0] 570 | command = [sim.mbdyn_path if sim.mbdyn_path is not None else "mbdyn", "-s", "-f", os.path.join(directory, context.scene.name + ".mbd")] 571 | self.report({'INFO'}, " ".join(command)) 572 | animation = database.element.filter("Stream animation") 573 | events = database.driver.filter("Event stream") 574 | drives = database.drive.filter("Event drive") 575 | if drives: 576 | self.values = [d.initial_value for d in drives] 577 | self.channels = {d.increment : (i, 1) for i, d in enumerate(drives)} 578 | self.channels.update({d.decrement : (i, -1) for i, d in enumerate(drives)}) 579 | self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 580 | if events: 581 | host_name, port_number = events[0].host_name, events[0].port_number 582 | self.sender = StreamSender(host_name=host_name, port_number=port_number) 583 | self.sender.send(self.values) 584 | if animation: 585 | host_name, port_number, self.nodes = animation[0].host_name, animation[0].port_number, animation[0].objects if hasattr(animation[0], "objects") else database.node 586 | self.preserve = [(n.location.copy(), n.rotation_euler.copy()) for n in self.nodes] 587 | initial_data = list() 588 | for v, e in self.preserve: 589 | initial_data.extend(v.to_tuple()) 590 | for row in e.to_matrix(): 591 | initial_data.extend(row) 592 | self.receiver = StreamReceiver('d'*12*len(self.nodes), initial_data, host_name=host_name, port_number=port_number) 593 | if self.receiver.socket: 594 | self.receiver.start() 595 | else: 596 | self.report({'INFO'}, "Animation stream socket failed to connect") 597 | del self.receiver 598 | self.out_file = os.path.join(directory, context.scene.name + ".out") 599 | self.t_final = sim.final_time if sim.final_time is not None else float("inf") 600 | self.t_range = self.t_final - (sim.initial_time if sim.initial_time is not None else 0.0) 601 | while not os.path.exists(self.out_file): 602 | sleep(0.5) 603 | wm = context.window_manager 604 | wm.progress_begin(0., 100.) 605 | self.timer = wm.event_timer_add(1./24., context.window) 606 | wm.modal_handler_add(self) 607 | self.platform = sys.platform 608 | return{'RUNNING_MODAL'} 609 | BPY.klasses.append(Simulate) 610 | 611 | class FileWrapper: 612 | def __init__(self, file): 613 | self.file = file 614 | self.pos = 0 615 | self.size = self.file.seek(0, 2) 616 | self.file.seek(0, 0) 617 | def __next__(self): 618 | line = next(self.file) 619 | self.pos += len(line) 620 | return line 621 | def __iter__(self): 622 | line = next(self.file) 623 | while line: 624 | self.pos += len(line) 625 | yield line 626 | line = next(self.file) 627 | def close(self): 628 | self.file.close() 629 | def seek(self, *args, **kwargs): 630 | self.file.seek(*args, **kwargs) 631 | 632 | class WriteKeyframes(bpy.types.Operator, Base): 633 | bl_idname = root_dot + "write_keyframes" 634 | bl_options = {'REGISTER', 'INTERNAL'} 635 | bl_label = "Write keyframes" 636 | bl_description = "Import each node's location and orientation into Blender keyframes starting at the next frame" 637 | steps = bpy.props.IntProperty(name="MBDyn steps between Blender keyframes", default=1, min=1) 638 | rate = bpy.props.IntProperty(name="Keyframes per MBDyn second", default=15, min=1) 639 | def invoke(self, context, event): 640 | return context.window_manager.invoke_props_dialog(self) 641 | def insert_keyframe(self, label, fields): 642 | database.node[label].location = fields[:3] 643 | if self.orientation == "orientation matrix": 644 | euler = Matrix([fields[3:6], fields[6:9], fields[9:12]]).to_euler() 645 | database.node[label].rotation_euler = euler[0], euler[1], euler[2] 646 | elif self.orientation == "euler321": 647 | database.node[label].rotation_euler = Euler((math.radians(fields[5]), math.radians(fields[4]), math.radians(fields[3])), 'XYZ') 648 | elif self.orientation == "euler123": 649 | database.node[label].rotation_euler = Euler((math.radians(fields[3]), math.radians(fields[4]), math.radians(fields[5])), 'ZYX').to_quaternion().to_euler('XYZ') 650 | #database.node[label].rotation_mode = 'ZYX' 651 | elif self.orientation == "orientation vector": 652 | #database.node[label].rotation_axis_angle = [math.sqrt(sum([x*x for x in fields[3:6]]))] + fields[3:6] 653 | database.node[label].rotation_euler = Quaternion(fields[3:6], math.sqrt(sum([x*x for x in fields[3:6]]))).to_euler('XYZ') 654 | for data_path in "location rotation_euler".split(): 655 | database.node[label].keyframe_insert(data_path) 656 | def execute(self, context): 657 | self.orientation = database.simulator[context.scene.simulator_index].job_control.default_orientation 658 | if self.orientation == "euler313": 659 | self.report({'ERROR'}, "euler313 cannot be imported. Simulate in another format, selected from Job Control -> Default Orientation") 660 | scene = context.scene 661 | frame_initial = scene.frame_current 662 | wm = context.window_manager 663 | wm.progress_begin(0., 100.) 664 | directory = os.path.splitext(context.blend_data.filepath)[0] 665 | dt = 1.0 / self.rate 666 | keytime = - float("inf") 667 | parser = lambda l: (int(l[0]), [float(x) for x in l[1:]]) 668 | with open(os.path.join(directory, scene.name + ".out")) as f_out, open(os.path.join(directory, scene.name + ".mov")) as f_mov: 669 | label, fields = parser(f_mov.readline().split()) 670 | fw_out = FileWrapper(f_out) 671 | for step, time in map(lambda l: (int(l[1]), float(l[2])), map(str.split, filter(lambda ln: ln.startswith("Step"), fw_out))): 672 | is_a_keyframe = dt < time - keytime 673 | if is_a_keyframe: 674 | keytime = time 675 | scene.frame_current += 1 676 | wm.progress_update(100. * float(fw_out.pos) / float(fw_out.size)) 677 | labels = list() 678 | while f_mov and label not in labels: 679 | if is_a_keyframe: 680 | self.insert_keyframe(label, fields) 681 | labels.append(label) 682 | split_line = f_mov.readline().split() 683 | if split_line: 684 | label, fields = parser(split_line) 685 | for node in database.node: 686 | node.rotation_mode = 'XYZ' 687 | scene.frame_current = frame_initial + 1 688 | wm.progress_end() 689 | return{'FINISHED'} 690 | def draw(self, context): 691 | layout = self.layout 692 | #layout.label("File has " + str(int(self.N/(self.i+1))) + " timesteps.") 693 | layout.prop(self, "rate") 694 | BPY.klasses.append(WriteKeyframes) 695 | 696 | bundle = Bundle(simulator_tree, Base, klasses, database.simulator) 697 | --------------------------------------------------------------------------------