1- from __future__ import annotations
2-
31import base64
42import collections
53import itertools
64import os
75import math
86import struct
97import urllib .parse
10- import pprint # pylint: disable=unused-import
118
129from dataclasses import dataclass
1310
14- from panda3d .core import * # pylint: disable=wildcard-import
11+ from panda3d .core import *
1512import panda3d .core as p3d
1613try :
1714 from panda3d import bullet
1815 HAVE_BULLET = True
1916except ImportError :
2017 HAVE_BULLET = False
21- from direct .stdpy .file import open # pylint: disable=redefined-builtin
18+ from direct .stdpy .file import open # noqa: A004
2219
2320from ._converter_maps import (
2421 ATTRIB_CONTENT_MAP ,
@@ -111,8 +108,8 @@ def get_lerp_factor(currtime: float, lasttime: float, nexttime: float) -> float:
111108class CharInfo :
112109 character : p3d .Character
113110 nodepath : p3d .NodePath
114- jvtmap : ' dict[int, p3d.JointVertexTransform]'
115- cvsmap : ' dict[tuple[int, str], p3d.CharacterVertexSlider]'
111+ jvtmap : dict [int , p3d .JointVertexTransform ]
112+ cvsmap : dict [tuple [int , str ], p3d .CharacterVertexSlider ]
116113
117114 def __init__ (self , name : str ):
118115 self .character = p3d .Character (name )
@@ -121,9 +118,7 @@ def __init__(self, name: str):
121118 self .cvsmap = {}
122119
123120
124- class Converter ():
125-
126-
121+ class Converter :
127122 def __init__ (
128123 self ,
129124 filepath ,
@@ -253,7 +248,7 @@ def add_node(root, gltf_scene, nodeid):
253248 charinfo = self .characters .get (skinid , None )
254249 scene_extras = get_extras (gltf_scene )
255250 node_name = gltf_node .get ('name' , 'node' + str (nodeid ))
256- if nodeid in self ._joint_nodes and not nodeid in self .skeletons :
251+ if nodeid in self ._joint_nodes and nodeid not in self .skeletons :
257252 # Handle non-joint children of joints, but don't add joints themselves
258253 for child_nodeid in gltf_node .get ('children' , []):
259254 add_node (root , gltf_scene , child_nodeid )
@@ -482,8 +477,10 @@ def load_buffer(self, buffid, gltf_buffer):
482477 uri = gltf_buffer ['uri' ]
483478 if uri == '_glb_bin' and buffid == 0 :
484479 buff_data = gltf_buffer ['_glb_bin' ]
485- elif uri .startswith ('data:application/octet-stream;base64' ) or \
486- uri .startswith ('data:application/gltf-buffer;base64' ):
480+ elif uri .startswith ((
481+ 'data:application/octet-stream;base64' ,
482+ 'data:application/gltf-buffer;base64' ,
483+ )):
487484 buff_data = gltf_buffer ['uri' ].split (',' )[1 ]
488485 buff_data = base64 .b64decode (buff_data )
489486 elif uri .endswith ('.bin' ):
@@ -538,8 +535,7 @@ def get_buffer_from_accessor(self, gltf_data, accid, unpack=True):
538535
539536 if unpack :
540537 return list (map (convertfn , struct .iter_unpack (f'<{ formatstr } ' , buffdata )))
541- else :
542- return buffdata
538+ return buffdata
543539
544540 def get_texture_stage (self , slot_name , texmode , texcoord ):
545541 texcoord = str (texcoord )
@@ -916,14 +912,17 @@ def load_primitive(self, geom_node, gltf_primitive, gltf_mesh, gltf_data):
916912 accessors = sorted (accessors , key = lambda x : x ['bufferView' ])
917913 data_copies = []
918914 is_skinned = 'JOINTS_0' in mesh_attribs
919- calc_normals = not 'NORMAL' in mesh_attribs
920- calc_tangents = not 'TANGENT' in mesh_attribs
915+ calc_normals = 'NORMAL' not in mesh_attribs
916+ calc_tangents = 'TANGENT' not in mesh_attribs
921917 normalize_weights = False
922918
923- for buffview , accs in itertools .groupby (accessors , key = lambda x : x ['bufferView' ]):
919+ for buffview , accs_unsorted in itertools .groupby (accessors , key = lambda x : x ['bufferView' ]):
924920 buffview = gltf_data ['bufferViews' ][buffview ]
925- accs = sorted (accs , key = lambda x : x .get ('byteOffset' , 0 ))
926- is_interleaved = len (accs ) > 1 and accs [1 ].get ('byteOffset' , 0 ) < buffview ['byteStride' ]
921+ accs = sorted (accs_unsorted , key = lambda x : x .get ('byteOffset' , 0 ))
922+ is_interleaved = (
923+ len (accs ) > 1
924+ and accs [1 ].get ('byteOffset' , 0 ) < buffview ['byteStride' ]
925+ )
927926
928927 varray = GeomVertexArrayFormat ()
929928 for acc in accs :
@@ -1585,18 +1584,18 @@ def calculate_frame_value(frame, path):
15851584
15861585 if interpolation_mode == 'STEP' :
15871586 return output_buff [lastidx ]
1588- elif interpolation_mode == 'LINEAR' :
1587+
1588+ if interpolation_mode == 'LINEAR' :
15891589 nexttime = input_buff [nextidx ]
15901590 lasttime = input_buff [lastidx ]
15911591 lerpfactor = get_lerp_factor (currtime , lasttime , nexttime )
15921592
15931593 if path == 'rotation' :
15941594 return slerp (output_buff [lastidx ], output_buff [nextidx ], lerpfactor )
15951595 return vlerp (output_buff [lastidx ], output_buff [nextidx ], lerpfactor )
1596- else :
1597- return RuntimeError (
1598- f'Unrecognized interpolation mode ({ interpolation_mode } ) found on { bone_name } :{ path } '
1599- )
1596+ raise RuntimeError (
1597+ f'Unrecognized interpolation mode ({ interpolation_mode } ) found on { bone_name } :{ path } '
1598+ )
16001599
16011600 for i in range (num_frames ):
16021601 frame_translation = calculate_frame_value (i , 'translation' )
@@ -1709,7 +1708,7 @@ def create_channels(parent, nodeid, target_names, default_weights):
17091708 + target_weights [nextidx ] * lerpfactor
17101709 )
17111710 else :
1712- return RuntimeError (
1711+ raise RuntimeError (
17131712 f'Unrecognized interpolation mode ({ interpolation_mode } ) found on { target_name } '
17141713 )
17151714
@@ -1866,8 +1865,9 @@ def load_physics_bullet(self, node_name, geomnode, shape_type, bounding_box, rad
18661865 mass = 1.0 if gltf_rigidbody is None else gltf_rigidbody .get ('mass' , 1.0 )
18671866 phynode .set_mass (mass )
18681867 return phynode
1869- else :
1870- print (f"Could not create collision shape for object ({ node_name } )" )
1868+
1869+ print (f"Could not create collision shape for object ({ node_name } )" )
1870+ return None
18711871
18721872 def load_physics_builtin (self , node_name , geomnode , shape_type , bounding_box , radius , height , intangible ):
18731873 phynode = CollisionNode (node_name )
@@ -1975,5 +1975,6 @@ def load_physics_builtin(self, node_name, geomnode, shape_type, bounding_box, ra
19751975
19761976 if phynode .solids :
19771977 return phynode
1978- else :
1979- print (f"Could not create collision shape for object ({ node_name } )" )
1978+
1979+ print (f"Could not create collision shape for object ({ node_name } )" )
1980+ return None
0 commit comments