[Bf-extensions-cvs] [242c9080] master: object_cloud_gen: moved to contrib: T63750
meta-androcto
noreply at git.blender.org
Fri May 24 08:15:54 CEST 2019
Commit: 242c90808f00fe85fd8e6bf1d4454c4c8f40aebc
Author: meta-androcto
Date: Fri May 24 16:15:24 2019 +1000
Branches: master
https://developer.blender.org/rBAC242c90808f00fe85fd8e6bf1d4454c4c8f40aebc
object_cloud_gen: moved to contrib: T63750
===================================================================
A object_cloud_gen.py
===================================================================
diff --git a/object_cloud_gen.py b/object_cloud_gen.py
new file mode 100644
index 00000000..5ddce14c
--- /dev/null
+++ b/object_cloud_gen.py
@@ -0,0 +1,991 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# 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 #####
+
+# <pep8 compliant>
+
+bl_info = {
+ "name": "Cloud Generator",
+ "author": "Nick Keeline(nrk)",
+ "version": (1, 0, 2),
+ "blender": (2, 79, 0),
+ "location": "Tool Shelf > Create Tab",
+ "description": "Creates Volumetric Clouds",
+ "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
+ "Scripts/Object/Cloud_Gen",
+ "category": "Object",
+}
+
+import bpy
+from bpy.props import (
+ BoolProperty,
+ EnumProperty,
+ )
+from bpy.types import (
+ Operator,
+ Panel,
+ )
+
+
+# For Cycles Render we create node groups or if it already exists we return it.
+def CreateNodeGroup(Type):
+
+ # Look for NodeTree if it already exists return it
+ CreateGroup = True
+ for Group in bpy.data.node_groups:
+ if Group.name == Type:
+ CreateGroup = False
+ NodeGroup = Group
+
+ if CreateGroup is True:
+ NodeGroup = bpy.data.node_groups.new(name=Type, type="ShaderNodeTree")
+ NodeGroup.name = Type
+ NodeGroup.bl_label = Type
+ NodeGroup.nodes.clear()
+
+ # Create a bunch of nodes and group them based on input to the def
+ # Function type
+ if Type == 'CloudGen_VolumeProperties':
+ AddAddAndEmission = NodeGroup.nodes.new('ShaderNodeAddShader')
+ AddAddAndEmission.location = [300, 395]
+ AddAbsorptionAndScatter = NodeGroup.nodes.new('ShaderNodeAddShader')
+ AddAbsorptionAndScatter.location = [0, 395]
+ VolumeAbsorption = NodeGroup.nodes.new('ShaderNodeVolumeAbsorption')
+ VolumeAbsorption.location = [-300, 395]
+ VolumeScatter = NodeGroup.nodes.new('ShaderNodeVolumeScatter')
+ VolumeScatter.location = [-300, 0]
+ VolumeEmission = NodeGroup.nodes.new('ShaderNodeEmission')
+ VolumeEmission.location = [-300, -300]
+ MathAbsorptionMultiply = NodeGroup.nodes.new('ShaderNodeMath')
+ MathAbsorptionMultiply.location = [-750, 395]
+ MathAbsorptionMultiply.operation = 'MULTIPLY'
+ MathScatterMultiply = NodeGroup.nodes.new('ShaderNodeMath')
+ MathScatterMultiply.location = [-750, 0]
+ MathScatterMultiply.operation = 'MULTIPLY'
+ MathEmissionMultiply = NodeGroup.nodes.new('ShaderNodeMath')
+ MathEmissionMultiply.location = [-750, -300]
+ MathEmissionMultiply.operation = 'MULTIPLY'
+ MathBrightnessMultiply = NodeGroup.nodes.new('ShaderNodeMath')
+ MathBrightnessMultiply.location = [-1200, 0]
+ MathBrightnessMultiply.operation = 'MULTIPLY'
+ MathGreaterThan = NodeGroup.nodes.new('ShaderNodeMath')
+ MathGreaterThan.location = [-1200, 600]
+ MathGreaterThan.operation = 'GREATER_THAN'
+ MathGreaterThan.inputs[1].default_value = 0
+
+ NodeGroup.links.new(AddAddAndEmission.inputs[0], AddAbsorptionAndScatter.outputs[0])
+ NodeGroup.links.new(AddAddAndEmission.inputs[1], VolumeEmission.outputs[0])
+ NodeGroup.links.new(AddAbsorptionAndScatter.inputs[0], VolumeAbsorption.outputs[0])
+ NodeGroup.links.new(AddAbsorptionAndScatter.inputs[1], VolumeScatter.outputs[0])
+ NodeGroup.links.new(VolumeAbsorption.inputs[1], MathAbsorptionMultiply.outputs[0])
+ NodeGroup.links.new(VolumeScatter.inputs[1], MathScatterMultiply.outputs[0])
+ NodeGroup.links.new(VolumeEmission.inputs[1], MathEmissionMultiply.outputs[0])
+ NodeGroup.links.new(MathAbsorptionMultiply.inputs[0], MathGreaterThan.outputs[0])
+ NodeGroup.links.new(MathScatterMultiply.inputs[0], MathGreaterThan.outputs[0])
+ NodeGroup.links.new(MathEmissionMultiply.inputs[0], MathGreaterThan.outputs[0])
+ NodeGroup.links.new(VolumeAbsorption.inputs[0], MathBrightnessMultiply.outputs[0])
+
+ # Create and Link In/Out to Group Node
+ # Outputs
+ group_outputs = NodeGroup.nodes.new('NodeGroupOutput')
+ group_outputs.location = (600, 395)
+ NodeGroup.outputs.new('NodeSocketShader', 'shader_out')
+ NodeGroup.links.new(AddAddAndEmission.outputs[0], group_outputs.inputs['shader_out'])
+
+ # Inputs
+ group_inputs = NodeGroup.nodes.new('NodeGroupInput')
+ group_inputs.location = (-1500, -300)
+ NodeGroup.inputs.new('NodeSocketFloat', 'Density')
+ NodeGroup.inputs.new('NodeSocketFloat', 'Absorption Multiply')
+ NodeGroup.inputs.new('NodeSocketColor', 'Absorption Color')
+ NodeGroup.inputs.new('NodeSocketFloat', 'Scatter Multiply')
+ NodeGroup.inputs.new('NodeSocketColor', 'Scatter Color')
+ NodeGroup.inputs.new('NodeSocketFloat', 'Emission Amount')
+ NodeGroup.inputs.new('NodeSocketFloat', 'Cloud Brightness')
+
+ NodeGroup.links.new(group_inputs.outputs['Density'], MathGreaterThan.inputs[0])
+ NodeGroup.links.new(group_inputs.outputs['Absorption Multiply'], MathAbsorptionMultiply.inputs[1])
+ NodeGroup.links.new(group_inputs.outputs['Absorption Color'], MathBrightnessMultiply.inputs[0])
+ NodeGroup.links.new(group_inputs.outputs['Scatter Multiply'], MathScatterMultiply.inputs[1])
+ NodeGroup.links.new(group_inputs.outputs['Scatter Color'], VolumeScatter.inputs[0])
+ NodeGroup.links.new(group_inputs.outputs['Emission Amount'], MathEmissionMultiply.inputs[1])
+ NodeGroup.links.new(group_inputs.outputs['Cloud Brightness'], MathBrightnessMultiply.inputs[1])
+
+ if Type == 'CloudGen_TextureProperties':
+ MathAdd = NodeGroup.nodes.new('ShaderNodeMath')
+ MathAdd.location = [-200, 0]
+ MathAdd.operation = 'ADD'
+ MathDensityMultiply = NodeGroup.nodes.new('ShaderNodeMath')
+ MathDensityMultiply.location = [-390, 0]
+ MathDensityMultiply.operation = 'MULTIPLY'
+ PointDensityRamp = NodeGroup.nodes.new('ShaderNodeValToRGB')
+ PointDensityRamp.location = [-675, -250]
+ PointRamp = PointDensityRamp.color_ramp
+ PElements = PointRamp.elements
+ PElements[0].position = 0.418
+ PElements[0].color = 0, 0, 0, 1
+ PElements[1].position = 0.773
+ PElements[1].color = 1, 1, 1, 1
+ CloudRamp = NodeGroup.nodes.new('ShaderNodeValToRGB')
+ CloudRamp.location = [-675, 0]
+ CRamp = CloudRamp.color_ramp
+ CElements = CRamp.elements
+ CElements[0].position = 0.527
+ CElements[0].color = 0, 0, 0, 1
+ CElements[1].position = 0.759
+ CElements[1].color = 1, 1, 1, 1
+ NoiseTex = NodeGroup.nodes.new('ShaderNodeTexNoise')
+ NoiseTex.location = [-940, 0]
+ NoiseTex.inputs['Detail'].default_value = 4
+ TexCoord = NodeGroup.nodes.new('ShaderNodeTexCoord')
+ TexCoord.location = [-1250, 0]
+
+ NodeGroup.links.new(MathAdd.inputs[0], MathDensityMultiply.outputs[0])
+ NodeGroup.links.new(MathAdd.inputs[1], PointDensityRamp.outputs[0])
+ NodeGroup.links.new(MathDensityMultiply.inputs[0], CloudRamp.outputs[0])
+ NodeGroup.links.new(CloudRamp.inputs[0], NoiseTex.outputs[0])
+ NodeGroup.links.new(NoiseTex.inputs[0], TexCoord.outputs[3])
+
+ # Create and Link In/Out to Group Nodes
+ # Outputs
+ group_outputs = NodeGroup.nodes.new('NodeGroupOutput')
+ group_outputs.location = (0, 0)
+ NodeGroup.outputs.new('NodeSocketFloat', 'Density W_CloudTex')
+ NodeGroup.links.new(MathAdd.outputs[0], group_outputs.inputs['Density W_CloudTex'])
+
+ # Inputs
+ group_inputs = NodeGroup.nodes.new('NodeGroupInput')
+ group_inputs.location = (-1250, -300)
+ NodeGroup.inputs.new('NodeSocketFloat', 'Scale')
+ NodeGroup.inputs.new('NodeSocketFloat', 'Point Density In')
+ NodeGroup.links.new(group_inputs.outputs['Scale'], NoiseTex.inputs['Scale'])
+ NodeGroup.links.new(group_inputs.outputs['Point Density In'], MathDensityMultiply.inputs[1])
+ NodeGroup.links.new(group_inputs.outputs['Point Density In'], PointDensityRamp.inputs[0])
+
+ return NodeGroup
+
+
+# This routine takes an object and deletes all of the geometry in it
+# and adds a bounding box to it.
+# It will add or subtract the bound box size by the variable sizeDifference.
+
+def getMeshandPutinEditMode(view_layer, object):
+
+ # Go into Object Mode
+ bpy.ops.object.mode_set(mode='OBJECT')
+
+ # Deselect All
+ bpy.ops.object.select_all(action='DESELECT')
+
+ # Select the object
+ object.select_set(True)
+ view_layer.objects.active = object
+
+ # Go into Edit Mode
+ bpy.ops.object.mode_set(mode='EDIT')
+
+ return object.data
+
+
+def maxAndMinVerts(view_layer, object):
+
+ mesh = getMeshandPutinEditMode(view_layer, object)
+ verts = mesh.vertices
+
+ # Set the max and min verts to the first vertex on the list
+ maxVert = [verts[0].co[0], v
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list