Skip to content

3) Modifying and extending the plugin

Buu342 edited this page May 20, 2024 · 10 revisions

This page covers how to extend or modify the Blender plugin. It assumes that you already have Python knowledge, and only serves to further document the plugin.

The meat of the plugin

Most of the plugin happens in 3 functions:

  • ObjectExport.execute - Where all the objects in the scene are placed in either meshList or skeletonList, depending on whether a mesh or an armature was found. The settingsList variable contains custom settings that can be selected on export (such as triangulation of the meshes, or only allowing selected models to be exported). This information is then passed into setupData, which returns the final mesh and animation list in a format which will be described shortly, and then calls the writeFile function.
  • setupData - Where each model+animation is disassembled and its information is stored in the finalList dictionary (which contains a collection of S64Mesh objects with each mesh (bone) name being the key) and the animList dictionary (which contains a collection of S64Anim objects, with the action name being the key). The mesh data is created with the assistance of the addFace function. The data is then sorted for efficiency (for instance, grouping all the faces that share materials together, and then correcting the vertex indices to start in order of apperance). These two dictionaries are returned and passed onto:
  • writeFile - Which then takes the finalList + animList dictionaries and writes the .s64 format. If you want to change the plugin to export files in other formats (such as N64 display lists), this is the function you'll want to mess with.

The helper classes

The helper classes are as follows:

Mesh related

S64Vertex

This class contains the information of a single vertex, being:

self.coor = Vector # Vertex coordinate
self.norm = Vector # Vertex normal vector
self.colr = Tuple  # Vertex R G B Color
self.uv   = Vector # Vertex U V coordinates

S64Face

This class contains the information of a single face, being:

self.verts = [] # List of vertex indices that make up this face
self.mat   = "" # Material name for this face

S64Mesh

This class contains the information of a single mesh, being:

self.name  = ""     # Mesh (Bone) name
self.verts = {}     # (Ordered) Dictionary of S64Vertex, with the key being the vertex index
self.faces = []     # List of S64Face
self.mats  = []     # List of materials used by this mesh
self.props = []     # List of custom properties
self.root  = Vector # Bone root location
self.parent = ""    # Parent mesh name

Animation related

S64KeyFrame

This class contains the information of a single mesh's frame data, being:

self.bone  = ""         # Affected mesh name
self.pos   = Vector     # Bone displacement from its rest position
self.ang   = Quaternion # Bone rotation from its rest angle
self.scale = Vector     # Bone scale from its rest size

S64Anim

This class contains the information of a single animation, being:

self.name   = "" # Animation name
self.frames = {} # (Ordered) Dictionary containing a dictionary of S64KeyFrame, 
                 # with the key of the outer dictionary being the keyframe number, 
                 # and the inner key being the mesh name.

Debugging the classes

All the classes are set up to let you convert them to strings via print() or other methods.

By modifying the value of the DebugS64acterExport global variable, you can get the contents of finalList and animList printed to your system console (IE by accessing Window > Toggle System Console. This option is only available on Windows, for other OSes you must start Blender from a terminal. More information available here).