Source code for ddg.conversion.blender.net

import bpy
from ddg.conversion.blender.halfedge import hes_to_bmesh
from ddg.datastructures.halfedge.surface_generator import icosphere

from ddg.datastructures.nets.net import (DiscreteNet, PointNet, EmptyNet,
                                         DiscreteCurve, NetCollection)

from ddg.datastructures.nets import utils as nutils
from ddg.visualization.blender.mesh import from_bmesh as mesh_from_bmesh
from ddg.visualization.blender.bmesh import join, from_pydata
from ddg.visualization.blender.curve import create_curve

bl_info = {"name": "ParameterPanel",
           "description": "DDG Parameterpanel", "author": "NONE",
           "version": (0, 1, 0), "blender": (2, 80, 0),
           "location": "", "category": "Object",
           "warning": ""}

bpy.types.Scene.params = []


[docs]def empty_to_bmesh(empty, bpy_data=None): if isinstance(empty, EmptyNet): if bpy_data is not None: bpy_data.clear() return bpy_data else: return from_pydata([], [], []) elif isinstance(empty, NetCollection) and isinstance(empty._nets[0], EmptyNet): if bpy_data is not None: bpy_data.clear() return bpy_data else: return from_pydata([], [], []) else: raise TypeError(point + ' is not of type EmptyNet.')
[docs]def point_to_bmesh(point, sphere_radius=0, sphere_subdivision=3, bpy_data=None): """ if not isinstance(point, PointNet): raise TypeError(point + ' is not of type PointNet.') if sphere_radius == 0: return from_pydata([net()], [], []) else: return create_icosphere(center=net(), radius= sphere_radius, sphere_subdivision=sphere_subdivision) """ if isinstance(point, PointNet): if sphere_radius == 0: return from_pydata([point()], [], [], bpy_data) else: center = point() ico = icosphere(sphere_subdivision, sphere_radius) for v in ico.verts: v.co += center return hes_to_bmesh(ico, bpy_data=bpy_data) elif isinstance(point, NetCollection) and isinstance(point._nets[0], PointNet): return join(*[point_to_bmesh(p) for p in point], free=True, bm=bpy_data)
[docs]def net_to_bmesh(net, bounding=10, only_wire=False, bpy_data=None): if isinstance(net, DiscreteNet): subdomain = nutils.bound_domain(net.domain, bounding) if only_wire or isinstance(net, DiscreteCurve): return from_pydata(net[subdomain], subdomain.edge_data, [], bm=bpy_data, doubles=subdomain.double_edged) else: return from_pydata(net[subdomain], [], subdomain.face_data, bm=bpy_data, doubles=subdomain.double_edged) elif isinstance(net, NetCollection): return join(*[net_to_bmesh(n, bounding=bounding, only_wire=only_wire) for n in net], free=True, bm=bpy_data) else: raise TypeError( 'Net does not support given type: {}'.format( net.__class__.__name__))
[docs]def curve_to_bpy_curve(net, bounding=10, curve_properties=None, curve_type=None, bpy_data=None, name=None): if name is None: name = net.name # TODO BOUNDING if isinstance(net, DiscreteCurve): subdomain = nutils.bound_domain(net.domain, bounding) curve_coordinates = list(net[subdomain]) cyclic = [net.domain.periodic] elif isinstance(net, NetCollection) and isinstance(net._nets[0], DiscreteCurve): curve_coordinates = [] cyclic = [] for c in net: # TODO BOUNDING subdomain = nutils.bound_domain(c.domain, bounding) curve_coordinates.append(list(c[subdomain])) cyclic.append(c.domain.periodic) else: raise TypeError(point + ' is not of type DiscreteCurve.') if curve_type is not None: curvedata = create_curve(curve_coordinates, name=name, type=curve_type, cyclic=cyclic, curve=bpy_data) else: curvedata = create_curve(curve_coordinates, name=name, cyclic=cyclic, curve=bpy_data)
[docs]def net_to_mesh(net, subdomain=None, bounding=10, sphere_radius=0, sphere_subdivision=3, only_wire=False, name=None, material=None, smooth_shading=False): if name is None: name = net.name if isinstance(net, NetCollection): net_bmesh = bmesh.new() for n in net: net_bmesh.from_mesh(net_to_mesh(n, subdomain=subdomain, bounding=bounding, only_wire=only_wire, sphere_radius=sphere_radius, sphere_subdivision=sphere_subdivision)) else: net_bmesh = to_bmesh(net, subdomain=subdomain, bounding=bounding, only_wire=only_wire, sphere_radius=sphere_radius, sphere_subdivision=sphere_subdivision) return mesh_from_bmesh(net_bmesh, name, material=material, smooth_shading=smooth_shading, free=True)
[docs]class ParameterPanel(bpy.types.Panel): bl_idname = 'WORKSPACE_PT_parameterpanel' bl_label = 'Parameterpanel' bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_context = "object"
[docs] def draw(self, context): col = self.layout.column(align=True) for para in bpy.context.scene.params: col.prop(bpy.context.scene, para, text=para)
bpy.utils.register_class(ParameterPanel)