Spark addon for Blender

BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
edited April 2015 in Mapping
a0d104e4f6273ff09b604cf3571e34.jpg

Hey guys, I'm releasing version 1.0 of a new addon for Blender that let's you transfer geometry (with textures!) from Spark, to Blender, and back again (also with textures!), all through the clipboard -- no more file clutter!!! :D

https://www.dropbox.com/s/mt2epzo9lh7lrtl/io_scene_spark_clip.zip?dl=1

First things first, I've created this to the best of my ability, but there's bound to be bugs in it. Try to avoid using Cut (Ctrl + X) , because if something does go wrong, that clipboard data might be corrupted, and maybe spark crashes and you lose that part of your level... idk, not likely to happen, but let's just play it safe, shall we?

Installation:
- Locate your main blender directory. Mine is "C:\Program Files\Blender Foundation\Blender".
- Inside, you'll find a folder that follows the version number. Mine is "2.71".
- Inside that, you'll find a "scripts" folder, inside that you'll find an "addons" folder.
- Extract the .zip such that your file structure will look like: "scripts/addons/io_scene_spark_clip/*.py"
- Open Blender, go to File -> User Preferences, Addons tab.
- You may have a lot, so filter by "import-export", and you should see an entry called "Import-Export: Natural Selection 2 Spark Geometry IO Script". Enable this one.

Usage:
From Spark to Blender
-Copy the geometry you want to transfer to the clipboard (Ctrl + C). NOTE: Any non-mesh data will be ignored, including layers and groups.
-In Blender, run the "File" -> "Import" -> "Spark Data (from clipboard)" script.
-You'll have a few options in front of you:
--Unit Correction. This make one blender unit equate to 1 Spark inch. Recommend you leave this on, as working with "correct" units in blender is a real nightmare, and it's best to just fool blender into thinking 1 BU = 1 inch.
--Axes Correction. Flips the axes around to match the orientation in both programs. (eg Spark's Y axis is the same as Blender's Z axis). Recommend you leave this on.
--Import Textures. Imports the materials applied to the geometry into blender as both materials AND the UV editor background textures.
--(5) Paths: These 5 paths are where the script will look for the corresponding .material file. By default, only the first one is used, and it's set to "C:\Program Files (x86)\Steam\steamapps\common\Natural Selection 2\ns2\". IMPORTANT: In order for texture importing to work, you MUST have valid paths here. If the script cannot find the textures, the import will replace them with dummy materials.
--In addition to the main ns2 folder, you can add additional paths to search in here. For example, I have my ns2 folder in path 1, and for path 2 I have "C:\Users\Trevor Harris_2\Desktop\Dropbox\ns2_temple\output\" This means the importer will search your mod's output folder for any additional textures if it can't find them in the ns2 folder. Yay custom content! NOTE: Ensure that the path you write in here is the OUTPUT folder, not the source folder. The script searches for .material files, then loads up the .dds textures into the materials from there.
--Please note that unless you save a preset with buttons at the top, you'll have to enter these paths in every time, which would be a huge pain in the butt! Just do it once, save a preset, and be happy!! :D

From Blender to Spark
-Select the mesh objects you want to export, and run the "File" -> "Export" -> "Spark Data (to clipboard)" script.
-You'll be prompted with a few options:
--Selection only. Exactly what it sounds like. Within Blender, you can break your mesh up into as many objects as you want. If this is enabled, only the selected objects will be exported. Otherwise, all visible objects will export.
--Unit Correction and Axes Correction are exactly the same as in the import script.
--Export Textures. This is substantially easier than importing, as all there is to do is strip off everything on the file path before and including the "ns2" or "output" folder. No paths to mess with! :)

Additional Notes
-When exporting textures, the material that is exported has NOTHING to do with the blender material, and EVERYTHING to do with the UV texture applied to the individual face. The blender materials are only setup as a nice convenience... also because some albedo maps have alpha channels for transparency, so if we only view the UV maps in the viewport, most, if not all, will be transparent and hard to see.
TLDR: Ensure that the material you want the face to have is the same one that is applied in the UV edtior, not the materials. Obviously the .material isn't being read by blender, so to export, the .material is replaced with .dds. Ensure that the materials you are using are named after their albedo map. (Example: if you want to use biodome_floor_01.material on a face, in blender, set the UV texture of that face to biodome_floor_01.dds)
-If the exporter cannot find a material, it will be replaced with "materials/dev/dev_1024x1024.material"
-If the importer cannot find a texture, it will be replaced with a dummy material, and no UV texture will be applied.
-Mapped materials (ie those that are created in spark using the "displacement tool") will import just fine, but exporting them is NOT currently supported.
-"Smooth" edges in spark are imported and exported correctly from Blender. They will appear as "Sharp" edges in Blender. However, there is a bug with Blender where edges will not appear to be sharp (cyan highlighting), until the user makes a change to the sharpness. So if you import a mesh with some edges marked to be smooth in spark, in order to see them in Blender, select an edge at random, and (in edit mode) "Ctrl + E" -> "Mark Sharp" to mark that edge as sharp in Blender (which we're just interpreting as "smooth" in Spark), and all the sharp edges will turn the right color.
-Faces that had holes in them in spark are triangulated, as Blender does not support having holes in faces.

Special Thanks
Special thanks to @Max for providing some insight and some code into how to triangulate faces with holes in them.

If you find any bugs, please provide a screenshot of the Blender console ("Window" -> "Toggle System Console"). Make sure you maximize it vertically and scroll as far up as the bottom line so I can see what's going on. If you find a bug that makes the spark editor crash, send me the .blend file you're exporting with.

Known issues
-Textures on faces with holes are a little bit off when imported into Blender.

Changelog
4-7-15
-Updated the scripts to work with Blender 2.73 and 2.74. Hopefully will be a while before Blender decides to break them again! :) Thanks @UncleCrunch !

3-10-15
-Fixed an issue that would cause entirely colinear (and therefore invalid) faces to crash when attempting to import. They are now ignored.

2-6-15
-Fixed an issue that would cause faces with holes to not triangulate properly.
-Fixed an issue caused merging vertices to "close" a hole in a face, but leaving behind a zero-length hole.

1-25-15
-Fixed an issue that would prevent vertices from using the proper coordinate system.
-Fixed an issue where some faces would be lost if exporting multiple objects.
-Fixed an issue where materials would not be indexed properly.
-Un-checking "Export Textures" actually does something now... (d'oh!!!).

12-27-14 (slightly later ;) )
-Fixed the "ValueError: faces.new(...) found the same (BMVERT) used multiple times" error. Invalid faces will be discarded.
-Fixed a divide by zero error caused by inline vertices.

12-27-14
-Fixed an issue where faces with holes in them would sometimes be flipped around the wrong way.
-Fixed an error caused by faces sharing all vertices (eg double-sided glass that has been merged). Double sided faces will be imported as single-sided faces.
-Changed how the triangulation algorithm figures out how to "flatten" a polygon. Previous method was giving incorrect results, and made some faces with holes refuse to import.

11-24-14
-Adjusted the tolerance values for determining if a polygon is "flat" or not to bring them more in line with spark. Very slight deviations in height in otherwise flat polygons should no longer cause a discrepancy between the visual position of the texture in spark and in blender.
-Fixed a bug caused by faces that had holes in them at one time, but were closed up. Spark was still reporting some inner edge loops, but the loops were empty. *facepalm* The cheese shop sketch from Monty Python comes to mind. Sure he claims it's a cheese shop, but there doesn't seem to be any cheese inside.
-Fixed a divide-by-zero caused by trying to calculate a normal vector for 3 inline vertices.

11-22-14
-Fixed a bug that would cause some "holy" polygons to not import properly.
«13

Comments

  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    edited November 2014
    Fixed a couple of bugs today. One that made texture angles go nuts sometimes, and one that was really spark's fault (thanks spark!!!).

    EDIT: AAaannnd another one. Can't calculate a normal vector from 3 inline points!!! Stupid Beige...
  • Rudy.czRudy.cz Join Date: 2012-02-13 Member: 145410Members
    Wow, this is great thing. I am planning to convert some geometry to Props for better performance and this one just comes in really handy.
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    edited November 2014
    Rudy.cz wrote: »
    Wow, this is great thing. I am planning to convert some geometry to Props for better performance and this one just comes in really handy.

    Thanks Rudy!

    EDIT: @Nordic what's there to disagree with buddy? XD
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    Anybody been using this? Been awfully quiet...
  • HowserHowser UK Join Date: 2010-02-08 Member: 70488Members, NS2 Playtester, Squad Five Blue, Reinforced - Shadow, WC 2013 - Shadow, Subnautica Playtester, Retired Community Developer
    NO ONE LIKES A SMARTASS! :lol:
    this is still a really cool tool. Nice one mate
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    Howser wrote: »
    NO ONE LIKES A SMARTASS! :lol:
    this is still a really cool tool. Nice one mate

    *beams with pride*
  • NordicNordic Long term camping in Kodiak Join Date: 2012-05-13 Member: 151995Members, NS2 Playtester, NS2 Map Tester, Reinforced - Supporter, Reinforced - Silver, Reinforced - Shadow
    BeigeAlert wrote: »
    Howser wrote: »
    NO ONE LIKES A SMARTASS! :lol:
    this is still a really cool tool. Nice one mate

    *beams with pride*
    I imagine it like this.
    5678.png
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    Nordic wrote: »
    BeigeAlert wrote: »
    Howser wrote: »
    NO ONE LIKES A SMARTASS! :lol:
    this is still a really cool tool. Nice one mate

    *beams with pride*
    I imagine it like this.
    5678.png

    WHY YOU DISAGREE WITH ME THANKING RUDY?????
  • NordicNordic Long term camping in Kodiak Join Date: 2012-05-13 Member: 151995Members, NS2 Playtester, NS2 Map Tester, Reinforced - Supporter, Reinforced - Silver, Reinforced - Shadow
    Misclick? I don't remember clicking anything.
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    Nordic wrote: »
    Misclick? I don't remember clicking anything.

    It's okay... I forgive you ;)
  • NordicNordic Long term camping in Kodiak Join Date: 2012-05-13 Member: 151995Members, NS2 Playtester, NS2 Map Tester, Reinforced - Supporter, Reinforced - Silver, Reinforced - Shadow
    BeigeAlert wrote: »
    Nordic wrote: »
    Misclick? I don't remember clicking anything.

    It's okay... I forgive you ;)

    You better. I gave you a snorlax beaming!
  • ArchieArchie Antarctica Join Date: 2006-09-19 Member: 58028Members, Constellation, Reinforced - Supporter, WC 2013 - Supporter
    edited December 2014
    Thanks man works awesomely, doesn't like large files though (but that's my fault) ;D I'd love to donate for your continued work and editing of these to add new features.
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    nizb0ag wrote: »
    Thanks man works awesomely, doesn't like large files though (but that's my fault) ;D I'd love to donate for your continued work and editing of these to add new features.

    No need to donate, but I am happy you guys like it!

    I am curious what you mean by "doesn't like large files". Should work with any size... are you getting an error message or something?
  • ArchieArchie Antarctica Join Date: 2006-09-19 Member: 58028Members, Constellation, Reinforced - Supporter, WC 2013 - Supporter
    Yeah, i think i accidentally tessellated the geometry, that's why it had a problem (but rightly so), Don't know if it was the size of the actual map though for some reason my map size was like 80mb (LOL) without tessellation.
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    edited December 2014
    nizb0ag wrote: »
    Yeah, i think i accidentally tessellated the geometry, that's why it had a problem (but rightly so), Don't know if it was the size of the actual map though for some reason my map size was like 80mb (LOL) without tessellation.

    Reflection probes are by far the biggest contributor to map file size because each one of them caches their cubemap in the file itself -- they're not generated at loadtime. Without those, how big is your map? It really should work with any size map... I'm intrigued.
  • ArchieArchie Antarctica Join Date: 2006-09-19 Member: 58028Members, Constellation, Reinforced - Supporter, WC 2013 - Supporter
    been trying to get 3dsmax with bsp imported into into it > blender (with textures) but i cannot, i really am looking forward to this kind of feature, i actually need it for some secret rooms/project im doing.

    Great work though.
  • SamusDroidSamusDroid Colorado Join Date: 2013-05-13 Member: 185219Members, Forum Moderators, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    edited December 2014
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    nizb0ag wrote: »
    been trying to get 3dsmax with bsp imported into into it > blender (with textures) but i cannot, i really am looking forward to this kind of feature, i actually need it for some secret rooms/project im doing.

    Great work though.

    Not 100% sure what you mean, but if you mean it's in 3dsmax correctly, I'd say your best bet is to use OBJ to transfer between max and blender.
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    Can I ask a theoretical question?

    If I was to take a section of a NS2 map, export the whole thing to Blender, then export it as a model. Would I be able to load it in Future Perfect?

    Thinking of a laszy way to get GorgeCraft maps into Future Perfect :P
  • SamusDroidSamusDroid Colorado Join Date: 2013-05-13 Member: 185219Members, Forum Moderators, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    Theoretically yes but nothing would have any collision
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    Soul_Rider wrote: »
    Can I ask a theoretical question?

    If I was to take a section of a NS2 map, export the whole thing to Blender, then export it as a model. Would I be able to load it in Future Perfect?

    Thinking of a laszy way to get GorgeCraft maps into Future Perfect :P

    Wouldn't have any props.

    As for collision.... I don't know how future perfect handles collision meshes. I mean... it's completely separate from the visual mesh, but I don't know if it requires convex hulls or not... haven't played around with it much.
  • ArchieArchie Antarctica Join Date: 2006-09-19 Member: 58028Members, Constellation, Reinforced - Supporter, WC 2013 - Supporter
    Because with 3dsmax I have bsp maps which have been converted to .obj files with all textures, 3ds max loads all textures to relevant locations.

    I was just assuming if I could 3dsmax > blender then textures could show too, but blender doesn't like those texture file positions. 3ds 2015 and 2009 actually imports as either single mesh or triangulated polygons I was using 2015 with wallworm mods to convert to hl2 and rip textures.
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    nizb0ag wrote: »
    Because with 3dsmax I have bsp maps which have been converted to .obj files with all textures, 3ds max loads all textures to relevant locations.

    I was just assuming if I could 3dsmax > blender then textures could show too, but blender doesn't like those texture file positions. 3ds 2015 and 2009 actually imports as either single mesh or triangulated polygons I was using 2015 with wallworm mods to convert to hl2 and rip textures.

    I'm not sure I follow. Blender isn't loading these images?
  • SamusDroidSamusDroid Colorado Join Date: 2013-05-13 Member: 185219Members, Forum Moderators, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    edited December 2014
    You could just import bsp with materials into blender
  • ArchieArchie Antarctica Join Date: 2006-09-19 Member: 58028Members, Constellation, Reinforced - Supporter, WC 2013 - Supporter
    edited December 2014
    I did try that and no matter what I do the textures won't know where to be placed however samus but they do load into blender. Doesn't spark have material/texture format support with conversion from valve vmt or something I was reading the wiki in which place 3ds >blender>spark should work assuming texture placements somehow transfer across, or blender>spark

    Bsp legacy import into blender refuses texture import.
  • SamusDroidSamusDroid Colorado Join Date: 2013-05-13 Member: 185219Members, Forum Moderators, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    Using 2.68 with v0.0.5 of the bsp importer worked for me. He updated it and it works now
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    nizb0ag wrote: »
    I did try that and no matter what I do the textures won't know where to be placed however samus but they do load into blender. Doesn't spark have material/texture format support with conversion from valve vmt or something I was reading the wiki in which place 3ds >blender>spark should work assuming texture placements somehow transfer across, or blender>spark

    Bsp legacy import into blender refuses texture import.

    What do you mean by "textures won't know where to be placed", I have no clue what that means. Do you mean the UV coordinates aren't transferring, or Blender doesn't know the file path of the texture files... come on, help me out here man.
  • ArchieArchie Antarctica Join Date: 2006-09-19 Member: 58028Members, Constellation, Reinforced - Supporter, WC 2013 - Supporter
    edited December 2014
    edit, seems to be working now thanks samus, i was using 2.67 it didn't seem to like the textures :|

    t4ubuxk3.3sf.png

    Now stuck with this, is this because blender can't export the textures?
  • InsaneInsane Anomaly Join Date: 2002-05-13 Member: 605Members, Super Administrators, Forum Admins, NS1 Playtester, Forum Moderators, NS2 Developer, Constellation, NS2 Playtester, Squad Five Blue, NS2 Map Tester, Subnautica Developer, Pistachionauts, Future Perfect Developer
    Soul_Rider wrote: »
    Can I ask a theoretical question?

    If I was to take a section of a NS2 map, export the whole thing to Blender, then export it as a model. Would I be able to load it in Future Perfect?

    Thinking of a laszy way to get GorgeCraft maps into Future Perfect :P

    That seems possible to me. It's certainly worth trying.
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited December 2014
    Why would the model not have collision @SamusDroid‌ ? Surely, all I would have to do is make a blueprint for it, and add a collision component...

    @BeigeAlert‌ - Have you seen my GorgeCraft maps? Apart from gc_crevice, and some rock props in the other maps, I don't have any props in the maps..
Sign In or Register to comment.