Scripting or API for Materials.

Started by Archaine, December 15, 2016, 12:39:25 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Archaine

Can the material settings be accessed through the scripting or API in any way?

The Task:
1.  Import a single  fbx from a large directory of models.
2. Set the view to front
3. Set the camera distance based on the size of the model,  ie.  zoom to extents essentially.
4. The imported model shows up with a plain diffuse material applied, though it does retain the diffuse texture map. (as with all my fbx imports)
       4a.   I need to fix/set the material parameters,  specular, roughness, and point to a normal and AO map that do not automatically hook up.
5.  Render to a file with the diffuse texture name appended to the rendered file name.
6.  Change the diffuse map to a different one and re-render.      (step six is then looped 20 or so times -  20 different fabric options)
7. Load a new model and do it all over again.  (Several thousand times)

I feel confident that I can accomplish everything except step 3 and 4a.   
Can anyone please help out with these steps.

Thanks
Shane

I will be happy to offer up some Material tricks in humble payment, Like my parallax carpet.



Archaine

I have everything working except steps 4a, and 6,   script access to material parameters is my final hurdle,   please if this is available to any level or degree I would appreciate the code,  I told our team we could get this done in Keyshot, they said "HA!  you will be in V-ray by next week"

richardfunnell

From our dev team:

I am not really really sure, but if the material is created and in the library you can just apply it to the geometry. we do not enable users to edit material, but it should be possible to assign existing materials to geometry.

setMaterial(...)
Set material of a node. If applying to a group then it will apply to all sub nodes.
mat = The name of the material to apply. *

from https://keyshot.com/scripting/doc/6.3/lux.html

Archaine

The data set I am working with is geared for Unity,  so there is a lot of work to convert the material to a Keyshot mat.
I have hundreds of models to do,  and that means hundreds base materials, and then the options for each turns into THOUSANDS of materials,  I would like to use the power of the API to automate this,  manually pre-creating the materials is not feasible.

I have a folder full of texture maps with strong naming conventions,  I just need a way to put them together with the API and set material sliders.



vjirgale

Hello,

I don't know whether you are still with Keyshot, but here is one way to get your materials imported in bulk.
I found that the keyshot materials are nothing but the text files as given below.
You may still be able to generate these material files by fetching values from other software and writing such text files.
Till Keyshot opens its API for material, this can be a choice.
Note : Confirm with Keyshot whether this is a good way in current situation.....


The format of a material file is something like below,
//--lux:mat:5--
//--lux:shader:5:0--
// KeyShot material file - KeyShot [64 bit] v6.1.59
#define shader 1 lux_brushed {
"color_1" 0 0.166674 0.500008,
"bump_height" 0.9,
"length" 10,
"contrast" 1,
"sync" on,
"transform_obj_to_uv" 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1,
"uvmap_projection" 4,
"uvmap_shift_u" 0,
"uvmap_shift_v" 0,
"uvmap_scale_u" 0.2,
"uvmap_scale_v" 0.2,
"uvmap_angle" 90,
"uvmap_texture_depth" 1,
"uvmap_two_sided" on,
}
#define shader 2 lux_brushed {
"color_1" 0 0.166674 0.500008,
"color_2" 0 0.166674 0.500008,
"bump_height" 0.5,
"length" 10,
"contrast" 1,
"sync" on,
"transform_obj_to_uv" 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1,
"uvmap_projection" 4,
"uvmap_shift_u" 0,
"uvmap_shift_v" 0,
"uvmap_scale_u" 0.2,
"uvmap_scale_v" 0.2,
"uvmap_angle" 90,
"uvmap_texture_depth" 1,
"uvmap_two_sided" on,
}
#define shader 3 lux_metal {
"color" 0.764706 0.764706 0.764706,
"color" ! 2,
"alpha" 1,
"roughness" 0.025,
"glossy" on,
"glossy_samples" 9,
}
#define shader 4 lux_bumpmap {
"bumpmap" 1,
"bumpmap" 1,
"shader" 3,
"shader" 3,
"bump_scale" 1,
}

#define material "Vinay Anodized Brushed Blue" {
icon <<binary value>>
surface 4
id 1003
}

zyre

Quote from: richardfunnell on December 20, 2016, 10:46:10 AM
From our dev team:

I am not really really sure, but if the material is created and in the library you can just apply it to the geometry. we do not enable users to edit material, but it should be possible to assign existing materials to geometry.

setMaterial(...)
Set material of a node. If applying to a group then it will apply to all sub nodes.
mat = The name of the material to apply. *

from https://keyshot.com/scripting/doc/6.3/lux.html

I'd also like to do the same thing. Materials I want to use will never be pre-existing. It's a real shame to see that this isn't possible.
Is it a case of it not being implemented or actually deciding not to allow it? If the later, could you elaborate as to why that is?

Thanks

CQ_Cumbers

I have a model where I need to apply different variations of a base material (with different colors, decals, and decal colors) to many objects. Since there are millions of possible variations, I've used vjirgale's workaround and created a (rather complicated) script to generate all the necessary materials as mtl files in my material library. My only problem now is applying these materials: after applying them once, subsequent changes to the material library materials don't affect the materials in the scene. It appears to me that setMaterial() is copying the library materials to the scene rather than linking them, and subsequent setMaterial() calls set the material to the version that already exists in the scene, rather than to the updated version in the library. Does anyone have a workaround to force setMaterial() to get the updated material from the library?