LOD TOOL Final
JO00
python
6 months ago
12 kB
4
No Index
import unreal
import datetime
##gets date time for my debug log printing
print(str(datetime.datetime.now()))
editor_stat_meshes=[]
textlibrary=unreal.TextLibrary()
transferlist=[]
geteditor=unreal.get_editor_subsystem(unreal.StaticMeshEditorSubsystem)
getselecteditor=unreal.EditorUtilityLibrary.get_selected_assets_of_class(unreal.StaticMesh)
getselectlevel=unreal.get_editor_subsystem(unreal.EditorActorSubsystem).get_selected_level_actors()
def clean_static_meshes(listofmeshes):
counter=0
for x in listofmeshes:
#is static mesh
if isinstance(listofmeshes[counter], unreal.StaticMeshActor):
editor_stat_meshes.append(listofmeshes[counter])
counter=counter+1
#not static mesh
else:
counter=counter+1
clean_static_meshes(getselectlevel)
def data_for_array_list(listofmeshes):
counteritems=0
#repeat for all selected items
while counteritems!=len(listofmeshes):
try:
thecomponent=listofmeshes[counteritems].static_mesh_component
getstaticmesh=thecomponent.static_mesh
except AttributeError:
getstaticmesh=listofmeshes[counteritems]
##thumb setting for first
if counteritems==0:
datapath=getstaticmesh.get_path_name()
data_for_thumb = unreal.EditorAssetLibrary.find_asset_data(datapath)
asset_thumb.set_asset(data_for_thumb)
#now for data adding
#mesh name and lod counter for later
nameofmesh=getstaticmesh.get_name()
transferlist.append(str(nameofmesh))
numberoflods=getstaticmesh.get_num_lods()
#instances
instcounter=0
theeditorworld=unreal.EditorLevelLibrary.get_editor_world()
worldactors=unreal.GameplayStatics.get_all_actors_of_class(theeditorworld, unreal.Actor)
for actor in worldactors:
staticchecker = actor.get_components_by_class(unreal.StaticMeshComponent)
for selected in staticchecker:
pickedmesh = selected.get_editor_property("static_mesh")
if pickedmesh == getstaticmesh:
instcounter += 1
transferlist.append(str(instcounter))
##current tricount and vertex count
transferlist.append(str(getstaticmesh.get_num_triangles(0)))
transferlist.append(str(geteditor.get_number_verts(getstaticmesh,0)))
##total lod count
transferlist.append(str(getstaticmesh.get_num_lods()))
#material count
numberofmats=geteditor.get_number_materials(getstaticmesh)
transferlist.append(str(numberofmats))
#scale info
scaleofmesh=getstaticmesh.get_bounding_box()
dimensionsx=round(scaleofmesh.max.x-scaleofmesh.min.x,1)
dimensionsy=round(scaleofmesh.max.y-scaleofmesh.min.y,1)
dimensionsz=round(scaleofmesh.max.z-scaleofmesh.min.z,1)
combineddimensions=str(dimensionsx)+"cm x "+str(dimensionsy)+"cm x "+str(dimensionsz)+"cm"
transferlist.append(combineddimensions)
#collision enabled, collision type and nanite
gettingcoll=getstaticmesh.get_editor_property('body_setup')
check_if_enabled = gettingcoll.get_editor_property('collision_reponse').value
if check_if_enabled==0:
transferlist.append("Enabled")
else:
transferlist.append("Disabled")
collisioncomp=geteditor.get_collision_complexity(getstaticmesh)
thenumberofflag=collisioncomp.value
if thenumberofflag==0:
transferlist.append("Default")
elif thenumberofflag==1:
transferlist.append("Simple and Complex")
elif thenumberofflag==2:
transferlist.append("Simple as Complex")
elif thenumberofflag==3:
transferlist.append("Complex as Simple")
get_nanite_settings = getstaticmesh.get_editor_property("nanite_settings")
checkenablednanite = get_nanite_settings.get_editor_property("enabled")
if checkenablednanite==True:
transferlist.append("Enabled")
else :
transferlist.append("Disabled")
#lod data for header 2
#biglodcounter
listlodcounter=0
LODNUMBERLISTER=""
while listlodcounter!=numberoflods:
LODNUMBERLISTER+="LOD0"+str(listlodcounter)+"{/n}"
listlodcounter+=1
replacelonglodcounter = LODNUMBERLISTER.replace("{/n}", "\n")
transferlist.append(replacelonglodcounter)
##lod tricount per lod and vertex count per lod
lodcounter=0
tricountlister=""
vertexlister=""
while lodcounter!=numberoflods:
tricountlister+=str(getstaticmesh.get_num_triangles(lodcounter))+"{/n}"
vertexlister+=str(geteditor.get_number_verts(getstaticmesh,lodcounter))+"{/n}"
lodcounter=lodcounter+1
replacetricountlister = tricountlister.replace("{/n}", "\n")
replacevertexlister = vertexlister.replace("{/n}", "\n")
transferlist.append(replacetricountlister)
transferlist.append(replacevertexlister)
##screensize per lod
getscreensizes=unreal.EditorStaticMeshLibrary.get_lod_screen_sizes(getstaticmesh)
nicerscreenlist=""
listcounter=0
while listcounter!= len(getscreensizes):
percentofscreen=round(getscreensizes[listcounter]*50,2)
nicerscreenlist+=str(percentofscreen)+"{/n}"
listcounter=listcounter+1
replacescreensize = nicerscreenlist.replace("{/n}", "\n")
transferlist.append(replacescreensize)
##lod reduction
tricountcounter=0
tricountreductionlist=""
while tricountcounter!=numberoflods:
currenttricountdensity=100-round(getstaticmesh.get_num_triangles(tricountcounter)/getstaticmesh.get_num_triangles(0)*100,2)
tricountreductionlist+=str(currenttricountdensity)+"{/n}"
tricountcounter=tricountcounter+1
replacetricount = tricountreductionlist.replace("{/n}", "\n")
transferlist.append(replacetricount)
##vertex density per cm
counter=0
listofvertexdensity=""
while counter!=numberoflods:
currentvertex=geteditor.get_number_verts(getstaticmesh,counter)
lodscaleofmesh=getstaticmesh.get_bounding_box()
lodlength=round(lodscaleofmesh.max.x-lodscaleofmesh.min.x,1)
diameterlod=round(currentvertex/lodlength,2)
listofvertexdensity+=str(diameterlod)+"{/n}"
counter=counter+1
replacingstringline = listofvertexdensity.replace("{/n}", "\n")
transferlist.append(replacingstringline)
print(replacingstringline)
###rowheader3 - materials info
matnamescollective=""
matcounter=0
while matcounter!=numberofmats:
materialselected=getstaticmesh.get_material(matcounter)
if materialselected:
gettingmat=materialselected.get_name()
matnamescollective+="Mat No "+str(matcounter)+"= "+str(gettingmat)
else:
print("No mat detected")
matcounter=matcounter+1
transferlist.append(matnamescollective)
##sending data to selection if first runtime
print(str(counteritems))
if counteritems==0:
print("first runtime")
text_solotricount=textlibrary.conv_int_to_text(getstaticmesh.get_num_triangles(0))
text_solovertcount=textlibrary.conv_int_to_text(geteditor.get_number_verts(getstaticmesh,0))
text_nameofmesh=textlibrary.conv_string_to_text(str(nameofmesh))
rep_mesh_name.set_text(text_nameofmesh)
text_dimensionsx=textlibrary.conv_string_to_text(combineddimensions)
scale_x.set_text(text_dimensionsx)
text_numberoflods=textlibrary.conv_string_to_text(str(numberoflods))
lod_counter_total.set_text(text_numberoflods)
text_LODNUMBERLISTER=textlibrary.conv_string_to_text(replacelonglodcounter)
lod_list_1.set_text(text_LODNUMBERLISTER)
lod_list_2.set_text(text_LODNUMBERLISTER)
text_tricountlister=textlibrary.conv_string_to_text(replacetricountlister)
text_vertexlister=textlibrary.conv_string_to_text(replacevertexlister)
lod_settings_lod_tricount.set_text(text_tricountlister)
lod_vert_list.set_text(text_vertexlister)
tricount_selected_1.set_text(text_solotricount)
vertcount_selected.set_text(text_solovertcount)
if checkenablednanite==True:
nanite_enabled.set_text(textlibrary.conv_string_to_text("Enabled"))
else :
nanite_enabled.set_text(textlibrary.conv_string_to_text("Disabled"))
scene_insts.set_text(textlibrary.conv_int_to_text(instcounter))
text_nicerscreenlist=textlibrary.conv_string_to_text(replacescreensize)
lod_settings_lod_screen_size.set_text(text_nicerscreenlist)
numberofmatsname=str(numberofmats)
text_numberofmats=textlibrary.conv_string_to_text(numberofmatsname)
material_count_1.set_text(text_numberofmats)
vertexredcounter=0
highestvertex=geteditor.get_number_verts(getstaticmesh,0)
vertexreductionlist=""
while vertexredcounter!=numberoflods:
vertexreductionlist+=str(100-round(geteditor.get_number_verts(getstaticmesh,vertexredcounter)/geteditor.get_number_verts(getstaticmesh,0)*100,2))+"{/n}"
vertexredcounter=vertexredcounter+1
replacevertextreductionlist = vertexreductionlist.replace("{/n}", "\n")
text_vertexreductionlist=textlibrary.conv_string_to_text(replacevertextreductionlist)
text_vertexreductionlist=textlibrary.conv_string_to_text(replacevertextreductionlist)
lod_settings_lod_screen_size_1.set_text(text_vertexreductionlist)
text_tricountreductionlist=textlibrary.conv_string_to_text(replacetricount)
lod_settings_lod_tricount_1.set_text(text_tricountreductionlist)
text_listofvertexdensity=textlibrary.conv_string_to_text(replacingstringline)
lod_settings_lod_screen_size_1.set_text(text_listofvertexdensity)
if thenumberofflag==0:
collision_type.set_text(textlibrary.conv_string_to_text("Default"))
elif thenumberofflag==1:
collision_type.set_text(textlibrary.conv_string_to_text("Simple and Complex"))
elif thenumberofflag==2:
collision_type.set_text(textlibrary.conv_string_to_text("Simple as Complex"))
elif thenumberofflag==3:
collision_type.set_text(textlibrary.conv_string_to_text("Complex as Simple"))
gettingcoll=getstaticmesh.get_editor_property('body_setup')
check_if_enabled = gettingcoll.get_editor_property('collision_reponse').value
collisionenabledquestion=False
if check_if_enabled==0:
collison_enable_disable.set_text(textlibrary.conv_string_to_text("Enabled"))
else:
collison_enable_disable.set_text(textlibrary.conv_string_to_text("Disabled"))
print("got here!!")
counteritems+=1
print("got here instead")
amountofitems=len(getselecteditor)
amountofitems2=len(editor_stat_meshes)
if dropdowncheck.get_selected_index()!=0: #content browser
asset_data_for_thumb=getselecteditor[0]
no_selected_assets_1.set_text(textlibrary.conv_int_to_text(amountofitems))
data_for_array_list(getselecteditor)
elif dropdowncheck.get_selected_index()!=1: #level
no_selected_assets_1.set_text(textlibrary.conv_int_to_text(amountofitems2))
data_for_array_list(editor_stat_meshes)
asset_data_for_thumb=editor_stat_meshes[0]
else: #no selection
print("empty no selection!")
Editor is loading...