Every Face Groups Into Surface Groups

Hello, I'd like to receive some help as I'm not familiar with DAZ's scripting system and Documentation page is bit complicated to understand frown

I'm trying to make a script that creates Surface Group from every Face Group exists within an object.

However, I couldn't find proper API reference that refers to either of those group...

If anybody is able to help that'll be great.. Thanks!

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,888

    You may want to look at the old DS3 scripting docs, the geometry sections of the current documentation were taken down a while back - not sure if it was because of updates being needed or to hide the work being done on dForce/strand hair - and haven't vcome back but I think you may be able to get started with the samples, the old docs, and if need be a bit of member discovery.

  • PraxisPraxis Posts: 254

    The Scripting Samples are also a good source of info, e.g. for your case try http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/geometry/geometry_triangulate/start

    I have not tested this extract from the above Sample, but I expect it will do something like you want (after some modifiactions):

    // Modified extract from http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/geometry/geometry_triangulate/start	var oNode = getRootNode( Scene.getPrimarySelection() );	// If nothing is selected	if( !oNode ){		// We are done...		return;	} 	// Get the mesh of the root node	var oMesh = getFacetMeshForNode( oNode, true, false );	// If we do not have a mesh	if( !oMesh ){		// We are done...		return;	} 	// Get the number of facets in the mesh	var nFacets = oMesh.getNumFacets(); 	// Decalre working variables	var oFaceGroup;	var oSurface; 	// Get the number of face groups	var nFaceGroups = oMesh.getNumFaceGroups(); 	// Pre-size the array of face group names	var aFaceGroups = new Array( nFaceGroups ); 	// Iterate over the face groups	for( var i = 0; i < nFaceGroups; i += 1 ){		// Get the 'current' face group		oFaceGroup = oMesh.getFaceGroup( i ); 		// Create a new Surface (i.e. a "MaterialGroup" using the name of the FaceGroup:		oSurface = createMaterialGroup( oFaceGroup.name + '_Surface' );	}         //... Now list the results:	// Get the number of surfaces	var nSurfaces = oMesh.getNumMaterialGroups(); 	// Iterate over the surfaces	for( var i = 0; i < nSurfaces; i += 1 ){		// Get the 'current' surface		oSurface = oMesh.getMaterialGroup( i ); 		// Report the surface name		print( i, oSurface.name );	} 

     

  • AscendedJoyAscendedJoy Posts: 44

    Hello Praxis, this is such a great resource! I'll try to build something with code your provided. It doesn't work as is, but surely seems promising place to start from

    Thank you!

  • PraxisPraxis Posts: 254

    You are welcome.

    ...  It doesn't work as is, ...

    You need to download the Sample .dsa code file at http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/geometry/geometry_triangulate/start and modify it to suit your situation.  For example,  in the code I posted, getRootNode() and getFacetMeshForNode() are not built-in functions of DAZ Script - they are utility routines in the Sample .dsa script.

    Enjoy!...

  • AscendedJoyAscendedJoy Posts: 44
    edited May 2020

    Hi Praxis, I slightly modified the script to have it running (as it was giving me an error). now it seems script is up and running, but although script IDE claims it has created Material groups, I cannot see them in neither Geometry Editor or Surface Editor. Am I doing something wrong here? (I gotta be xD ;; )

    	var oNode = getRootNode( Scene.getPrimarySelection() );	// If nothing is selected	if( !oNode ){		// We are done...		return;	} 	// Get the mesh of the root node	var oMesh = getFacetMeshForNode( oNode, true, false );	// If we do not have a mesh	if( !oMesh ){		// We are done...		return;	} 	// Get the number of facets in the mesh	var nFacets = oMesh.getNumFacets();    	// Decalre working variables	var oFaceGroup;	var oSurface; 	// Get the number of face groups	var nFaceGroups = oMesh.getNumFaceGroups();    print(nFaceGroups);	// Pre-size the array of face group names	var oFaceGroups = new Array( nFaceGroups ); 	// Iterate over the face groups	for( var i = 0; i < nFaceGroups; i += 1 ){		// Get the 'current' face group		oFaceGroup = oMesh.getFaceGroup( i );		// Create a new Surface (i.e. a "MaterialGroup" using the name of the FaceGroup:		oMesh.createMaterialGroup( oFaceGroup.name + '_Surface' );	}    //... Now list the results:	// Get the number of surfaces	var nSurfaces = oMesh.getNumMaterialGroups(); 	// Iterate over the surfaces	for( var i = 0; i < nSurfaces; i += 1 ){		// Get the 'current' surface		oSurface = oMesh.getMaterialGroup( i ); 		// Report the surface name		print( i, oSurface.name );	}

     

    Post edited by AscendedJoy on
  • PraxisPraxis Posts: 254

    Oops...  After creating each new Surface, you need to add the relevant Faces to it - I left out that code.

    I'll post an update soon, after I've tested a few things...

  • PraxisPraxis Posts: 254

    OK...
    This runs OK, and at the end it lists the newly-created Surfaces,

    BUT: Those new Surfaces don't appear in the Surfaces Editor or the Geometry Editor.sad

    I'm out of ideas on this one... maybe someone else can help?

    // Test creation of Surfacesvar bShowKeys = true;                             // For "Self-Discovery"var oNode = Scene.getPrimarySelection();if( !oNode ) {  print( 'You must select a Node in the Scene' );} else {  if( oNode.inherits( 'DzBone' ) ) {    oNode = oNode.getSkeleton();                  // Because the Mesh belongs to the Skeleton, not the Bone  }  var oObj = oNode.getObject();  if( oObj ) {    var oMesh = oObj.getCachedGeom();             // or oMesh = oObj.getCurrentShape().getGeometry();    if( oMesh ) {      if( bShowKeys ) {        print( ' ' );        print( '----------------------' );        print( oMesh.className());        print( Object.keys( oMesh ) );            // shows e.g. findMaterialGroup(QString), createMaterialGroup(QString)      }      var nFaceGroupNum;      var oFaceGroup;      var sSurfaceName;      var nSurfaceNum;      var oSurface;      var j;      var nIdx;      var bFaceGroupKeysShown = false;      for( nFaceGroupNum = 0; nFaceGroupNum < oMesh.getNumFaceGroups(); nFaceGroupNum++ ) {        oFaceGroup = oMesh.getFaceGroup( nFaceGroupNum );        if( oFaceGroup ) {          if( bShowKeys && (!bFaceGroupKeysShown) ) {            print( ' ' );            print( '----------------------' );            print( oFaceGroup.className());            print( Object.keys( oFaceGroup ) );   // shows e.g. count(), getIndex(int)            bFaceGroupKeysShown = true;          }          sSurfaceName = nFaceGroupNum.toString() +'='+ oFaceGroup.name +'_Surface';          if( !oMesh.findMaterialGroup( sSurfaceName ) ) {            // Create the new Surface:            nSurfaceNum = oMesh.createMaterialGroup( sSurfaceName );            oSurface = oMesh.getMaterialGroup( nSurfaceNum );            if( oSurface ) {              // Copy the Facet Index #s from the FaceGroup:              for( j = 0; j < oFaceGroup.count(); j++ ) {                nIdx = oFaceGroup.getIndex( j );    // Facet Index #                oSurface.addIndex( nIdx );          // Facet Index #              }            }          }        }      }      // List all Surfaces:      var bSurfaceKeysShown = false;      print( ' ' );      for( j = 0; j < oMesh.getNumMaterialGroups(); j++ ) {        oSurface = oMesh.getMaterialGroup( j );        if( bShowKeys && (!bSurfaceKeysShown) ) {          print( ' ' );          print( '----------------------' );          print( oSurface.className() );          print( Object.keys( oSurface ) );   // shows e.g. addIndex(int)          bSurfaceKeysShown = true;          print( ' ' );        }        // >>> ??? This lists the Surfaces created above, but they don't show in the Geometry Editor or Surface Editor:        print( j, oSurface.name );      }      print( ' ' );    }  }}

     

  • AscendedJoyAscendedJoy Posts: 44
    edited May 2020

    Hello Praxis, I also tried coding on my own; Borrowed first few lines from your code..

    Following code shows very interesting result;

    // DAZ Studio version 4.12.0.86 filetype DAZ Scriptvar oNode = Scene.getPrimarySelection();if( !oNode ) {  print( 'You must select a Node in the Scene' );} else {  if( oNode.inherits( 'DzBone' ) ) {    oNode = oNode.getSkeleton();                  // Because the Mesh belongs to the Skeleton, not the Bone  }  var oObj = oNode.getObject();  if( oObj ) {    var oMesh = oObj.getCachedGeom();             // or oMesh = oObj.getCurrentShape().getGeometry();    if( oMesh ) {		/*	        print( ' ' );	        print( '----------------------' );	        print( oMesh.className());	        print( Object.keys( oMesh ) );            // shows e.g. findMaterialGroup(QString), createMaterialGroup(QString)		*/		var i;		var j;		var nFacets;		var nFaceGroups;		var nMaterialGroups;		var sMaterialName;		var oFaceGroup;		var oFacet;		nFaceGroups = oMesh.getNumFaceGroups();		nFacets = oMesh.getNumFacets();		nMaterialGroups = oMesh.getNumMaterialGroups();		//print( nFacets );		print( nFaceGroups ) ;		for ( i=0; i < nFaceGroups; i++){			//oMesh.deselectAllFacets();			oMesh.selectFacets( oMesh.getFaceGroup(i) );			oFaceGroup = oMesh.getFaceGroup(i);			//print( Object.keys( oFaceGroup ) );			//print( oFaceGroup.count() + ' ' + oFaceGroup.getName() );			sMaterialName = oFaceGroup.getName() + '_Surface';			oMesh.createMaterialGroup( sMaterialName );			oMesh.addSelectedFacetsToMaterialGroup(nMaterialGroups+i);			oMesh.activateMaterial(sMaterialName);			print ( oMesh.getMaterialGroup(nMaterialGroups+i) );		}    }  }}

    When I run this script, I don't see a faces on my viewport - when I try "Show All Polygons", DazStudio crashes. So something weird has happened to the polygons with code above

    Also, I made DazStudio to print vertex IDs with getMaterialGroup - result shows same vertices appear on multiple MaterialGroup.

    Or to be more precise; group A gets added to group B, group B gets added to group C, and etc..

    And like your example, mine doesn't show the list either. I'm pretty sure we're missing something ... : /

    Post edited by AscendedJoy on
  • AscendedJoyAscendedJoy Posts: 44

    Update: After de-commenting DeselctAllFacets, now I don't see duplicated vertices in Surface Group. However, they still don't appear in the list T_T

  • PraxisPraxis Posts: 254
    edited May 2020

    After some experimentation using both your method (via Selections) and my method (via setting individual facet Index #s), I have occasionally got it to behave as desired - BUT not reliably or repeatedly:  Sometimes it works, and sometimes not.

    I suspect the problem is that (probably - I assume so) each Facet must at all times belong to a Surface ("MaterialGroup"), and so you need to remove each Facet Index from its current Surface (e.g. "default") before adding it to the new Surface.  But I'm just guessing.

    Hopefully someome who knows will step in here...smiley

     

    Post edited by Praxis on
Sign In or Register to comment.