Beispiel #1
0
    def __init__(self, app, layerId, layerConstructor=MeshLayer):
        super().__init__(app)

        layer = app.createLayer(layerId, layerConstructor, area=False)
        self.layer = layer
        # set layer offsets <layer.location>, <layer.meshZ> and <layer.parentLocation> to zero
        layer.location = None
        layer.meshZ = 0.
        if layer.parentLocation:
            layer.parentLocation[2] = 0.
        else:
            layer.parentLocation = zeroVector()

        if app.terrain:
            # the attribute <singleObject> of the buildings layer doesn't depend on availability of a terrain
            # no need to apply any Blender modifier for buildings
            layer.modifiers = False
            # no need to slice Blender mesh
            layer.sliceMesh = False

        self.initRoofs()
        self.defaultRoof = self.roofs[app.defaultRoofShape]

        # set renderer for each roof
        for r in self.roofs:
            self.roofs[r].r = self
        self.flatRoofMulti.r = self

        self.defaultMaterialIndices = [None, None]
        # References to Blender materials used by roof Blender meshes
        # loaded from a .blend library file
        self.defaultMaterials = [None, None]
Beispiel #2
0
    def init(self):
        terrain = self.terrain

        # transform <terrain.bound_box> to the world system of coordinates
        bound_box = tuple(terrain.matrix_world * Vector(v)
                          for v in terrain.bound_box)
        self.minZ = min(bound_box, key=lambda v: v[2])[2]
        self.maxZ = max(bound_box, key=lambda v: v[2])[2]

        self.minX = min(bound_box, key=lambda v: v[0])[0]
        self.maxX = max(bound_box, key=lambda v: v[0])[0]
        self.minY = min(bound_box, key=lambda v: v[1])[1]
        self.maxY = max(bound_box, key=lambda v: v[1])[1]

        self.projectLocation = self.maxZ + self.projectOffset

        # An attribute to store the original location of the terrain Blender object,
        # if the terrain isn't located at the origin of the world system of coordinates
        self.location = None
        if terrain.location.length_squared:
            self.location = terrain.location.copy()
            # set origin of the terrain Blender object to zero
            self.setOrigin(zeroVector())
            # execute the line below to get correct results (i.e. update transformation matrix)
            bpy.context.scene.update()
        bm = bmesh.new()
        bm.from_mesh(terrain.data)
        self.bvhTree = BVHTree.FromBMesh(bm)
        # <bm> is no longer needed
        bm.free()
Beispiel #3
0
 def getLayerParent(self):
     layerIndex = self.layerIndex
     layerParents = self.layerParents
     layerParent = layerParents[layerIndex]
     if not layerParent:
         layerParent = createEmptyObject(self.getLayerName(
             layerIndex, self.op),
                                         zeroVector(),
                                         empty_draw_size=0.01)
         layerParent.parent = Renderer.parent
         layerParents[layerIndex] = layerParent
     return layerParent
Beispiel #4
0
 def getLayerParent(self):
     layerIndex = self.layerIndex
     layerParents = self.layerParents
     layerParent = layerParents[layerIndex]
     if not layerParent:
         layerParent = createEmptyObject(
             self.getLayerName(layerIndex, self.op),
             zeroVector(),
             empty_draw_size=0.01
         )
         layerParent.parent = Renderer.parent
         layerParents[layerIndex] = layerParent
     return layerParent
Beispiel #5
0
    def __init__(self, app, layerId):
        super().__init__(app)
        layer = app.getLayer(layerId)
        self.layer = layer
        # set layer offsets <layer.location>, <layer.meshZ> and <layer.parentLocation> to zero
        layer.location = None
        layer.meshZ = 0.
        if layer.parentLocation:
            layer.parentLocation[2] = 0.
        else:
            layer.parentLocation = zeroVector()

        if app.terrain:
            # the attribute <singleObject> of the buildings layer doesn't depend on availability of a terrain
            layer.singleObject = app.singleObject
            # the attribute <singleObject> of the buildings layer doesn't depend on availability of a terrain
            layer.layered = app.layered
            # no need to add a SHRINKWRAP modifier for buildings
            layer.swModifier = False
            # no need to slice Blender mesh
            layer.sliceMesh = False
        # create instances of classes that deal with specific roof shapes
        self.flatRoofMulti = RoofFlatMulti()
        self.roofs = {
            'flat': RoofFlat(),
            'gabled': RoofProfile(gabledRoof),
            'pyramidal': RoofPyramidal(),
            'skillion': RoofSkillion(),
            'hipped': RoofHipped(gabledRoof),
            'dome': RoofMesh("roof_dome"),
            'onion': RoofMesh("roof_onion"),
            'round': RoofProfile(roundRoof),
            'half-hipped': RoofHalfHipped(),
            'gambrel': RoofProfile(gambrelRoof),
            'saltbox': RoofProfile(saltboxRoof)
        }
        self.defaultRoof = self.roofs[app.defaultRoofShape]

        # set renderer for each roof
        for r in self.roofs:
            self.roofs[r].r = self
        self.flatRoofMulti.r = self

        self.defaultMaterialIndices = [None, None]
        # References to Blender materials used by roof Blender meshes
        # loaded from a .blend library file
        self.defaultMaterials = [None, None]
Beispiel #6
0
    def begin(self, app):
        self.name = os.path.basename(app.osmFilepath)
        
        if app.layered or not app.singleObject:
            self.parent = createEmptyObject(
                self.name,
                zeroVector(),
                empty_draw_size=0.01
            )
        if app.singleObject and not app.layered:
            self.bm = bmesh.new()
            self.obj = self.createBlenderObject(self.name, None, None)
            # cache material indices in <self.materialIndices>
            self.materialIndices = {}

        # store here Blender object that are to be joined
        self.toJoin = {}
Beispiel #7
0
    def begin(self, op):
        self.name = os.path.basename(op.filepath)

        if op.layered or not op.singleObject:
            self.parent = createEmptyObject(self.name,
                                            zeroVector(),
                                            empty_draw_size=0.01)
        if op.singleObject:
            if op.layered:
                self.layerMeshes = [None for _ in op.layerIndices]
                self.layerObjects = [None for _ in op.layerIndices]
                # cache material indices in <self.materialIndices>
                self.materialIndices = [None for _ in op.layerIndices]
            else:
                self.bm = bmesh.new()
                self.obj = self.createBlenderObject(self.name, None)
                # cache material indices in <self.materialIndices>
                self.materialIndices = {}
        else:
            if op.layered:
                self.layerParents = [None for _ in op.layerIndices]
Beispiel #8
0
 def begin(self, op):
     self.name = os.path.basename(op.filepath)
     
     if op.layered or not op.singleObject:
         self.parent = createEmptyObject(
             self.name,
             zeroVector(),
             empty_draw_size=0.01
         )
     if op.singleObject:
         if op.layered:
             self.layerMeshes = [None for _ in op.layerIndices]
             self.layerObjects = [None for _ in op.layerIndices]
             # cache material indices in <self.materialIndices>
             self.materialIndices = [None for _ in op.layerIndices]
         else:
             self.bm = bmesh.new()
             self.obj = self.createBlenderObject(self.name, None)
             # cache material indices in <self.materialIndices>
             self.materialIndices = {}
     else:
         if op.layered:
             self.layerParents = [None for _ in op.layerIndices]
Beispiel #9
0
 def center(self):
     """
     Returns geometric center of the polygon
     """
     return sum(tuple(self.verts), zeroVector())/self.n