40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
# coding: utf-8
|
|
# Copyright (C) 2023 Ilia Kurochkin <brothermechanic@yandex.com>
|
|
#
|
|
# 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 3 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.
|
|
'''
|
|
DESCRIPTION.
|
|
Convert all deformers and modifiers of object to it's mesh.
|
|
'''
|
|
__version__ = '0.1'
|
|
|
|
import bpy
|
|
|
|
|
|
def mesh_to_mesh(obj):
|
|
''' Convert all deformers and modifiers of object to it's mesh. '''
|
|
if obj and obj.type == 'MESH':
|
|
deg = bpy.context.evaluated_depsgraph_get()
|
|
eval_mesh = obj.evaluated_get(deg).data.copy()
|
|
|
|
orig_name = obj.name
|
|
obj.name = '{}_temp'.format(orig_name)
|
|
converted_obj = bpy.data.objects.new(orig_name, eval_mesh)
|
|
converted_obj.matrix_world = obj.matrix_world
|
|
|
|
bpy.context.view_layer.update()
|
|
converted_obj.matrix_world = obj.matrix_world.copy()
|
|
|
|
obj.users_collection[0].objects.link(converted_obj)
|
|
|
|
bpy.data.objects.remove(obj, do_unlink=True)
|
|
|
|
return converted_obj
|