Module import_nif :: Class NifImport
[hide private]
[frames] | no frames]

Class NifImport

source code

nif_common.NifImportExport --+
                             |
                            NifImport

A class which bundles the main import function along with all helper functions and data shared between these functions.

Instance Methods [hide private]
 
__init__(self, **config)
Main import function: open file and import all trees.
source code
 
importRoot(self, root_block)
Main import function.
source code
 
importBranch(self, niBlock)
Read the content of the current NIF tree branch to Blender recursively.
source code
 
importArmatureBranch(self, b_armature, niArmature, niBlock, group_mesh=None)
Reads the content of the current NIF tree branch to Blender recursively, as meshes parented to a given armature or parented to the closest bone in the armature.
source code
 
importName(self, niBlock, max_length=22, postfix='')
Get unique name for an object, preserving existing names.
source code
 
importMatrix(self, niBlock, relative_to=None)
Retrieves a niBlock's transform matrix as a Mathutil.Matrix.
source code
 
decompose_srt(self, m)
Decompose Blender transform matrix as a scale, rotation matrix, and translation vector.
source code
 
importEmpty(self, niBlock)
Creates and returns a grouping empty.
source code
 
importArmature(self, niArmature)
Scans an armature hierarchy, and returns a whole armature.
source code
 
importBone(self, niBlock, b_armature, b_armatureData, niArmature)
Adds a bone to the armature in edit mode.
source code
 
find_correction_matrix(self, niBlock, niArmature)
Returns the correction matrix for a bone.
source code
 
getTextureHash(self, source)
Helper function for importTexture.
source code
 
importTexture(self, source)
Convert a NiSourceTexture block, or simply a path string, to a Blender Texture object, return the Texture object and stores it in the self.textures dictionary to avoid future duplicate imports.
source code
 
getMaterialHash(self, matProperty, textProperty, alphaProperty, specProperty, textureEffect, wireProperty, bsShaderProperty, extraDatas)
Helper function for importMaterial.
source code
 
importMaterial(self, matProperty, textProperty, alphaProperty, specProperty, textureEffect, wireProperty, bsShaderProperty, extraDatas)
Creates and returns a material.
source code
 
importMaterialControllers(self, b_material, n_geom)
Import material animation data for given geometry.
source code
 
importMaterialUVController(self, b_material, n_geom)
Import UV controller data.
source code
 
getMaterialIpo(self, b_material)
Return existing material ipo data, or if none exists, create one and return that.
source code
 
importMesh(self, niBlock, group_mesh=None, applytransform=False, relative_to=None)
Creates and returns a raw mesh, or appends geometry data to group_mesh.
source code
 
importTextkey(self, niBlock)
Stores the text keys that define animation start and end in a text buffer, so that they can be re-exported.
source code
 
storeBonesExtraMatrix(self)
Stores correction matrices in a text buffer so that the original alignment can be re-exported.
source code
 
storeNames(self)
Stores the original, long object names so that they can be re-exported.
source code
 
getFramesPerSecond(self, roots)
Scan all blocks and return a reasonable number for FPS.
source code
 
store_animation_data(self, rootBlock) source code
 
find_controller(self, niBlock, controllerType)
Find a controller.
source code
 
find_property(self, niBlock, propertyType)
Find a property.
source code
 
find_extra(self, niBlock, extratype)
Find extra data.
source code
 
set_parents(self, niBlock)
Set the parent block recursively through the tree, to allow crawling back as needed.
source code
 
markArmaturesBones(self, niBlock)
Mark armatures and bones by peeking into NiSkinInstance blocks.
source code
 
complete_bone_tree(self, bone, skelroot)
Make sure that the bones actually form a tree all the way down to the armature node.
source code
 
is_bone(self, niBlock)
Tests a NiNode to see if it's a bone.
source code
 
is_armature_root(self, niBlock)
Tests a block to see if it's an armature.
source code
 
get_closest_bone(self, niBlock, skelroot)
Detect closest bone ancestor.
source code
 
get_blender_object(self, niBlock)
Retrieves the Blender object or Blender bone matching the block.
source code
 
is_grouping_node(self, niBlock)
Determine whether node is grouping node.
source code
 
set_animation(self, niBlock, b_obj)
Load basic animation info for this object.
source code
 
importBhkShape(self, bhkshape)
Import an oblivion collision shape as list of blender meshes.
source code
 
importHavokConstraints(self, hkbody)
Imports a bone havok constraint as Blender object constraint.
source code
 
importBSBound(self, bbox)
Import a bounding box.
source code
 
getUVLayerName(self, uvset) source code
 
importKfRoot(self, kf_root, root)
Merge kf into nif.
source code

Inherited from nif_common.NifImportExport: get_bone_name_for_blender, get_bone_name_for_nif, get_extend_from_flags, get_flags_from_extend, msg_progress

Class Variables [hide private]
  BONE_CORRECTION_MATRICES = ([0.000000, -1.000000, 0.000000](ma...
  IDENTITY44 = [1.000000, 0.000000, 0.000000, 0.000000](matrix [...
  R2D = 0.0174532925199

Inherited from nif_common.NifImportExport: EXTRA_SHADER_TEXTURES, USED_EXTRA_SHADER_TEXTURES, progress_bar

Method Details [hide private]

importArmatureBranch(self, b_armature, niArmature, niBlock, group_mesh=None)

source code 

Reads the content of the current NIF tree branch to Blender recursively, as meshes parented to a given armature or parented to the closest bone in the armature. Note that niArmature must have been imported previously as an armature, along with all its bones. This function only imports meshes and armature ninodes.

If this imports a mesh, then it returns the a nif block and a mesh object. The nif block is the one relative to which the mesh transform is calculated (so the mesh should be parented to the blender object corresponding to this block by the caller). It corresponds either to a Blender bone or to a Blender armature.

importName(self, niBlock, max_length=22, postfix='')

source code 

Get unique name for an object, preserving existing names. The maximum name length defaults to 22, since this is the maximum for Blender objects. Bone names can reach length 32.

Parameters:
  • niBlock (NiObjectNET) - A named nif block.
  • max_length (int) - The maximum length of the name.
  • postfix (str) - Extra string to append to the name.

importArmature(self, niArmature)

source code 

Scans an armature hierarchy, and returns a whole armature. This is done outside the normal node tree scan to allow for positioning of the bones before skins are attached.

getTextureHash(self, source)

source code 

Helper function for importTexture. Returns a key that uniquely identifies a texture from its source (which is either a NiSourceTexture block, or simply a path string).

getMaterialHash(self, matProperty, textProperty, alphaProperty, specProperty, textureEffect, wireProperty, bsShaderProperty, extraDatas)

source code 

Helper function for importMaterial. Returns a key that uniquely identifies a material from its properties. The key ignores the material name as that does not affect the rendering.

importMesh(self, niBlock, group_mesh=None, applytransform=False, relative_to=None)

source code 

Creates and returns a raw mesh, or appends geometry data to group_mesh.

Parameters:
  • niBlock (NiTriBasedGeom) - The nif block whose mesh data to import.
  • group_mesh (A Blender object that has mesh data.) - The mesh to which to append the geometry data. If None, a new mesh is created.
  • applytransform (bool) - Whether to apply the niBlock's transformation to the mesh. If group_mesh is not None, then applytransform must be True.

importTextkey(self, niBlock)

source code 

Stores the text keys that define animation start and end in a text buffer, so that they can be re-exported. Since the text buffer is cleared on each import only the last import will be exported correctly.

storeBonesExtraMatrix(self)

source code 

Stores correction matrices in a text buffer so that the original alignment can be re-exported. In order for this to work it is necessary to mantain the imported names unaltered. Since the text buffer is cleared on each import only the last import will be exported correctly.

storeNames(self)

source code 

Stores the original, long object names so that they can be re-exported. In order for this to work it is necessary to mantain the imported names unaltered. Since the text buffer is cleared on each import only the last import will be exported correctly.

complete_bone_tree(self, bone, skelroot)

source code 

Make sure that the bones actually form a tree all the way down to the armature node. Call this function on all bones of a skin instance.

is_grouping_node(self, niBlock)

source code 

Determine whether node is grouping node. Returns the children which are grouped, or empty list if it is not a grouping node.

importKfRoot(self, kf_root, root)

source code 

Merge kf into nif.

*** Note: this function will eventually move to PyFFI. ***


Class Variable Details [hide private]

BONE_CORRECTION_MATRICES

Value:
([0.000000, -1.000000, 0.000000](matrix [row 0])
[1.000000, 0.000000, 0.000000](matrix [row 1])
[0.000000, 0.000000, 1.000000](matrix [row 2]),
 [1.000000, 0.000000, 0.000000](matrix [row 0])
[0.000000, 1.000000, 0.000000](matrix [row 1])
[0.000000, 0.000000, 1.000000](matrix [row 2]),
 [1.000000, 0.000000, 0.000000](matrix [row 0])
[0.000000, 0.000000, 1.000000](matrix [row 1])
...

IDENTITY44

Value:
[1.000000, 0.000000, 0.000000, 0.000000](matrix [row 0])
[0.000000, 1.000000, 0.000000, 0.000000](matrix [row 1])
[0.000000, 0.000000, 1.000000, 0.000000](matrix [row 2])
[0.000000, 0.000000, 0.000000, 1.000000](matrix [row 3])