[Bf-extensions-cvs] [e5dd868d] master: Initial commit add mesh castle (experimental) T45596 T51145

meta-androcto noreply at git.blender.org
Thu Apr 13 06:34:00 CEST 2017


Commit: e5dd868d2d6faaf4d0733f65f82b958419e75bc9
Author: meta-androcto
Date:   Thu Apr 13 14:33:31 2017 +1000
Branches: master
https://developer.blender.org/rBACe5dd868d2d6faaf4d0733f65f82b958419e75bc9

Initial commit add mesh castle (experimental) T45596 T51145

===================================================================

A	add_mesh_castle/Castle.py
A	add_mesh_castle/__init__.py

===================================================================

diff --git a/add_mesh_castle/Castle.py b/add_mesh_castle/Castle.py
new file mode 100644
index 00000000..e0435aa8
--- /dev/null
+++ b/add_mesh_castle/Castle.py
@@ -0,0 +1,3539 @@
+################################################################################
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This is free software under the terms of the GNU General Public License
+# you may redistribute it, and/or modify it.
+#
+# This code is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License (http://www.gnu.org/licenses/) for more details.
+#
+# ***** END GPL LICENSE BLOCK *****
+'''
+Generate an object: (OBJ_N) "Castle", complex mesh collection.
+ Derived from many sources, inspired by many in the "community",
+ - see documentation for details on use and credits.
+'''
+# mod list, in order of complexity and necessity...
+#  some want, some needed, some a feature not a bug just need controls.
+#
+# @todo: fix dome radius -  not complete when wall width or depth < 15
+#        globe (z/2) is fun but not intended design.
+# @todo: check width minimum as is done for height, maybe depth too.
+# @todo: fix grout for bottom of first row (adjust wall base).
+#
+# @todo: eleminate result of "None" if possible from  circ() and other subroutines.
+# @todo: review defaults and limits for all UI entries.
+#
+#
+# Abstract/experimental use only:
+# @todo: Curve (wallSlope) inverts walls: reverse slope and adjust sizing to fit floor.
+# @todo: Tunnel, paired sloped walls, need to create separate objects and adjust sizing.
+# @todo: Turret/tower - uses rotated wall, need to change curvature/slope orientation/sizing
+#  allow openings and placement (corners, center wall, etc.).
+#
+#
+# wish list:
+# @todo: do not allow opening overlap.
+# @todo: implement "Oculus" for dome (top center opening). See "Radial" floor with door.
+# @todo: make "true" roof: top of castle walls or turret, multiple levels, style options - peaked, flat.
+# @todo: integrate portal with doorway.
+# @todo: add stair_builder; keep (wall) steps.
+# @todo: integrate balcony with shelf.
+# @todo: add block shapes: triangle, hexagon, octagon, round (disc/ball), "Rocks" (Brikbot author), etc...
+#        - possible window/door/opening shapes?
+#
+################################################################################
+
+import bpy
+from bpy.props import IntProperty, FloatProperty, FloatVectorProperty, BoolProperty, EnumProperty
+from random import random
+
+import math
+from math import fmod, sqrt, sin, cos, atan
+
+################################################################################
+
+################################################################################
+
+#####
+# constants
+#####
+
+OBJ_N = "Castle"  # Primary object name (base/floor/foundation)
+OBJ_CF = "CFloor"  # Multi-level "floor"
+OBJ_CR = "CRoof"  # roofing
+OBJ_WF = "CWallF"  # front, left, back, right wall objects
+OBJ_WL = "CWallL"
+OBJ_WB = "CWallB"
+OBJ_WR = "CWallR"
+
+# not sure if this is more efficient or not, just seems no need to import value.
+cPie = 3.14159265359
+cPieHlf = cPie / 2  # used to rotate walls 90 degrees (1.570796...)
+
+BLOCK_MIN = 0.1  # Min block sizing; also used for openings.
+
+WALL_MAX = 100
+HALF_WALL = WALL_MAX / 2  # edging, openings, etc., limited to half wall limit.
+
+WALL_MIN = BLOCK_MIN * 3  # min wall block size*3 for each dimension.
+WALL_DEF = 20  # Default wall/dome size
+
+LVL_MAX = 10  # castle levels (vertical wall repeat).
+
+# riser BLOCK_XDEF should be 0.75 and tread BLOCK_DDEF 1.0 for stair steps.
+BLOCK_XDEF = 0.75  # stanadard block width, including steps and shelf.
+BLOCK_DDEF = 1.0  # standard block depth.
+BLOCK_MAX = WALL_MAX  # Max block sizing.
+BLOCK_VMAX = BLOCK_MAX / 2  # block variations, no negative values.
+
+# gap 0 makes solid wall but affects other options, like openings, not in a good way.
+# Negative gap creates "phantom blocks" (extraneous verts) inside the faces.
+GAP_MIN = 0.01  # min space between blocks.
+GAP_MAX = BLOCK_MAX / 2  # maybe later... -BLOCK_MIN # max space between blocks.
+
+ROW_H_WEIGHT = 0.5  # Use 0.5, else create parameter:
+#  0=no effect, 1=1:1 relationship, negative values allowed.
+
+BASE_TMIN = BLOCK_MIN  # floor min thickness
+BASE_TMAX = BLOCK_MAX / 2  # floor max thickness, limit to half (current) block height.
+
+# Default Door settings
+DEF_DOORW = 2.5
+DEF_DOORH = 3.5
+DEF_DOORX = 2.5
+
+#####
+# working variables, per option per level.
+#####
+
+# wall/block Settings
+settings = {'w': 1.2, 'wv': 0.3, 'h': .6, 'hv': 0.1, 'd': 0.3, 'dv': 0.1,
+            'g': 0.1, 'sdv': 0.1,
+            'eoff': 0.3,
+            'Steps': False, 'StepsL': False, 'StepsB': False, 'StepsO': False,
+            'Shelf': False, 'ShelfO': False,
+            'Radial': False, 'Slope': False}
+# 'w':width 'wv':width Variation
+# 'h':height 'hv':height Variation
+# 'd':depth 'dv':depth Variation
+# 'g':grout
+# 'sdv':subdivision(distance or angle)
+# 'eoff':edge offset
+# passed as params since modified per object; no sense to change UI values.
+# 'Steps' create steps, 'StepsL'step left, 'StepsB' fill with blocks, 'StepsO' outside of wall.
+# 'Shelf' add shelf/balcony, 'ShelfO'outside of wall.
+# 'Radial' create "disc"; makes dome when combined with "Slope" (globe when height/2).
+# 'Slope' curve wall - forced for Dome
+
+# dims = area of wall (centered/splitX from 3D cursor); modified for radial/dome.
+dims = {'s': -10, 'e': 10, 't': 15}
+# dims = {'s':0, 'e':cPie*3/2, 't':12.3} # radial
+# 's' start, 'e' end, 't' top
+
+# Apertures in wall, includes all openings for door, window, slot.
+#openingSpecs = []
+# openingSpecs indexes, based on order of creation.
+OP_DOOR = 0
+OP_PORT = 1
+OP_CREN = 2
+OP_SLOT = 3
+
+openingSpecs = [{'a': False, 'w': 0.5, 'h': 0.5, 'x': 0.8, 'z': 0, 'n': 0, 'bvl': 0.0,
+                 'v': 0, 'vl': 0, 't': 0, 'tl': 0}]
+# 'a': active (apply to object),
+# 'w': opening width, 'h': opening height,
+# 'x': horizontal position, 'z': vertical position,
+# 'n': repeat opening with a spacing of x,
+# 'bvl': bevel the inside of the opening,
+# 'v': height of the top arch, 'vl':height of the bottom arch,
+# 't': thickness of the top arch, 'tl': thickness of the bottom arch
+
+
+################################################################################
+
+############################
+#
+# Psuedo macros:
+#
+# random values (in specific range).
+# random value +-0.5
+def rndc(): return (random() - 0.5)
+
+# random value +-1
+
+
+def rndd(): return rndc() * 2
+
+# line/circle intercepts
+# COff = distance perpendicular to the line to the center
+# cRad=radius
+# return the distance paralell to the line to the center of the circle at the intercept.
+# @todo: eleminate result of "None" if possible from  circ() and other subroutines.
+
+
+def circ(COff=0, cRad=1):
+    absCOff = abs(COff)
+    if absCOff > cRad:
+        return None
+    elif absCOff == cRad:
+        return 0
+    else:
+        return sqrt(cRad**2 - absCOff**2)
+
+# bevel blocks.
+# pointsToAffect are: left=(4,6), right=(0,2)
+
+
+def bevelBlockOffsets(offsets, bevel, pointsToAffect):
+    for num in pointsToAffect:
+        offsets[num] = offsets[num][:]
+        offsets[num][0] += bevel
+
+############################
+#
+# Simple material management.
+# Return new, existing, or modified material reference.
+#
+# @todo: create additional materials based on diffuse options.
+#
+
+
+def uMatRGBSet(matName, RGBs, matMod=False, dShader='LAMBERT', dNtz=1.0):
+
+    if matName not in bpy.data.materials:
+        mtl = bpy.data.materials.new(matName)
+        matMod = True
+    else:
+        mtl = bpy.data.materials[matName]
+
+    if matMod:  # Set material values
+        mtl.diffuse_color = RGBs
+        mtl.diffuse_shader = dShader
+        mtl.diffuse_intensity = dNtz
+
+    return mtl
+
+################################################################################
+
+################################################################################
+#
+#  UI functions and object creation.
+#
+
+
+class add_castle(bpy.types.Operator):
+    bl_idname = "mesh.add_castle"
+    bl_label = OBJ_N
+    bl_description = OBJ_N
+    bl_options = {'REGISTER', 'UNDO'}
+
+    # only create object when True
+    # False allows modifying several parameters without creating object
+    ConstructTog = BoolProperty(name="Construct", description="Generate the object", default=True)
+
+    # Base area - set dimensions - Width (front/back) and Depth (sides),
+    # floor origin/offset, thickness, and, material/color.
+    cBaseW = FloatProperty(name="Width", min=WALL_MIN, max=WALL_MAX, default=WALL_DEF, description="Base Width (X)")
+    cBaseD = FloatProperty(name="Depth", min=WALL_MIN, max=WALL_MAX, default=WALL_DEF, description="Base Depth (Y)")
+    cBaseO = FloatProperty(name='Base', min=0, max=WALL_MAX, default=0, description="vert offset from 3D cursor.")
+    cBaseT = FloatProperty(min=BASE_TMIN, max=BASE_TMAX, default=BASE_TMIN, description="Base thickness")
+
+    cBaseRGB = FloatVectorProperty(min=0, max=1, default=(0.1, 0.1, 0.1), subtype='COLOR', size=3)
+
+    CBaseB = BoolProperty(name="BloX", default=False, description="Block flooring")
+    CBaseR = BoolProperty(default=False, description="Round flooring")
+
+    CLvls = IntProperty(name="Levels", min=1, max=LVL_MAX, default=1)
+
+    # current wall level parameter value display.
+    CLvl = IntProperty(name="Level", min=1, max=LVL_MAX, default=1)
+
+#    curLvl=CLvl
+
+    # block sizing
+    blockX = FloatProperty(name="Width", min=BLOCK_MIN, max=BLOCK_MAX, default=BLOCK_XDEF)
+    blockZ = FloatProperty(name="Height", min=BLOCK_MIN, max=BLOCK_MAX, default=BLOCK_XDEF)
+    blockD = FloatProperty(name="Depth", min=BLOCK_MIN, max=BLOCK_MAX, default=BLOCK_DDEF)
+# allow 0 for test cases...
+#    blockD=FloatProperty(name="Depth",min=0,max=BLOCK_MAX,default=BLOCK_DDEF)
+
+    blockVar = BoolProperty(name="Vary", default=True, description="Randomize block sizing")
+
+    blockWVar = FloatProperty(name="Width", min=0, max=BLOCK_VMAX, d

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list