Trimming a dForce skirt via scripting

Hi there, all.

I'm trying to create a script that would cut a maxi dForce skirt to different lengths by deleting N rows from the bottom. Because it has a surface for the hem, it can be done by selecting it, growing it, reassigning to the hem surface, shrinking it down to what is actually be deleted, and then deleting the selection. And the sprawling, sparse documentation has been tough to navigate, but I got it mostly figured out. Deleting a selection of facets seems... clunky, at best. There's an undocumented function, `removeSelectedFacets()`, and it does not seem to do anything. So instead I make a face group, assign the facets to be deleted to that face group, and use `removeFaceGroup()`, and that deletes them.

But I have clearly done it the completely wrong way, because there are a whole bunch of problems when I use the cut script on the skirt.

The first, and most pressing one, is that you can't reload the original skirt to get back the original length if you cut too much off. When you delete the trimmed skirt and load the original one, it has the trimmed length. It's not permanent as in the file has been modified; if you exit and reload Daz Studio, you can get the original length back.

You can't save scenes with the trimmed skirt. If you do, and then you reload the scene, instead of the skirt, you get bounding boxes for all of the areas of the skirt.

It doesn't *immediately* nuke morphs on the skirt... but it nukes morphs on the skirt. If the smoothing modifier is on and you use a particularly strong morph right after trimming, you can notice it trying to taper at the edges of the modified shape toward the unmorphed, original shape. It's a weird thing that's hard to describe. But when you reload the scene or reload the skirt and get the trimmed length, the morphs are gone.

I've uploaded my script as an attachment; what am I doing wrong? Should I be taking another approach entirely?

Another method I've thought about is hiding polygons instead of deleting them. That way, you could actually even go back to a longer length, and there's less risk of nuking the morphs, which in and of itself might be a good enough reason. I tried this once manually when trying to conceptualize this script. One good thing is that the hidden polygons are ignored by dForce, which is exactly what we'd want. But the very last row of non-hidden polygons has weird shading, because it's connected to the unhidden polygons. This can be worked around by creating a new surface with a cutout opacity of 0, and leaving one row of polygons unhidden. This method seems to work great when I do it manually. But I'd have to figure out how to clone the hem surface in creating it, so it retains its dForce properties. Further to the point, there is a `hideSelectedPolygons()` method, but not a `showSelectedPolygons()` method, so I am not sure how I would reverse trimming if I did it this way. Still, should I prefer this method of trimming a skirt, perhaps?

Thanks for your time. :)

dsa
dsa
SkirtTrimmer.dsa
6K

Comments

  • MadaMada Posts: 2,004
    edited October 2022

    You can use conditional grafts to do what you want, and it won't destroy the mesh :) Dforce will ignore the faces in the graft completley. You can set up different lengths with a bool button to turn them on and off.

    Post edited by Mada on
  • All copies of the skirt rfrence the same asset - if you edit that, by removing polygons, then that version is what any newly-loaded skirt will use.

  • TiZTiZ Posts: 21
    edited October 2022

    Mada said:

    You can use conditional grafts to do what you want, and it won't destroy the mesh :) Dforce will ignore the faces in the graft completley. You can set up different lengths with a bool button to turn them on and off.

    Hi Mada, thanks for your time, and for the neat tutorial!

    I am not sure that it is the case that dForce ignores the faces in the graft while it is enabled; because when I had the graft enabled, I ran a simulation, then turned off the graft and found that the hidden facets had been simulated. I used a spin animation to test it, and the entire skirt was flared rather than just the parts that were visible. When you hide geometry with the geometry editor, the hidden faces remain at their pre-sim position the entire time. It also seemed like simulation time was entirely unaffected with the graft, whereas hiding with the geometry did shorten the simulation time.

    To be extra sure it wasn't a thing where it didn't affect collision, I lowered the skirt onto an sphere that it would hit were it full length, and that it would miss were it short, and sure enough, I could see the skirt being pulled as if it was caught on the object. Graft off, and the skirt's all wrapped around it. It sounds like it's picky, but it does matter, because the skirt is very full, and I want the user to be able to put objects, poses, etc in the space where the trimmed faces used to be without worrying that it actually is affecting simulation and will make the skirt pull in an unnatural way, or worse, explode.

    Richard Haseltine said:

    All copies of the skirt rfrence the same asset - if you edit that, by removing polygons, then that version is what any newly-loaded skirt will use.

    Hi Richard, thanks for the info.

    Is there anything I can do to get around this, like creating a copy of the asset before editing it? I noticed when I reloaded a cut skirt that the relocated hem surface was still in its new location, which means the approach of hiding the faces instead would probably fall flat the same way.

    EDIT: Okay, so I redid all my steps manually via the UI. I grew the hem surface, I deleted some rows back from it, I saved it as a scene. It kept my changes, *and* it kept the morphs. And I could still load the original skirt. I could even save it as a wearable and it would still keep the changes and even the morphs. So that tells me that the UI is doing something behind the scenes to make these changes stick nondestructively, that I need to do in script.

    Post edited by TiZ on
  • MadaMada Posts: 2,004

    Interesing - I should play some more with it again - thanks :)

  • TiZTiZ Posts: 21

    Mada, no problem; I am glad I was able to help you learn something new.

    I got a little bit closer.

    So thanks to the detriangulation sample and its triangulation sibling, I discovered that you have to use the completely undocumented makeCopy function to create a copy of the mesh before messing with it. So when that is added into the script, you can then delete and reload the skirt after cutting it as many times as you like...

    ...but you still can't save it. If you load a saved scene with the new mesh, it will have no face groups, no surfaces, and no regions, and it's nothing but boxes for every bone. I wish I had any idea what the two boolean parameters to makeCopy do; I would hope they'd copy them over too, but I guess not. I don't know why the rest of the script works and then it all falls apart on save.

    And I don't know what I'm supposed to really do about this. The samples recreated every single facet. Is that what I'm supposed to do here? That can't be right.

    I am going to tap out for the night since I am now waist deep in undocumented shadow realm territory. I've attached the most recent version of the script. Thank you.

    dsa
    dsa
    SkirtTrimmer.dsa
    7K
  • The SDK docs dscribe DzVertexMesh* DzFacetMesh::makeCopy( bool shareVerts, bool shareFacets )

  • TiZTiZ Posts: 21
    edited October 2022

    Richard Haseltine said:

    The SDK docs dscribe DzVertexMesh* DzFacetMesh::makeCopy( bool shareVerts, bool shareFacets )

    At first I was like "SDK docs"? And then I searched it, couldn't find any online docs, but found this item in the store, and the offline documentation indeed does describe makeCopy; the two parameters being false let it make deep copies of the vertices and facets, which is what we want; don't want to botch the vertices on all instances of the skirt.

    Thank you for the information on the SDK documentation. It's good to have a backup plan should the scripting website be missing something.

    So it's cool to finally know that... but it doesn't really explain why I'm stuck. If I examine the copy of the mesh with some print statements, right after the copy of the mesh is made, it has all the face groups and material groups. But if I load a saved scene with a cut skirt, it doesn't have a shape. I'm not sure how it lost its shape, or more crucially, what the de/triangulation samples are doing differently to let it keep its shape, aside from recreating every facet.

    Post edited by TiZ on
  • TiZTiZ Posts: 21

    Hi, all. I know it's bad manners to bump, but I'm still completely stuck on this and I don't know what to do.

    I have a freebie morph set that I want to release for a certain skirt, and it depends on this script being able to come together. The skirt comes in eight different lengths, all of them different assets. I can't redo the work I did on all eight of them, particularly because the morph changes the length of each facet so they don't match up anymore anyways, but I can instruct users to load the longest skirt and then run a script to cut it to their desired length. Because this is supposed to accompany a morph set, I can't recreate all of the facets, because then the morphs will be lost.

    The only thing I was able to discover is that there is an alternate copyFrom method that is documented in the scripting center, and it can be used instead of the SDK-only makeCopy. It seems to do pretty much the same thing. You can cut the skirt, delete it and reload the original. But if you cut the skirt, save to a scene, and reload the scene, there's no DzShape and each bone has a bounding box-sized gray box. Just like where I was before. Latest script is attached once more. As you can see, I'm officially in "throw stuff at the wall and see what sticks" territory. I'm completely out of ideas.

    Again, all of the steps I'm trying to do work just fine if I do them manually via the GUI. The skirt is cut, you can delete it and reload it, you can save it to a scene and load that, and morphs are preserved. So should I be scripting the GUI somehow???

    Is there a point where I should just make a ticket? Is that something I can do for this sort of thing? If I can't fix this, then I just can't release this freebie.

    dsa
    dsa
    SkirtTrimmer.dsa
    9K
  • TiZTiZ Posts: 21

    Hello again.

    I've got a few updates. I have *not* solved this yet, I'm still stuck. I've resorted to examining the saved scenes in a text editor for differences. And there are a lot of *crucial* differences.

    One thing that became apparent to me immediately is that makeCopy and copyFrom are *not* the same. If you use copyFrom, the source asset URL is lost. If you use makeCopy instead, the source asset URL does survive. I don't know what that means in practical terms for how the item behaves, but it does tell me not to take for granted that the behavior between two functions that appear to be the same actually is.

    But even more pressingly, here are some important items present in the manually cut saved scene that are *not* present in the script cut saved scene:

    • An abridged list of vertices. The saved cut seems to keep the vertex count the same as the original cut.
    • A modified UV map to account for removed vertices and facets.
    • The entire library of morphs, recreated.

    I am not sure what to do to cause a facet deletion to trigger all of that. And maybe I just *can't* do that from script. If the UI has been working well, then maybe I should script the UI instead, right? But I've tried that too, and it's not working; unless "DzPGDeleteSelectedFacetsAction" is different than what I've been doing in the UI with the geometry editor tool, triggering that action does nothing. It could be that I have to give it a confirmation somehow, because doing it in the UI causes a confirmation window to pop up.

    Anyways, still stuck. I filed a tech support ticket, but they seem to have ignored me. I hope that at least giving more information is making these bumps okay. :/

Sign In or Register to comment.