コード例 #1
0
def render2spline(point_xyz, save_dir, obj_num, point_num):
    delete_all()

    #Worldに関する設定
    world = bpy.data.worlds['World']  # 編集する World の取得
    world.horizon_color = (1.0, 1.0, 1.0)
    world.zenith_color = (1.0, 1.0, 1.0)
    world.ambient_color = (0.01, 0.01, 0.01)
    #world.light_settings.use_ambient_occlusion = True # 環境光を使う
    world.light_settings.ao_factor = 1.0  # 環境光の明るさ
    world.light_settings.use_environment_light = True
    world.use_sky_blend = True
    world.light_settings.use_ambient_occlusion = True

    #球オブジェクト作成
    bpy.ops.mesh.primitive_uv_sphere_add()
    uv_sphere_ob = bpy.context.object
    uv_sphere_mat = bpy.data.materials.new('uv_spere_mat')
    obj = bpy.context.scene.objects.active
    # print(obj)
    obj.data.materials.append(uv_sphere_mat)
    # print(type(uv_sphere_ob))
    # print(uv_sphere_ob)
    # print(bpy.data.materials)
    uv_sphere_ob.location = (point_xyz[0], point_xyz[1], point_xyz[2])

    #color変更
    for item in bpy.data.materials:
        item.diffuse_color.hsv = (0.0, 0.0, 0.0)

    #質感変更
    for item in bpy.data.materials:
        item.diffuse_shader = ('FRESNEL')
        item.diffuse_fresnel = 1.0
        item.emit = 1.0
        item.specular_intensity = 0.0
        item.ambient = 0.0
        item.translucency = 0.0
        item.use_raytrace = False
        item.use_mist = False
        # シェーディングを切る
        item.use_shadeless = True

    # アンチエイリアシングを切る
    bpy.data.scenes["Scene"].render.use_antialiasing = False

    #カメラ撮影
    camera.setCirclePathCamera(4, save_dir, obj_num, point_num)
コード例 #2
0
def render2instance(leaf_dname, stem_dname, save_dir):
    delete_all()

    #Worldに関する設定
    world = bpy.data.worlds['World']  # 編集する World の取得
    world.horizon_color = (1.0, 1.0, 1.0)
    world.zenith_color = (1.0, 1.0, 1.0)
    world.ambient_color = (0.01, 0.01, 0.01)
    #world.light_settings.use_ambient_occlusion = True # 環境光を使う
    world.light_settings.ao_factor = 1.0  # 環境光の明るさ
    world.light_settings.use_environment_light = True
    world.use_sky_blend = True
    world.light_settings.use_ambient_occlusion = True

    #照明を太陽光にする
    # lamp=bpy.data.objects['Lamp']
    # lamp.data.type='SUN'
    # lamp.location=(0,40,50)
    """
    #objファイルのimport
    # bpy.ops.import_scene.obj(filepath='./plant_obj/original/all/adel900nsect1.obj')
    bpy.ops.import_scene.obj(filepath=obj_fname)
    sel = bpy.context.selected_objects

    #色のテクスチャ環境作成
    for obj1 in sel:
        obj1.data.materials.clear()
        mat2 = bpy.data.materials.new('COLOR')
        obj1.data.materials.append(mat2)

    #color変更
    j=0
    for item in bpy.data.materials:
        item.diffuse_color.hsv=(j*0.1,1.0,0.4)
        j+=0.15
    #exit()

    #csv書き込み
    with open('color.csv','w',newline='') as f:
        writer=csv.writer(f)
        #print('materials num  ', bpy.data.materials)

        for item in bpy.data.materials:
            print(item.diffuse_color.r)
            writer.writerow([item.diffuse_color.r, item.diffuse_color.g, item.diffuse_color.b])
        f.close()
    """
    def import_obj_and_write_color(dname, saturation, sel, type='leaf'):
        sat = saturation
        fn = len(os.listdir(dname))

        pattern = '(.*)age(.*)'
        d = re.search(pattern, dname)
        age = d.group(2)

        with open(save_dir + '/color_age{}.csv'.format(age), 'a+',
                  newline='') as f:
            writer = csv.writer(f)
            writer.writerow(['age', age])
            writer.writerow(['type', type])

        for i in range(fn):
            obj_fname = dname + '/' + '{}.obj'.format(i)
            #objファイルのimport
            bpy.ops.import_scene.obj(filepath=obj_fname)
            sel.append(bpy.context.selected_objects[0])

            #色のテクスチャ環境作成
            obj_temp = bpy.context.selected_objects[0]
            obj_temp.data.materials.clear()
            mat_temp = bpy.data.materials.new('COLOR')
            obj_temp.data.materials.append(mat_temp)

            #color変更
            mat_temp.diffuse_color.hsv = (sat * 0.1, 1.0, 0.4)
            sat += 0.15

            #csv書き込み
            with open(save_dir + '/color_age{}.csv'.format(age),
                      'a+',
                      newline='') as f:
                writer = csv.writer(f)
                writer.writerow([
                    i, mat_temp.diffuse_color.r, mat_temp.diffuse_color.g,
                    mat_temp.diffuse_color.b
                ])

        return sat

    saturation = 0
    sel = []
    print(leaf_dname)
    print(stem_dname)
    saturation = import_obj_and_write_color(leaf_dname,
                                            saturation,
                                            sel,
                                            type='leaf')
    print(sel)
    print(bpy.data.materials)
    saturation = import_obj_and_write_color(stem_dname,
                                            saturation,
                                            sel,
                                            type='stem')
    print(sel)
    print(bpy.data.materials)

    #厚み付け・細分割曲面
    for obj in sel:
        bpy.context.scene.objects.active = obj  #sets the obj accessible to bpy.ops
        bpy.ops.object.modifier_add(type='SOLIDIFY')
        bpy.context.object.modifiers["Solidify"].thickness = 0.05
        bpy.ops.object.modifier_add(type='SUBSURF')
        bpy.context.object.modifiers["Subsurf"].levels = 3
        #obj.data.materials.clear()

        # bpy.context.scene.objects.active = obj
        # bpy.ops.mesh.uv_texture_add()
        # bpy.ops.object.editmode_toggle()
        # bpy.ops.uv.smart_project(angle_limit=66, island_margin=0)

    #厚み付け
    for obj in sel:
        bpy.context.scene.objects.active = obj  #sets the obj accessible to bpy.ops
        bpy.ops.object.modifier_add(type='SOLIDIFY')
        bpy.context.object.modifiers["Solidify"].thickness = 0.05
        #bpy.ops.object.modifier_add(type='SUBSURF')
        #bpy.context.object.modifiers["Subsurf"].levels=0
        #obj.data.materials.clear()

        # bpy.context.scene.objects.active = obj
        # bpy.ops.mesh.uv_texture_add()
        # bpy.ops.object.editmode_toggle()
        # bpy.ops.uv.smart_project(angle_limit=66, island_margin=0)

    #オブジェクトの回転
    for obj in sel:
        bpy.context.scene.objects.active = obj
        obj.rotation_euler = (0, 0, 0)
        # bpy.ops.transform.rotate(value=-3.14/2,axis=(-1,0,0))
        # bpy.ops.transform.rotate(value=-3.14/2,axis=(0,-1,0))
        # bpy.ops.transform.rotate(value=-3.14/2,axis=(0,0,-1))
        # bpy.ops.transform.rotate(value=3.14/2,axis=(-1,0,0))
        # bpy.ops.transform.rotate(value=3.14/2,axis=(0,-1,0))
        # bpy.ops.transform.rotate(value=3.14/2,axis=(0,0,-1))
        #bpy.ops.transform.translate(180)

    #質感変更
    for item in bpy.data.materials:
        item.diffuse_shader = ('FRESNEL')
        item.diffuse_fresnel = 1.0
        item.emit = 1.0
        item.specular_intensity = 0.0
        item.ambient = 0.0
        item.translucency = 0.0
        item.use_raytrace = False
        item.use_mist = False
        # シェーディングを切る
        item.use_shadeless = True

    # lamp=bpy.data.objects['Lamp']

    #lamp.data.type='SUN'
    #lamp.location=(0,30,40)

    # アンチエイリアシングを切る
    bpy.data.scenes["Scene"].render.use_antialiasing = False

    #カメラ撮影
    camera.setCirclePathCamera(3, save_dir)
コード例 #3
0
def render2color(obj_fname, save_dir):
    delete_all()

    #Worldに関する設定
    world = bpy.data.worlds['World']  # 編集する World の取得
    world.horizon_color = (1.0, 1.0, 1.0)
    world.zenith_color = (1.0, 1.0, 1.0)
    world.ambient_color = (0.01, 0.01, 0.01)
    #world.light_settings.use_ambient_occlusion = True # 環境光を使う
    world.light_settings.ao_factor = 1.0  # 環境光の明るさ
    world.light_settings.use_environment_light = True
    world.use_sky_blend = True
    world.light_settings.use_ambient_occlusion = True

    #照明を太陽光にする
    # lamp=bpy.data.objects['Lamp']
    # lamp.data.type='SUN'
    # lamp.location=(0,40,50)

    #objファイルのimport
    # bpy.ops.import_scene.obj(filepath='./plant_obj/original/all/adel400nsect1.obj')
    bpy.ops.import_scene.obj(filepath=obj_fname)
    sel = bpy.context.selected_objects
    leaf = sel[:]

    #選択オブジェクトを代入
    sel = bpy.context.selected_objects

    #active?
    act = bpy.context.active_object

    #厚み付け,細分割曲面
    for obj in sel:
        bpy.context.scene.objects.active = obj  #sets the obj accessible to bpy.ops
        bpy.ops.object.modifier_add(type='SOLIDIFY')
        bpy.context.object.modifiers["Solidify"].thickness = 0.05
        bpy.ops.object.modifier_add(type='SUBSURF')
        bpy.context.object.modifiers["Subsurf"].levels = 3
        obj.data.materials.clear()

        bpy.context.scene.objects.active = obj
        bpy.ops.mesh.uv_texture_add()
        bpy.ops.object.editmode_toggle()
        bpy.ops.uv.smart_project(angle_limit=66, island_margin=0)

    #厚み付け
    for obj in sel:
        bpy.context.scene.objects.active = obj  #sets the obj accessible to bpy.ops
        bpy.ops.object.modifier_add(type='SOLIDIFY')
        bpy.context.object.modifiers["Solidify"].thickness = 0.05
        #bpy.ops.object.modifier_add(type='SUBSURF')
        #bpy.context.object.modifiers["Subsurf"].levels=0
        obj.data.materials.clear()

        bpy.context.scene.objects.active = obj
        bpy.ops.mesh.uv_texture_add()
        bpy.ops.object.editmode_toggle()
        bpy.ops.uv.smart_project(angle_limit=66, island_margin=0)

    sel = bpy.context.selected_objects
    leaf2 = sel[:]
    #leaf.extend(leaf2)

    # オブジェクトの回転
    for obj in sel:
        bpy.context.scene.objects.active = obj
        # bpy.ops.transform.rotate(value=-3.14/2,axis=(0,-1,0))
        obj.rotation_euler = (0, 0, 0)

    #オブジェクトの選択
    for i in sel:
        i.select = False
        # i.select=True

    for i in leaf:
        i.select = True
        # i.select=False

    sel = bpy.context.selected_objects

    for obj in sel:
        mat1 = bpy.data.materials.new('GREEN')
        tex1 = bpy.data.textures.new('Texture', type='IMAGE')
        bpy.ops.texture.new('INVOKE_DEFAULT')
        # bpy.ops.image.open(filepath='C:/Users/matsuoka/Desktop/sub.jpg')
        # tex1.image = bpy.data.images.load('C:/Users/matsuoka/Desktop/ko.png')
        tex1.image = bpy.data.images.load(os.getcwd() + '/ko.PNG')
        mat1.texture_slots.add()
        mat1.texture_slots[0].texture = tex1
        bpy.context.scene.objects.active = obj
        obj.data.materials.append(mat1)

    for i in sel:
        i.select = False

    for i in leaf2:
        i.select = True

    sel = bpy.context.selected_objects

    #テクスチャ付け
    for obj1 in sel:
        mat2 = bpy.data.materials.new('BLUE')
        tex2 = bpy.data.textures.new('Texture', type='IMAGE')
        bpy.ops.texture.new('INVOKE_DEFAULT')
        # bpy.ops.image.open(filepath='C:/Users/matsuoka/Desktop/sub.jpg')
        # tex2.image = bpy.data.images.load('C:/Users/matsuoka/Desktop/ko.png')
        tex2.image = bpy.data.images.load(os.getcwd() + '/ko.PNG')
        mat2.texture_slots.add()
        mat2.texture_slots[0].texture = tex2
        bpy.context.scene.objects.active = obj1
        obj1.data.materials.append(mat2)

    #カメラ撮影
    camera.setCirclePathCamera(1, save_dir)
コード例 #4
0
def render2instance(obj_fname, save_dir):
    delete_all()

    #Worldに関する設定
    world = bpy.data.worlds['World']  # 編集する World の取得
    world.horizon_color = (1.0, 1.0, 1.0)
    world.zenith_color = (1.0, 1.0, 1.0)
    world.ambient_color = (0.01, 0.01, 0.01)
    #world.light_settings.use_ambient_occlusion = True # 環境光を使う
    world.light_settings.ao_factor = 1.0  # 環境光の明るさ
    world.light_settings.use_environment_light = True
    world.use_sky_blend = True
    world.light_settings.use_ambient_occlusion = True

    #照明を太陽光にする
    # lamp=bpy.data.objects['Lamp']
    # lamp.data.type='SUN'
    # lamp.location=(0,40,50)

    #objファイルのimport
    # bpy.ops.import_scene.obj(filepath='./plant_obj/original/all/adel900nsect1.obj')
    bpy.ops.import_scene.obj(filepath=obj_fname)
    sel = bpy.context.selected_objects

    #色のテクスチャ環境作成
    for obj1 in sel:
        obj1.data.materials.clear()
        mat2 = bpy.data.materials.new('COLOR')
        obj1.data.materials.append(mat2)

    #color変更
    j = 0
    for item in bpy.data.materials:
        item.diffuse_color.hsv = (j * 0.1, 1.0, 0.4)
        j += 0.15
    #exit()

    #csv書き込み
    with open('color.csv', 'w', newline='') as f:
        writer = csv.writer(f)
        #print('materials num  ', bpy.data.materials)

        for item in bpy.data.materials:
            print(item.diffuse_color.r)
            writer.writerow([
                item.diffuse_color.r, item.diffuse_color.g,
                item.diffuse_color.b
            ])
        f.close()

    #bpy.ops.import_scene.obj(filepath='E:/share/compare/0/adel900nsect1.obj')
    sel = bpy.context.selected_objects
    leaf = sel[:]

    #全要素を代入
    sel = bpy.context.selected_objects

    #active?
    act = bpy.context.active_object

    #厚み付け・細分割曲面
    for obj in sel:
        bpy.context.scene.objects.active = obj  #sets the obj accessible to bpy.ops
        bpy.ops.object.modifier_add(type='SOLIDIFY')
        bpy.context.object.modifiers["Solidify"].thickness = 0.05
        bpy.ops.object.modifier_add(type='SUBSURF')
        bpy.context.object.modifiers["Subsurf"].levels = 3
        #obj.data.materials.clear()

        # bpy.context.scene.objects.active = obj
        # bpy.ops.mesh.uv_texture_add()
        # bpy.ops.object.editmode_toggle()
        # bpy.ops.uv.smart_project(angle_limit=66, island_margin=0)

    # bpy.ops.import_scene.obj(filepath='./plant_obj/original/all/adel900nsect1.obj')
    # sel = bpy.context.selected_objects
    # act = bpy.context.active_object

    #厚み付け
    for obj in sel:
        bpy.context.scene.objects.active = obj  #sets the obj accessible to bpy.ops
        bpy.ops.object.modifier_add(type='SOLIDIFY')
        bpy.context.object.modifiers["Solidify"].thickness = 0.05
        #bpy.ops.object.modifier_add(type='SUBSURF')
        #bpy.context.object.modifiers["Subsurf"].levels=0
        #obj.data.materials.clear()

        # bpy.context.scene.objects.active = obj
        # bpy.ops.mesh.uv_texture_add()
        # bpy.ops.object.editmode_toggle()
        # bpy.ops.uv.smart_project(angle_limit=66, island_margin=0)

    sel = bpy.context.selected_objects
    leaf2 = sel[:]

    #オブジェクトの回転
    for obj in sel:
        bpy.context.scene.objects.active = obj
        obj.rotation_euler = (0, 0, 0)
        # bpy.ops.transform.rotate(value=-3.14/2,axis=(-1,0,0))
        # bpy.ops.transform.rotate(value=-3.14/2,axis=(0,-1,0))
        # bpy.ops.transform.rotate(value=-3.14/2,axis=(0,0,-1))
        # bpy.ops.transform.rotate(value=3.14/2,axis=(-1,0,0))
        # bpy.ops.transform.rotate(value=3.14/2,axis=(0,-1,0))
        # bpy.ops.transform.rotate(value=3.14/2,axis=(0,0,-1))
        #bpy.ops.transform.translate(180)

    #質感変更
    for item in bpy.data.materials:
        item.diffuse_shader = ('FRESNEL')
        item.diffuse_fresnel = 1.0
        item.emit = 1.0
        item.specular_intensity = 0.0
        item.ambient = 0.0
        item.translucency = 0.0
        item.use_raytrace = False
        item.use_mist = False
        # シェーディングを切る
        item.use_shadeless = True

    # lamp=bpy.data.objects['Lamp']

    #lamp.data.type='SUN'
    #lamp.location=(0,30,40)

    # アンチエイリアシングを切る
    bpy.data.scenes["Scene"].render.use_antialiasing = False

    #カメラ撮影
    camera.setCirclePathCamera(3, save_dir)