def getShapeFunction(self): print("GenerateGeometricalTree") b = dfgeom.Box([1.5,0.5,1.0]) u = dfgeom.Sphere([0.0,0.0,0.0], 0.1) s = dfgeom.Sphere([0.0,0.0,0.0], 0.5) shape = dfgeom.Difference( dfgeom.Difference(b, u), dfgeom.Sphere([1.0,0.5,0.0], 1.0) ) shape = dfgeom.Difference( dfgeom.Union(s, shape), dfgeom.Box([1.0,0.1,1.2]) ) return shape
def toPythonShape(node): print("TO PYY: "+str(node.name)) type = node.getData("type") if type == None: for child in node.getChildren(): cc = toPythonShape(child) if cc != None: return cc return None if node.type == "shape.ShapeTree": c = node.getChildren() if len(c) == 0: return None u=toPythonShape(c[0]) for child in c[1:]: uc = toPythonShape(child) if uc != None: u=dfgeom.Union(u, uc) print("OUT: "+str(u)) return u elif node.type == "shape.Difference": c = node.getChildren() if len(c) == 0: return None left=toPythonShape(c[0]) right=toPythonShape(c[1]) return dfgeom.Difference(left, right) elif node.type == "shape.Box": print("BOX ? "+str(node.size)+ "=================") b = dfgeom.Box(node.size[0]) kmap[node.getLinkPath()]=(node, b) return b elif node.type == "shape.Sphere": print("SPHERE GEOM: "+str(node.center[0])) s = dfgeom.Sphere(center=node.center[0], radius=node.radius) kmap[node.getLinkPath()]=(node, s) return s print("Un-recognized type:"+str(node.type)) return None
import pyximport pyximport.install(reload_support=True) import sys import dfgeom import math from math import sqrt b = dfgeom.Box([0.5, 0.5, 1.0]) u = dfgeom.Sphere([0.0, 0.0, 0.0], 0.5) s = dfgeom.Sphere([0.0, 0.0, 0.0], 0.5) shape = dfgeom.Difference(dfgeom.Difference(b, u), dfgeom.Sphere([1.0, 0.5, 0.0], 1.0)) shape = dfgeom.Difference(dfgeom.Union(s, shape), dfgeom.Box([1.0, 0.1, 1.2])) shape = dfgeom.Tiling(shape, [0.5, 0.5, 0.5]) #shape = dfgeom.Twist(shape, [1,1.0,1.0]) def glslFunction(): context = {} function = shape.toGLSL(context) return (context.values(), function) def evalField(x, y, z): return dfgeom.evalField(shape, x, y, z)
def toPythonShape(node, kmap): type = node.getData("xtype").value if type == None and hasattr(node, "children"): for child in node.children: cc = toPythonShape(child, kmap) if cc != None: return cc return None if type == "XShape": c = list(node.children) if len(c) == 0: return None u=toPythonShape(c[0], kmap) for child in c[1:]: uc = toPythonShape(child, kmap) if uc != None: u=dfgeom.Union(u, uc) return u elif type == "Difference": c = list(node.children) if len(c) == 0: return None left=toPythonShape(c[0], kmap) right=toPythonShape(c[1], kmap) d = dfgeom.Difference(left, right) d.setName(node.name.value) t = dfgeom.Translate(d, node.translation.value) t.setName(node.name.value) return t elif type == "Intersection": c = list(node.children) if len(c) == 0: return None left=toPythonShape(c[0], kmap) right=toPythonShape(c[1], kmap) d = dfgeom.Intersection(left, right) d.setName(node.name.value) return d elif type == "Box": b = dfgeom.Box(list(node.size.value)) b.setName(node.name.value) def update(): b.setAttr("size", node.size.value) #node.componentState.onChange = update return b elif type == "Sphere": s = dfgeom.Sphere(position=list(node.position.value), radius=node.radius.value) s.setName(node.name.value) def update(): s.setAttr("position", list(node.position.value)) s.setAttr("radius", node.radius.value) #node.componentState.onChange = update return s elif type == "Twist": ps = toPythonShape(node.children[0], kmap) s = dfgeom.Twist(ps, angle=node.angle.value) s.setName(node.name.value) return s elif type == "Offset": ps = toPythonShape(node.children[0], kmap) s = dfgeom.Offset(ps, node.offset.value) s.setName(node.name.value) return s elif type == "Tiling": ps = toPythonShape(node.children[0], kmap) s = dfgeom.Tiling(ps, factor=node.mod.value) s.setName(node.name.value) return s print("Un-recognized type:"+str(type)) return None