Plugin SDK: Adding Material / Surface groups crash

Cross22Cross22 Posts: 66

Here is a question for you SDK developers out there. If the user has selected some polygons and I have a pointer to the mesh, I can create a new face group like so:


mesh->beginEdit();
mesh->createFaceGroup( "NewGroupName" ); 
mesh->addSelectedFacetsToGroup(  "NewGroupName" );
mesh->finishEdit();

Easy-peasy. Now if I try the same approach to create a new material/Surface group then all I get is a crash inside Daz:


mesh->beginEdit();
int newGroupNum= mesh->createMaterialGroup( "NewGroupName" ); 
mesh->addSelectedFacetsToMaterialGroup( newGroupNum );
mesh->finishEdit();

Any thoughts on how to fix this?

Post edited by Cross22 on

Comments

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

    Moved to the SDK forum.

  • Cross22Cross22 Posts: 66
    edited December 1969

    Tried to file a bug report for this, but it's blocked by "Tech Support" trying to find out how to reproduce this with "Visual Basic"...

    DAZ really needs a way to reach the dev team directly or at least file a bug report.

  • edited December 1969

    I'm getting a similar crash using DzShape

    
     DzNode* node = dzScene->getPrimarySelection();
    DzObject* object = node->getObject();
    DzShape* shape = object->getCurrentShape();
    DzFacetMesh* mesh = qobject_cast(shape->getGeometry());
    
  • LpProjectLpProject Posts: 41
    edited December 1969

    As I understand it, in Daz Studio not all nodes have geometry, so you must check if shape have geom.
    In my code i do like this:

            DzObject *obj = node->getObject();
     DzShape *shape = obj ? obj->getCurrentShape() : NULL; 
     DzGeometry *geom = shape ? shape->getGeometry() : NULL; 
     if( shape == NULL || geom == NULL ){
      return; // No geometry for the node
     }
     DzFacetMesh *mesh = qobject_cast( geom );
  • edited December 1969

    Thanks LpProject that worked great

  • rbtwhizrbtwhiz Posts: 2,249
    edited January 2017

     

    grubertm said:

    Any thoughts on how to fix this?

     

    C++:

     

    DzNode* node = dzScene->getPrimarySelection();DzObject* obj = node ? node->getObject() : NULL;DzShape* shape = obj ? obj->getCurrentShape() : NULL;DzFacetMesh* mesh = shape ? qobject_cast<DzFacetMesh*>( shape->getGeometry() ) : NULL;if ( mesh ){	const QString matName( "Test" );	int idx = shape->findMaterialIndex( matName );	if ( idx < 0 )	{		idx = mesh->createMaterialGroup( matName );		DzDefaultMaterial* mat = new DzDefaultMaterial();		mat->setName( matName );		shape->addMaterial( mat );	}	if ( idx > -1 )	{		mesh->addSelectedFacetsToMaterialGroup( idx );	}}

     

    Script:

     

    var oNode = Scene.getPrimarySelection();var oObject = oNode ? oNode.getObject() : undefined;var oShape = oObject ? oObject.getCurrentShape() : undefined;var oMesh = oShape ? oShape.getGeometry() : undefined;if( oMesh && oMesh.inherits( "DzFacetMesh" ) ){	var sMatName = "Test";	var nIdx = oShape.findMaterialIndex( sMatName );	if( nIdx < 0 ){		nIdx = oMesh.createMaterialGroup( sMatName );		var oMaterial = new DzDefaultMaterial();		oMaterial.name = sMatName;		oShape.addMaterial( oMaterial );	}		if( nIdx > -1 ){		oMesh.addSelectedFacetsToMaterialGroup( nIdx );	}}

     

    -Rob

    (sorry, been a little busy)

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