表面纹理
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
5.1 KiB

# coding=utf-8
import bpy
import bmesh
import os
import sys
import numpy as np
from mathutils import Vector
from ..project_config import PROJECT_CONFIG
import datetime
import json
def boundary_condition_mesh_callback(scene, context):
items = []
object_list = bpy.context.scene.objects
for i in object_list:
if i.type == 'MESH':
items.append((i.name, i.name, i.name))
return items
class SurfaceHoleOperator(bpy.types.Operator):
bl_idname: str = "designauto.manual_texture_3d_surface_hole"
bl_label: str = "手动选面"
bl_options = {"REGISTER", "UNDO"}
style_items = [
('圆台1', '圆台1', ''),
('圆台2', '圆台2', ''),
('圆柱', '圆柱', ''),
('方形', '方形', ''),
('三角形', '三角形', ''),
('六边形', '六边形', ''),
('八边形', '八边形', '')
]
part_mesh: bpy.props.EnumProperty(name="打孔区域", items=boundary_condition_mesh_callback)
hole_height: bpy.props.FloatProperty(name="孔洞深度", default=0.05)
hole_radius: bpy.props.FloatProperty(name="孔洞半径", default=0.3)
use_honeycomb_type:bpy.props.BoolProperty(name="蜂窝型采样", default=False)
hole_distance: bpy.props.FloatProperty(name="孔洞间距", default=0.1)
texture_style:bpy.props.EnumProperty(name="纹理样式",items=style_items,
description="Choose the style of texture", default="圆柱")
boundary_margin:bpy.props.FloatProperty(name="边缘距离",
description="边缘距离", default=0.25)
number_id:bpy.props.IntProperty(name="数字id",
description="ID", default=0)
def execute(self, context):
working_object = context.active_object
part_object = bpy.context.scene.objects.get(self.part_mesh)
workplace = PROJECT_CONFIG.workplace_dir_path
executable_path = PROJECT_CONFIG.executable_dir_path
tri_mesh_path = os.path.join(workplace, "assets", "model.obj")
part_mesh_path = os.path.join(workplace, "assets", "part.obj")
bpy.ops.export_scene.obj(filepath=tri_mesh_path, use_selection=True, axis_forward='Y', axis_up='Z', use_edges=False, use_animation=False, use_materials=False, use_uvs=False, use_normals=False,
use_mesh_modifiers=False, use_nurbs=False, use_smooth_groups=False, use_vertex_groups=False, use_blen_objects=False, use_smooth_groups_bitflags=False)
working_object.select_set(False)
part_object.select_set(True)
bpy.ops.export_scene.obj(filepath=part_mesh_path, use_selection=True, axis_forward='Y', axis_up='Z', use_edges=False, use_animation=False, use_materials=False, use_uvs=False, use_normals=False,
use_mesh_modifiers=False, use_nurbs=False, use_smooth_groups=False, use_vertex_groups=False, use_blen_objects=False, use_smooth_groups_bitflags=False)
working_object.select_set(True)
part_object.select_set(False)
import dapy_t3d_surface_hole
os.chdir(executable_path)
sample_distance = 2.0*self.hole_radius+self.hole_distance
hole_factor = 2.0*self.hole_radius / sample_distance
texture_num = 0
if self.texture_style == "圆台1":
texture_num=1
elif self.texture_style == "圆台2":
texture_num=2
elif self.texture_style == "圆柱":
texture_num=3
elif self.texture_style == "方形":
texture_num=4
elif self.texture_style == "三角形":
texture_num=5
elif self.texture_style == "六边形":
texture_num=6
elif self.texture_style == "八边形":
texture_num=7
mesh_with_hole = dapy_t3d_surface_hole.GenerateSurfaceHoles(self.hole_height, hole_factor,self.use_honeycomb_type,
sample_distance, texture_num,True,0.24,15,self.boundary_margin,self.number_id,True,False)
# print(lattice_mesh_beams)
new_mesh = bpy.data.meshes.new("mesh-" + working_object.name + "-hole")
new_mesh.from_pydata(mesh_with_hole.mat_coordinates.tolist(), [], mesh_with_hole.mat_faces.tolist())
new_mesh.update()
new_object = bpy.data.objects.new(working_object.name + "-hole", new_mesh)
found = False
for c in bpy.data.collections:
if c.name == 'designauto':
found = True
new_collection = c
if not found:
new_collection = bpy.data.collections.new('designauto')
bpy.context.scene.collection.children.link(new_collection)
new_collection.objects.link(new_object)
working_object.select_set(True)
return {'FINISHED'}
def invoke(self, context, event):
if context.active_object.type == 'MESH':
return context.window_manager.invoke_props_dialog(self)
else:
self.report({'ERROR'}, "Selected object is not a mesh!")
return {'CANCELLED'}