Last active
December 29, 2019 16:54
-
-
Save SiggyF/1d58995b47e368d204b8c5ef4a1b7272 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
scene = bpy.context.scene | |
for key, val in bpy.data.collections.items(): | |
if key == 'Collection': | |
continue | |
# remove all others | |
bpy.data.collections.remove(val) | |
for key, val in bpy.data.objects.items(): | |
if key in {'Camera', 'Light'}: | |
continue | |
bpy.data.objects.remove(val) | |
for key, val in bpy.data.meshes.items(): | |
bpy.data.meshes.remove(val) | |
for key, val in bpy.data.materials.items(): | |
bpy.data.materials.remove(val) | |
for key, val in bpy.data.images.items(): | |
bpy.data.images.remove(val) | |
tiles = bpy.data.collections.new("tiles") | |
scene.collection.children.link(tiles) | |
# Link active object to the new collection | |
plane = [ | |
[-0.5, -0.5, 0], | |
[0.5, -0.5, 0], | |
[0.5, 0.5, 0], | |
[-0.5, 0.5, 0] | |
] | |
edges = [] | |
faces = [[0,1,2,3]] | |
N = 6 | |
for i in range(N): | |
for j in range(N): | |
# bpy.ops.mesh.primitive_plane_add(size=1, enter_editmode=False, location=(i, j, 0)) | |
id = 'tile-{}-{}'.format(i, j) | |
g_d = bpy.data.meshes.new(name="{}-mesh".format(id)) | |
g_d.from_pydata(plane, edges, faces) | |
g_o = bpy.data.objects.new(name="{}-object".format(id), object_data = g_d) | |
tiles.objects.link(g_o) | |
g_o.location = (-j, i, 0) | |
# material name | |
mat = bpy.data.materials.new('{}-mat'.format(id)) | |
mat.use_nodes = True | |
bsdf_node = mat.node_tree.nodes['Principled BSDF'] | |
image_node = mat.node_tree.nodes.new('ShaderNodeTexImage') | |
rgbtobw_node = mat.node_tree.nodes.new('ShaderNodeRGBToBW') | |
colorramp_node = mat.node_tree.nodes.new("ShaderNodeValToRGB") | |
colorramp_node.color_ramp.elements[1].position = 0.1 | |
col = 50 + j | |
row = 204 + i | |
path = '//../../../data/video/s1-ice/s1-ice-video/8/{col}/{row}.webm'.format(**dict(row=row, col=col)) | |
image = bpy.data.images.load(path) | |
image_node.image = image | |
image_node.image_user.use_cyclic = True | |
image_node.image_user.use_auto_refresh = True | |
mat.node_tree.links.new(image_node.outputs['Color'], bsdf_node.inputs['Base Color']) | |
mat.node_tree.links.new(image_node.outputs['Color'], rgbtobw_node.inputs['Color']) | |
mat.node_tree.links.new(rgbtobw_node.outputs['Val'], colorramp_node.inputs['Fac']) | |
mat.node_tree.links.new(colorramp_node.outputs['Color'], bsdf_node.inputs['Roughness']) | |
# connect to | |
g_o.active_material = mat | |
for key, val in bpy.data.objects.items(): | |
if 'tile' not in key: | |
continue | |
bpy.context.view_layer.objects.active = val | |
val.select_set(True) | |
# uv unwrap all objects | |
bpy.ops.object.editmode_toggle() | |
bpy.ops.mesh.select_all(action='SELECT') | |
bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.001) | |
bpy.ops.object.editmode_toggle() | |
val.select_set(False) | |
# Set cloud to procedural | |
tree = bpy.context.scene.world.node_tree | |
tree.nodes["Cloud_density"].inputs[0].default_value = 0.9 | |
print(tree.nodes["Cloud_density"].inputs[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment