DAZ Script to create a one-sided-square primitive: DS3, DS4.5 versions ok, DS4.0 errors?
3dcheapskate
Posts: 2,719
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.setLabel( oPolyShape.name );
var oPolyMesh = new DzPolyMesh;
oPolyShape.setPolyMesh( oPolyMesh );
// Create the groundplane material
var oMaterial = new DzDefaultMaterial();
oMaterial.name = "Preview";
oMaterial.setLabel( oMaterial.name );
oPolyShape.addMaterial( oMaterial );
var iMat = oPolyShape.findMaterialIndex( oMaterial )
oPolyMesh.activateMaterial( iMat ); //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.appendPnt2Vec( DzVec3(0,1,0) );
oMap.appendPnt2Vec( DzVec3(1,1,0) );
oMap.appendPnt2Vec( DzVec3(1,0,0) );
oMap.appendPnt2Vec( DzVec3(0,0,0) );
oPolyMesh.finishEdit();
// Final stuff
oObject.addShape( oPolyShape );
oNode.setObject( oObject );
oNode.setOrigin( DzVec3(0,0,0), true );
oNode.setOrigin( DzVec3(0,0,0) );
oNode.setEndPoint( DzVec3(0,1,0), true );
oNode.setEndPoint( DzVec3(0,1,0) );
var oPresentation = oNode.getPresentation();
if( !oPresentation ){
oPresentation = new DzPresentation();
oNode.setPresentation( oPresentation );
}
oPresentation.type = "Prop";
// And finally add it to the scene
Scene.addNode( oNode );
}
This script crashes with a QtScript error, something like 'popContext doesn't match pushContext', and it appears to be associated with this line...
oPolyMesh.activateMaterial( iMat ); //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?
Post edited by 3dcheapskate on
Comments
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
Thanks Richard, oPolyMesh seems to be a valid object - no error-trapping, but if I just comment out the activatematerial() like so...
...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:
()@: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):
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:
()@: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! ;-)
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.