Script Needed: Semi-Dynamic Cloth Idea

Lord_AshesLord_Ashes Posts: 91
edited December 1969 in Art Studio

I just discovered Blender. It is a free open source 3D modeling software.

I have not played with it much but I did not that Blender does have a Dynamic Cloth engine.

Since Daz Studio's Dynamic Cloth engine is very limited (i.e. you can not make your own dynamic clothing), I was thinking if it would be possible to combine Blender with Daz Studio. Basically build the dynamic clothing in Blender and then export them to Daz.

I found that if I export an animation from Blender, there is a option to export to OBJ. This generates one OBJ (and one material) file per frame. Although it would be a pain in the butt to insert each frame into Daz Studio (without a script to do so quickly), this would be one possible way to get some dynamic cloth into Daz Studio.

The problem is that this would be great for something like a hanging curtain, flag or some other cloth that does not have interaction with figures in the scene but, as far as I can see, it still could not be used to make clothing because it would require bringing the Daz figures into Blender (probably possible if you export as OBJ from Daz and import into Blender) and then posing them in the exact same way that you would pose them in Daz Studio so that the cloth can be properly simulated.

This would defeat the whole purpose of using Daz Studio because you would end up modeling it in Blender and then again in Daz Studio (so you might as well just use Blender).

The only solution that I can think of is a compromise solution...it would not be true dynamic cloth simulation but it could make Daz Studio clothing a little more realistic. Basically create the clothing in blender with some movement. For example, a little swing to the bottom of the dress. In addition create any additional sequences which may be needed, such as the dress bottom flying up a bit (for spinning and/or jumping movement). Then one can import these into Daz Studio and use the Transfer Utility to attach them to the Daz Studio figure in whatever pose he/she is in. As far as Daz Studio will be concerned these are all just individual objects but strung together they will give the dress some flow. Of course this also means that one would need to swap out the different instances of the same object...which would need, once again, a script.

Can anyone think of an easier way to do this?

Comments

  • Lord_AshesLord_Ashes Posts: 91
    edited December 1969

    I am new to Daz3D and thus, at this point, know absolutely nothing about scripting Daz3D. However, I have what I believe to be a good idea for implementing semi dynamic clothing in Daz Studio.

    As everyone probably knows, Daz Studio has conforming clothing (via Genesis and the Transfer Utility) which allows different models to use the same clothing. However, although this clothing conforms to model poses it can look stiff. Daz Studio also has a Dynamic Cloth plugin but it only allows users to use pre-made clothing with no support for making your own clothing. So I think I have come up with a way to generate clothing that is a little more dynamic than conforming clothing but does not have the full functionality of dynamic clothing.

    Blender is a free open source software which contains a dynamic cloth engine. I have found that it can be used to export an animation using a series of OBJ (and material) files. These should be compatible with Daz Studio. As such, one should be able to make whatever clothing they want in their favorite modeling software, import it into Blender using an OBJ file, run the dynamic cloth simulation to add some flow to the clothing and then export it as a series of OBJ files.

    These OBJ files (along with their material files) can then be imported into Daz Studio and fitted to the Daz model using the Transfer Utility. This will make them fit the current figure pose but since each frame will be slightly different the result should be a little less stiff. By creating additional cloth simulation like a dress lifting up a bit, these sequences can be used, at the right Daz Studio frames, when the Daz Studio model spins or jumps.

    I guess it would be a little like making a few aniBlock for clothing. I know this would be far from having a full dynamic cloth engine in Daz Studio but it should add a little life to otherwise stiff materials.

    So, here is where the script or plugin comes in: in order to make this work with minimal effort to the user, the script would need to load objects into the scene based on a predetermined file prefix and a sequence number (e.g. Object1, Object2, Object3, ...), automatically attach them to the selected figure (similar to using the Transfer Utility) and hide and unhide them at specific key frames. For example, consider a simple sequence of 10 frames. Assuming that the objects are called Object1 to Object10 then the script would have to load Object1 to Object10 and fit them to the selected figure. Then go to frame 1 and make Object1 visible and Object2 to Object10 invisible. On frame 2 it would make Object2 visible and all other Object objects invisible. And so on.

    Since this would result in many objects, the simulation using this method would have to be kept small but typically in a movie there are plenty of scene cuts which can all be rendered independently.

    If someone would be willing to tackle such a script or plugin, I think it could be very useful. Ideally this should be a plugin so that it has a dialog where you can specify the file prefix, the starting frame, the ending frame (since you many not want to add the dynamic clothing from frame 1) and the figure to which the dynamic clothing will be attached. However, at this stage I am, gladly, willing to accept a script which as these selections "hard-coded" so that I can see if the theory will work.

  • Richard HaseltineRichard Haseltine Posts: 100,888
    edited December 1969

    It would be more logical to rig the base clothing on the base Genesis, then load the other shapes as Morphs (Morph Loader Pro will add multiple OBJ morphs in one go). I believe there was a script which used this route with Marvellous Designer, though I'm not sure whether it was a DS script for loading and animating morphs or an MD script for exporting a PP2 or .dsf with morphs embedded. If the morphs were named with suitable prefixes it would be fairly simple to have a script run through them in sequence.

  • Lord_AshesLord_Ashes Posts: 91
    edited June 2013

    It would be more logical to rig the base clothing on the base Genesis, then load the other shapes as Morphs

    I tried to do research on Morphs and didn't get too far...why is it always like pulling teeth when you need documentation regarding DAZ?!

    Anyway, Morphs, as far as I can tell, refer to a few different technologies in DAZ and are used to make modifications to typically a figure but can be used, probably, on any object.

    There seems to be something called Delta Injection Morphs which seem to be a method of building morphs that does not need the figure itself. DAZ supported this method with V3 figures and promoted it saying that by using Delta Injection Morphs, third parties can create these morphs. As far as I understand, another Morphing method is to use figures or objects which provide built in morphing such as the Genesis figure whose mesh can be morphed by using the provided sliders.

    I think I understand the concept you were suggesting...I fit the clothing to the Genesis figure as always and then use morphs to make small modifications to the clothing. However, I am not sure how I would make such morphs. So far my experience with conforming clothing has been very limited...I follow a very simple tutorial of exporting the figure, making clothing based on that, re-importing the clothing and using the Transfer Utility to fit it to a Genesis figure. Thus I have not made any clothing that has embedded morph (i.e. morphing sliders) to adjust the clothing. I touched a tad on creating bones for a figure, is that basically how one would do it? Add bones to the clothing to allow parts of the clothing to be moved independent of the figure it is on? And then you would create some morph presents that adjust the bone values? Or is there some easier way to create clothing that has morphing sliders? I also have not made any Dynamic Injection Morphs. So both Morphing methods would require study (and the documentation for doing this is not great...or at least hard to find).

    This is why initially I was thinking of the import many objects and swap them solution...it is definitely not an elegant solution but I think I will need less help to implement it than I will trying to generate Morphs from the Blender objects.

    Post edited by Lord_Ashes on
  • Lord_AshesLord_Ashes Posts: 91
    edited December 1969

    1. The Scripting samples include a Import OBJ example. I tried it and it seems to work for importing OBJ files.

    However, the other two parts of the puzzle elude me...even after searching through the Scripting documentation.

    1. The scripting documentation describes the scene as a hierarchy of nodes off of the global scene (root) node. I understand that but what I don't understand is how the timeline fits into this. Is the timeline just a array of scenes? I am guessing not because that would require each frame to hold the entire scene when in most cases only a scene changes are necessary to store. Thus is the time line a completely separate object which just holds data changes? If so what is the object name and can someone point me to the relevant functions for manipulating it?

    2. I don't see any function for tripping the Transfer Utility. Is there one or would one have to re-script all the effects that the Transfer Utility does? I hope not the second case because I wouldn't even know where to begin scripting that.

  • Richard HaseltineRichard Haseltine Posts: 100,888
    edited December 1969

    Merged the two threads on this idea.

    I was wrong to say you would rig the OBJ - just load as an OBJ, parent to the figure's hip, and then load the extra frames as morphs. It would, however, make sense to rig and load morphs if only limited areas of the clothing were being simulated - this is how a lot of drape morphs for skirts are made.

    All properties in the scene (there may be some exceptions - I don't think the Perspective switch on a camera is animateable for example) can have keys, values tied to a time and with an interpolation type. As the current time is changed (via the Timeline) the appropriate values for properties are calculated from the time and the keys.

  • Lord_AshesLord_Ashes Posts: 91
    edited June 2013

    Merged the two threads on this idea.

    Thanks I first posted this as an idea in Animation but then followed up with a similar post in Development for implementing the script.

    I was wrong to say you would rig the OBJ - just load as an OBJ, parent to the figure’s hip, and then load the extra frames as morphs.

    Correct me if I am wrong but, in the case of clothing, you would want to Transfer Utility it instead of just parent it, so that it would adjust along with poses.

    It would, however, make sense to rig and load morphs if only limited areas of the clothing were being simulated - this is how a lot of drape morphs for skirts are made.

    Yes. This is what I am after.

    All properties in the scene (there may be some exceptions - I don’t think the Perspective switch on a camera is animateable for example) can have keys, values tied to a time and with an interpolation type. As the current time is changed (via the Timeline) the appropriate values for properties are calculated from the time and the keys.

    I understand what you are saying...but I am not sure how I would take the OBJ files from Blender and turn them into Morphs since I know very little about Morphs and can't seem to find a lot of information about them. Or are you saying than when an OBJ file is load as a Morph instead of the usual Import method it automatically becomes a morph instead of new object instance?

    Post edited by Lord_Ashes on
  • Lord_AshesLord_Ashes Posts: 91
    edited June 2013

    Looks like there is a article about creating Morphs in Blender...

    http://www.daz3d.com/forums/discussion/6728/

    I tried it and it seems to work great (after I figured out what scale to use when importing back from Blender...its not the Blender scale...its the Lightwave scale).

    Okay so now I should be able to load the clothing in blender, generate the cloth simulation and thereby get a bunch of OBJ files for each slight variation of the clothing. I can load each one of these, in to Daz, as a morph and then apply them sequentially to get back the cloth simulation. Brilliant! I realize that if I was doing this from scratch I could just make a bunch of morph points and then by manipulating multiple morphs at once I could generate the cloth simulation. However, since I want to be able to use the Blender cloth engine (as opposed to manually setting morph points to manually simulate the cloth movement) each morph will basically become a frame and thus only one morph will be active at any one time.

    This brings me back to my original request...although somewhat modified: If the cloth simulation has many frames (thus many morphs) I need a quick way to sequentially turn the morphs on and off. Thus a script that takes the start frame and then sequentially applies each morph until it runs out of morphs. Thus on the starting frame it would dial Morph1 to 100 and all others to 0, on frame 2 it would dial Morph 2 to 100 and all others to 0 and so on.

    Yes, I realize that for most objects these morphs are set manually. For example, a lot of the morph dials on hair is set manually but I would like to automate this so that the cloth simulation does not need to be done manually by the user.

    As I posted, I read up on scripting a bit but I did not see any obvious objects for accessing the timeline. In order for this to work, I the script would need access to the timeline so that it can dial up and dial down the corresponding Morphs on the corresponding frames.

    Post edited by Lord_Ashes on
  • Richard HaseltineRichard Haseltine Posts: 100,888
    edited December 1969

    The reason you probably wouldn't want to rig the clothing is that the simulation embeds the pose changes, so having the clothes move through rigging and through the dynamic-simulation-as-morph would end up with a double effect.

    As for the script, you'd want to get the node with the morphs (usually the root figure or the prop - just make sure it's the only thing selected when you run the script and then use

    var myNode = Scene.getPrimarySelection();

    to get it into the script.

    var frameNo;
    frameNo = Scene.getFrame();

    will give the current frame number and

    Scene.stepFrame();

    will move forward one frame If your morphs are all named MySim### then a way of getting the morphs for the current and previous frames would be

    var thisFrmLabel, prevFrmLabel;
    thisFrmLabel = "MySim%1".arg( frameNo );
    prevFrmLabel = "MySim%1".arg( frameNo - 1 );

    and you could then use

    var thisFrmMorph, prevFrmMorph;
    thisFrmMorph = myNode.findPropertyByLabel( thisFrmLabel );
    prevFrmMorph = myNode.findPropertyByLabel( prevFrmLabel );

    to get the morphs. Then just use

    thisFrmMorph.setValue( 1 , Scene.getTime() );
    prevFrmMorph.setValue( 0 , Scene.getTime() );

    All of which is thoroughly untested, of course, but I think should set you along the right lines (do make sure you check for errors, though - for example, there won't be a previous frame morph in frame 0)

  • Lord_AshesLord_Ashes Posts: 91
    edited December 1969

    The reason you probably wouldn’t want to rig the clothing is that the simulation embeds the pose changes, so having the clothes move through rigging and through the dynamic-simulation-as-morph would end up with a double effect.

    My theory was NOT to pose the clothing in Blender. I was thinking of just making the clothing in the 0-pose position and then adding the cloth simulation to it to make it not completely static (by say applying a bit of wind to make the hem of the dress move a bit). Then I would repeat this process for other morphs like the dress flying up a big (for jumps and spins). This would result in a bunch of generic morphs that I could insert at the correct frames in Daz. Obviously this would be only applicable for small fluctuations in the fabric. For any significant cloth deformation, you would be correct that the pose would have to be re-created in Blender. This is what I am trying to avoid because then you would need to create the figure poses twice...which would defeat the purpose of dragging it back to Daz.

    As for the script, you’d want to get the node with the morphs (usually the root figure or the prop - just make sure it’s the only thing selected when you run the script and then use

    var myNode = Scene.getPrimarySelection();

    to get it into the script.

    var frameNo;
    frameNo = Scene.getFrame();

    will give the current frame number and

    Scene.stepFrame();

    will move forward one frame If your morphs are all named MySim### then a way of getting the morphs for the current and previous frames would be

    var thisFrmLabel, prevFrmLabel;
    thisFrmLabel = “MySim%1”.arg( frameNo );
    prevFrmLabel = “MySim%1”.arg( frameNo - 1 );

    and you could then use

    var thisFrmMorph, prevFrmMorph;
    thisFrmMorph = myNode.findPropertyByLabel( thisFrmLabel );
    prevFrmMorph = myNode.findPropertyByLabel( prevFrmLabel );

    to get the morphs. Then just use

    thisFrmMorph.setValue( 1 , Scene.getTime() );
    prevFrmMorph.setValue( 0 , Scene.getTime() );

    All of which is thoroughly untested, of course, but I think should set you along the right lines (do make sure you check for errors, though - for example, there won’t be a previous frame morph in frame 0)

    Thanks. That is a big help even if I have to tinker with it a bit...I must have missed the getFrame() and stepFrame() function of Scene.

    Am I correct in assuming that using Morphs will also resolve my Transfer Utility issue? I mean if the clothing is Fit To a figure then applying a morph will not change this, right? So, if I want to use the first method where I don't pose the cloth in Blender, then I should be able to use the Transfer Utility at the beginning of the process and then applying Morphs should keep the clothing fitted to the figure, right?

    I assume that if I load the morphs and then Save As Asset then all the morphs will be saved with the clothing so I don't need to re-load the morphs every time I want to use the clothing.

  • Richard HaseltineRichard Haseltine Posts: 100,888
    edited December 1969

    Yes, what you are doing is pretty much what people have been doing for some time to generate drape morphs for skirts, except you are taking a sequence of shapes to animate rather than a single finished shape for a leg pose.

  • Lord_AshesLord_Ashes Posts: 91
    edited December 1969

    I tried it with a simple draping exported out of Blender and it worked fine.

    However, it was a lot of work (mostly to pin the cloth in Blender to get the desired morphs) and thus I think creating some basic morphs and the manually adjusting them to make the fabric flow might actually be quicker.

    I also tried experimenting with the idea of rigging the cloth in Blender. I exported an animation from Daz as a BHV file which Blender was able to import. Thus one could still animate the figure in Daz, export it to Blender, do the clothing rigging and draping in Blender and the export via BHV back into Daz. This could be used from more complex draping scenes.

    The only problem that I ran into is that by default, when the BHV file was opened in Blender it showed the figure skeleton (which animated when I exported an animated sequence from Daz that was Baked to the timeline) but it did not have the actual figure mesh. This means that draping clothing would not be correct since limbs would not be as fat as they should be. However there seemed to be some kind of a Load Map and Save Map option with BHV files which, I am guessing, can be used to load the actual meshes associated with the skeletal structure.

  • Richard HaseltineRichard Haseltine Posts: 100,888
    edited December 1969

    I'm not familiar with Blender, so I don't know how you would bind a skeleton created from a bvh file to a mesh. I'm glad the basic technique worked, though.

Sign In or Register to comment.