setNormalValueMap()
I'm trying to write a script that, among other things:
1. stores the image used as a normal map for each surface
2. loads a new shader preset (that was created in shader mixer)
3. applies the stored normal map
Attached is a screencap of a simplified shader preset (algo-01.duf) that illustrates the problem, and below is a small snippet of the relevant code, followed by the log.
A sphere is created with the DAZ Default Material applied and the file "normal.jpg" is assigned as the normal map before running the script. The call to getNormalMap() is working and the shader preset gets loaded, but the normal map does not get set.
normalMap[arrayIndex] = mat.getNormalValueMap();
oContentMgr.openFile(thePath + "algo-01.duf", true);
mat.setNormalValueMap(normalMap[arrayIndex]);
Executing DAZ Script file: algo-apply-02.dsa
File loaded in 0 min 0.0 sec.
Loaded file: algo-01.duf
Compiled C:/Users/algo-02/AppData/Roaming/DAZ 3D/Studio4/shaders/brickyard/{dad32682-8394-4714-aa2f-c7a48f3e4e7c}/shader_Surface.sdl...
Compiled C:/Users/algo-02/AppData/Roaming/DAZ 3D/Studio4/shaders/brickyard/{dad32682-8394-4714-aa2f-c7a48f3e4e7c}/shader_Displacement.sdl...
stdin: in function dzNormalMap
stdin:78: WARNING: variable 'dPdu' should be declared as 'extern'
stdin:78: WARNING: variable 'dPdv' should be declared as 'extern'
stdin:83: WARNING: variable 'dPdu' should be declared as 'extern'
stdin:83: WARNING: variable 'dPdv' should be declared as 'extern'
Script executed successfully.
If anybody can point me in the right direction to assign a normal map via script, I'd greatly appreciate it! Thanks in advance.
- Greg
Comments
The NormalValueMap functions are part of dzDefaultMaterial but not DzShaderMaterial. Shader Mixer shaders are either DzShaderMaterial or a special case (DzBrickShader?), I can't recall, but they certainly aren't DzDefault Material. Instead you need to make sure you use a sensible name for the property, then use findProperty() to get it for the Shader Mixer shader. I would strongly advise checking that you have received what you asked for at every stage - it's true that the nested if ( check property ) {} blocks can get a bit intense as you scroll right to read the actual code, but it does make it easier to find problems.
Actually, I think even aside from how you get the normal map property you should probably be getting the material afresh after applying the .duf.
Thanks for your prompt response, Richard. I appreciate you taking the time.
I decided to take a different approach and use copyFrom() in order to transfer the normal map and it appears as though that will do the trick. Your reminder that I needed to get the mat again after loading the duf pointed me in the right direction.
- Greg
Just as a follow-up, I thought I'd mention 2 things that confused me in the hopes of possibly preventing somebody in the future from the same confusion:
1. When importing a material into shader mixer from object X in the scene, the material will not be of the class DzDefaultMaterial even when object X has the default material applied.
2. Likewise, using the "DS Default Material" brick in Shader Mixer has nothing to do with DzDefault Material.
- Greg
Oh! If I'm lucky this may explain why I don't manage to have both my previous and new material simultaneously in my script (I'm doing the same, apply the duf in the middle of the script).
What is the command for refreshing the material? Just ’’materialrefresh’’?
I meant, as I recall, that the material is replaced with a new material on applying a preset - so you can't assume that your pointers are still valid after applying the .duf file, you need to repeat the get property steps (at least to be safe).
Yes thanks, that is what I did, repeat the getproperty, and the collect nodes, and the rest too.. well all the family, but the script always had the same oNewMaterial and oOldMaterial at the end. But I can't swear it's not a mistake I made, I'm so confused by what I'm writing down.
If I remember well, the oNewMaterial was the same as the old one.
This is why I finally opted to create two arrays, one with surface names, and one with maps. (not sure the first one is useful but easier for seeing what is happening in the script.
Now my array seems to work, I just have an issue when the normal maps do not exist, the conditional I'm using does not seem to work, maybe you'll have an idea why :
I'm using :
But even when the normal mapped is unmapped, I enter in the if... This is really annoying!
Oh and by the way the message error is :
TypeError: Result of expression 'grabNormalMap.getFilename' [undefined] is not a function.
I finally ended up with that on the conditional for normal map. EDIT : but it does not work either.
...
It works just a bit.
Surely
oProperty.getValue (k);
should be
oProperty.getValue ();
I'll try that thanks a lot, once again, Richard.
For some obscure reason I still don't understand the difference between (), nothing, and (k)... So I apply them randomly until one of them work. Shame on me, this is not a way to work!
what makes me sad is that I realise that not only I don't know the synthax needed for scripting, but also I don't understand the structure of the elements I use. The "objects" things (as well as classnames, properties). I tend to see everything as big arrays, and everything behaving not as a big array seem for me to come from another far away deep space planet.
I should try to find a book explaining how all this is structure and behave. (I checked, "Daz scripting for the dummies" is not on amazon!)
That looks suspicious: the oProperty.getValue () is applied the array-element , but the label oLabel is from
It does not look like those two have much to do with each other. Likely an error, but hard to tell without seeing the whole picture.
Yes you are right, there must be a "k" issue.
I finally manage to solve my issues with a strong help of Draagonstorm. And thanks to her help, and to the helps of all of you here, there are a la few things had did not understand at all before which are more clear today.
This is really great for someone like me to have support from people like you, thanks for that!
IMHO, I think that if you share the solution this thread might help others in the same need and at the same time add value to the thread and forums.
Saludos.
Lol, I just came back to here to re-read the thread because.. It still does not work in certain cases....
Once again I thought it was solved, but this is not. A never ending project for me!