Skip to content

Commit

Permalink
v1.2.6-b5
Browse files Browse the repository at this point in the history
small change animation toolbar
update fix for blender 4.1 (calc_normals_split() replaced with me.corner_normals)
updated vertex normals to find better match.
  • Loading branch information
hypov8 authored Mar 16, 2024
1 parent e840922 commit 6af3514
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 50 deletions.
70 changes: 35 additions & 35 deletions kingpin/anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def chkBox_autoUpdateFrame(self, context):
],
default="AUTO",
)

# used
key_frame = BoolProperty(
name="Live Update",
Expand Down Expand Up @@ -285,46 +284,47 @@ def draw(self, context):
layout = self.layout
box1 = layout.box()
box1.enabled = enable_box
row = box1.column_flow(columns=2, align=True)
boxFlow = box1.column_flow(columns=1, align=True)#start 1 row box flow
# row.alignment = 'EXPAND' # 'EXPAND', 'LEFT', 'CENTER', 'RIGHT']
row.label(text="Selected")
row.label(text="All Vertex")
row = box1.column_flow(columns=2, align=True)

boxFlow.label(text="Selected Vertex")
row = boxFlow.column_flow(columns=2, align=True)
row.scale_y = 1.2
row.operator("anim.insert_keyframe_animall_kp", icon="KEY_HLT")
row.operator("anim.insert_keyframe_animall_all_kp", icon="KEYINGSET")
row.operator("anim.delete_keyframe_animall_kp", icon="KEY_DEHLT")
boxFlow.label(text="All Vertex")
row = boxFlow.column_flow(columns=2, align=True)
row.scale_y = 1.2
row.operator("anim.insert_keyframe_animall_all_kp", icon="KEYINGSET")
row.operator("anim.delete_keyframe_animall_all_kp", icon="KEY_DEHLT")
row = box1.column_flow(columns=1, align=True)
row.operator("kp.ui_btn_driver_clear", icon="X")
row.label(text="Interpolation", icon="IPO_CONSTANT")
row.prop(kp_tool_anim, "key_keytype_in")
row.prop(kp_tool_anim, "key_keytype_out")
boxFlow.separator(factor=1.2)
boxFlow.operator("kp.ui_btn_driver_clear", icon="X")

box2 = layout.box()
boxFlow2 = box2.column_flow(columns=1, align=True)#start 1 row box flow
boxFlow2.label(text="Interpolation", icon="IPO_CONSTANT")
boxFlow2.prop(kp_tool_anim, "key_keytype_in")
boxFlow2.prop(kp_tool_anim, "key_keytype_out")
# end box1 #
############

# frame change box. fix for vertex animation bug
box2 = layout.box()
# box2.enabled = enable_box
# live update option for vertex? not working
# row = box.row(align=True) # row 1
box3 = layout.box()
# row = box3.row(align=True) # row 1. mode
# row.alignment = 'LEFT'
# row.prop(kp_tool_anim, "key_frame")
row = box2.row(align=True) # row 1. mode
row.alignment = 'LEFT'
if is_vertex:
row.label(text="Vertex Mode", icon="VERTEXSEL")
box3.row().label(text="Vertex Mode", icon="VERTEXSEL")
else:
row.label(text="Shape Key Mode", icon="SHAPEKEY_DATA")
box3.row().label(text="Shape Key Mode", icon="SHAPEKEY_DATA")

# arrows
row = box2.column_flow(columns=3, align=True)
row.alignment = 'EXPAND'
row.operator("anim.frame_prev_kp") # left arrow
row.operator("anim.frame_next_kp") # right arror
row.operator("anim.frame_update_kp") # update/sync button
row = box2.column_flow(columns=1, align=True)
row.alignment = 'LEFT'
boxFlow3 = box3.column_flow(columns=3, align=True)
boxFlow3.alignment = 'EXPAND'
boxFlow3.operator("anim.frame_prev_kp") # left arrow
boxFlow3.operator("anim.frame_next_kp") # right arror
boxFlow3.operator("anim.frame_update_kp") # update/sync button
boxFlow3 = box3.column_flow(columns=1, align=True)
boxFlow3.alignment = 'LEFT'
# frame number
str_row = ("Fr: %i" % bpy.context.scene.frame_current)

Expand All @@ -335,26 +335,26 @@ def draw(self, context):
####################
# absalute shapekeys
if not sk_data.use_relative: # sk absolute
row.label(text="%s SK: %s" % (str_row, sk_name)) # , icon="SHAPEKEY_DATA")
boxFlow3.label(text="%s SK: %s" % (str_row, sk_name)) # , icon="SHAPEKEY_DATA")
if (sk_data and sk_data.key_blocks):
sk_frame = sk_data.key_blocks[sk_index].frame
val = float(bpy.context.scene.frame_current * 10)
frame_min = val - 0.01 # find close float
frame_max = val + 0.01 #
if not (sk_frame > frame_min and sk_frame < frame_max):
row.label(text="Shape Key Not sync'd", icon="INFO")
boxFlow3.label(text="Shape Key Not sync'd", icon="INFO")
####################
# relative shapekeys
elif sk_index > 0:
row.label(text="%s SK: %s" % (str_row, sk_name)) # , icon="SHAPEKEY_DATA")
boxFlow3.label(text="%s SK: %s" % (str_row, sk_name)) # , icon="SHAPEKEY_DATA")
if sk_activ.value < 1:
row.label(text='sKey not 1.0? sync?', icon="INFO")
boxFlow3.label(text='sKey not 1.0? sync?', icon="INFO")
elif sk_activ or sk_data:
key0_Name = sk_data.key_blocks[0].name if sk_data else sk_name
row.label(text="%s SK: %s (Base)" % (str_row, key0_Name)) # icon="SHAPEKEY_DATA"
row.label(text="sKey: Index 0", icon="ERROR") # index invalid
boxFlow3.label(text="%s SK: %s (Base)" % (str_row, key0_Name)) # icon="SHAPEKEY_DATA"
boxFlow3.label(text="sKey: Index 0", icon="ERROR") # index invalid
# else:
# row.label(text="Vertex Mode", icon="VERTEXSEL")
# boxFlow3.label(text="Vertex Mode", icon="VERTEXSEL")


# button frame 'prev'
Expand Down Expand Up @@ -606,7 +606,7 @@ def execute(self, context):
class KP_UI_BTN_ANIM_DEL_ALL_ANIM(Operator):
'''remove all animation data'''
bl_idname = "kp.ui_btn_driver_clear"
bl_label = "Clear Anim"
bl_label = "Clear All Anim"
bl_options = {"REGISTER", "UNDO"}
bl_description = ("Remove all animations and shape keys")

Expand Down
34 changes: 27 additions & 7 deletions kingpin/common_kp.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ def get_hide(context):
return context.hide_viewport # B2.8
return context.hide

def set_empty_draw_type(context, type):
'''
2.80: <context.empty_draw_type>
2.79: <context.empty_display_type>
'''
if hasattr(context, "empty_draw_type"):
context.empty_draw_type = type # B3.0
else:
context.empty_display_type = type

def set_mode_get_obj(context):
'''set object mode=OBJECT, get active.object and selected.objects
Expand Down Expand Up @@ -773,8 +782,14 @@ def triangulateMesh_fn(object, depsgraph,
return me, depMesh
# done triangulateMesh_fn()

def veckey3d(v):
return round(v.x, 4), round(v.y, 4), round(v.z, 4)

def fillMeshArrays(me, faceuv, uv_texture, uv_layer, custom_vn):
''' Make our own list so it can be sorted to reduce context switching '''
'''
generate arrays
'''
# Make our own list so it can be sorted to reduce context switching
face_index_pairs = [(face, index) for index, face in enumerate(me.polygons)]
me_verts = me.vertices[:] # get vert array
loops = me.loops
Expand All @@ -798,7 +813,7 @@ def fillMeshArrays(me, faceuv, uv_texture, uv_layer, custom_vn):
# tmp_XYZ_norm.append(v.normal[:]) # XYZ float

# Vertex normals
if not hasattr(me, "calc_normals_split"): # if check_version(4, 10, 0) >= 0: #B4.1
if not hasattr(me, "calc_normals_split"): # if check_version(4, 10, 0) >= 0: # B4.1
if custom_vn:
vNorms = me.corner_normals
for v in loops:
Expand All @@ -808,13 +823,18 @@ def fillMeshArrays(me, faceuv, uv_texture, uv_layer, custom_vn):
for i, v in enumerate(me.vertex_normals):
tmp_XYZ_norm[i] = (v.vector.x, v.vector.y, v.vector.z)
else:
me.calc_normals_split() # !B4.1
me.calc_normals_split() # version < B4.1
if custom_vn:
# self.ui_opt_cust_vn: #option custom normals
# note: model is not split at vertex.
# set mesh to smoothed and detatch faces at hard edge
for v in loops:
tmp_XYZ_norm[v.vertex_index] = (v.normal.x, v.normal.y, v.normal.z)
# or use 'edge split' modifier with hard edges marked
loops_split = me.loops
for f, f_index in face_index_pairs:
for l_idx in f.loop_indices:
v_idx = loops_split[l_idx].vertex_index
v_norm = veckey3d(loops_split[l_idx].normal)
if tmp_XYZ_norm[v_idx] is None:
tmp_XYZ_norm[v_idx] = v_norm
else:
for i, v in enumerate(me_verts):
tmp_XYZ_norm[i] = (v.normal[:]) # XYZ float
Expand Down Expand Up @@ -877,7 +897,7 @@ def fillMeshArrays(me, faceuv, uv_texture, uv_layer, custom_vn):
continue
faceuv = uv_layer = None
if getUV:
faceuv = len(me.uv_layers) > 0
faceuv = bool(len(me.uv_layers) > 0)
if not faceuv:
me.uv_layers.new() # add uv map
faceuv = True
Expand Down
29 changes: 21 additions & 8 deletions kingpin/export_kp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import struct
import bpy
from mathutils import Vector as Vec
from bpy.types import Operator, PropertyGroup
from bpy.props import (
BoolProperty,
Expand Down Expand Up @@ -237,7 +238,7 @@ def draw_export(self, context):
# misc options box
box = layout.box()
miscBox = box.column_flow(columns=1, align=True)
# miscBox.prop(ui_export_, "ui_opt_apply_modify") # apply movifiers
# miscBox.prop(ui_export_, "ui_opt_apply_modify") # apply modifiers
# if ui_export_.ui_opt_apply_modify:
miscBox.prop(ui_export_, "ui_opt_cust_vn") # custom vertex normals
miscBox.prop(ui_export_, "ui_opt_is_hd") # HD version
Expand Down Expand Up @@ -383,13 +384,14 @@ def setupInternalArrays_fn(self):
# --------------------------------------------
# TODO find why this is taking lots of time...
# 5 seconds with no items to seek 700 frames
frame_idx = start_frame + frame
scene.frame_set(frame_idx)
if self.ui_opt_animated: # dont move frame unless animated
frame_idx = start_frame + frame
scene.frame_set(frame_idx)
# --------------------------------------------
self.frameData.append(
getMeshArrays_fn(
obj_sel,
getUV=1 if frame == 0 else 0, # ignore uv for animated frames
getUV=bool(frame == 0), # ignore uv for animated frames
apply_modifyer=apply_modifyer,
custom_vn=custom_vn)
)
Expand Down Expand Up @@ -697,6 +699,7 @@ def findFanLength_fn(usedFace, mesh, startTri, startVert, numFaces,
# print("GLCommands. (Count: {})".format(numCommands))
del cmdVerts, cmdUV, cmdTris, bestVerts, bestUV, bestTris
return numCommands
# end

# TODO
def getSkins_fn(self, obj_sel, method):
Expand Down Expand Up @@ -802,10 +805,10 @@ def updateWH(size, found, outW, outH):

printDone_fn(self.start_time, prefix) # Done.
print("Count: {}\n".format(len(skins)) +
"Width: {}\n".format(width) +
"Height: {}".format(height))
"Width: {}\n".format(width) +
"Height: {}".format(height))
for idx, skin in enumerate(skins):
print("skin{}: {}".format(idx + 1, skin[0:MD2_MAX_SKINNAME]))
print("skin{}: {}".format(idx + 1, skin[0:MD2_MAX_SKINNAME-1]))
if height > 480 or width > 480:
print("WARNING: found texture larger than kingpin max 480px")

Expand All @@ -823,6 +826,7 @@ def updateWH(size, found, outW, outH):
self.skinWidth = width
self.skinHeight = height
self.skins = skins
# end getSkins_fn

def buildFrameNames_fn(self):
'''
Expand Down Expand Up @@ -858,6 +862,7 @@ def buildFrameNames_fn(self):
else:
name.append("frame_" + str(frame_idx))
return name
# end buildFrameNames_fn

def calcSharedBBox_fn(self):
''' option to make bbox size across all frames the same
Expand Down Expand Up @@ -891,6 +896,7 @@ def calcSharedBBox_fn(self):
if self.ui_opt_share_bbox: # .options
self.bbox_min.append(min)
self.bbox_max.append(max)
# end calcSharedBBox_fn

def calculateHitBox_fn(self):
''' mdx hitbox '''
Expand Down Expand Up @@ -920,6 +926,7 @@ def calculateHitBox_fn(self):
hitboxMax[0], hitboxMax[1], hitboxMax[2]])

self.hitbox.append(hitboxTmp)
# end

# TODO speed boost VN list
def calculateVNornIndex_fn(self):
Expand All @@ -940,6 +947,8 @@ def calculateVNornIndex_fn(self):
for tmp_mesh in self.frameData[frame]:
vn_tmp = [0] * tmp_mesh[IDX_I_VERT]
for i, vn in enumerate(tmp_mesh[IDX_XYZ_VN]):
vn = Vec.normalized(Vec(vn))
vn = (vn.x, vn.y, vn.z)
maxDot = vn[0] * MD2_VN[0][0] + vn[1] * MD2_VN[0][1] + vn[2] * MD2_VN[0][2]
bestIdx = 0
for iN in range(1, 162):
Expand All @@ -949,14 +958,15 @@ def calculateVNornIndex_fn(self):
if dot > maxDot:
maxDot = dot
bestIdx = iN
if maxDot > 0.99: # stop wasting time
if maxDot > 0.99999: # stop wasting time
break
vn_tmp[i] = bestIdx # normal index
m_tmp.append(vn_tmp) # object
del vn_tmp
self.vNormData.append(m_tmp) # frame
del m_tmp
printDone_fn(self.start_time, prefix) # Done.
# end calculateVNornIndex_fn

def get_numTris(self):
triCount = 0 # self.numTris
Expand All @@ -974,6 +984,7 @@ def get_numTris(self):
"Object has too many (triangulated) faces (%i), at most %i are supported in md2"
% (triCount, MD2_MAX_TRIANGLES))
return triCount
# end get_numTris

def get_numVerts(self):
vertCount = 0 # self.numVerts
Expand All @@ -991,12 +1002,14 @@ def get_numVerts(self):
"Object has too many (triangulated) faces (%i), at most %i are supported in md2"
% (vertCount, MD2_MAX_VERTS))
return vertCount
# end get_numVerts

def get_numUV(self):
uvCount = 0
for tmp_mesh in self.frameData[0]:
uvCount += tmp_mesh[IDX_I_UV]
return uvCount
# end get_numUV

self.obj_array = []
self.frameData = []
Expand Down

0 comments on commit 6af3514

Please sign in to comment.