GithubHelp home page GithubHelp logo

baddogskyrim / pynifly Goto Github PK

View Code? Open in Web Editor NEW
153.0 9.0 14.0 552.72 MB

Export/Import tools between Blender and the Nif format, using Bodyslide/Outfit Studio's Nifly layer. Supports Skyrim LE, Skyrim SE, Fallout 4, Fallout New Vegas, Fallout 76, and Fallout 3.

License: GNU General Public License v3.0

C++ 37.20% C 1.39% Python 60.71% CMake 0.70%

pynifly's Introduction

PyNifly

Export/Import tools between Blender and the Nif format, using Bodyslide/Outfit Studio's Nifly layer. Works with official Blender versions 3.0 and higher. Can handle nifs for Skyrim LE, Skyrim SE, Fallout 4, and Fallout 76, Fallout New Vegas, and Fallout 3.

Windows only.

Full documentation in the wiki.

Features

  • Supports FO4, Skyrim LE, Skyrim SE
  • Handles tris and base mesh in one step. No need to separate UV seams or triangulate before exporting
  • Handles expression and chargen tri files for Skyrim and FO4
  • Import tris into an existing mesh or on their own
  • Supports Bodyslide tri files on import and export for body morphs
  • Handles multiple bodyweights in one step. Export _0 and _1 armor weights for Skyrim from a single mesh.
  • Handles Skyrim and FO4 partitions and FO4 segments
  • Handles skinned and unskinned meshes correctly. Exports head parts to SE correctly.
  • Handles shaders correctly. Set them up in Blender and export.
  • Import-and-forget. What you import will behave correctly on export without fiddling.

Background

Outfit Studio has working export/import for a bunch of the Bethesda games. I'm a modder and I've been using the niftools scripts for years, but I've started modding for Fallout 4 and there's no direct support for that at all.

BS/OS has separated much of their code to deal with nif files into a separate library, nifly. I've used this library and some additional OS code as the core of an export/import addon for Blender.

My interest is primarily Skyrim, Skyrim SE, and Fallout 4 so I'll be focusing on supporting those games.

Status

Import/Export of most nifs is complete works well.

Import/Export of animations is currently under development.

Import/Export of Skyrim collisions is complete except for MOPP collisions. Those may never happen. Fallout 4 collisions are not implemented but there's a tool that ships with Fallout to help with that. Check the Collisions page of the wiki (https://github.com/BadDogSkyrim/PyNifly/wiki/Collisions) for more.

pynifly's People

Contributors

baddogskyrim avatar enpinion avatar jgernandt avatar zenithval avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pynifly's Issues

Import errors

Skimpy/Vampire/Clothes.blend - body does not export correctly if body + clothes exported together
General Carius's armor doesn't import correctly

If a boundary between partitions coincides with a boundary between UV areas, when the vert is split to handle the UV

Improved handling of tri files

  • If the mesh has a "BODYTRI" extradata, look for the tri file and load it with the body if present
  • Select multiple nif files and export them together as one mesh with shape keys (is this even possible with the file selector UI?)
  • AND/OR on import, if the current selection has the same number of verts as the new file, load the new file as a shape key

Are these good ideas?

Pretty sure that the issue with texture files wasn't fixed

So today, I tried to import .nif file into blender, but it said that some texture files weren't found. But of course they weren't-first off, the file paths of the supposedly missing files skipped one of the folders, and the console window had two backslashes in between each folder of the file path to the files that were supposedly missing. None of the folders or file names have backslashes in them. I have confirmed that all three texture files are, in fact, on my computer, they just aren't in the exact same folder. Like for example-this isn't the real file path, but just to give an idea-two of the textures may be located in C:\Users\MyUserName\Desktop\SEObjects\Objects Vanilla\Textures\textures\stuff\sovngarde (the third one has the same file path up until the folder named textures) whereas the mesh might be located in C:\Users\MyUserName\Desktop\SEObjects\Objects Vanilla\Meshes\meshes\stuff\sovngarde
I'm using blender version 2.90.
I'll copy and paste what the console window said below, and then edit my username out of all the file paths (so the text doesn't seem to want to paste properly, so I'll bold the file paths that have two backspaces between each folder):
Read prefs: C:\Users\MyUserName\AppData\Roaming\Blender Foundation\Blender\2.90\config\userpref.blend
found bundled python: C:\Users\MyUserName\Downloads\blender-2.90.0-windows64\blender-2.90.0-windows64\2.90\python
Info: Deleted 1 object(s)

Warning: This script was written Blender version 2.92.0 and might not function (correctly), though it is enabled

Must select an object to export
Must select an object to export
. . Some texture files not found: ['C:\Users\MyUserName\Desktop\Skyrim Creation Kit Objects\Objects Vanilla\textures\architecture\sovngarde\SOVFloor02.dds', 'C:\Users\MyUserName\Desktop\Skyrim Creation Kit Objects\Objects Vanilla\textures\architecture\sovngarde\SOVFloor02_n.dds', '', '', 'C:\Users\MyUserName\Desktop\Skyrim Creation Kit Objects\Objects Vanilla\textures\cubemaps\ShinyBright_e.dds', '', '', '', '']
Import of nif failed
Traceback (most recent call last):
File "C:\Users\MyUserName\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\io_scene_nifly_init_.py", line 895, in execute
NifImporter.do_import(self.filepath, flags)
File "C:\Users\MyUserName\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\io_scene_nifly_init_.py", line 853, in do_import
imp.execute()
File "C:\Users\MyUserName\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\io_scene_nifly_init_.py", line 814, in execute
self.import_shape(s)
File "C:\Users\MyUserName\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\io_scene_nifly_init_.py", line 668, in import_shape
obj_create_material(new_object, the_shape)
File "C:\Users\MyUserName\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\io_scene_nifly_init_.py", line 242, in obj_create_material
import_shader_attrs(mat, bdsf, shape)
File "C:\Users\MyUserName\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\io_scene_nifly_init_.py", line 184, in import_shader_attrs
shader.inputs['Emission Strength'].default_value = attrs.Emissive_Mult
KeyError: 'bpy_prop_collection[key]: key "Emission Strength" not found'
Must select an object to export
Button '' in menu 'TIME_MT_editor_menus' is a menu item with unsupported RNA type 5

Misplaced bones not handled correctly

When a body has its bones in a non-standard position (DIMONIZED UNP female body) the body is imported with the bones in that position. Then when you try to import a body part with bones in the normal position, it's imported with an offset.

Not clear what the fix should be. Import to standard position always? Apply the same offset to any subsequent imports?

Corrupt Tri error due to UV coordinates not equal to vertices

"Number of verticies differs from number of UV coordinates: 918 != 996
TRI file has valid header, but file appears to be corrupt
!! Since 'Base Verticies' != 'UV Coordinates', file is probably corrupt.
However, if TRI file is not corrupted, then it is possible that Author's
assertion regarding TRI files always correlating V and UV array indices
might be wrong.
Probably should post if you see this error and are sure file is not corrupt"

I was trying to import the tri files from the expressive facial expressions mod for Skyrim SE. The tri imports with a different tool and works in game. I assume this means it's not corrupt.

Import certain tri file failed

Downloads.zip
file is part of Trophihunter's work, which can be easily found on his site.
I can't get "IKAROSBaseFemaleHeadChargen.tri" into Blender but another similar file "BaseFemaleHeadChargen.tri" could.
The console told me if it's corrupted or it's caused by mod auther.
I believe it's not corrupted on my hand since I've tried from scratch for 2 times and these attempts are several months apart.
I also wonder if it's caused by mod auther so I've downloaded another mod using the same mesh and it worked, but I'm aware of these tri files differ from size.
The mod haven't been updated for quiet a time, I wonder if this tri file will work in game cuz I don't have fo4 on my pc right now.
I guess this is not a issue but this is the best place I could find to ask a question :)

Handle directx normal maps on import

Directx tangent space normal maps have an inverted green channel compared to opengl normal maps (the format blender uses).

I have been fixing it by inverting the green channel in the shader like so:

InvertGreen

Would be cool if pynifly could do this automatically on import, like it separates red and on the specular maps.

Results:

Directx (inverted green)

directx-normals

OpenGL (non-inverted green)

opengl-normals

Mesh causes CTD on export

FO4 "Meshes\Actors\Supermutant\CharacterAssets\SMArmor0_Torso.nif" causes a crash on re-export from Blender.

PF_START_NET_BONESET is on all partitions

I have tested it with Skyrim SE meshes.

Generally good, but when there are multiple partitions of BSDismemberSkinPartition, this plugin attaches the flag PF_START_NET_BONESET is on all partitions.
This is only required for the first partition. Multiple flags will cause a crash.

I'm very happy that PyNifly is here, because niftools doesn't support Fallout 4 or Skyrim SE.

Non-Character Armatures

Seems like I ran into an edge case. You can test yourself using a bow weapon from SSE. Imports fine but the armature is blown apart on export. It does not do this for character related nifs, so my guess was that you didnt add the needed bits to handle that particular armature case?

I found a workaround for now, using the olde blender 2.83 and niftools addon, convert nif to LE then import to blender, tinker, then export and bones etc are all in place. So no rush or demands or anything, you may not even want this feature, since mostly nifly is for character stuff anyhow, still I thought I'd let ya know just in case its useful.

Can't enable plugin

Traceback (most recent call last):
File "...\Blender 3.0\3.0\scripts\modules\addon_utils.py", line 351, in enable
mod = import(module_name)
File "...\Blender\3.0\scripts\addons\io_scene_nifly_init_.py", line 91, in
def transform_to_matrix(xf: TransformBuf) -> Matrix:
NameError: name 'TransformBuf' is not defined

Settings in export dialog should be remembered

When exporting an object I choose a destination path and set the game target in the export dialog.
At the moment these settings are not remembered in the next export.

In my view the settings should be remembered per session alternatively persisted.

Handle imported shapes with transform/rotate overrides

I guess it is a bad practice, but some nifs including BGS's nifs have the transform/rotation values overridden in the shape node.

Example nif: Fallout 4 - SetDressing/Vehicles/Crane03.nif

  1. Open the nif in NifScope and find the BSTriShape named 'Glass:0'
  2. Right click on the BSTriShape node and select Transform/Edit

See the shape's translation and rotation is not reset / applied (or what it is called)

PyNifly seems to ignore the shape node transform/rotations.

I guess this is not a high priority issue, but nice to know as it seems like many users does transform edits in e.g. NifScope etc.

Feature Suggestion: Copy Custom Properties

It would be awesome to be able to transfer/copy custom properties as part of the plugin for easier set up of root nodes, collision, extra data, etc.

I did find a script that can do this here: https://blenderartists.org/t/addon-copy-custom-properties/591562
It seems to work okay for me. There's an updated version for Blender 3.0+ if you scroll down the comments. It's released under a GNU General Public License, so I believe you could even redistribute it with your plugin if you wanted.
Or maybe just add a link to it somewhere in the wiki as a suggested resource. :D

OSError: exception: access violation reading 0x0000000000000000

I'm batch importing a bunch of Skyrim SE files and I've occasionally run into this exception when processing some .nif files:

Import of nif failed
Traceback (most recent call last):
  File "C:\Users\scott-gig\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_nifly\__init__.py", line 895, in execute
    NifImporter.do_import(self.filepath, flags)
  File "C:\Users\scott-gig\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_nifly\__init__.py", line 853, in do_import
    imp.execute()
  File "C:\Users\scott-gig\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_nifly\__init__.py", line 814, in execute
    self.import_shape(s)
  File "C:\Users\scott-gig\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_nifly\__init__.py", line 668, in import_shape
    obj_create_material(new_object, the_shape)
  File "C:\Users\scott-gig\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_nifly\__init__.py", line 242, in obj_create_material
    import_shader_attrs(mat, bdsf, shape)
  File "C:\Users\scott-gig\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_nifly\__init__.py", line 177, in import_shader_attrs
    attrs = shape.shader_attributes
  File "C:\Users\scott-gig\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_nifly\pynifly.py", line 940, in shader_attributes
    NifFile.nifly.getShaderAttrs(self.parent._handle, self._handle,
OSError: exception: access violation reading 0x0000000000000000

I'm using PyNifly V1.3

One example .nif that does this is meshes/clutter/woodfires/spitpotopen01.nif from within Skyrim Special Edition/Data/Skyrim - Meshes0.bsa
I've uploaded it here for quicker access: spitpotopen01.zip

Outfit Studio appears to open it without error.

I can list some more files with the same exception if it's helpful.

Vertex bone weights not limited to 4

Seems like the export is not limiting bone weights to 4 automatically. This can be fixed in blender in Weight Paint mode, Limit Totals, Deform Bones only, but it should be done automatically on export.

Wrong weights when skeleton is not renamed

When the skeleton is not renamed upon importing (unticking the rename option), weights are still assigned to the .L / .R bones. The weights with the original bone names are empty.

bonz

Possible scale issue

So when I used this addon to import a .nif file-specifically a vanilla floor mesh from SSE-I had issues with clipping. Also, upon further investigation, I learned that just one side of the floor mesh was 1680 ft long, which was waaaaaaaaaaaaay too big to be realistic, so I opened that mesh in the Skyrim Creation kit, and used my own method to measure the mesh. It turned out to be either 12 ft sq or 24 ft sq.
TLDR: I have reason to believe that the addon scales meshes waaaaaaaaaaaaaay up and then applies the transformations during the conversion process. I would like it to not do that.

Suggested improvement to handling materials

Right now PyNifly loads the specular, splits the channel, plugs the red channel (Spec) into Blender's specular, and then Green (Gloss) into Blender's Metallic. The former is okay, but the latter is wrong. Green should be inverted and plugged into Roughness, since Roughness is literally just inverse of Glossiness.

In theory any FO4 materials using an envmap would also have the Spec (red) plugged into Blender's Metallic, but unless you can somehow read the .BGSM files to check for the "Environment Map" flag, I'd say it'd be safer to just leave Blender's Metallic node alone.
Also the normal map node only inverts the green channel by default, which makes sense because Blender wants OpenGL normals but FO4 uses DirectX ones. But since most FO4 normal maps are mainly saved as BC5 (i.e. they have no blue channel), you'd also need to invert the blue channel itself. I've had trouble with normals looking wonky because Blender expected a full white blue channel but got a full black one instead.
So basically:

For speculars, invert green channel and plug it into Roughness. (Also remove green channel from Metallic).

For normals, also invert the blue channel and not just the green one.

Imported armature not working well with animations

please skip first 2 sections and just go to third section directly.

any bone with name like Lxxxx or Rxxxx will be renamed to xxxx.L or xxxx.R.
this is fitting blender habbit but I just can't apply anim to armature unless I change these names manually or by code.
wishing to have a checkbox to enable the function :)

after checking the code I found out that this is not a issue but a feature, so I wrote a file with blender text editor to solve the naming problem.
so the nearest animating tutor for FO4 I can find is F4AK, which is finally released in 2016, and that's a bit too old, there are many different naming conflicts bwtween skeleton in F4AK's outputted .fbx anims and skeleton we are using now, but this is not a big problem as it can be easily fixed in blender.
what's confusing me now, is the anim still looks weird after the problem above solved.
I downloaded CBBE modder file and game file and imported them seperately with blender fbx importer and pynifly.
pynifly imported armature is not working good.
I will give a .blend file to show the result. It seems like a result of wrong bone base rotation, but after I tried all bone axis combination importing anim.fbx, none of them give a correct result.
so i assume it a none unified problem, so far I can't find a clue to solve it.
PS:I'll seperate talking and files cuz github keeps resetting link.
and I dont think it's caused by nif files cuz they work in game(should be working, I've just played fo4 for story ).

Unnecessary multiple-partitions warning reported

If the boundary between partitions coincides with the boundary between UVs, when the system splits the verts along the boundary, some faces may end up in both partitions. The system will only consider a face in a partition if ALL its verts are in the partition, so after the splitting happens all the other verts that make up the face have to be in the partition. BUT since the verts are split they aren't in the initial mesh so the verts can't be added to the MULTIPLE_PARTITIONS error partition. See the panther male head.

Feature Request: Collision Export

Thank you so much for the great work! This addon works so much easier than the Niftools addon and it actually WORKS without hours of tweaking.

The primary reason I have been working with Niftools is because it has a method to setup a collision object and export it to a Physics collision object in the NIF so my models function as intended. (At least that's the idea - I cannot get it to work.)

Can you please look into implementing this same feature so our custom meshes behave properly once put in the game instead of having the need to try to find "like-shaped / like-sized" items in-game and importing/exporting their physics data? This doesn't work in all cases.

Thanks!

Linux Support

While blender runs natively, this plugin seems to only support Windows. I just wanted to know whether you plan to support other platforms in the future. nif -> OS -> obj -> Blender and the reverse work but there are a few inconveniences.

Feature Request: import / export models with (optional?) front facing -Y

Right now pynifly imports models with their front facing Y. This is what blender calls back:

image

This is mostly fine, but the studio / materials lights have to be adjusted, and there are a few symmetry issues with some addons (retopoflow) expecting the front to be the front.

Outfit studio outputs objs the correct way (for blender anyways) while nifskope outputs objs like pynifly.

Version 4.0.0 Exports Meshes to BSDynamicTriShapes when no Shape Keys Exist

Hello,

I've run into an issue with the most recent release (v 4.0.0) where exporting meshes to Skyrim SE will result in a Nif file with a BSDynamicTriShape even when no shape keys are present in the object data.

Importing a vanilla Skyrim SE mesh and exporting it to Skyrim SE without any changes still results in a BSDynamicTriShape being created for me, so unless I've completely missed something, I think there's a bug related to detecting shape keys.

I'm using Blender version 3.1.0 to export the meshes.

Please let me know if there's more information I can provide that'll help. And thanks for creating this awesome tool!

ssf file limit

Can't return a ssf file name longer than 48 characters.

Skyrim SE femalehead.tri can not import for facegen head.nif

I hope to edit old cusotm follower facegen in blender. then follow wiki. Import facegen.nif have no problem. but without import tri files. exported (from blender) nif not generate BSDynamicTriShape node. then I get the BSTriShape nodes for the facegen nif.

So I try to import femalehead.tri (it should be much as current face part mesh = FemaleHeadNord object.) with select the head part. as object mode. Then I only get these error log .

Traceback (most recent call last): File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_nifly\trihandler.py", line 391, in from_file tri.read(file) File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_nifly\trihandler.py", line 313, in read raise ValueError("Error reading TRI file") ValueError: Error reading TRI file Import of tri failed Traceback (most recent call last): File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_nifly\__init__.py", line 1125, in execute import_tri(self.filepath, bpy.context.object) File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_nifly\__init__.py", line 1006, in import_tri log.debug(f"Selected mesh vertex match: {len(cobj.data.vertices)}/{len(tri.vertices)}") AttributeError: 'set' object has no attribute 'vertices'

My blender version is 2.93 LTS

I use MO2 as mod manager, then test both case (running blender from MO2 then load from virtual data directory / directly load file without use MO2. it show same error. and not generate shape keys. so it seems not matter.

At same time, Is there way without import tri, but just edit and export se face gen nif but generate as BSDynamicTriShape? I do not plan to edit face tri morphs. but just need detail adjust for face gen meshes. About LE version mesh, I have way to copy and paste vertex position only with nif scope. or nif tools.. but about SE, we do not have the way I think.. (it corrupt nif)

Exporter doesn't create NiTriStrips for FONV

Ousnius says:

  • NiTriShape will generally work in game, tho might not render as fast
  • The foundations for writing NiTriStrips are there but the nifly code doesn't do it
  • Also the code always triangulates skin partitions with NiSkinPartition (implies NiTriStrips don't need triangulation?)

So likely could export TriStrips but will require code paralleling the nifly layer.

Figure out how draugr are handled

Draugr clothes don't import & export consistently with the body. Import a draugr--export just the skirt--try and copy the exported skirt into a draugr nif using nifskope. whatup?

Quality of life : Apply modifiers on export

It would be nice to have an option to 'auto apply' all modifiers in the export dialog.

  1. Create a standard cube
  2. Add a bevel modifier
  3. Export with nifly

Actual result: The bevel modifier is not applied on the result nif
Expected: Have an option in the export dialog to apply all modifiers. See the built-in obj exporter.

I guess the vanilla obj exporter just applies modifiers in the order as seen in the UI/modifier stack (e.g. from top to bottom)
Probably not ideal in some cases, but better than nothing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.