Script to import Blender animations to Studio
Hi all,
I am getting back into 3D stuff after about 20 years (used Vue d'esprit and Poser then). Now I am using Daz Studio and Blender and having fun. I also want to get into scripting and tried a few from mCasual's incredible collection. One I tried is mcjObjsToMorphingProp to import animations from Blender to Studio but somehow it did not work properly, so I decided to write my own.
So I got a very simple script to work (almost by chance since there were a few shots in the dark). It is very short, there is no error checking and no user interface. The actual script is at the end of this post.
The way it works is as follow:
- Export the animation from Blender as a series of OBJ
- Import the first object in Studio
- Import all the objects as morphs using Morph Loader Pro
- Select the object and run the script.
I realised that the statement objRef.getModifier(i) makes it easy the access the morphs one by one. So what the script does is loop througout the morphs and set the value of the morph to 100% if the morph's "number" is equal to the frame number, and sets it to 0% for all the other frames.
I made a quick video with 2 scenes:
One using the animated Sapling Tree add-on and one using the Ocean modifier to create a river.
Note that the script rely on the fact that the morphs seems to always be loaded in the correct sequence by Morph Loader Pro. Also the saved Studio scene can get HUGE.
Improvements are very welcome and if you know of a better way to do this please let me know.
Here's the script:
// DAZ Studio version 4.11.0.383 filetype DAZ Script
var playRange = Scene.getPlayRange();
print("playRange ", playRange);
var Tick = Scene.getTimeStep();
var nTick = Tick.valueOf();
print("tick " , Tick, nTick);
var nodex = Scene.getPrimarySelection();
var objRef = nodex.getObject( );
numMods = objRef.getNumModifiers();
print("numMods ", numMods);
// main loop
// for each morph
for (i = 0 ; i < numMods ; i++)
{
curMod = objRef.getModifier(i);
print(i, curMod.getName());
if( ! curMod )
print("OK")
var prop = curMod.getValueChannel();
print(prop.valueOf());
for (fr = 0; fr < numMods ; fr++)
{
if (fr == i)
prop.setValue( fr * nTick, 1);
else
prop.setValue( fr * nTick, 0);
}
}
// end of script


Comments
So in first scene only tree was from Blender and 2nd Scene only water? Were then both scenes then rendered in Iray in DAZ?
Hi kwannie,
Yes only the tree and the water were from blender and then imported in Daz. In the second scene the sky and mountains were from Bryce. It was all rendered with Iray within Daz. Each scene was rendered in about 12 hours.
Wow, several questions here if you don't mind
How long did it take you to render your scenes in iray, or did you use some other like lux? Sorry about the question ambush but it is very impressive. I really like the trees but it must take forever to render.
Ooopps.........sorry you already said took 12 hours each.......
What a great idea (both script and the forum thread) and it realisation.
I really like, that the script seems to be simple and short enough, to try to understand, how it works.
I have really missed the thread, when one can exchange experiences about scripting and imports from Blender.
Hope that more people will join the thread and share their knowledge.
For the sky I used Bryce's Sky Lab to adjust clouds, sun's position etc. Then I made a scene with nothing in it. In the document setup I set the aspect ratio to 2:1 and the resolution to the maximum of 4000x2000. In the render settings I select the 360 panoramic projection option and render the image. Then you go File / Export Image and save as file type HDR Image Files with format 96 bits per pixel. That HDR file can then be used in Studio's Iray Environment Map with the Draw Dome option set to ON.
It works fine but I think the dynamic range is not as wide as some HDRI images I have seen. I wish I could render the Bryce image with different exposure settings to combine them to improve the dynamic range.
The terrains are simply exported as Wavefront OBJ files. I wish I could find a way to export the materials also. In Vue d'esprit it was easy to create procedural textures for terrains with variations for altitude ans stuff like that. I don't know if this could be done in Studio. I haven't look at the Shader Mixer and Builder yet.
The tree was created using the Sapling Tree add-on that comes with Blender. I am using the new 2.8 version of Blender. The add-on must be activated in user preferences by clicking the <Add Curve:Sapling Tree Gen> option.
Then you create a scene with just the one tree with Add - Curve - Sapling Tree Gen. You then get a menu with multiple panes where you can adjust the geometry, the branches splitting, growth, the animation where you define the wind's parameters etc. I learned mostly from a YouTube tutorial from CG Geek. When you get used to it, a tree can be done in a few minutes. I'll post another video with 2 different trees with different wind settings.
Note that there is also a newer add-on called Modular Tree that produces better looking trees, but they cannot be animated yet however it is sopposed to be coming soon.
Thanks Artini
One thing I would like to improve is find a way to have the animation loop after say 3 seconds and then create aniblocks to be used in aniMate. That would make the size of the Studio file more manageable for longer animations.
Hi kwannie,
Just saw that there is a recent thread where they discuss HDRI from Bryce. See Horo's post in particular.
Made another quick video to show how very different trees can be produced in Blender, with different wind settings. The creation of both trees and the import/setup in Studio took about 15 minutes. Limited the Iray render to 100 iterations per frame for a quick render.
Oh Man!!!!!! This is great information. I love this kind of insight, and I'm so glad you are willing to share. I love using DS and I'm just not well versed on using Blender at all, we all really need to learn to have advantage of its power. Do you think it will ever be possible to bring atomospherics or particles in from Blender. I'm dying to find a way to have a haze effect that I use to make the light cones come out in my concert scenes. I have tried using the philosipher cloud product but can't get it to work as haze (hopefully something that doesn't take iray 15 years to render...lol).
I just noticed that you said you used to use Poser, so I assume you don't have the latest version. Poser Pro can now import FBX files very smoothly. I have thread a thread about MMD (MikuMikuDance) where we were discussing converting FBX files via 3DXchange, so I thought I'd try bringing a MMD FBX with motion into Poser and it work fantastic. The MMD character the motion and even sliders for the morphs all imported in by simply selecting import FBX. There were twist bone issues like we talked about in my tread, but from what I understand you can save files as cr2 and bring them into DAZ. Would love more techniques if you have more insight. Thanks
Kwannie, glad you appreciate it. Regarding what will be possible with Blender I really don't know yet. I last used Vue and Poser about 20 years ago. I just got back into 3D stuff 2 months ago but I spend a LOT of time at the moment because I bought a PC from Costco as they have a 90 day return policy. Wanted to try first to see if it was interested in this. I am quite sure I will go on (would like to make a short movie) , and I am debating if I should buy somethig more powerfull.
The woman's body movements from my first post were imported from mixamo in FBX format and so far it works quite well.
I managed to modify the script to create a looping animation and will post the result later.
I most definately appreciate it, I am constantly trying to get the most out of DAZ, Blender, Gimp or anything that allows for high quality 3D Animation without costing a fortune.
I do not know, if you have tried Daz Studio 4.12 beta. Ivy says it is even faster to make animations in it:
https://www.daz3d.com/forums/discussion/comment/4842966/#Comment_4842966
One can have both versions of Daz Studio installed on the same computer: like 4.11 and 4.12 beta.
Hi
Here's an update regarding my tests with tree animations from blender. First I didn't realise before that the Sapling Tree add-on has an option to produce a looping animation where you can specify the number of frames for the loop. I specified 125 frames. Then instead of loading all 125 .obj files, I only loaded every 4th object and modified the script to create a key frame at every 4th frame. This reduces the size of the .duf file a lot because there are less morphs. And the animation is smooth because of the interpolation between key frames.
But loading every 4th object with Morph Loader Pro is a bit tedious. So I had a look at the "Silent OBJ Morph Loader Import" sample script from Daz (http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/file_io/import_obj_morph_loader_silent/start) and modified it to drop 3 files out of 4. But I got the following error message:
The load mode set is not compatible with mynodename
Looking at the code I don't understand what is being checked so I tought Hey I simply have to remove that check. I ran the script, every 4th morph loaded OK. So I ran my script to generate the keyframes and then oops! The tree does not get morphed but rather it's scale and position are modified. But when I used Morp Loader Pro it works fine. Any help on this would be great, then I could combine the 2 scripts to import the morphs and generate the keyframes in one shot with the possibility to choose the space between keyframes.
Here's a 500 frames video with looping animation using Morph Loader Pro.
WOW, I'm loving this. Blender has so many cool things that would be great to import into DS I saw some physics simulations being brought in from Poser in the same way. I wish there was a way to get volumetric effects into DS like this that did not hugely increase render times.