Lugaru Map Import / Export scripts for Blender

The place to discuss all things Lugaru.
User avatar
rudel_ic
official Wolfire heckler
Posts: 2193
Joined: Sun Aug 28, 2005 11:19 pm
Location: Hamburg City
Contact:

Lugaru Map Import / Export scripts for Blender

Post by rudel_ic » Wed May 05, 2010 10:34 pm

You can now load, edit and merge maps with Blender.

You can get the scripts in a ZIP archive right here: viewtopic.php?f=7&t=5620&p=232622#p232622
(Used to be http://www.alice-dsl.net/wolf.mathwig/tools/py/ -- not anymore though)


These scripts really only handle object placement. Character starting points, enemies, dialogues et cetera should be edited with Lugaru or other third-party tools.

Here's some help regarding the other things you might want to do as a modder:
viewtopic.php?f=7&t=6297

The objects this stuff is interested in is the immobile meshes in a map. This is the list of files the script bothers with:
- Box.solid
- Weird.solid
- Spike.solid
- Treetrunk.solid
- Leaves.solid
- Bush.solid
- Rock.solid
- Wall.solid
- Chimney.solid
- Platform.solid
- HIDDEN (no file)
- Tunnel.solid
- Cool.solid
- FIRE (no file)

The zip file you download at the above URL contains a Blender project named lugarumapping.blend and the script files for importing and for merging.
You want to install the scripts before opening the .blend file.

I strongly recommend you start with opening lugarumapping.blend every time you want to make a new map.

Image
lugarumapping.blend setup (click for full view)

Workflow:
- Open lugarumapping.blend
- Import a map that has the objects you want to place
... - If you import a map from a location where there's no .solids in ../Models/,
..... the previously existing template meshes will be used (see Layer 2)
- Duplicate, delete, translate, rotate, scale objects
- WYSIWYG - What You See Is What You Get
- Don't switch to Edit Mode
- Start the merging script (File -> Lugaru map merge...)
- Choose a map to merge with. Click "Merge Map".
... - If you choose a map named MYMAP, the merge result will be in MYMAP.merge
... - The merge script only replaces objects. It replaces all immobile objects. Everything else in the map stays the same.


Limitations:
- Only operate on Layer 1. Layer 2 is reserved for template meshes.
- Do not duplicate template meshes from Layer 2 to Layer 1. You need to import some map that has the objects you need instead. Use those imported objects. The objects in Layer 2 don't have the right properties set.
- The maximum number of objects in a map is 299. This limitation comes from Lugaru.
- You can only rotate around the X and the Z axis. This limitation comes from Lugaru.
- ScaleX sets the general scale. If you scale ScaleY and ScaleZ in some crazy way, it won't affect the outcome.
- The Z jitter that's built into the terrain of Lugaru isn't represented. So some objects may be further in the ground than they appear.
- In general, the heightmap displacement is a rough approximation. It's good enough though.
- Fire is displayed as a text saying FIRE in red
- Hidden stuff is displayed as a text saying HIDDEN in black
- Meshes are UV-mapped, but the textures aren't loaded automatically for a bunch of reasons

Sweet features:
- If you want to change the heightmap, choose one in the Texture View (bottom, middle).
Image
Don't forget to load it beforehand in the UV/Image View (bottom, right).
Image
After you've chosen a new heightmap, click once into "Texture: heightmap" in the displacement modifier (bottom, left) and press Return. The new heightmap is then applied.
Image

- The template meshes will be re-imported every time you import a new map. So if you have N sets of template meshes, I recommend making N template data folders, like this:
TEMPLATE_1/
---------------Data/
--------------------Models/
----------------------------Box.solid
----------------------------Weird.solid
----------------------------(et cetera)
--------------------Maps/
----------------------------map1
----------------------------map2
----------------------------(et cetera)
TEMPLATE_2/
---------------Data/
etcpp.
The advantage is that when you import map1 from the folder TEMPLATE_K/Data/Maps/, the script automagically pulls the matching meshes from the folder TEMPLATE_K/Data/Models/.

Good to know:
- Lugaru's Rotation1 is in 30° increments (meaning that if you choose 57.2°, you end up with 30°)
- Lugaru's Rotation2 is in 1° increments (meaning that if you choose 121.06°, you end up with 121°)
- Leaves are rotated randomly around the local Y axis (up local) unless you have more than 2° in Rotation2
- Bushes are always rotated randomly around the local Y axis (up local)

Useless knowledge for map editing in Lugaru:
- Rocks have a weird rotation scheme: Rotation2 is Rotation1*7+Rotation2. Meaning that if you rotate a Box by 150° and 55° and a Rock has the exact same mesh, then the Rock would have to be rotated by 150° and 1105° to match orientation (or 150° and 25°)
- Platforms have a similar thing with Rotation2 being Rotation2+90° (so if you rotate a Platform by 0° and 37° and a Box has the exact same mesh, then the Box would have to be rotated by 0° and 127° to match orientation)

I've dealt with all this in my scripts though, so you can rotate away and go by what you see in Blender no matter what kind of .solid you have on your hands. It's completely transparent.
One thing I might add later is rounding to the nearest 30° / 1° increment upon export on the proper axis, together with applying rotation increments as Lugaru exports them if it's wanted. It's not really essential though.

READ THE THREAD please. It helps.

I guess that's really all you have to know. Ask away if something isn't clear to you.
Last edited by rudel_ic on Thu Jan 08, 2015 8:17 am, edited 3 times in total.

User avatar
Sandurz
Posts: 1105
Joined: Wed Dec 31, 2008 10:55 pm
Location: My House

Re: Lugaru Map Import / Export scripts for Blender

Post by Sandurz » Wed May 05, 2010 10:59 pm

Dude, YOU ARE AWESOME! All of this stuff you keep coming out with is really bad ass!

User avatar
rudel_ic
official Wolfire heckler
Posts: 2193
Joined: Sun Aug 28, 2005 11:19 pm
Location: Hamburg City
Contact:

Re: Lugaru Map Import / Export scripts for Blender

Post by rudel_ic » Wed May 05, 2010 11:08 pm

Thank you!

If you guys need a hotkey reference for Blender: http://wiki.blender.org/index.php/Doc:R ... otkeys/Map

User avatar
Lotus Wolf
Posts: 2218
Joined: Sun Aug 31, 2008 6:03 pm

Re: Lugaru Map Import / Export scripts for Blender

Post by Lotus Wolf » Sun May 09, 2010 11:37 am

Once again, magnificent work rudel! Like the other scripts I'll use them when I get some time to sit down with them and check back with you. Great job rudel!

melior
Posts: 2
Joined: Thu May 13, 2010 10:05 am

Re: Lugaru Map Import / Export scripts for Blender

Post by melior » Thu May 13, 2010 10:23 am

Quick question, rudel_ic:

Would you have an issue relicensing your scripts to GPLv2? Mostly for simplicity's sake, since the current license appears to be compatible with GPL. I was thinking icculus could make a Tools folder in his repository and these would make a great addition.

User avatar
rudel_ic
official Wolfire heckler
Posts: 2193
Joined: Sun Aug 28, 2005 11:19 pm
Location: Hamburg City
Contact:

Re: Lugaru Map Import / Export scripts for Blender

Post by rudel_ic » Thu May 13, 2010 12:42 pm

melior wrote:Quick question, rudel_ic:

Would you have an issue relicensing your scripts to GPLv2? Mostly for simplicity's sake, since the current license appears to be compatible with GPL. I was thinking icculus could make a Tools folder in his repository and these would make a great addition.
Sure, but I'll have to fix some stuff first. Expect a license switch upon next release. Thanks for the suggestion!

User avatar
Lotus Wolf
Posts: 2218
Joined: Sun Aug 31, 2008 6:03 pm

Re: Lugaru Map Import / Export scripts for Blender

Post by Lotus Wolf » Mon May 31, 2010 10:16 pm

Just finished messing with it. I like it, it works, and I'll be using for my projects!

User avatar
rudel_ic
official Wolfire heckler
Posts: 2193
Joined: Sun Aug 28, 2005 11:19 pm
Location: Hamburg City
Contact:

Re: Lugaru Map Import / Export scripts for Blender

Post by rudel_ic » Tue Jun 01, 2010 6:39 am

Lotus Wolf wrote:Just finished messing with it. I like it, it works, and I'll be using for my projects!
Good to hear! If it breaks something, hit me.

User avatar
ChosenOne
Posts: 46
Joined: Sat Jul 17, 2010 4:00 pm

Re: Lugaru Map Import / Export scripts for Blender

Post by ChosenOne » Mon Jul 19, 2010 9:35 pm

You speak of Z axis mesh jitter for Lugaru's terrain. I've found that only Snow and Sand do this. Grass does not.

I edited heightmap.jpg to be entirely black. Even with a black heightmap Snow and Sand still had arbitrary Z jitter. Grass didn't.

Physically, it makes sense, too. You're going to have random little mounds of piled up snowdrifts in a snowy place and likewise in a desert. Though I'd rather it not be there. You see the issues it causes when you hit "J" and switch environments. Plus, it makes the heightmap inaccurate.

I would like to eliminate that in my mod. It's very annoying IMO.


Oh, and BTW. Yes, I got your scripts working. But not getting the expected results.


*EDIT Do you think it would it work to use your script to import the Lugaru map into Blender, then export that to 3D Studio Max format for modifying, then export back to Blender, then use your export script to get the map back into Lugaru format? Or might object properties be lost?

User avatar
rudel_ic
official Wolfire heckler
Posts: 2193
Joined: Sun Aug 28, 2005 11:19 pm
Location: Hamburg City
Contact:

Re: Lugaru Map Import / Export scripts for Blender

Post by rudel_ic » Tue Jul 20, 2010 2:25 am

If something's not working as you'd expect it to, please point out what your expectation and what your result is.
You can save the .blend, zip it and attach that to a post also. If you're using custom .solid meshes, you'd have to include them, of course.
ChosenOne wrote: I would like to eliminate that in my mod. It's very annoying IMO.
That shouldn't be a problem. Don't know where it comes in, but it's some if-clause that looks at the environment kind. Should be easy to spot. Start at heightmap.png read and dig your way down.
ChosenOne wrote: *EDIT Do you think it would it work to use your script to import the Lugaru map into Blender, then export that to 3D Studio Max format for modifying, then export back to Blender, then use your export script to get the map back into Lugaru format? Or might object properties be lost?
Yeah, you'd lose vital object properties.

User avatar
ChosenOne
Posts: 46
Joined: Sat Jul 17, 2010 4:00 pm

Re: Lugaru Map Import / Export scripts for Blender

Post by ChosenOne » Tue Jul 20, 2010 1:33 pm

Ok, for the record everyone, Rudel's system is working great for me. We've PM'ed a bit about it, but just wanted to make known that it does work as intended.

This mod may take a while, but at least it's able to move forward.

User avatar
ChosenOne
Posts: 46
Joined: Sat Jul 17, 2010 4:00 pm

Re: Lugaru Map Import / Export scripts for Blender

Post by ChosenOne » Sun Jul 25, 2010 5:43 pm

Ok, update on using the script. It's still functioning for me. But it's inaccuracy is killin' me.

When the stationary Lugaru map objects are imported into BLender, their coordinates get fudged around. This makes it incredibly difficult to create multi-shape structures. Creating any sort of architecture is extremely time-consuming because you basically have to guess how far you need to move objects so that they're positioned correctly.

See an example:

Image

This depicts "map4", or the 4th challenge level.

Top of image: I imported map4 into Blender and moved the 9 cubes around very precisely so that their corners are touching. I then used the export script.
Bottom of image: Flying above the cubes in their new positions, you can see where they're placed at run-time. Quite a difference. (I highlighted the top edges of each cube in pink for clarity, ignore the test checker texture)

And the bigger the objects the more inaccurate their placement seems to become.

Rudel, I applaud you for your brilliant work so far. And thanks for taking the time to create the scripts and release for everyone!
But, I didn't see this coming when I set out to create my new campaign. If I can't find a way to get around the difficulty of level design in Lugaru I'll have to abort my campaign. It's simply too time-consuming. I feel foolish spending hours just to create a few rooms. But that's what it takes to get the results I'm after.
Apparently the level design caliber I'm going for is beyond Lugaru's scope. I believe David never intended for anyone to do what I'm trying to do in map mode.

Though, if the import script placed objects accurately in Blender, so that everything matched the game world, I could sufficiently circumvent Lugaru's inherent level design limitations.

Perhaps determining the X,Y and Z differences in placement could be used to amend the import script with an opposite offset for each object.

User avatar
rudel_ic
official Wolfire heckler
Posts: 2193
Joined: Sun Aug 28, 2005 11:19 pm
Location: Hamburg City
Contact:

Re: Lugaru Map Import / Export scripts for Blender

Post by rudel_ic » Sun Jul 25, 2010 10:17 pm

Hmm, the script just directly writes the placement. Must be either scaling inaccuracy or rounding issues. Weird that I didn't catch this though, I thought I tackled with something like it already.

My guess is that there's some stupid mistake on my part in the mesh import part of the map importer.

I'll take a look next weekend. I'll make super-certain that all values are identical on both ends. Can't get at it earlier though, sorry. I'm really busy and stuff.

The game principially can handle accurate object placement just fine as far as I know. I'll check the code though, just in case there's something fishy going on. The rotations are rather inaccurate though.

Don't give up, you're the first guy who really uses this thing in a productive manner. With all the wildcards involved, something was bound to break eventually. We'll figure this out for sure.

Question: Did you make sure that the rotations were as accurate as Lugaru handles them?
One of the axes is in 1° increments, the other in 30° increments. If you mimic this inaccuracy in Blender, results should be identical in terms of rotation. Otherwise, stuff gets rounded, I guess? Not sure.

Edit: Oh, if you could mail the Blender project and the map file from your example above zipped to [email protected] — that would be great. Or attach the zip file to a post.

User avatar
ChosenOne
Posts: 46
Joined: Sat Jul 17, 2010 4:00 pm

Re: Lugaru Map Import / Export scripts for Blender

Post by ChosenOne » Mon Jul 26, 2010 2:06 am

Ah you're willing to revise the script, awesome!

The rotations may be off as well. I read what you wrote about Lugaru snapping to certain increments of rotation. So you're right, it could be a combo of scale, rotation and location. Yikes.

I didn't save the above pictured example. So, instead I created a new one for you. Just cropped out a chunk of a level where the behavior is well apparent - some multi-shape architecture created by tons of back and forth trial and error tweaking. Play the map and you see everything is fit together quite well, but in Blender it's a different story.


Image

Perhaps a simpler more straight-forward example would be better. I can send you another if you like.

Check PM's for link.

bossmonster
Posts: 2
Joined: Sat Jul 31, 2010 5:34 pm

Re: Lugaru Map Import / Export scripts for Blender

Post by bossmonster » Sat Jul 31, 2010 5:39 pm

In line 127 of lugaru_map_import.py, it says:

Code: Select all

factor = 0.25
Change that to

Code: Select all

factor = 0.3
Save the script

If Blender is currently running, quit Blender

Start Blender

Import your map (the script now uses the correct factor)

Fix stuff by moving etc

Merge map

Post Reply