[Bf-extensions-cvs] [311b03bd] blender2.8: Rock Generator: Update for 2.8
florianfelix
noreply at git.blender.org
Tue Oct 23 15:53:02 CEST 2018
Commit: 311b03bd2ce4c5b3c3fc5e2b58a4ee1a629ea6a9
Author: florianfelix
Date: Tue Oct 23 15:48:05 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBAC311b03bd2ce4c5b3c3fc5e2b58a4ee1a629ea6a9
Rock Generator: Update for 2.8
- deleted material creation
- has to be redone for eevee/cycles
- lots of style/formatting fixes
- split randomize texture into own file
TODO:
- add materials for eevee/cycles
- remove material settings from presets
- maybe rethink how the presets are handled anyways, not userfriendly
===================================================================
M add_mesh_rocks/__init__.py
A add_mesh_rocks/randomize_texture.py
M add_mesh_rocks/rockgen.py
M add_mesh_rocks/settings.py
M add_mesh_rocks/utils.py
===================================================================
diff --git a/add_mesh_rocks/__init__.py b/add_mesh_rocks/__init__.py
index 57bc9e8b..e00bd87f 100644
--- a/add_mesh_rocks/__init__.py
+++ b/add_mesh_rocks/__init__.py
@@ -36,18 +36,18 @@ bl_info = {
"name": "Rock Generator",
"author": "Paul Marshall (brikbot)",
"version": (1, 4),
- "blender": (2, 68, 0),
+ "blender": (2, 80, 0),
"location": "View3D > Add > Rock Generator",
"description": "Adds a mesh rock to the Add Mesh menu",
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
- "Scripts/Add_Mesh/Rock_Generator",
+ "Scripts/Add_Mesh/Rock_Generator",
"tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
"category": "Add Mesh"}
if "bpy" in locals():
- import imp
- imp.reload(rockgen)
+ from importlib import reload
+ reload(rockgen)
else:
from add_mesh_rocks import rockgen
@@ -55,22 +55,12 @@ import bpy
# Register:
-def menu_func_rocks(self, context):
- self.layout.operator(rockgen.rocks.bl_idname,
- text="Rock Generator",
- icon="PLUGIN")
-
-
def register():
- bpy.utils.register_module(__name__)
-
- bpy.types.VIEW3D_MT_mesh_add.append(menu_func_rocks)
+ rockgen.register()
def unregister():
- bpy.utils.unregister_module(__name__)
-
- bpy.types.VIEW3D_MT_mesh_add.remove(menu_func_rocks)
+ rockgen.unregister()
if __name__ == "__main__":
diff --git a/add_mesh_rocks/randomize_texture.py b/add_mesh_rocks/randomize_texture.py
new file mode 100644
index 00000000..25849d46
--- /dev/null
+++ b/add_mesh_rocks/randomize_texture.py
@@ -0,0 +1,157 @@
+# This try block allows for the script to psudo-intelligently select the
+# appropriate random to use. If Numpy's random is present it will use that.
+# If Numpy's random is not present, it will through a "module not found"
+# exception and instead use the slower built-in random that Python has.
+try:
+ from numpy.random import random_integers as randint
+ from numpy.random import normal as gauss
+ from numpy.random import (
+ beta,
+ uniform,
+ )
+except:
+ from random import (
+ randint,
+ gauss,
+ uniform,
+ )
+ from random import betavariate as beta
+
+from add_mesh_rocks.utils import skewedGauss
+
+
+def randomizeTexture(texture, level=1):
+ '''
+ Set the values for a texture from parameters.
+
+ param: texture - bpy.data.texture to modify.
+ level - designated tweaked settings to use
+ -> Below 10 is a displacment texture
+ -> Between 10 and 20 is a base material texture
+ '''
+ noises = ['BLENDER_ORIGINAL', 'ORIGINAL_PERLIN', 'IMPROVED_PERLIN',
+ 'VORONOI_F1', 'VORONOI_F2', 'VORONOI_F3', 'VORONOI_F4',
+ 'VORONOI_F2_F1', 'VORONOI_CRACKLE']
+ if texture.type == 'CLOUDS':
+ if randint(0, 1) == 0:
+ texture.noise_type = 'SOFT_NOISE'
+ else:
+ texture.noise_type = 'HARD_NOISE'
+ if level != 11:
+ tempInt = randint(0, 6)
+ else:
+ tempInt = randint(0, 8)
+ texture.noise_basis = noises[tempInt]
+ texture.noise_depth = 8
+
+ if level == 0:
+ texture.noise_scale = gauss(0.625, 1 / 24)
+ elif level == 2:
+ texture.noise_scale = 0.15
+ elif level == 11:
+ texture.noise_scale = gauss(0.5, 1 / 24)
+
+ if texture.noise_basis in ['BLENDER_ORIGINAL', 'ORIGINAL_PERLIN',
+ 'IMPROVED_PERLIN', 'VORONOI_F1']:
+ texture.intensity = gauss(1, 1 / 6)
+ texture.contrast = gauss(4, 1 / 3)
+ elif texture.noise_basis in ['VORONOI_F2', 'VORONOI_F3', 'VORONOI_F4']:
+ texture.intensity = gauss(0.25, 1 / 12)
+ texture.contrast = gauss(2, 1 / 6)
+ elif texture.noise_basis == 'VORONOI_F2_F1':
+ texture.intensity = gauss(0.5, 1 / 6)
+ texture.contrast = gauss(2, 1 / 6)
+ elif texture.noise_basis == 'VORONOI_CRACKLE':
+ texture.intensity = gauss(0.5, 1 / 6)
+ texture.contrast = gauss(2, 1 / 6)
+ elif texture.type == 'MUSGRAVE':
+ # musgraveType = ['MULTIFRACTAL', 'RIDGED_MULTIFRACTAL',
+ # 'HYBRID_MULTIFRACTAL', 'FBM', 'HETERO_TERRAIN']
+ texture.musgrave_type = 'MULTIFRACTAL'
+ texture.dimension_max = abs(gauss(0, 0.6)) + 0.2
+ texture.lacunarity = beta(3, 8) * 8.2 + 1.8
+
+ if level == 0:
+ texture.noise_scale = gauss(0.625, 1 / 24)
+ texture.noise_intensity = 0.2
+ texture.octaves = 1.0
+ elif level == 2:
+ texture.intensity = gauss(1, 1 / 6)
+ texture.contrast = 0.2
+ texture.noise_scale = 0.15
+ texture.octaves = 8.0
+ elif level == 10:
+ texture.intensity = gauss(0.25, 1 / 12)
+ texture.contrast = gauss(1.5, 1 / 6)
+ texture.noise_scale = 0.5
+ texture.octaves = 8.0
+ elif level == 12:
+ texture.octaves = uniform(1, 3)
+ elif level > 12:
+ texture.octaves = uniform(2, 8)
+ else:
+ texture.intensity = gauss(1, 1 / 6)
+ texture.contrast = 0.2
+ texture.octaves = 8.0
+ elif texture.type == 'DISTORTED_NOISE':
+ tempInt = randint(0, 8)
+ texture.noise_distortion = noises[tempInt]
+ tempInt = randint(0, 8)
+ texture.noise_basis = noises[tempInt]
+ texture.distortion = skewedGauss(2.0, 2.6666, (0.0, 10.0), False)
+
+ if level == 0:
+ texture.noise_scale = gauss(0.625, 1 / 24)
+ elif level == 2:
+ texture.noise_scale = 0.15
+ elif level >= 12:
+ texture.noise_scale = gauss(0.2, 1 / 48)
+ elif texture.type == 'STUCCI':
+ stucciTypes = ['PLASTIC', 'WALL_IN', 'WALL_OUT']
+ if randint(0, 1) == 0:
+ texture.noise_type = 'SOFT_NOISE'
+ else:
+ texture.noise_type = 'HARD_NOISE'
+ tempInt = randint(0, 2)
+ texture.stucci_type = stucciTypes[tempInt]
+
+ if level == 0:
+ tempInt = randint(0, 6)
+ texture.noise_basis = noises[tempInt]
+ texture.noise_scale = gauss(0.625, 1 / 24)
+ elif level == 2:
+ tempInt = randint(0, 6)
+ texture.noise_basis = noises[tempInt]
+ texture.noise_scale = 0.15
+ elif level >= 12:
+ tempInt = randint(0, 6)
+ texture.noise_basis = noises[tempInt]
+ texture.noise_scale = gauss(0.2, 1 / 30)
+ else:
+ tempInt = randint(0, 6)
+ texture.noise_basis = noises[tempInt]
+ elif texture.type == 'VORONOI':
+ metrics = ['DISTANCE', 'DISTANCE_SQUARED', 'MANHATTAN', 'CHEBYCHEV',
+ 'MINKOVSKY_HALF', 'MINKOVSKY_FOUR', 'MINKOVSKY']
+ # Settings for first dispalcement level:
+ if level == 0:
+ tempInt = randint(0, 1)
+ texture.distance_metric = metrics[tempInt]
+ texture.noise_scale = gauss(0.625, 1 / 24)
+ texture.contrast = 0.5
+ texture.intensity = 0.7
+ elif level == 2:
+ texture.noise_scale = 0.15
+ tempInt = randint(0, 6)
+ texture.distance_metric = metrics[tempInt]
+ elif level >= 12:
+ tempInt = randint(0, 1)
+ texture.distance_metric = metrics[tempInt]
+ texture.noise_scale = gauss(0.125, 1 / 48)
+ texture.contrast = 0.5
+ texture.intensity = 0.7
+ else:
+ tempInt = randint(0, 6)
+ texture.distance_metric = metrics[tempInt]
+
+ return
diff --git a/add_mesh_rocks/rockgen.py b/add_mesh_rocks/rockgen.py
index eb66c77a..6aa39e24 100644
--- a/add_mesh_rocks/rockgen.py
+++ b/add_mesh_rocks/rockgen.py
@@ -111,18 +111,24 @@
# <pep8 compliant>
import bpy
-import math
import time
-from add_mesh_rocks import (settings,
- utils)
+from add_mesh_rocks import (
+ settings,
+ utils
+)
+from add_mesh_rocks.utils import skewedGauss
+from add_mesh_rocks.randomize_texture import randomizeTexture
from bpy_extras import object_utils
-from mathutils import (Color,
- Vector)
-from bpy.props import (BoolProperty,
- IntProperty,
- FloatProperty,
- FloatVectorProperty,
- EnumProperty)
+from mathutils import (
+ Vector
+)
+from bpy.props import (
+ BoolProperty,
+ IntProperty,
+ FloatProperty,
+ FloatVectorProperty,
+ EnumProperty
+)
# This try block allows for the script to psudo-intelligently select the
# appropriate random to use. If Numpy's random is present it will use that.
@@ -131,24 +137,22 @@ from bpy.props import (BoolProperty,
try:
from numpy.random import random_integers as randint
from numpy.random import normal as gauss
- from numpy.random import (beta,
- uniform,
- seed,
- weibull)
+ from numpy.random import (
+ seed,
+ weibull)
print("Rock Generator: Numpy found.")
numpy = True
except:
- from random import (randint,
- gauss,
- uniform,
- seed)
- from random import betavariate as beta
+ from random import (
+ randint,
+ gauss,
+ seed)
from random import weibullvariate as weibull
print("Rock Generator: Numpy not found. Using Python's random.")
numpy = False
# Global variables:
-lastRock = 0
+LASTROCK = 0
# Creates a new mesh:
@@ -173,329 +177,6 @@ def createMeshObject(context, verts, edges, faces, name):
return object_utils.object_data_add(context, mesh, operator=None)
-# Set the values for a texture from parameters.
-#
-# param: texture - bpy.data.texture to modify.
-# level - designated tweaked settings to use
-# -> Below 10 is a displacment texture
-#
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list