Digital Art Zone

 
     
DAZ Script to create a one-sided-square primitive: DS3, DS4.5 versions ok, DS4.0 errors?
Posted: 17 June 2013 10:13 PM   [ Ignore ]
Active Member
Avatar
RankRank
Total Posts:  457
Joined  2007-09-01

DAZ Script 2 extract for creating a simple UV-mapped one-sided square primitive below - this is a version for DS4.0 that I can’t get to work.
- I have a version that works for DAZ Studio 3, using oPolyShape, etc (based on sample code from the SDK)
- I have another version that works for DAZ Studio 4.5, using oFacetShape, etc (based on sample code from the DAZ website)
- Neither of those works for DAZ Studio 4.0, so I’m doing a DAZ Studio 4.0 version too. Started with the DS4.5 version and replaced all the ‘Facet’ stuff with the corresponding ‘Poly’ stuff from the DS3 version. Here’s the combined code…

DsActions.prototype.createGroundPropDS4zero = function()
{
    
var oNode = new DzNode();
    
oNode.setName"WorldBall Ground DS4zero" );
    
oNode.setLabel"WorldBall Ground DS4zero" );
    var 
oObject = new DzObject();
    
oObject.name "WorldBall Ground DS4zero";
    var 
oPolyShape = new DzPolyShape;
    
oPolyShape.name "WorldBall Ground DS4zero";
    
oPolyShape.setLabeloPolyShape.name );
    var 
oPolyMesh = new DzPolyMesh;
    
oPolyShape.setPolyMeshoPolyMesh );
    
// Create the groundplane material
    
var oMaterial = new DzDefaultMaterial();
    
oMaterial.name "Preview";
    
oMaterial.setLabeloMaterial.name );
    
oPolyShape.addMaterialoMaterial );
 var 
iMat oPolyShape.findMaterialIndexoMaterial )
    
oPolyMesh.activateMaterialiMat ); //THIS IS WHERE IT ERRORS NOW, WITH iMat=0
    // Create the geometry and UVs
    
oPolyMesh.beginEdit();
    
oPolyMesh.addVertex(-500,0,-500); //far left
    
oPolyMesh.addVertex(500,0,-500); // far right
    
oPolyMesh.addVertex(500,0,500); // near right
    
oPolyMesh.addVertex(-500,0,500); // near left
    // Edges (i.e. face)
    
oPolyMesh.startFace();
    
oPolyMesh.addFaceEdge(0,0);
    
oPolyMesh.addFaceEdge(1,1);
    
oPolyMesh.addFaceEdge(2,2);
    
oPolyMesh.addFaceEdge(3,3);
    
oPolyMesh.finishFace();
    
// Don't forget the UVs!
    
var oMap oPolyMesh.getUVs(); // get the empty map and fill it
    
oMap.appendPnt2VecDzVec3(0,1,0) );
    
oMap.appendPnt2VecDzVec3(1,1,0) );
    
oMap.appendPnt2VecDzVec3(1,0,0) );
    
oMap.appendPnt2VecDzVec3(0,0,0) );
    
oPolyMesh.finishEdit();
    
// Final stuff
    
oObject.addShapeoPolyShape );
    
oNode.setObjectoObject );
    
oNode.setOriginDzVec3(0,0,0), true );
    
oNode.setOriginDzVec3(0,0,0) );
    
oNode.setEndPointDzVec3(0,1,0), true );
    
oNode.setEndPointDzVec3(0,1,0) );
    var 
oPresentation oNode.getPresentation();
    if( !
oPresentation ){
        oPresentation 
= new DzPresentation();
        
oNode.setPresentationoPresentation );
    
}
    oPresentation
.type "Prop";
    
// And finally add it to the scene
    
Scene.addNodeoNode );

This script crashes with a QtScript error, something like ‘popContext doesn’t match pushContext’, and it appears to be associated with this line…

oPolyMesh.activateMaterialiMat ); //THIS IS WHERE IT ERRORS NOW, WITH iMat=0 

I get the same error if I try using my DS3 version of the script from DS4.0.

Anyone spot what I’m doing wrong?

 Signature 

Website: UnrealImperfect | Freebies: Renderosity, ShareCG | ‘Art’: DeviantArt | Blog: Blogger
(aka Pete Williams)

Profile
 
 
Posted: 18 June 2013 05:29 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  14433
Joined  2003-10-09

Have you checked that oPolyMesh is a valid object? Presumably it is or you wouldn’t be able to create your oPolyShape, but it might be worth checking with some error trapping code

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 21 June 2013 12:09 AM   [ Ignore ]   [ # 2 ]
Active Member
Avatar
RankRank
Total Posts:  457
Joined  2007-09-01

Thanks Richard, oPolyMesh seems to be a valid object - no error-trapping, but if I just comment out the activatematerial() like so…

...
 var 
iMat oPolyShape.findMaterialIndexoMaterial )
    
//oPolyMesh.activateMaterial( iMat ); // WITH THIS LINE COMMENTED OUT...
    // Create the geometry and UVs
    
oPolyMesh.beginEdit();
    
oPolyMesh.addVertex(-500,0,-500); //far left
    
oPolyMesh.addVertex(500,0,-500); // far right
    
oPolyMesh.addVertex(500,0,500); // near right
    
oPolyMesh.addVertex(-500,0,500); // near left
    // Edges (i.e. face)
    
oPolyMesh.startFace();     // ...IT NOW CRASHES ON THIS LINE
    
... 

...it now crashes on startFace() like this…

WARNING: Script Error: Line 1129
WARNING: TypeError: Result of expression ‘oPolyMesh.startFace’ [undefined] is not a function.
WARNING: Stack Trace:
<anonymous>()@:1129
Error in script execution!

So beginEdit() and addVertex() were fine?

The only pattern I can see is that the methods that fail, i.e. activateMaterial() and startFace(), are explicit DzPolyMesh methods, but the methods that work, i.e. beginEdit() and addVertex(), are inherited. But that doesn’t help to explain anything!

I then wondered if, perhaps, some of the new ‘Facet’ functionality had been implemented in the DzPolyMesh class for DS4.0 and tried this (i.e. replacing the DS3 ‘add face’ methods with the DS4.5 ‘add face’ methods):

...
    
oPolyMesh.addVertex(-500,0,500); // near left
    // Edges (i.e. face)
    //oPolyMesh.startFace();
    
oPolyMesh.preSizeFacets);
    
oPolyMesh.addFacet[0,1,2,3][0,1,2,3] );
    ... 

Result?

WARNING: Script Error: Line 1130
WARNING: TypeError: cannot call addFacet(): argument 1 has unknown type `const int[4]’ (register the type with qScriptRegisterMetaType())
WARNING: Stack Trace:
<anonymous>()@:1130
Error in script execution!

Meaning that preSizeFacets() was okay, and addFacet() was okay but I passed the wrong parameters?

The fact that preSizeFacets() and addFacet() seem to work hints that some of the DzFacetMesh functionality was at this stage being implemented in DzPolyMesh, and it was only later that the replacement of DzPolyMesh with DzFacetMesh occured.


I’m not sure it’s worth trying to handle this DS4.0 case - maybe I’ll just open a dialogue and tell the user “Sorry, Doesn’t Work With DS4.0” (maybe include a pointer to this thread too! wink

 

 

 

 Signature 

Website: UnrealImperfect | Freebies: Renderosity, ShareCG | ‘Art’: DeviantArt | Blog: Blogger
(aka Pete Williams)

Profile
 
 
Posted: 21 June 2013 12:46 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  14433
Joined  2003-10-09

Given that we aren’t going to get documentation for the older version I think giving up is the wisest course, but I always favour discretion in valour.

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile