View Full Version : Morphs2OBJs - New script for LW to Unity 3D with Megafiers

07-16-2011, 07:31 AM
Hey all,

In case you are using the amazing mesh modifier add-on for Unity 3D, Megafiers, which among its many features adds morphing in the game engine, I've created a new script to aid the workflow between Lightwave and Unity - especially if you are using Mega-Fiers.

This Modeler script Morphs2OBJs exports morphmaps (Endomorphs) as separate OBJ files in one click. It's not rocket science by any means, however I find it useful since I haven't seen a script that does it.

Btw Mega-Fiers allows you to use your standard FBX model/scene from LW as usual in Unity but allows you to use external OBJ files as the morph maps (since morphmap data is not obtainable in the LWO to FBX conversion or the FBX import into Unity). So instead of manually exporting each morphmap, this script does it for you. Plus it ensures your General Options settings will export them in a way that works. Once exported from the script, just load the gameobject into Unity and load the exported OBJs. Add the morphing component and voila - morphing works a charm! If you use Unity, I highly recommend Mega-Fiers (http://www.west-racing.com/megadoc/) from the Unity Asset store (I am not related to the company) as it works great with Lightwave - and this free script improves its workflow for LW users.

However, this script is probably also useful for other reasons as well, possibly including working with Poser or Daz 3D. Or for anyone who wants to export morphs out as OBJs for other applications.

Here's what my script looks like:

There's a readme included for more info and some sample objects to test with. Feel free to critique or give feedback if it is useful etc. I've incorporated my MsgBox script in it to make it a bit more responsive and intelligent in various situations - though it may not be 1000% bulletproof.

Hope it saves someone some time. :)

07-18-2011, 06:10 PM
Really Nice! Thanks for sharing!

07-24-2011, 11:58 PM
cool. hope it's useful. Let me know if you have any problems with it and I'll tweak it...

08-08-2011, 01:35 PM
Heya Sami! This looks like a REALLY useful plugin. :) But i'm having an issue...

I'm in 10.1 and whenever it run the plugin to export all my shapes i get an error as foolows...

line 219, illegal arithmetic operation on data type

Any clue there?

BTW i'm on a mac running OSx 10.6

08-09-2011, 05:06 AM
I'm still on 9.6.1 and it works fine. I've tested it in Win 7 32bit and 64bit versions of Modeler and it's fine. I'll test it on the mac in 9.6.1 too if you like, but off the top of my head I'm not sure what that problem is. I plan to upgrade to 10.x between projects sometime in September. I'll also have a look at line 219 and let you know if I see anything obvious I can quick fix without actually having 10 to try it out on. Sorry I can't be of more immediate help. I'll post after I have a look...

08-09-2011, 05:18 AM
Thanks for this.
Tested on lw 9.6 and lw 10.1 and works great.

08-09-2011, 05:26 AM
Haven't tested it on Mac Modeler 9.6.1 yet, but I just had a look at the source code. Turns out line 219 was a comment - but line 218 (the line at the end of this code snippet) might be the culprit...

// Validate that User hasn't entered a crappy folder name
var validateSaveFolder;
var sfDrive;
var sfPath;
var sfFile;
var sfExt;

(sfDrive,sfPath,sfFile,sfExt) = split(saveFolder);

validateSaveFolder = matchdirs(sfDrive + sfPath,"*.*");
Only it DOES work in LW 9.6.1 Lscript. Is there a link to a v 10.x LScript release notes someone could point me to? Lscripters who use v10.x, is there any reason a simple string concatenation would work in 9.6.1 but fail in 10.1?

Has matchdirs() changed for LW10? I can try and concatenating that in a separate variable and then passing it in if that may fix the 'illegal arithmetic' issue...?

If there's a quick fix I'll recompile and reupload the fix. Sorry I can't be of more help without me having LW10 to test it in. :)

08-11-2011, 04:10 AM
bpritchard, are you still having issues with the script? Could you please try restarting Modeler and ONLY loading JUST the model with the morphs you want to export and then retry the script? It is possible this script is not bulletproof when multiple objects with multiple morphs are loaded at the same time.... I'll keep checking though.

08-11-2011, 05:28 AM
Hi !

Thanks for this great tool :)
I'm starting to use Unity, and would like to use morphs on bones animated objects inside Unity... Do you know if it's possible, or has some limitations ?

I'm also planning to do a lwo import script for Unity (and maybe lws), if you are interested to share ideas on this subject, send me a private message ;)

08-11-2011, 03:01 PM
I haven't had a change to try it like you said.. i'll give it a whirl tonight.

08-21-2011, 08:48 PM
Hi Alexx,
I use the third-party addon Mega-fiers for morphing within Unity. Unity gives you access to vertices in C#, but instead of "rolling-my-own" I bought Mega-fiers and it is awesome. Morphing with that on my boned FBX rigs exported from LW works fine in Unity. With boned objects I've used the morphing primarily for facial expressions and mouth shapes and it seems to work fine.

08-22-2011, 11:46 PM
Hi Sami,

Thanks very much for making this available. Do you know what would be involved with importing morph mixer animation data into Mega-Fiers to accompany this script, in the same way that Chris has done for Max?

08-25-2011, 06:50 PM
Hi Sami,

Thanks very much for making this available. Do you know what would be involved with importing morph mixer animation data into Mega-Fiers to accompany this script, in the same way that Chris has done for Max?

Hi jonny,

In Unity, I don't tend to use the editor Animations as I usually do all my animations in code or have them embedded in the FBX. I view the Unity editor Animations much like the timeline in Flash - useful for banner ads ;) or people who don't code, but most of the time I find it more robust and flexible to code the animations or just access them from within the content (the FBX) as opposed to having yet another timeline (on top of the LW channel envelopes and the dynamic tweening using iTween in the C# code in Unity).

Sorry for the diatribe, just I don't see too much value (for me) for using that editor animations. But to answer your question, I think the pseudo-code/algorithm would be something like this:

enumerate the scene's objects
enumerate each object's channels
determine which were morphmixer channels
enumerate that channels keyframes
transfer scene/object/keyframes of morphmixer to Unity's animation timeline (or Mega-fiers MorphAnimation Component)

Without rewriting a new FBX importer for Unity (which would be a big job) and assuming that the existing Unity FBX importer does not import MorphMixer data or at least have access to it (Chris knows much more about the specifics of the Unity FBX importer than I do), then we would need a way to transfer that morph mixer animation from LW to Unity with some intermediate file or LWS reader in Unity.

Sorry I can't be of more help, and at this stage for me the benefits of me doing that are not great enough to warrant the time it would take me to do it - I just don't have the free time - but if anyone else wanted to do that and needed a hand or if I could assist a little, I'd be happy to do so :)

Probably not the answer you wanted, but hope it helps a bit...

08-28-2011, 12:26 PM

Thanks for your reply :)

09-01-2011, 06:38 PM
Thanks for the reply Sami,

That's a bit of overkill :p

I just meant parsing the text file that Motion Mixer exports (with keyframe/channel data), and recreate the keys in the existing channels in Unity. I was going to ask my coder to look at it, and I thought since you'd been looking at Mega-Fiers that you might have some tips.

04-18-2012, 04:39 AM
Nice, haven't seen this until now! Good job! :thumbsup:

07-09-2012, 12:28 AM
Just tried to use this again and something wierd is going on.
In another pc it exports the morphed obj fine but using another pc it exports all obj with no morphs. Is there a config file for this plugin that can be reset?
Also in lw 11.01 there's an error 21026.

07-09-2012, 12:43 AM
Deleted configs on the other pc. Still exporting non-morphed objs.

07-10-2012, 08:00 AM
Deleted configs on the other pc. Still exporting non-morphed objs.

Hi geo_n,

Sorry youre Having trouble with the script. I've got 11.01 and it works for me. I will test further though. Have you made sure that you start Modeler fresh with ONLY the object with the morphs you want to export? Modeler LScript cannot distinguish which morph maps belong to which object in LScript. And are you certain that you've selected all the morphs you want to export from the list box? Also, can you try exporting the morphs for the included sample object?

If none of this works for you can you send me your object to test with and see what's wrong?


07-10-2012, 08:02 AM
Btw are you on Mac or PC? I haven't tested this on Mac yet. I have both systems but don't have LW installed on Mac cuz traditionally it was WAY buggier than PC LW so I never tried again...

07-10-2012, 08:06 AM
One more thing, there is a switch that sets a Zbrushmode and other Modeler OBJ settings correctly for exporting OBJs which work with other apps. If the settings in Modeler are not correct, then it may not export correctly, hence my switch which should set them right... Check the pc that it didn't work on and see if that is the difference...

01-14-2013, 11:31 AM
I've decided to delete the attachments that I've been posting to the forums and host them myself so that my plugins can easily be found in one place. I've also added them to the LWPluginDB with tags and info.

If you are looking for the plugin that was the original attachment for this thread, you can now find it here (http://phtn.me/appsmorphs2objs) (along with its updates and other plugins). Hope that makes things easier. :)