Simple change with DAZ Script (DIffuse Color / Base Color)
vega_ska
Posts: 4
I want to change the path/file name of the texture (also called: 'Base Color' or 'Diffuse Color' of a Genesis 8 Female Model... How can i change it using DAZ Script? Should be simple to access the value it already has and change it to another one, thanks for your help
In the below image is where the value is at (the icon with the texture has the path of the file)
Comments
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/material_dz#a_1a0ce8c1937122a8decf0c3f3985e52cd0
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/material_dz#a_1a38f23b683481251e0ec475eae2f61bd3
hanbdle the base colour (as far as I know it is overidden by the derived classes for fancier materials.
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/imagemgr_dz
will let you load a new map as a texture, which you can then set as the new base colour 9you don't just edit the text of the path).
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/start#materials
should give the gernal methods for geting and handling materials on an item.
Thanks for the reply... yes i have already seen/read the documentation before, but its all confusing to me, there is not enough examples...
This code supossedly changes the texture, but it does not compile, it says:
TypeError: no constructor for DzTexture
So i have no idea of what to do... im at a loss, i mean i get what i am suppossed to be doing, but i dont understand the code behing it, specially the one or two lines needed to make the darned change..!
var oNode = Scene.getPrimarySelection();
var oObject = oNode.getObject();
var oShape = oObject.getCurrentShape();
var nMaterials = oShape.getNumSelectedMaterials();
for (var i = 0; i < nMaterials; i++) {
var oMaterial = oShape.getSelectedMaterial(i);
var aProperty = oMaterial.findProperty("Diffuse Color");
if (aProperty.name === 'Diffuse Color') {
// Replace the texture with your desired texture
var newTexturePath = "path/to/your/texture.jpg"; // Update this path
// Load the new texture
var oNewTexture = new DzTexture(newTexturePath);
oMaterial.setColorMap(oNewTexture);
// Set a new diffuse color (optional)
aProperty.setValue(new QColor(0, 255, 0));
}
}
You are mot meant to create the DzTexture object:
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/texture_dz
So you want something like
var oImageMgr = App.getImageMgr();
if ( oImageMgr ) {
var oNewTexture = oImageMgr.getImage(newTexturePath, gamma, type);
}
where the gamma is the required gamma value and the type is a value listed on the DzTexture page (usually DzTexture.Standard by the look of it)