Author Topic: WIP Blender 2.8x MD2 Importer  (Read 9272 times)

Toolwut

  • Stingray
  • Posts: 60
WIP Blender 2.8x MD2 Importer
« on: April 15, 2020, 02:47:33 AM »
Since there has been no native .md2 support in blender since version 2.4x (2009!) or something and there apparently are no working community made .md2 add-ons for later versions I thought I'd start writing my own one.

What can this importer (!) do so far?
load an MD2 object in blender
either attach the skin linked in the .md2 file or a custom one
load and run animations (in DP2 all animated .md2 files are the flag models in pball/players/male and pball/models/items/flag)

What is missing?
proper error handling (some .md2 files store broken skin pathes (some of the gun models) or ones to files that don't exist)
aligning the animation keyframes to the fps used for the different animations (see https://forums.digitalpaint.org/index.php?topic=28720.msg259085#new)
.pcx is no longer natively supported by blender so I used a different package that unfortunately loads all skins as grayscale ... instead of fixing this I'd prefer jitspoe to finally replace all remaining pcx skins with jpg/png (or tga)

How to install the importer?
put the (extracted) script (attached) somewhere and follow this guide: https://github.com/rlguy/Blender-FLIP-Fluids/wiki/Addon-Installation-and-Uninstallation
install PIL (for loading .pcx files) - use the ensurepip answer here: https://blender.stackexchange.com/questions/5287/using-3rd-party-python-modules

So far this importer isn't useful for anything else but inspecting models (.skm aren't supported btw so you cannot load those models). But it can probably be turned into an import/export script easier than by starting from scratch. Oh and you can export the UV layout in blender and replace a model skin with it, gives a wireframe-ish effect (only on offline servers of course) :).

I'd be thankful for feedback regarding the installation, errors during execution, code readability (coding in blender isn't much fun) etc.

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: WIP Blender 2.8x MD2 Importer
« Reply #1 on: April 22, 2020, 01:22:14 AM »
Kind of crazy how all those old formats (md2, md3, etc) were almost standard formats back in the day, and lots of engines and software supported them.  Then they just... faded away.

CombineS

  • PGP
  • Posts: 4
Re: WIP Blender 2.8x MD2 Importer
« Reply #2 on: September 05, 2021, 09:27:25 PM »
this version is updated? i tried to run on blender 2.83 and i got this


Toolwut

  • Stingray
  • Posts: 60
Re: WIP Blender 2.8x MD2 Importer
« Reply #3 on: September 06, 2021, 03:04:42 PM »
I tried both Blender 2.93 and 2.83 on windows, both should work.

After doing step 1 (installing the script) you must also install pillow (python library for image processing, required for loading pcx skins). Otherwise you get this error message, where the next lines would have said "ModuleNotFoundError: No module named 'PIL'"

For that, please follow this reply (https://blender.stackexchange.com/a/122337). You must open the blender python console as shown on the screenshot (nowadays accessible via the Scripting menu on top). For the second part of that answer, make sure to run the command prompt or windows power shell as administrator if you're on windows. In windows command prompt you might need to replace "./python" with "python.exe". Also, don't install scipy as in that reply, but install "pillow".

I hope this works for you, otherwise please ask again :)



Also ... the code has some parts of reading paths in a non-cross platform way. Might need to update this at some point.

CombineS

  • PGP
  • Posts: 4
Re: WIP Blender 2.8x MD2 Importer
« Reply #4 on: September 06, 2021, 08:58:06 PM »
Now it's working, thank you for the help i was confused  ;D

Toolwut

  • Stingray
  • Posts: 60
Re: WIP Blender 2.8x MD2 Importer
« Reply #5 on: September 29, 2021, 02:51:09 PM »
Glad it works for you now :)

Toolwut

  • Stingray
  • Posts: 60
Re: WIP Blender 2.8x MD2 Importer
« Reply #6 on: March 10, 2022, 03:51:57 PM »
To extend the list of possible applications - with the 3D-Print Toolbox Add-On you can relatively easily turn imported BSP maps into a sliceable STL file :)

Edit: oops I never made a thread (nor a proper Add-on) for my BSP importer. Same still applies for MD2 models, as long as you properly solidify them if needed.

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: WIP Blender 2.8x MD2 Importer
« Reply #7 on: June 03, 2022, 03:27:05 PM »
Ooh, now I want to 3D print some PB2 maps. :)  You have a .bsp importer available somewhere?

Toolwut

  • Stingray
  • Posts: 60
Re: WIP Blender 2.8x MD2 Importer
« Reply #8 on: July 07, 2022, 08:12:22 AM »
Did some refactoring on the MD2 importer. Now it is a folder containing multiple python modules as compared to a single file addon as before. This separates blender-related and parser logic and allows to re-use parsers from other projects.

Also fixed loading of a custom skin path (in most cases for dp, .md2 files don't contain the name of the associated skin) which didn't work (well) on windows systems.

Toolwut

  • Stingray
  • Posts: 60
Re: WIP Blender 2.8x MD2 / BSP Importer
« Reply #9 on: July 07, 2022, 08:24:03 AM »
Added a first, very restricted BSP loader for Blender 2.8x. Other versions are probably not supported because Blender keeps changing it's python API again and again. This probably requires changing add-ons every few months since there seems to be no compatibility between versions by design.

So this add-on can simply be installed via Edit -> Preferences, then Install... on the still zipped file attached. Afterwards activate the script in the same window. Once a map is opened, you will probably need to scale it down by a factor of 0.01 or something.

For 3D printing, you will need to solidify the outer walls as qbsp only keeps faces touching the worldspawn (not sure if this is the right terminology). So in contrast to .map files, a .bsp only contains polygon surfaces and not closed, convex brushes. For solidifying, I added a primitive shape and subtracted the map object from it. Obviously works best if the sky / walls touching the sky are all on the same xy plane. Then I used the 3D printing toolbox add-on I mentioned in a previous post here, I think it fixes some flipped normals or something. Then export as .stl and import that in the slicing program of your choice.

Let me know if you find a better approach for solidifying or if there are any bugs in the (quick and dirty) add-on! :)

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: WIP Blender 2.8x MD2 Importer
« Reply #10 on: August 06, 2022, 12:19:09 AM »
Neat!  Hopefully I can find time to play around with this.

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: WIP Blender 2.8x MD2 Importer
« Reply #11 on: October 17, 2022, 07:34:41 AM »
In case anybody needs an MD2 exporter, I've found this one seems to work with blender 3.3: https://kingpin.info/hosted/hypov8/dl_misc.htm

Note that you need to name the material the full path of the skin (it won't just use what's in the directory), like models/mymodel/myskin.pcx or whatever.

Edit: Just realized I should probably attach this file in case the site veer goes down in the future.
« Last Edit: February 01, 2023, 07:57:13 AM by jitspoe »

Toolwut

  • Stingray
  • Posts: 60
Re: WIP Blender 2.8x MD2 Importer
« Reply #12 on: December 18, 2022, 06:57:43 PM »
Gave it a quick go in blender 3.4. The 'Blender 2.79 Plugins'   doesn't install there anymore but the 'Blender 2.80 Plugins' installs and import / export works smoothly. Only thing I missed was an option for skin import, but maybe that feature got lost in higher blender versions due to API changes.