File size: 1,719 Bytes
4d3af08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 画面右上 (「情報」エリア → ヘッダー)
import bpy, bmesh
from . import common

# メニュー等に項目追加
def menu_func(self, context):
	self.layout.operator('mesh.vertices_count_checker', icon_value=common.preview_collections['main']['KISS'].icon_id)

class vertices_count_checker(bpy.types.Operator):
	bl_idname = 'mesh.vertices_count_checker'
	bl_label = "Check Vertice Count"
	bl_description = "Check whether the exporter can output the selected mesh."
	bl_options = {'REGISTER', 'UNDO'}
	
	@classmethod
	def poll(cls, context):
		ob = context.active_object
		if ob:
			if ob.type == 'MESH':
				return True
		return False
	
	def execute(self, context):
		me = context.object.data
		if not me.uv_layers.active:
			self.report(type={'ERROR'}, message="No UV Map. Cannot be Counted.")
			return {'FINISHED'}
		bm = bmesh.new()
		bm.from_mesh(me)
		
		alreadys = {}
		uv_lay = bm.loops.layers.uv.active
		
		for face in bm.faces:
			for loop in face.loops:
				info = (loop.vert.index, loop[uv_lay].uv.x, loop[uv_lay].uv.y)
				if info not in alreadys:
					alreadys[info] = None
		bm.free()
		
		inner_count = len(alreadys)
		real_count = len(me.vertices)
		if inner_count <= 65535:
			self.report(type={'ERROR'}, message="Good, There is space for more vertices, you may add %d more vertices (Vertices:%d(+%d) UV Splitting:+%d%)" % (65535 - inner_count, real_count, inner_count - real_count, int(inner_count / real_count * 100)))
		else:
			self.report(type={'ERROR'}, message="X, Too many vertices、please remove %d Vertices (Vertices:%d(+%d) Uv Splitting:+%d%)" % (inner_count - 65535, real_count, inner_count - real_count, int(inner_count / real_count * 100)))
		
		return {'FINISHED'}