Skip to content
Snippets Groups Projects
Commit dbe050de authored by lijenstina's avatar lijenstina
Browse files

Cleanup and fixes to mesh_discombobulator

Run Flake8 on __init__ and mesh_discombobulator
Clean up the bl_info (the scipt is now a module)
Moved the discombobulator props to a separate property group
Removed the duplicate entries of props in the script
Added poll functions for discombobulator operators
Used a prop_dialog instead of popup
Moved the execution operator from draw to execute
Added a remove all doodads option
Moved the list of doodads from the label to a separate menu
Expanded on Usage Information to cover more limitations
and changed it to a menu
Limit the repeat protusions to 4 instead of 10
(There is no RAM and CPU big enough in the world
to take all in the hubris of unrealistic ambitions)
parent d20975b8
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# #
# ##### END GPL LICENSE BLOCK ##### # ##### END GPL LICENSE BLOCK #####
# Contributed to by # Contributed to by:
# Pontiac, Fourmadmen, varkenvarken, tuga3d, meta-androcto, metalliandy, dreampainter, cotejrp1 # # Pontiac, Fourmadmen, varkenvarken, tuga3d, meta-androcto, metalliandy, dreampainter, cotejrp1 #
# liero, Kayo Phoenix, sugiany, dommetysk, Phymec, Anthony D'Agostino, Pablo Vazquez, Richard Wilks # # liero, Kayo Phoenix, sugiany, dommetysk, Phymec, Anthony D'Agostino, Pablo Vazquez, Richard Wilks #
# xyz presets by elfnor # xyz presets by elfnor
...@@ -85,7 +85,13 @@ else: ...@@ -85,7 +85,13 @@ else:
from . import add_mesh_beam_builder from . import add_mesh_beam_builder
from . import Wallfactory from . import Wallfactory
from . import Blocks from . import Blocks
import bpy import bpy
from bpy.props import (
BoolProperty,
IntProperty,
FloatProperty,
)
class INFO_MT_mesh_vert_add(bpy.types.Menu): class INFO_MT_mesh_vert_add(bpy.types.Menu):
...@@ -97,13 +103,13 @@ class INFO_MT_mesh_vert_add(bpy.types.Menu): ...@@ -97,13 +103,13 @@ class INFO_MT_mesh_vert_add(bpy.types.Menu):
layout = self.layout layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN' layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.primitive_vert_add", layout.operator("mesh.primitive_vert_add",
text="Add Single Vert ") text="Add Single Vert ")
layout.operator("mesh.primitive_emptyvert_add", layout.operator("mesh.primitive_emptyvert_add",
text="Object Origin Only") text="Object Origin Only")
layout.operator("mesh.primitive_symmetrical_vert_add", layout.operator("mesh.primitive_symmetrical_vert_add",
text="Origin & Vert Mirrored") text="Origin & Vert Mirrored")
layout.operator("mesh.primitive_symmetrical_empty_add", layout.operator("mesh.primitive_symmetrical_empty_add",
text="Object Origin Mirrored") text="Object Origin Mirrored")
class INFO_MT_mesh_gears_add(bpy.types.Menu): class INFO_MT_mesh_gears_add(bpy.types.Menu):
...@@ -115,9 +121,9 @@ class INFO_MT_mesh_gears_add(bpy.types.Menu): ...@@ -115,9 +121,9 @@ class INFO_MT_mesh_gears_add(bpy.types.Menu):
layout = self.layout layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN' layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.primitive_gear", layout.operator("mesh.primitive_gear",
text="Gear") text="Gear")
layout.operator("mesh.primitive_worm_gear", layout.operator("mesh.primitive_worm_gear",
text="Worm") text="Worm")
class INFO_MT_mesh_diamonds_add(bpy.types.Menu): class INFO_MT_mesh_diamonds_add(bpy.types.Menu):
...@@ -129,11 +135,11 @@ class INFO_MT_mesh_diamonds_add(bpy.types.Menu): ...@@ -129,11 +135,11 @@ class INFO_MT_mesh_diamonds_add(bpy.types.Menu):
layout = self.layout layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN' layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.primitive_brilliant_add", layout.operator("mesh.primitive_brilliant_add",
text="Brilliant Diamond") text="Brilliant Diamond")
layout.operator("mesh.primitive_diamond_add", layout.operator("mesh.primitive_diamond_add",
text="Diamond") text="Diamond")
layout.operator("mesh.primitive_gem_add", layout.operator("mesh.primitive_gem_add",
text="Gem") text="Gem")
class INFO_MT_mesh_math_add(bpy.types.Menu): class INFO_MT_mesh_math_add(bpy.types.Menu):
...@@ -145,9 +151,9 @@ class INFO_MT_mesh_math_add(bpy.types.Menu): ...@@ -145,9 +151,9 @@ class INFO_MT_mesh_math_add(bpy.types.Menu):
layout = self.layout layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN' layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.primitive_z_function_surface", layout.operator("mesh.primitive_z_function_surface",
text="Z Math Surface") text="Z Math Surface")
layout.operator("mesh.primitive_xyz_function_surface", layout.operator("mesh.primitive_xyz_function_surface",
text="XYZ Math Surface") text="XYZ Math Surface")
self.layout.operator("mesh.primitive_solid_add", text="Regular Solid") self.layout.operator("mesh.primitive_solid_add", text="Regular Solid")
...@@ -161,19 +167,19 @@ class INFO_MT_mesh_extras_add(bpy.types.Menu): ...@@ -161,19 +167,19 @@ class INFO_MT_mesh_extras_add(bpy.types.Menu):
layout.operator_context = 'INVOKE_REGION_WIN' layout.operator_context = 'INVOKE_REGION_WIN'
layout.menu("INFO_MT_mesh_diamonds_add", text="Diamonds", icon="PMARKER_SEL") layout.menu("INFO_MT_mesh_diamonds_add", text="Diamonds", icon="PMARKER_SEL")
layout.operator("mesh.add_beam", layout.operator("mesh.add_beam",
text="Beam Builder") text="Beam Builder")
layout.operator("mesh.wall_add", layout.operator("mesh.wall_add",
text="Wall Factory") text="Wall Factory")
layout.operator("mesh.primitive_star_add", layout.operator("mesh.primitive_star_add",
text="Simple Star") text="Simple Star")
layout.operator("mesh.primitive_steppyramid_add", layout.operator("mesh.primitive_steppyramid_add",
text="Step Pyramid") text="Step Pyramid")
layout.operator("mesh.honeycomb_add", layout.operator("mesh.honeycomb_add",
text="Honeycomb") text="Honeycomb")
layout.operator("mesh.primitive_teapot_add", layout.operator("mesh.primitive_teapot_add",
text="Teapot+") text="Teapot+")
layout.operator("mesh.menger_sponge_add", layout.operator("mesh.menger_sponge_add",
text="Menger Sponge") text="Menger Sponge")
class INFO_MT_mesh_torus_add(bpy.types.Menu): class INFO_MT_mesh_torus_add(bpy.types.Menu):
...@@ -185,11 +191,11 @@ class INFO_MT_mesh_torus_add(bpy.types.Menu): ...@@ -185,11 +191,11 @@ class INFO_MT_mesh_torus_add(bpy.types.Menu):
layout = self.layout layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN' layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.primitive_twisted_torus_add", layout.operator("mesh.primitive_twisted_torus_add",
text="Twisted Torus") text="Twisted Torus")
layout.operator("mesh.primitive_supertoroid_add", layout.operator("mesh.primitive_supertoroid_add",
text="Supertoroid") text="Supertoroid")
layout.operator("mesh.primitive_torusknot_add", layout.operator("mesh.primitive_torusknot_add",
text="Torus Knot") text="Torus Knot")
class INFO_MT_mesh_pipe_joints_add(bpy.types.Menu): class INFO_MT_mesh_pipe_joints_add(bpy.types.Menu):
...@@ -201,64 +207,146 @@ class INFO_MT_mesh_pipe_joints_add(bpy.types.Menu): ...@@ -201,64 +207,146 @@ class INFO_MT_mesh_pipe_joints_add(bpy.types.Menu):
layout = self.layout layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN' layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.primitive_elbow_joint_add", layout.operator("mesh.primitive_elbow_joint_add",
text="Pipe Elbow") text="Pipe Elbow")
layout.operator("mesh.primitive_tee_joint_add", layout.operator("mesh.primitive_tee_joint_add",
text="Pipe T-Joint") text="Pipe T-Joint")
layout.operator("mesh.primitive_wye_joint_add", layout.operator("mesh.primitive_wye_joint_add",
text="Pipe Y-Joint") text="Pipe Y-Joint")
layout.operator("mesh.primitive_cross_joint_add", layout.operator("mesh.primitive_cross_joint_add",
text="Pipe Cross-Joint") text="Pipe Cross-Joint")
layout.operator("mesh.primitive_n_joint_add", layout.operator("mesh.primitive_n_joint_add",
text="Pipe N-Joint") text="Pipe N-Joint")
class discombobulator_scene_props(bpy.types.PropertyGroup):
DISC_doodads = []
# Protusions Buttons:
repeatprot = IntProperty(
name="Repeat protusions",
description=("Make several layers of protusion \n"
"Use carefully, runs recursively the discombulator"),
default=1, min=1, max=4 # set to 4 because it's 2**n reqursive
)
doprots = BoolProperty(
name="Make protusions",
description="Check if we want to add protusions to the mesh",
default=True
)
subpolygon1 = BoolProperty(
name="1",
default=True
)
subpolygon2 = BoolProperty(
name="2",
default=True
)
subpolygon3 = BoolProperty(
name="3",
default=True
)
subpolygon4 = BoolProperty(
name="4",
default=True
)
polygonschangedpercent = FloatProperty(
name="Polygon %",
description="Percentage of changed polygons",
default=1.0
)
minHeight = FloatProperty(
name="Min height",
description="Minimal height of the protusions",
default=0.2
)
maxHeight = FloatProperty(
name="Max height",
description="Maximal height of the protusions",
default=0.4
)
minTaper = FloatProperty(
name="Min taper",
description="Minimal height of the protusions",
default=0.15, min=0.0, max=1.0,
subtype='PERCENTAGE'
)
maxTaper = FloatProperty(
name="Max taper",
description="Maximal height of the protusions",
default=0.35, min=0.0, max=1.0,
subtype='PERCENTAGE'
)
# Doodads buttons:
dodoodads = BoolProperty(
name="Make doodads",
description="Check if we want to generate doodads",
default=False
)
mindoodads = IntProperty(
name="Minimum doodads number",
description="Ask for the minimum number of doodads to generate per polygon",
default=1, min=0, max=50
)
maxdoodads = IntProperty(
name="Maximum doodads number",
description="Ask for the maximum number of doodads to generate per polygon",
default=6, min=1, max=50
)
doodMinScale = FloatProperty(
name="Scale min", description="Minimum scaling of doodad",
default=0.5, min=0.0, max=1.0,
subtype='PERCENTAGE'
)
doodMaxScale = FloatProperty(
name="Scale max",
description="Maximum scaling of doodad",
default=1.0, min=0.0, max=1.0,
subtype='PERCENTAGE'
)
# Materials buttons:
sideProtMat = IntProperty(
name="Side's prot mat",
description="Material of protusion's sides",
default=0, min=0
)
topProtMat = IntProperty(
name="Prot's top mat",
description="Material of protusion's top",
default=0, min=0
)
# Register all operators and panels # Register all operators and panels
# Define "Extras" menu # Define "Extras" menu
def menu_func(self, context): def menu_func(self, context):
self.layout.separator() lay_out = self.layout
self.layout.menu("INFO_MT_mesh_vert_add", text="Single Vert", icon="LAYER_ACTIVE") lay_out.operator_context = 'INVOKE_REGION_WIN'
self.layout.operator("mesh.primitive_round_cube_add", text="Round Cube", icon="MOD_SUBSURF") lay_out.separator()
self.layout.menu("INFO_MT_mesh_math_add", text="Math Function", icon="PACKAGE") lay_out.menu("INFO_MT_mesh_vert_add", text="Single Vert", icon="LAYER_ACTIVE")
self.layout.operator("mesh.generate_geodesic_dome", text="Geodesic Dome",icon="MESH_ICOSPHERE") lay_out.operator("mesh.primitive_round_cube_add", text="Round Cube", icon="MOD_SUBSURF")
self.layout.operator("discombobulate.ops", text="Discombobulator",icon="MESH_ICOSPHERE") lay_out.menu("INFO_MT_mesh_math_add", text="Math Function", icon="PACKAGE")
self.layout.menu("INFO_MT_mesh_pipe_joints_add", text="Pipe Joints", icon="SNAP_PEEL_OBJECT") lay_out.operator("mesh.generate_geodesic_dome", text="Geodesic Dome", icon="MESH_ICOSPHERE")
self.layout.menu("INFO_MT_mesh_gears_add", text="Gears", icon="SCRIPTWIN") lay_out.operator("discombobulate.ops", text="Discombobulator", icon="RETOPO")
self.layout.menu("INFO_MT_mesh_torus_add", text="Torus Objects", icon="MESH_TORUS") lay_out.menu("INFO_MT_mesh_pipe_joints_add", text="Pipe Joints", icon="SNAP_PEEL_OBJECT")
self.layout.menu("INFO_MT_mesh_extras_add", text="Extras", icon="MESH_DATA") lay_out.menu("INFO_MT_mesh_gears_add", text="Gears", icon="SCRIPTWIN")
self.layout.separator() lay_out.menu("INFO_MT_mesh_torus_add", text="Torus Objects", icon="MESH_TORUS")
self.layout.operator("object.parent_to_empty", text="Parent To Empty", icon="LINK_AREA") lay_out.menu("INFO_MT_mesh_extras_add", text="Extras", icon="MESH_DATA")
self.layout.separator() lay_out.separator()
lay_out.operator("object.parent_to_empty", text="Parent To Empty", icon="LINK_AREA")
lay_out.separator()
def register(): def register():
bpy.utils.register_module(__name__) bpy.utils.register_module(__name__)
# Protusions Buttons:
bpy.types.Scene.repeatprot = bpy.props.IntProperty(name="Repeat protusions", description="make several layers of protusion", default = 1, min = 1, max = 10)
bpy.types.Scene.doprots = bpy.props.BoolProperty(name="Make protusions", description = "Check if we want to add protusions to the mesh", default = True)
bpy.types.Scene.polygonschangedpercent = bpy.props.FloatProperty(name="Polygon %", description = "Percentage of changed polygons", default = 1.0)
bpy.types.Scene.minHeight = bpy.props.FloatProperty(name="Min height", description="Minimal height of the protusions", default=0.2)
bpy.types.Scene.maxHeight = bpy.props.FloatProperty(name="Max height", description="Maximal height of the protusions", default = 0.4)
bpy.types.Scene.minTaper = bpy.props.FloatProperty(name="Min taper", description="Minimal height of the protusions", default=0.15, min = 0.0, max = 1.0, subtype = 'PERCENTAGE')
bpy.types.Scene.maxTaper = bpy.props.FloatProperty(name="Max taper", description="Maximal height of the protusions", default = 0.35, min = 0.0, max = 1.0, subtype = 'PERCENTAGE')
bpy.types.Scene.subpolygon1 = bpy.props.BoolProperty(name="1", default = True)
bpy.types.Scene.subpolygon2 = bpy.props.BoolProperty(name="2", default = True)
bpy.types.Scene.subpolygon3 = bpy.props.BoolProperty(name="3", default = True)
bpy.types.Scene.subpolygon4 = bpy.props.BoolProperty(name="4", default = True)
# Doodads buttons:
bpy.types.Scene.dodoodads = bpy.props.BoolProperty(name="Make doodads", description = "Check if we want to generate doodads", default = True)
bpy.types.Scene.mindoodads = bpy.props.IntProperty(name="Minimum doodads number", description = "Ask for the minimum number of doodads to generate per polygon", default = 1, min = 0, max = 50)
bpy.types.Scene.maxdoodads = bpy.props.IntProperty(name="Maximum doodads number", description = "Ask for the maximum number of doodads to generate per polygon", default = 6, min = 1, max = 50)
bpy.types.Scene.doodMinScale = bpy.props.FloatProperty(name="Scale min", description="Minimum scaling of doodad", default = 0.5, min = 0.0, max = 1.0, subtype = 'PERCENTAGE')
bpy.types.Scene.doodMaxScale = bpy.props.FloatProperty(name="Scale max", description="Maximum scaling of doodad", default = 1.0, min = 0.0, max = 1.0, subtype = 'PERCENTAGE')
# Materials buttons:
bpy.types.Scene.sideProtMat = bpy.props.IntProperty(name="Side's prot mat", description = "Material of protusion's sides", default = 0, min = 0)
bpy.types.Scene.topProtMat = bpy.props.IntProperty(name = "Prot's top mat", description = "Material of protusion's top", default = 0, min = 0)
# Register Discombobulator properties
bpy.types.Scene.discomb = bpy.props.PointerProperty(
type=discombobulator_scene_props
)
# Add "Extras" menu to the "Add Mesh" menu # Add "Extras" menu to the "Add Mesh" menu
bpy.types.INFO_MT_mesh_add.append(menu_func) bpy.types.INFO_MT_mesh_add.append(menu_func)
...@@ -267,6 +355,8 @@ def unregister(): ...@@ -267,6 +355,8 @@ def unregister():
# Remove "Extras" menu from the "Add Mesh" menu. # Remove "Extras" menu from the "Add Mesh" menu.
bpy.types.INFO_MT_mesh_add.remove(menu_func) bpy.types.INFO_MT_mesh_add.remove(menu_func)
del bpy.types.Scene.discomb
bpy.utils.unregister_module(__name__) bpy.utils.unregister_module(__name__)
......
# ##### BEGIN GPL LICENSE BLOCK ##### # GPL # Original Authors: Evan J. Rosky (syrux), Chichiri, Jace Priester #
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program 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 for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "Discombobulator",
"description": "Its job is to easily add scifi details to a surface to create nice-looking space-ships or futuristic cities.",
"author": "Evan J. Rosky (syrux), Chichiri, Jace Priester",
"version": (0,2),
"blender": (2, 71, 0),
"location": "View3D > Toolshelf > Tools Tab",
"warning": '',
'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts',
'tracker_url': 'https://developer.blender.org/maniphest/task/create/?project=3&type=Bug',
"category": "Mesh"}
import bpy import bpy
import random import random
import mathutils
import math import math
from mathutils import * from bpy.types import (
Operator,
Menu,
)
from mathutils import (
Vector,
Quaternion,
)
# ################### Globals #################### #
doprots = True doprots = True
...@@ -43,42 +23,46 @@ Verts = [] ...@@ -43,42 +23,46 @@ Verts = []
Polygons = [] Polygons = []
dVerts = [] dVerts = []
dPolygons = [] dPolygons = []
i_prots = [] # index of the top polygons on whow we will generate the doodads i_prots = [] # index of the top polygons on which we'll generate the doodads
i_dood_type = [] # type of doodad (given by index of the doodad obj) i_dood_type = [] # type of doodad (given by index of the doodad obj)
bpy.types.Scene.DISC_doodads = [] # ############### Utility Functions ############### #
def randnum(a, b): def randnum(a, b):
return random.random()*(b-a)+a return random.random() * (b - a) + a
def randVertex(a, b, c, d, Verts): def randVertex(a, b, c, d, Verts):
"""Return a vector of a random vertex on a quad-polygon""" """Return a vector of a random vertex on a quad-polygon"""
i = random.randint(1,2) i = random.randint(1, 2)
A, B, C, D = 0, 0, 0, 0 A, B, C, D = 0, 0, 0, 0
if(a==1): if(a == 1):
A, B, C, D = a, b, c, d A, B, C, D = a, b, c, d
else: else:
A, B, C, D = a, d, c, b A, B, C, D = a, d, c, b
i = randnum(0.1, 0.9) i = randnum(0.1, 0.9)
vecAB = Verts[B] - Verts[A]
E = Verts[A] + vecAB * i
vecAB=Verts[B]-Verts[A] vecDC = Verts[C] - Verts[D]
E=Verts[A]+vecAB*i F = Verts[D] + vecDC * i
vecDC=Verts[C]-Verts[D]
F=Verts[D]+vecDC*i
i = randnum(0.1, 0.9) i = randnum(0.1, 0.9)
vecEF=F-E vecEF = F - E
O=E+vecEF*i O = E + vecEF * i
return O return O
################################ Protusions ###################################
# ################## Protusions #################### #
def fill_older_datas(verts, polygon): def fill_older_datas(verts, polygon):
""" Specifically coded to be called by the function addProtusionToPolygon, its sets up a tuple which contains the vertices from the base and the top of the protusions. """ """ Specifically coded to be called by the function addProtusionToPolygon,
its sets up a tuple which contains the vertices from the base and the top of the protusions.
"""
temp_vertices = [] temp_vertices = []
temp_vertices.append(verts[polygon[0]].copy()) temp_vertices.append(verts[polygon[0]].copy())
temp_vertices.append(verts[polygon[1]].copy()) temp_vertices.append(verts[polygon[1]].copy())
...@@ -90,15 +74,19 @@ def fill_older_datas(verts, polygon): ...@@ -90,15 +74,19 @@ def fill_older_datas(verts, polygon):
temp_vertices.append(verts[polygon[3]].copy()) temp_vertices.append(verts[polygon[3]].copy())
return temp_vertices return temp_vertices
def extrude_top(temp_vertices, normal, height): def extrude_top(temp_vertices, normal, height):
""" This function extrude the polygon composed of the four first members of the tuple temp_vertices along the normal multiplied by the height of the extrusion.""" """ This function extrude the polygon composed of the four first members of the tuple
temp_vertices along the normal multiplied by the height of the extrusion.
"""
j = 0 j = 0
while j < 3: while j < 3:
temp_vertices[0][j]+=normal[j]*height temp_vertices[0][j] += normal[j] * height
temp_vertices[1][j]+=normal[j]*height temp_vertices[1][j] += normal[j] * height
temp_vertices[2][j]+=normal[j]*height temp_vertices[2][j] += normal[j] * height
temp_vertices[3][j]+=normal[j]*height temp_vertices[3][j] += normal[j] * height
j+=1 j += 1
def scale_top(temp_vertices, center, normal, height, scale_ratio): def scale_top(temp_vertices, center, normal, height, scale_ratio):
""" This function scale the polygon composed of the four first members of the tuple temp_vertices. """ """ This function scale the polygon composed of the four first members of the tuple temp_vertices. """
...@@ -109,41 +97,47 @@ def scale_top(temp_vertices, center, normal, height, scale_ratio): ...@@ -109,41 +97,47 @@ def scale_top(temp_vertices, center, normal, height, scale_ratio):
j = 0 j = 0
while j < 3: while j < 3:
center[j]+=normal[j]*height center[j] += normal[j] * height
vec1[j] = temp_vertices[0][j] - center[j] vec1[j] = temp_vertices[0][j] - center[j]
vec2[j] = temp_vertices[1][j] - center[j] vec2[j] = temp_vertices[1][j] - center[j]
vec3[j] = temp_vertices[2][j] - center[j] vec3[j] = temp_vertices[2][j] - center[j]
vec4[j] = temp_vertices[3][j] - center[j] vec4[j] = temp_vertices[3][j] - center[j]
temp_vertices[0][j] = center[j] + vec1[j]*(1-scale_ratio) temp_vertices[0][j] = center[j] + vec1[j] * (1 - scale_ratio)
temp_vertices[1][j] = center[j] + vec2[j]*(1-scale_ratio) temp_vertices[1][j] = center[j] + vec2[j] * (1 - scale_ratio)
temp_vertices[2][j] = center[j] + vec3[j]*(1-scale_ratio) temp_vertices[2][j] = center[j] + vec3[j] * (1 - scale_ratio)
temp_vertices[3][j] = center[j] + vec4[j]*(1-scale_ratio) temp_vertices[3][j] = center[j] + vec4[j] * (1 - scale_ratio)
j+=1 j += 1
def add_prot_polygons(temp_vertices): def add_prot_polygons(temp_vertices):
""" Specifically coded to be called by addProtusionToPolygon, this function put the data from the generated protusion at the end the tuples Verts and Polygons, which will later used to generate the final mesh. """ """ Specifically coded to be called by addProtusionToPolygon, this function
put the data from the generated protusion at the end the tuples Verts and Polygons,
which will later used to generate the final mesh.
"""
global Verts global Verts
global Polygons global Polygons
global i_prots global i_prots
findex = len(Verts) findex = len(Verts)
Verts+=temp_vertices Verts += temp_vertices
polygontop = [findex+0, findex+1, findex+2, findex+3] polygontop = [findex + 0, findex + 1, findex + 2, findex + 3]
polygon1 = [findex+0, findex+1, findex+5, findex+4] polygon1 = [findex + 0, findex + 1, findex + 5, findex + 4]
polygon2 = [findex+1, findex+2, findex+6, findex+5] polygon2 = [findex + 1, findex + 2, findex + 6, findex + 5]
polygon3 = [findex+2, findex+3, findex+7, findex+6] polygon3 = [findex + 2, findex + 3, findex + 7, findex + 6]
polygon4 = [findex+3, findex+0, findex+4, findex+7] polygon4 = [findex + 3, findex + 0, findex + 4, findex + 7]
Polygons.append(polygontop) Polygons.append(polygontop)
i_prots.append(len(Polygons)-1) i_prots.append(len(Polygons) - 1)
Polygons.append(polygon1) Polygons.append(polygon1)
Polygons.append(polygon2) Polygons.append(polygon2)
Polygons.append(polygon3) Polygons.append(polygon3)
Polygons.append(polygon4) Polygons.append(polygon4)
def addProtusionToPolygon(obpolygon, verts, minHeight, maxHeight, minTaper, maxTaper): def addProtusionToPolygon(obpolygon, verts, minHeight, maxHeight, minTaper, maxTaper):
"""Create a protusion from the polygon "obpolygon" of the original object and use several values sent by the user. It calls in this order the following functions: """Create a protusion from the polygon "obpolygon" of the original object and use
several values sent by the user. It calls in this order the following functions:
- fill_older_data; - fill_older_data;
- extrude_top; - extrude_top;
- scale_top; - scale_top;
...@@ -151,24 +145,20 @@ def addProtusionToPolygon(obpolygon, verts, minHeight, maxHeight, minTaper, maxT ...@@ -151,24 +145,20 @@ def addProtusionToPolygon(obpolygon, verts, minHeight, maxHeight, minTaper, maxT
""" """
# some useful variables # some useful variables
polygon = obpolygon.vertices polygon = obpolygon.vertices
polygontop = polygon
polygon1 = [] tVerts = list(fill_older_datas(verts, polygon)) # list of temp vertices
polygon2 = [] height = randnum(minHeight, maxHeight) # height of generated protusion
polygon3 = []
polygon4 = []
vertices = []
tVerts = list(fill_older_datas(verts, polygon)) # list of temp vertices
height = randnum(minHeight, maxHeight) # height of generated protusion
scale_ratio = randnum(minTaper, maxTaper) scale_ratio = randnum(minTaper, maxTaper)
# extrude the top polygon # extrude the top polygon
extrude_top(tVerts, obpolygon.normal, height) extrude_top(tVerts, obpolygon.normal, height)
# Now, we scale, the top polygon along its normal # Now, we scale, the top polygon along its normal
scale_top(tVerts, GetPolyCentroid(obpolygon,verts), obpolygon.normal, height, scale_ratio) scale_top(tVerts, GetPolyCentroid(obpolygon, verts), obpolygon.normal, height, scale_ratio)
# Finally, we add the protusions to the list of polygons # Finally, we add the protusions to the list of polygons
add_prot_polygons(tVerts) add_prot_polygons(tVerts)
################################## Divide a polygon ##################################
# ################# Divide a polygon ############### #
def divide_one(list_polygons, list_vertices, verts, polygon, findex): def divide_one(list_polygons, list_vertices, verts, polygon, findex):
""" called by divide_polygon, to generate a polygon from one polygon, maybe I could simplify this process """ """ called by divide_polygon, to generate a polygon from one polygon, maybe I could simplify this process """
...@@ -178,63 +168,73 @@ def divide_one(list_polygons, list_vertices, verts, polygon, findex): ...@@ -178,63 +168,73 @@ def divide_one(list_polygons, list_vertices, verts, polygon, findex):
temp_vertices.append(verts[polygon[2]].copy()) temp_vertices.append(verts[polygon[2]].copy())
temp_vertices.append(verts[polygon[3]].copy()) temp_vertices.append(verts[polygon[3]].copy())
list_vertices+=temp_vertices list_vertices += temp_vertices
list_polygons.append([findex + 0, findex + 1, findex + 2, findex + 3])
list_polygons.append([findex+0, findex+1, findex+2, findex+3])
def divide_two(list_polygons, list_vertices, verts, polygon, findex): def divide_two(list_polygons, list_vertices, verts, polygon, findex):
""" called by divide_polygon, to generate two polygons from one polygon and add them to the list of polygons and vertices which form the discombobulated mesh""" """ called by divide_polygon, to generate two polygons from one polygon and
add them to the list of polygons and vertices which form the discombobulated mesh
"""
temp_vertices = [] temp_vertices = []
temp_vertices.append(verts[polygon[0]].copy()) temp_vertices.append(verts[polygon[0]].copy())
temp_vertices.append(verts[polygon[1]].copy()) temp_vertices.append(verts[polygon[1]].copy())
temp_vertices.append(verts[polygon[2]].copy()) temp_vertices.append(verts[polygon[2]].copy())
temp_vertices.append(verts[polygon[3]].copy()) temp_vertices.append(verts[polygon[3]].copy())
temp_vertices.append((verts[polygon[0]]+verts[polygon[1]])/2) temp_vertices.append((verts[polygon[0]] + verts[polygon[1]]) / 2)
temp_vertices.append((verts[polygon[2]]+verts[polygon[3]])/2) temp_vertices.append((verts[polygon[2]] + verts[polygon[3]]) / 2)
list_vertices+=temp_vertices list_vertices += temp_vertices
list_polygons.append([findex + 0, findex + 4, findex + 5, findex + 3])
list_polygons.append([findex + 1, findex + 2, findex + 5, findex + 4])
list_polygons.append([findex+0, findex+4, findex+5, findex+3])
list_polygons.append([findex+1, findex+2, findex+5, findex+4])
def divide_three(list_polygons, list_vertices, verts, polygon, findex, center): def divide_three(list_polygons, list_vertices, verts, polygon, findex, center):
""" called by divide_polygon, to generate three polygons from one polygon and add them to the list of polygons and vertices which form the discombobulated mesh""" """ called by divide_polygon, to generate three polygons from one polygon and
add them to the list of polygons and vertices which form the discombobulated mesh
"""
temp_vertices = [] temp_vertices = []
temp_vertices.append(verts[polygon[0]].copy()) temp_vertices.append(verts[polygon[0]].copy())
temp_vertices.append(verts[polygon[1]].copy()) temp_vertices.append(verts[polygon[1]].copy())
temp_vertices.append(verts[polygon[2]].copy()) temp_vertices.append(verts[polygon[2]].copy())
temp_vertices.append(verts[polygon[3]].copy()) temp_vertices.append(verts[polygon[3]].copy())
temp_vertices.append((verts[polygon[0]]+verts[polygon[1]])/2) temp_vertices.append((verts[polygon[0]] + verts[polygon[1]]) / 2)
temp_vertices.append((verts[polygon[2]]+verts[polygon[3]])/2) temp_vertices.append((verts[polygon[2]] + verts[polygon[3]]) / 2)
temp_vertices.append((verts[polygon[1]]+verts[polygon[2]])/2) temp_vertices.append((verts[polygon[1]] + verts[polygon[2]]) / 2)
temp_vertices.append(center.copy()) temp_vertices.append(center.copy())
list_vertices+=temp_vertices list_vertices += temp_vertices
list_polygons.append([findex + 0, findex + 4, findex + 5, findex + 3])
list_polygons.append([findex + 1, findex + 6, findex + 7, findex + 4])
list_polygons.append([findex + 6, findex + 2, findex + 5, findex + 7])
list_polygons.append([findex+0, findex+4, findex+5, findex+3])
list_polygons.append([findex+1, findex+6, findex+7, findex+4])
list_polygons.append([findex+6, findex+2, findex+5, findex+7])
def divide_four(list_polygons, list_vertices, verts, polygon, findex, center): def divide_four(list_polygons, list_vertices, verts, polygon, findex, center):
""" called by divide_polygon, to generate four polygons from one polygon and add them to the list of polygons and vertices which form the discombobulated mesh""" """ called by divide_polygon, to generate four polygons from one polygon and
add them to the list of polygons and vertices which form the discombobulated mesh
"""
temp_vertices = [] temp_vertices = []
temp_vertices.append(verts[polygon[0]].copy()) temp_vertices.append(verts[polygon[0]].copy())
temp_vertices.append(verts[polygon[1]].copy()) temp_vertices.append(verts[polygon[1]].copy())
temp_vertices.append(verts[polygon[2]].copy()) temp_vertices.append(verts[polygon[2]].copy())
temp_vertices.append(verts[polygon[3]].copy()) temp_vertices.append(verts[polygon[3]].copy())
temp_vertices.append((verts[polygon[0]]+verts[polygon[1]])/2) temp_vertices.append((verts[polygon[0]] + verts[polygon[1]]) / 2)
temp_vertices.append((verts[polygon[2]]+verts[polygon[3]])/2) temp_vertices.append((verts[polygon[2]] + verts[polygon[3]]) / 2)
temp_vertices.append((verts[polygon[1]]+verts[polygon[2]])/2) temp_vertices.append((verts[polygon[1]] + verts[polygon[2]]) / 2)
temp_vertices.append(center.copy()) temp_vertices.append(center.copy())
temp_vertices.append((verts[polygon[0]]+verts[polygon[3]])/2) temp_vertices.append((verts[polygon[0]] + verts[polygon[3]]) / 2)
temp_vertices.append(center.copy()) temp_vertices.append(center.copy())
list_vertices+=temp_vertices list_vertices += temp_vertices
list_polygons.append([findex + 0, findex + 4, findex + 7, findex + 8])
list_polygons.append([findex + 1, findex + 6, findex + 7, findex + 4])
list_polygons.append([findex + 6, findex + 2, findex + 5, findex + 7])
list_polygons.append([findex + 8, findex + 7, findex + 5, findex + 3])
list_polygons.append([findex+0, findex+4, findex+7, findex+8])
list_polygons.append([findex+1, findex+6, findex+7, findex+4])
list_polygons.append([findex+6, findex+2, findex+5, findex+7])
list_polygons.append([findex+8, findex+7, findex+5, findex+3])
def dividepolygon(obpolygon, verts, number): def dividepolygon(obpolygon, verts, number):
"""Divide the poly into the wanted number of polygons""" """Divide the poly into the wanted number of polygons"""
...@@ -242,38 +242,45 @@ def dividepolygon(obpolygon, verts, number): ...@@ -242,38 +242,45 @@ def dividepolygon(obpolygon, verts, number):
global nVerts global nVerts
poly = obpolygon.vertices poly = obpolygon.vertices
tVerts = []
if(number==1): if(number == 1):
divide_one(nPolygons, nVerts, verts, poly, len(nVerts)) divide_one(nPolygons, nVerts, verts, poly, len(nVerts))
elif(number==2): elif(number == 2):
divide_two(nPolygons, nVerts, verts, poly, len(nVerts)) divide_two(nPolygons, nVerts, verts, poly, len(nVerts))
elif(number==3): elif(number == 3):
divide_three(nPolygons, nVerts, verts, poly, len(nVerts), GetPolyCentroid(obpolygon,verts)) divide_three(nPolygons, nVerts, verts, poly, len(nVerts), GetPolyCentroid(obpolygon, verts))
elif(number==4): elif(number == 4):
divide_four(nPolygons, nVerts, verts, poly, len(nVerts), GetPolyCentroid(obpolygon,verts)) divide_four(nPolygons, nVerts, verts, poly, len(nVerts), GetPolyCentroid(obpolygon, verts))
############################### Discombobulate ################################ # ################## Discombobulate ################ #
def GetPolyCentroid(obpolygon,allvertcoords): def GetPolyCentroid(obpolygon, allvertcoords):
centroid=mathutils.Vector((0,0,0)) centroid = Vector((0, 0, 0))
for vindex in obpolygon.vertices: for vindex in obpolygon.vertices:
centroid+=mathutils.Vector(allvertcoords[vindex]) centroid += Vector(allvertcoords[vindex])
centroid/=len(obpolygon.vertices) centroid /= len(obpolygon.vertices)
return centroid return centroid
def division(obpolygons, verts, sf1, sf2, sf3, sf4): def division(obpolygons, verts, sf1, sf2, sf3, sf4):
"""Function to divide each of the selected polygons""" """Function to divide each of the selected polygons"""
divide = [] divide = []
if(sf1): divide.append(1) if (sf1):
if(sf2): divide.append(2) divide.append(1)
if(sf3): divide.append(3) if (sf2):
if(sf4): divide.append(4) divide.append(2)
if (sf3):
divide.append(3)
if (sf4):
divide.append(4)
for poly in obpolygons: for poly in obpolygons:
if(poly.select == True and len(poly.vertices)==4): if(poly.select is True and len(poly.vertices) == 4):
a = random.randint(0, len(divide)-1) a = random.randint(0, len(divide) - 1)
dividepolygon(poly, verts, divide[a]) dividepolygon(poly, verts, divide[a])
def protusion(obverts, obpolygons, minHeight, maxHeight, minTaper, maxTaper): def protusion(obverts, obpolygons, minHeight, maxHeight, minTaper, maxTaper):
"""function to generate the protusions""" """function to generate the protusions"""
verts = [] verts = []
...@@ -281,30 +288,33 @@ def protusion(obverts, obpolygons, minHeight, maxHeight, minTaper, maxTaper): ...@@ -281,30 +288,33 @@ def protusion(obverts, obpolygons, minHeight, maxHeight, minTaper, maxTaper):
verts.append(vertex.co) verts.append(vertex.co)
for polygon in obpolygons: for polygon in obpolygons:
if(polygon.select == True): if(polygon.select is True):
if(len(polygon.vertices) == 4): if(len(polygon.vertices) == 4):
addProtusionToPolygon(polygon, verts, minHeight, maxHeight, minTaper, maxTaper) addProtusionToPolygon(polygon, verts, minHeight, maxHeight, minTaper, maxTaper)
def test_v2_near_v1(v1, v2): def test_v2_near_v1(v1, v2):
if(v1.x - 0.1 <= v2.x <= v1.x + 0.1 if (v1.x - 0.1 <= v2.x <= v1.x + 0.1 and
and v1.y - 0.1 <= v2.y <= v1.y + 0.1 v1.y - 0.1 <= v2.y <= v1.y + 0.1 and
and v1.z - 0.1 <= v2.z <= v1.z + 0.1): v1.z - 0.1 <= v2.z <= v1.z + 0.1):
return True return True
return False return False
def angle_between_nor(nor_orig, nor_result): def angle_between_nor(nor_orig, nor_result):
angle = math.acos(nor_orig.dot(nor_result)) angle = math.acos(nor_orig.dot(nor_result))
axis = nor_orig.cross(nor_result).normalized() axis = nor_orig.cross(nor_result).normalized()
q = mathutils.Quaternion() q = Quaternion()
q.x = axis.x*math.sin(angle/2) q.x = axis.x * math.sin(angle / 2)
q.y = axis.y*math.sin(angle/2) q.y = axis.y * math.sin(angle / 2)
q.z = axis.z*math.sin(angle/2) q.z = axis.z * math.sin(angle / 2)
q.w = math.cos(angle/2) q.w = math.cos(angle / 2)
return q return q
def doodads(object1, mesh1, dmin, dmax): def doodads(object1, mesh1, dmin, dmax):
"""function to generate the doodads""" """function to generate the doodads"""
global dVerts global dVerts
...@@ -312,61 +322,67 @@ def doodads(object1, mesh1, dmin, dmax): ...@@ -312,61 +322,67 @@ def doodads(object1, mesh1, dmin, dmax):
i = 0 i = 0
# on parcoure cette boucle pour ajouter des doodads a toutes les polygons # on parcoure cette boucle pour ajouter des doodads a toutes les polygons
# english translation: this loops adds doodads to all polygons # english translation: this loops adds doodads to all polygons
while(i<len(object1.data.polygons)): while(i < len(object1.data.polygons)):
if object1.data.polygons[i].select==False: if object1.data.polygons[i].select is False:
continue continue
doods_nbr = random.randint(dmin, dmax) doods_nbr = random.randint(dmin, dmax)
j = 0 j = 0
while(j<=doods_nbr):
origin_dood = randVertex(object1.data.polygons[i].vertices[0], object1.data.polygons[i].vertices[1], object1.data.polygons[i].vertices[2], object1.data.polygons[i].vertices[3], Verts) while(j <= doods_nbr):
type_dood = random.randint(0, len(bpy.context.scene.DISC_doodads)-1) origin_dood = randVertex(object1.data.polygons[i].vertices[0], object1.data.polygons[i].vertices[1],
object1.data.polygons[i].vertices[2], object1.data.polygons[i].vertices[3], Verts)
type_dood = random.randint(0, len(bpy.context.scene.discomb.DISC_doodads) - 1)
polygons_add = [] polygons_add = []
verts_add = [] verts_add = []
# First we have to apply scaling and rotation to the mesh # First we have to apply scaling and rotation to the mesh
bpy.ops.object.select_pattern(pattern=bpy.context.scene.DISC_doodads[type_dood],extend=False) bpy.ops.object.select_pattern(pattern=bpy.context.scene.discomb.DISC_doodads[type_dood], extend=False)
bpy.context.scene.objects.active=bpy.data.objects[bpy.context.scene.DISC_doodads[type_dood]] bpy.context.scene.objects.active = bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]]
bpy.ops.object.transform_apply(rotation=True, scale=True) bpy.ops.object.transform_apply(rotation=True, scale=True)
for polygon in bpy.data.objects[bpy.context.scene.DISC_doodads[type_dood]].data.polygons: for polygon in bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]].data.polygons:
polygons_add.append(polygon.vertices) polygons_add.append(polygon.vertices)
for vertex in bpy.data.objects[bpy.context.scene.DISC_doodads[type_dood]].data.vertices: for vertex in bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]].data.vertices:
verts_add.append(vertex.co.copy()) verts_add.append(vertex.co.copy())
normal_original_polygon = object1.data.polygons[i].normal normal_original_polygon = object1.data.polygons[i].normal
nor_def = mathutils.Vector((0.0, 0.0, 1.0)) nor_def = Vector((0.0, 0.0, 1.0))
qr = nor_def.rotation_difference(normal_original_polygon.normalized()) qr = nor_def.rotation_difference(normal_original_polygon.normalized())
case_z = False
if(test_v2_near_v1(nor_def, -normal_original_polygon)): if(test_v2_near_v1(nor_def, -normal_original_polygon)):
case_z = True qr = Quaternion((0.0, 0.0, 0.0, 0.0))
qr = mathutils.Quaternion((0.0, 0.0, 0.0, 0.0))
#qr = angle_between_nor(nor_def, normal_original_polygon) # qr = angle_between_nor(nor_def, normal_original_polygon)
for vertex in verts_add: for vertex in verts_add:
vertex.rotate(qr) vertex.rotate(qr)
vertex+=origin_dood vertex += origin_dood
findex = len(dVerts) findex = len(dVerts)
for polygon in polygons_add: for polygon in polygons_add:
dPolygons.append([polygon[0]+findex, polygon[1]+findex, polygon[2]+findex, polygon[3]+findex]) dPolygons.append([polygon[0] + findex, polygon[1] + findex, polygon[2] + findex, polygon[3] + findex])
i_dood_type.append(bpy.data.objects[bpy.context.scene.DISC_doodads[type_dood]].name) i_dood_type.append(bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]].name)
for vertex in verts_add: for vertex in verts_add:
dVerts.append(vertex) dVerts.append(vertex)
j+=1 j += 1
i+=5 i += 5
def protusions_repeat(object1, mesh1, r_prot): def protusions_repeat(object1, mesh1, r_prot):
for j in i_prots: for j in i_prots:
if j<len(object1.data.polygons): if j < len(object1.data.polygons):
object1.data.polygons[j].select=True object1.data.polygons[j].select = True
else: else:
print("Warning: hit end of polygons in object1") print("Warning: hit end of polygons in object1")
# add material to discombobulated mesh # add material to discombobulated mesh
def setMatProt(discObj, origObj, sideProtMat, topProtMat): def setMatProt(discObj, origObj, sideProtMat, topProtMat):
# First we put the materials in their slots # First we put the materials in their slots
bpy.ops.object.select_pattern(pattern = discObj.name,extend=False) bpy.ops.object.select_pattern(pattern=discObj.name, extend=False)
bpy.context.scene.objects.active=bpy.data.objects[discObj.name] bpy.context.scene.objects.active = bpy.data.objects[discObj.name]
try: try:
origObj.material_slots[topProtMat] origObj.material_slots[topProtMat]
origObj.material_slots[sideProtMat] origObj.material_slots[sideProtMat]
...@@ -385,30 +401,32 @@ def setMatProt(discObj, origObj, sideProtMat, topProtMat): ...@@ -385,30 +401,32 @@ def setMatProt(discObj, origObj, sideProtMat, topProtMat):
else: else:
polygon.material_index = 1 polygon.material_index = 1
def setMatDood(doodObj): def setMatDood(doodObj):
# First we add the materials slots # First we add the materials slots
bpy.ops.object.select_pattern(pattern = doodObj.name,extend=False) bpy.ops.object.select_pattern(pattern=doodObj.name, extend=False)
bpy.context.scene.objects.active=doodObj bpy.context.scene.objects.active = doodObj
for name in bpy.context.scene.DISC_doodads: for name in bpy.context.scene.discomb.DISC_doodads:
try: try:
bpy.ops.object.material_slot_add() bpy.ops.object.material_slot_add()
doodObj.material_slots[-1].material = bpy.data.objects[name].material_slots[0].material doodObj.material_slots[-1].material = bpy.data.objects[name].material_slots[0].material
for polygon in doodObj.data.polygons: for polygon in doodObj.data.polygons:
if i_dood_type[polygon.index] == name: if i_dood_type[polygon.index] == name:
polygon.material_index = len(doodObj.material_slots)-1 polygon.material_index = len(doodObj.material_slots) - 1
except: except:
print() print()
def clean_doodads(): def clean_doodads():
current_doodads=list(bpy.context.scene.DISC_doodads) current_doodads = list(bpy.context.scene.discomb.DISC_doodads)
for name in current_doodads: for name in current_doodads:
if name not in bpy.data.objects: if name not in bpy.data.objects:
bpy.context.scene.DISC_doodads.remove(name) bpy.context.scene.discomb.DISC_doodads.remove(name)
def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4, dmin, dmax, r_prot, sideProtMat, topProtMat, isLast): def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4,
dmin, dmax, r_prot, sideProtMat, topProtMat, isLast):
global doprots global doprots
global nVerts global nVerts
global nPolygons global nPolygons
...@@ -418,14 +436,11 @@ def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4, ...@@ -418,14 +436,11 @@ def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4,
global dPolygons global dPolygons
global i_prots global i_prots
bpy.ops.object.mode_set(mode="OBJECT") bpy.ops.object.mode_set(mode="OBJECT")
# start by cleaning up doodads that don't exist anymore
#start by cleaning up doodads that don't exist anymore
clean_doodads() clean_doodads()
# Create the discombobulated mesh # Create the discombobulated mesh
mesh = bpy.data.meshes.new("tmp") mesh = bpy.data.meshes.new("tmp")
object = bpy.data.objects.new("tmp", mesh) object = bpy.data.objects.new("tmp", mesh)
...@@ -443,8 +458,8 @@ def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4, ...@@ -443,8 +458,8 @@ def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4,
# There we collect the rotation, translation and scaling datas from the original mesh # There we collect the rotation, translation and scaling datas from the original mesh
to_translate = bpy.context.active_object.location to_translate = bpy.context.active_object.location
to_scale = bpy.context.active_object.scale to_scale = bpy.context.active_object.scale
to_rotate = bpy.context.active_object.rotation_euler to_rotate = bpy.context.active_object.rotation_euler
# First, we collect all the informations we will need from the previous mesh # First, we collect all the informations we will need from the previous mesh
obverts = bpy.context.active_object.data.vertices obverts = bpy.context.active_object.data.vertices
...@@ -457,12 +472,12 @@ def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4, ...@@ -457,12 +472,12 @@ def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4,
# Fill in the discombobulated mesh with the new polygons # Fill in the discombobulated mesh with the new polygons
mesh.from_pydata(nVerts, [], nPolygons) mesh.from_pydata(nVerts, [], nPolygons)
mesh.update(calc_edges = True) mesh.update(calc_edges=True)
# Reload the datas # Reload the datas
bpy.ops.object.select_all(action="DESELECT") bpy.ops.object.select_all(action="DESELECT")
bpy.ops.object.select_pattern(pattern = object.name,extend=False) bpy.ops.object.select_pattern(pattern=object.name, extend=False)
bpy.context.scene.objects.active=bpy.data.objects[object.name] bpy.context.scene.objects.active = bpy.data.objects[object.name]
obverts = bpy.context.active_object.data.vertices obverts = bpy.context.active_object.data.vertices
obpolygons = bpy.context.active_object.data.polygons obpolygons = bpy.context.active_object.data.polygons
...@@ -473,213 +488,276 @@ def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4, ...@@ -473,213 +488,276 @@ def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4,
object1 = bpy.data.objects.new("discombobulated_mesh", mesh1) object1 = bpy.data.objects.new("discombobulated_mesh", mesh1)
bpy.context.scene.objects.link(object1) bpy.context.scene.objects.link(object1)
mesh1.from_pydata(Verts, [], Polygons) mesh1.from_pydata(Verts, [], Polygons)
mesh1.update(calc_edges = True) mesh1.update(calc_edges=True)
# Set the material's of discombobulated object # Set the material's of discombobulated object
setMatProt(object1, origObj, sideProtMat, topProtMat) setMatProt(object1, origObj, sideProtMat, topProtMat)
bpy.ops.object.select_pattern(pattern = object1.name,extend=False) bpy.ops.object.select_pattern(pattern=object1.name, extend=False)
bpy.context.scene.objects.active=bpy.data.objects[object1.name] bpy.context.scene.objects.active = bpy.data.objects[object1.name]
bpy.ops.object.mode_set(mode='EDIT') bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.normals_make_consistent(inside=False) bpy.ops.mesh.normals_make_consistent(inside=False)
bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')
#if(bpy.context.scene.repeatprot): # if(bpy.context.scene.repeatprot):
protusions_repeat(object1, mesh1, r_prot) protusions_repeat(object1, mesh1, r_prot)
if(len(bpy.context.scene.DISC_doodads) != 0 and bpy.context.scene.dodoodads and isLast): if(len(bpy.context.scene.discomb.DISC_doodads) != 0 and bpy.context.scene.discomb.dodoodads and isLast):
doodads(object1, mesh1, dmin, dmax) doodads(object1, mesh1, dmin, dmax)
mesh2 = bpy.data.meshes.new("dood_mesh") mesh2 = bpy.data.meshes.new("dood_mesh")
object2 = bpy.data.objects.new("dood_obj", mesh2) object2 = bpy.data.objects.new("dood_obj", mesh2)
bpy.context.scene.objects.link(object2) bpy.context.scene.objects.link(object2)
mesh2.from_pydata(dVerts, [], dPolygons) mesh2.from_pydata(dVerts, [], dPolygons)
mesh2.update(calc_edges = True) mesh2.update(calc_edges=True)
setMatDood(object2) setMatDood(object2)
object2.location = to_translate object2.location = to_translate
object2.rotation_euler = to_rotate object2.rotation_euler = to_rotate
object2.scale = to_scale object2.scale = to_scale
bpy.ops.object.select_pattern(pattern = object.name,extend=False) bpy.ops.object.select_pattern(pattern=object.name, extend=False)
bpy.context.scene.objects.active=bpy.data.objects[object.name] bpy.context.scene.objects.active = bpy.data.objects[object.name]
bpy.ops.object.delete() bpy.ops.object.delete()
bpy.ops.object.select_pattern(pattern=object1.name,extend=False) bpy.ops.object.select_pattern(pattern=object1.name, extend=False)
bpy.context.scene.objects.active=bpy.data.objects[object1.name] bpy.context.scene.objects.active = bpy.data.objects[object1.name]
bpy.context.scene.update() bpy.context.scene.update()
# translate, scale and rotate discombobulated results # translate, scale and rotate discombobulated results
object1.location = to_translate object1.location = to_translate
object1.rotation_euler = to_rotate object1.rotation_euler = to_rotate
object1.scale = to_scale object1.scale = to_scale
#set all polys to selected. this allows recursive discombobulating. # set all polys to selected. this allows recursive discombobulating.
for poly in mesh1.polygons: for poly in mesh1.polygons:
poly.select=True poly.select = True
############ Operator to select and deslect an object as a doodad ############### # ### Operators for selecting and deselecting an object as a doodad ### #
class chooseDoodad(bpy.types.Operator): class chooseDoodad(Operator):
bl_idname = "object.discombobulate_set_doodad" bl_idname = "object.discombobulate_set_doodad"
bl_label = "Discombobulate set doodad object" bl_label = "Discombobulate set doodad object"
bl_description = ("Save the Active Object as Doodad \n"
"Object has to be quads only")
bl_options = {'REGISTER'}
@classmethod
def poll(cls, context):
obj = bpy.context.active_object
if (obj is not None and obj.type == "MESH"):
mesh = obj.data
for polygon in mesh.polygons:
is_ok = len(polygon.vertices)
if is_ok != 4:
return False
return True
return False
def execute(self, context): def execute(self, context):
bpy.context.scene.DISC_doodads.append(bpy.context.active_object.name) obj_name = bpy.context.active_object.name
msg = "Object with this name already saved"
if obj_name not in bpy.context.scene.discomb.DISC_doodads:
bpy.context.scene.discomb.DISC_doodads.append(obj_name)
msg = "Saved Doodad object: {}".format(obj_name)
self.report({'INFO'}, message=msg)
def invoke(self, context, event): def invoke(self, context, event):
self.execute(context) self.execute(context)
return {'FINISHED'} return {'FINISHED'}
class unchooseDoodad(bpy.types.Operator):
class unchooseDoodad(Operator):
bl_idname = "object.discombobulate_unset_doodad" bl_idname = "object.discombobulate_unset_doodad"
bl_label = "Discombobulate unset doodad object" bl_label = "Discombobulate unset doodad object"
bl_description = "Remove the saved Doodad Object(s)"
bl_options = {'REGISTER'}
remove_all = bpy.props.BoolProperty(
name="Remove all Doodads",
default=False,
)
def execute(self, context): def execute(self, context):
for name in bpy.context.scene.DISC_doodads: msg = ("No doodads to remove")
if name == bpy.context.active_object.name: doodadery = bpy.context.scene.discomb.DISC_doodads
bpy.context.scene.DISC_doodads.remove(name) if len(doodadery) > 0:
if not self.remove_all:
name = bpy.context.active_object.name
if name in doodadery:
bpy.context.scene.discomb.DISC_doodads.remove(name)
msg = ("Removed Doodad object: {}".format(name))
else:
bpy.context.scene.discomb.DISC_doodads[:] = []
msg = "Removed all Doodads"
else:
msg = "No Doodads to Remove"
self.report({'INFO'}, message=msg)
def invoke(self, context, event): def invoke(self, context, event):
self.execute(context) self.execute(context)
return {'FINISHED'} return {'FINISHED'}
################################## Interpolygon ####################################
class discombobulator(bpy.types.Operator): # ################## Interpolygon ################## #
class discombobulator(Operator):
bl_idname = "object.discombobulate" bl_idname = "object.discombobulate"
bl_label = "Discombobulate" bl_label = "Discombobulate"
bl_description = "Apply"
bl_options = {'REGISTER', 'UNDO'} bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): def execute(self, context):
scn = context.scene scn = context.scene.discomb
i=0 i = 0
while i<scn.repeatprot: while i < bpy.context.scene.discomb.repeatprot:
isLast=False isLast = False
if i==scn.repeatprot-1: if i == scn.repeatprot - 1:
isLast=True isLast = True
discombobulate(scn.minHeight, scn.maxHeight, scn.minTaper, scn.maxTaper, scn.subpolygon1, scn.subpolygon2, scn.subpolygon3, scn.subpolygon4, scn.mindoodads, scn.maxdoodads, scn.repeatprot, scn.sideProtMat, scn.topProtMat, isLast) discombobulate(scn.minHeight, scn.maxHeight, scn.minTaper, scn.maxTaper, scn.subpolygon1,
i+=1 scn.subpolygon2, scn.subpolygon3, scn.subpolygon4, scn.mindoodads, scn.maxdoodads,
scn.repeatprot, scn.sideProtMat, scn.topProtMat, isLast)
i += 1
return {'FINISHED'} return {'FINISHED'}
class discombob_help(bpy.types.Operator):
bl_idname = 'help.discombobulator' class discombobulator_dodads_list(Menu):
bl_label = '' bl_idname = "object.discombobulator_dodad_list"
bl_label = "List of saved Doodads"
bl_description = "List of the saved Doodad Object Names"
bl_options = {'REGISTER'}
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
layout.label('To use:')
layout.label('Works with Quads only not Ngons.')
layout.label('Select a face or faces')
layout.label('Press Discombobulate to create greebles')
doodle = len(bpy.context.scene.discomb.DISC_doodads)
layout.label("Saved doodads : {}".format(doodle))
layout.separator()
if doodle > 0:
for name in bpy.context.scene.discomb.DISC_doodads:
layout.label(text=name)
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event): class discombob_help(Menu):
return context.window_manager.invoke_popup(self, width = 300) bl_idname = "help.discombobulator"
bl_label = "Usage Information"
bl_description = "Help"
bl_options = {'REGISTER'}
class VIEW3D_PT_tools_discombobulate(bpy.types.Operator): def draw(self, context):
bl_idname = 'discombobulate.ops' layout = self.layout
layout.label(text="Usage Information:", icon="INFO")
layout.separator()
layout.label(text="Quads only, not Triangles or Ngons", icon="ERROR")
layout.label("Works only with Mesh object that have faces")
layout.separator()
layout.label("Select a face or faces")
layout.label("Press Discombobulate to create greebles")
layout.label("In object mode, still needs a selection in Edit Mode")
layout.separator()
layout.label("Doodads - additional objects layered on the mesh surface")
layout.label("(Similar to dupliverts - but as one separate object)")
layout.separator()
layout.label(text="Limitations:", icon="MOD_EXPLODE")
layout.label("Be careful with the repeat protusions setting")
layout.label("(Runs reqursively)")
layout.label("If possible, avoid using on a high polycount base mesh")
layout.label("(It can run out of memory and take a long time to compute)")
class VIEW3D_OT_tools_discombobulate(Operator):
bl_idname = "discombobulate.ops"
bl_label = "Discombobulator" bl_label = "Discombobulator"
bl_description = ("Easily add sci-fi details to a surface \n"
"Needs an existing active Mesh with Faces")
bl_options = {'REGISTER'}
executing = False
@classmethod
def poll(cls, context):
return (context.active_object is not None and
context.active_object.type == "MESH")
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
row = layout.row() row = layout.row()
row = layout.split(0.80) row.menu('help.discombobulator', icon='INFO')
row.operator('object.discombobulate', text = 'Discombobulate', icon = 'PLUGIN')
row.operator('help.discombobulator', icon = 'INFO')
box = layout.box() box = layout.box()
box.label("Protusions settings") box.label("Protusions settings")
row = box.row() row = box.row()
row.prop(context.scene, 'doprots') row.prop(context.scene.discomb, 'doprots')
row = box.row() row = box.row()
row.prop(context.scene, 'minHeight') row.prop(context.scene.discomb, 'minHeight')
row = box.row() row = box.row()
row.prop(context.scene, 'maxHeight') row.prop(context.scene.discomb, 'maxHeight')
row = box.row() row = box.row()
row.prop(context.scene, 'minTaper') row.prop(context.scene.discomb, 'minTaper')
row = box.row() row = box.row()
row.prop(context.scene, 'maxTaper') row.prop(context.scene.discomb, 'maxTaper')
row = box.row() row = box.row()
col1 = row.column(align = True) col1 = row.column(align=True)
col1.prop(context.scene, "subpolygon1") col1.prop(context.scene.discomb, "subpolygon1")
col2 = row.column(align = True) col2 = row.column(align=True)
col2.prop(context.scene, "subpolygon2") col2.prop(context.scene.discomb, "subpolygon2")
col3 = row.column(align = True) col3 = row.column(align=True)
col3.prop(context.scene, "subpolygon3") col3.prop(context.scene.discomb, "subpolygon3")
col4 = row.column(align = True) col4 = row.column(align=True)
col4.prop(context.scene, "subpolygon4") col4.prop(context.scene.discomb, "subpolygon4")
row = box.row() row = box.row()
row.prop(context.scene, "repeatprot") row.prop(context.scene.discomb, "repeatprot")
box = layout.box() box = layout.box()
box.label("Doodads settings") box.label("Doodads settings")
row = box.row() row = box.row()
row.prop(context.scene, 'dodoodads') is_doodad = context.scene.discomb.dodoodads
row.prop(context.scene.discomb, 'dodoodads')
row = box.row() row = box.row()
row.prop(context.scene, "mindoodads") row.enabled = is_doodad
row.prop(context.scene.discomb, "mindoodads")
row = box.row() row = box.row()
row.prop(context.scene, "maxdoodads") row.enabled = is_doodad
row.prop(context.scene.discomb, "maxdoodads")
row = box.row() row = box.row()
row.operator("object.discombobulate_set_doodad", text = "Pick doodad") row.enabled = is_doodad
row.operator("object.discombobulate_set_doodad", text="Pick doodad")
row = box.row() row = box.row()
row.operator("object.discombobulate_unset_doodad", text = "Remove doodad") splits = row.split(0.5)
col = box.column(align = True) splits.enabled = is_doodad
for name in bpy.context.scene.DISC_doodads: splits.operator("object.discombobulate_unset_doodad",
col.label(text = name) text="Remove active doodad").remove_all = False
splits.operator("object.discombobulate_unset_doodad",
text="Remove all doodads").remove_all = True
col = box.column(align=True)
doodle = len(bpy.context.scene.discomb.DISC_doodads)
col.enabled = (True if doodle > 0 else False)
col.menu("object.discombobulator_dodad_list",
text="List of saved Doodads ({})".format(doodle))
box = layout.box() box = layout.box()
box.label("Materials settings") box.label("Materials settings")
row = box.row() row = box.row()
row.prop(context.scene, 'topProtMat') row.prop(context.scene.discomb, 'topProtMat')
row = box.row() row = box.row()
row.prop(context.scene, "sideProtMat") row.prop(context.scene.discomb, "sideProtMat")
row = box.row()
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event): def invoke(self, context, event):
return context.window_manager.invoke_popup(self, width = 300) return context.window_manager.invoke_props_dialog(self, width=300)
# registering and menu integration
def register(): def check(self, context):
# Protusions Buttons: return not self.executing
bpy.types.Scene.repeatprot = bpy.props.IntProperty(name="Repeat protusions", description="make several layers of protusion", default = 1, min = 1, max = 10)
bpy.types.Scene.doprots = bpy.props.BoolProperty(name="Make protusions", description = "Check if we want to add protusions to the mesh", default = True) def execute(self, context):
bpy.types.Scene.polygonschangedpercent = bpy.props.FloatProperty(name="Polygon %", description = "Percentage of changed polygons", default = 1.0) self.executing = True
bpy.types.Scene.minHeight = bpy.props.FloatProperty(name="Min height", description="Minimal height of the protusions", default=0.2) bpy.ops.object.discombobulate('INVOKE_DEFAULT')
bpy.types.Scene.maxHeight = bpy.props.FloatProperty(name="Max height", description="Maximal height of the protusions", default = 0.4)
bpy.types.Scene.minTaper = bpy.props.FloatProperty(name="Min taper", description="Minimal height of the protusions", default=0.15, min = 0.0, max = 1.0, subtype = 'PERCENTAGE') return {'FINISHED'}
bpy.types.Scene.maxTaper = bpy.props.FloatProperty(name="Max taper", description="Maximal height of the protusions", default = 0.35, min = 0.0, max = 1.0, subtype = 'PERCENTAGE')
bpy.types.Scene.subpolygon1 = bpy.props.BoolProperty(name="1", default = True)
bpy.types.Scene.subpolygon2 = bpy.props.BoolProperty(name="2", default = True)
bpy.types.Scene.subpolygon3 = bpy.props.BoolProperty(name="3", default = True)
bpy.types.Scene.subpolygon4 = bpy.props.BoolProperty(name="4", default = True)
# Doodads buttons:
bpy.types.Scene.dodoodads = bpy.props.BoolProperty(name="Make doodads", description = "Check if we want to generate doodads", default = True)
bpy.types.Scene.mindoodads = bpy.props.IntProperty(name="Minimum doodads number", description = "Ask for the minimum number of doodads to generate per polygon", default = 1, min = 0, max = 50)
bpy.types.Scene.maxdoodads = bpy.props.IntProperty(name="Maximum doodads number", description = "Ask for the maximum number of doodads to generate per polygon", default = 6, min = 1, max = 50)
bpy.types.Scene.doodMinScale = bpy.props.FloatProperty(name="Scale min", description="Minimum scaling of doodad", default = 0.5, min = 0.0, max = 1.0, subtype = 'PERCENTAGE')
bpy.types.Scene.doodMaxScale = bpy.props.FloatProperty(name="Scale max", description="Maximum scaling of doodad", default = 1.0, min = 0.0, max = 1.0, subtype = 'PERCENTAGE')
# Materials buttons:
bpy.types.Scene.sideProtMat = bpy.props.IntProperty(name="Side's prot mat", description = "Material of protusion's sides", default = 0, min = 0)
bpy.types.Scene.topProtMat = bpy.props.IntProperty(name = "Prot's top mat", description = "Material of protusion's top", default = 0, min = 0)
bpy.utils.register_class(discombobulator)
bpy.utils.register_class(chooseDoodad)
bpy.utils.register_class(unchooseDoodad)
bpy.utils.register_class(VIEW3D_PT_tools_discombobulate)
bpy.utils.register_class(discombob_help)
# unregistering and removing menus
def unregister():
bpy.utils.unregister_class(discombobulator)
bpy.utils.unregister_class(chooseDoodad)
bpy.utils.unregister_class(unchooseDoodad)
bpy.utils.unregister_class(VIEW3D_PT_tools_discombobulate)
bpy.utils.unregister_class(discombob_help)
if __name__ == "__main__":
register()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment