• script


    import bpy
    import random
    
    # Clear all nodes in a mat
    def clear_material( material ):
        if material.node_tree:
            material.node_tree.links.clear()
            material.node_tree.nodes.clear()
            
    
    def newMaterial(id, r , g ,b):
        #mat = bpy.data.materials.get(id)
    
        mat = bpy.data.materials.new(name=id)
    
        mat.diffuse_color = (r, g, b, 1)
        
        print(id)
        print(mat.name)
        print('----------------------')
        return mat
    
    def offsetVertex(vertices):
        vNum = len(vertices)
        random.randint(0, vNum)
        
        for i in range(0, int(vNum/3)):
            vertices[random.randint(0, vNum-1)].co.z += random.uniform(-1.5, 1.5)
        
        
    
    def createUnique(subdivLevel, x, y, z, r, g, b, id):
        bpy.ops.mesh.primitive_plane_add(size=6, enter_editmode=False, align='WORLD', location=(x, y, z), scale=(1, 1, 1))
        
        bpy.ops.object.modifier_add(type='SUBSURF')
        bpy.context.object.modifiers["Subdivision"].render_levels = 2
        bpy.context.object.modifiers["Subdivision"].levels = subdivLevel
        bpy.ops.object.modifier_apply(modifier="Subdivision")
        
        
        obj = bpy.context.object  # Select the active object.
        offsetVertex(obj.data.vertices)
    
    
        mat = newMaterial(id,r,g,b)
        # because there is already a material with name NAME from the op this will have name NAME.00x 
        print(mat.name)
        obj.data.materials.clear()
        obj.data.materials.append(mat)  # Assign the new material.
    
        return
    
    def RandomScene():
        count = 1000
        
        cubeLen = 300
        startNum = 0
        for i in range(startNum, startNum + count):
            createUnique(2, random.randint(-cubeLen, cubeLen) , random.randint(-cubeLen, cubeLen) , random.randint(-cubeLen, cubeLen) ,random.uniform(0.0, 1.0), random.uniform(0.0, 1.0),random.uniform(0.0, 1.0),"mat" + str(i))
    
    
    
    RandomScene()
    
    #bpy.ops.mesh.primitive_plane_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
    
    #bpy.ops.material.new()
    #bpy.data.materials["Material.001"].node_tree.nodes["Diffuse BSDF"].inputs[0].default_value = (0.0804491, 0.8, 0.116792, 1)
    
  • 相关阅读:
    ubuntu16.04 下安装opencv2.4.9
    ubuntu16.04下CMake学习
    Ubuntu 16.04上用CMake图形界面交叉编译树莓派的OpenCV3.0
    BMP图片的C++水印算法
    OpenCV 2 学习笔记(9): 定义ROI(regions of interest):给图像加入水印
    OpenCV入门教程
    免费、高性能的人脸检测库(二进制)
    DBCP与C3P0数据库连接池
    (android高仿系列)今日头条 --新闻阅读器 (三) 完结 、总结 篇
    hadoop之WordCount源代码分析
  • 原文地址:https://www.cnblogs.com/Searchor/p/16196125.html
Copyright © 2020-2023  润新知