-
Notifications
You must be signed in to change notification settings - Fork 3
/
blender.py
32 lines (25 loc) · 1020 Bytes
/
blender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# blender python module
import bpy
def displaceGeomtry(pathToOBJ, pathForExport):
scene = bpy.context.screen.scene
for object_ in scene.objects:
bpy.data.objects.remove(object_, True)
imported_object = bpy.ops.import_scene.obj(filepath=pathToOBJ)
obj_object = bpy.context.selected_objects[0]
bpy.context.scene.objects.active = obj_object
for item in bpy.data.materials:
#Enable "use_shadeless"
item.use_shadeless = True
subd = obj_object.modifiers.new("subd", type='SUBSURF')
# # subd.levels = 2
bpy.ops.object.modifier_apply(modifier=subd.name)
tex = obj_object.active_material.active_texture
dispMod = obj_object.modifiers.new("Displace", type='DISPLACE')
dispMod.texture = tex
dispMod.texture_coords = "UV"
dispMod.strength = -0.002
bpy.ops.object.modifier_apply(modifier=dispMod.name)
bpy.ops.export_scene.obj(filepath=pathForExport)
if __name__ == "__main__":
displaceGeomtry("forBlender.obj",
"fromBlender.obj")