Forum

#1 2015-06-29 10:08:30

Julian
Member

Maya Shader Assignation > Guerilla

Hi,

I am all new to Guerilla, so sorry if I look like a noob with this question, but i didn't find an answer anywhere else ( i always use google ^^)

I would like to know the best way to keep a shader assignation on an asset in maya when we export it to Guerilla?
I understand that the best workflow would be to do all the work in guerilla, but in the case of an old asset previously shaded in maya, it is important to keep, at least, the shader assignation.

I am currently looking in to add tag, based on the shader assignation of my asset in maya, but i don't know if it is the best approach since, to my understanding, tag apply to the all hierachy of an object. I also didn't quite figure out how to use tag in maya (but guerilla i am all good ).

Thank You for your respond smile.

Offline

 

#2 2015-06-29 10:17:14

Ben
Guerilla dev, the guy to hug

Re: Maya Shader Assignation > Guerilla

Hi Julian,

Guerilla doesn't export shaders at all, nor any shader assignment information, since you assign shaders/shading information using the RenderGraph in Guerilla (which is very different -- and much more powerful -- from what you usually do in Maya.)

Please have a look at the video tutorials on Youtube here, especially the Lookdev for Alembic and Look development videos.

Cheers,
Ben


Benjamin 'Ben' Legros
Guerilla developer
http://www.guerillarender.com

Offline

 

#3 2015-06-29 10:45:29

Ben
Guerilla dev, the guy to hug

Re: Maya Shader Assignation > Guerilla

As Hulud suggests, you can add a tag on the objects in Maya with the name of the shader (create a string Extra Attribute named GuerillaTags, and set it to the name of the shader.) Then, in Guerilla, build your RenderGraph using the tags.

Cheers,
Ben


Benjamin 'Ben' Legros
Guerilla developer
http://www.guerillarender.com

Offline

 

#4 2015-06-29 10:50:19

Julian
Member

Re: Maya Shader Assignation > Guerilla

Hi Ben,

Thank you for your quick answer.

I think i didn't explain myself correctly. I want Maya to export it's shader assignment to guerilla.

In French :

Salut Ben,

En fait c'est l'inverse, j'aimerais récupérer dans guerilla l'assignation des shaders fait dans maya. J'imagine un truc du style, tous les shader que j'ai dans maya deviennent des tag dans guerilla pour ne pas avoir a deviner quels objets ont quel shader ( vue que cela a  déja  été fait dans maya pour cet asset ).
Si il s'agissais d'un objet simple, ça me dérangerais pas de refaire le travail dans gueilla, mais la  je parle de 40 shader assigné a  un asset composé d'environ 500 différents mesh.

Ne t’inquiète pas, j'ai bien compris que l'assignation des shader dans guerilla permet beaucoup plus de chose, et j'ai déja  regardé tous les tutoriels sur youtube wink.

Last edited by Julian (2015-06-29 10:58:45)

Offline

 

#5 2015-06-29 10:53:20

Julian
Member

Re: Maya Shader Assignation > Guerilla

Ben :

As Hulud suggests, you can add a tag on the objects in Maya with the name of the shader (create a string Extra Attribute named GuerillaTags, and set it to the name of the shader.) Then, in Guerilla, build your RenderGraph using the tags.

Cheers,
Ben

Ok, that's what i was afraid of, I need to write a script in maya, because I won't do that on 500 object manually ^^.

Thank your for your respond wink

Last edited by Julian (2015-06-29 10:53:38)

Offline

 

#6 2015-06-29 11:01:13

Ben
Guerilla dev, the guy to hug

Re: Maya Shader Assignation > Guerilla

Hi Julian,

We'll soon add a Python script so you can tag the objects with their shader.
In the meantime, you can do it by yourself (and then compare your solution with ours later wink

Ben


Benjamin 'Ben' Legros
Guerilla developer
http://www.guerillarender.com

Offline

 

#7 2015-06-29 12:02:45

hulud
Guerilla dev, the guy to hug

Re: Maya Shader Assignation > Guerilla

Here is a Maya script that tags all the objects in the scene with their shader name :

Code:

import maya.cmds as cmds

# Add a tag to the node Guerilla tags
def GuerillaAddTag(node, tag):
    gt = ""
    try:
        gt = cmds.getAttr (node + "." + "GuerillaTags", asString=True) or ""
    except ValueError:
        cmds.addAttr (node, longName='GuerillaTags', dt='string')
    tags = [x.strip() for x in gt.split(',') if x]
    if tag not in tags:
        tags.append (tag)
        gt = ",".join(tags)
        cmds.setAttr (node + "." + "GuerillaTags", gt, type="string")

# Iterate all the transforms and tag them with the name of their shape shaders
def GuerillaTagNodesWithShader():
    obj = cmds.ls(dag=1,o=1,s=1)
    for i in obj:
        transformNodes = cmds.listRelatives (i, fullPath=True, parent=True)
        shadingGrps = cmds.listConnections(i, type='shadingEngine')
        shaders = cmds.ls(cmds.listConnections(shadingGrps), materials=1) 
        for transformNode in transformNodes:
            for shader in shaders:
                GuerillaAddTag (transformNode, shader)

GuerillaTagNodesWithShader ()

Cyril 'Hulud' Corvazier
Guerilla developer
http://www.mercs-eng.com

Offline

 

#8 2015-06-29 12:59:58

Julian
Member

Re: Maya Shader Assignation > Guerilla

Thank you a lot Hulud, your code is so much nicer than what i was planning to do smile.

Offline

 

#9 2015-11-17 09:31:31

ravikumar_vsp
Member

Re: Maya Shader Assignation > Guerilla

Hi Ben/ Hulud,

On the same requirement,
I was able to extract a report of the meshname, its assigned material name, the textures connected within as an excel as seperate columns from the Maya asset.

After opening the exported asset in Guerilla, we need to feed in Guerilla Console via Lua that is something like this:

eg:
grp_geometry|grp_head|geo_head         head_mat         col          d:\test_char\char_head_dif.png
                                                                                   bmp       d:\test_char\char_head_bmp.png
                                                                                   spc         d:\test_char\char_head_bmp.png
grp_geometry|grp_head|geo_head         body_mat         col          d:\test_char\char_body_dif.png
                                                                                   bmp       d:\test_char\char_body_bmp.png
                                                                                   spc         d:\test_char\char_body_bmp.png


I am able to see that Guerilla gives out Lua for each operation that I do. So I was able to create a base template for what I was planning for to rebuild the same shading network. (wont be working for face selection materials I guess)
For eg, after we open the asset scene in Guerilla:

-- to go from Root to RenderGraph:

local mod=Document:modify()
mod.select({},"replace")
mod.finish()

-- for creating a new material and renaming as head_mat(should be read from excel?? how??):
local mod=Document:modify()
_"RenderGraph":loadfile("$(LIBRARY)/rendergraph/shader.gnode")
mod.renamenode(_"RenderGraph|Shader","Surface")
mod.set(_"RenderGraph|Surface1.Shader","Surface")
mod.set(_"RenderGraph|Surface1.Mode","surface")
mod.select({_"RenderGraph|Surface1"})
mod.finish()
local mod=Document:modify()
mod.renamenode(_"RenderGraph|Surface1","head_mat")
mod.finish()

-- Dragging and dropping the required mesh into rendergraph window(should be read from excel?? how?):
local mod=Document:modify()
_"RenderGraph":loadfile("$(LIBRARY)/rendergraph/path.gnode")
mod.set(_"RenderGraph|Path.Path","^grp_root|ctr_originOffset|grp_geometry|grp_head|geo_head$")
mod.renamenode(_"RenderGraph|Path","geo_head")
mod.finish()

-- Connecting the geo_head node to the shader created earlier:
local mod=Document:modify()
mod.connect(_"RenderGraph|head_mat|Input1.Plug",_"RenderGraph|geo_head|Output1.Plug")
mod.finish()

-- creating the union node and merging the shading network as part of scene rendergraph:
local mod=Document:modify()
_"RenderGraph":loadfile("$(LIBRARY)/rendergraph/binop.gnode")
mod.renamenode(_"RenderGraph|Binop","union")
mod.set(_"RenderGraph|union.Mode","union")
mod.disconnect(_"RenderGraph|Trace|Input1.Plug",_"RenderGraph|Surface|Output1.Plug")
mod.set(_"RenderGraph|Trace|Input1.Plug",nil,true)
mod.connect(_"RenderGraph|union|Input1.Plug",_"RenderGraph|Surface|Output1.Plug")
mod.connect(_"RenderGraph|union|Input2.Plug",_"RenderGraph|head_mat|Output1.Plug")
mod.connect(_"RenderGraph|Trace|Input1.Plug",_"RenderGraph|union|Output1.Plug")
mod.finish()

-- Assigning the file textures as in the excel( how to read the excel file that contains the texture paths for this shader??)
local mod=Document:modify()
mod.select({_"RenderGraph|head_mat"},"replace")
mod.finish()
local mod=Document:modify()
mod.createnode(_"RenderGraph|head_mat","AttributeShader","DiffuseColor")
mod.finish()
_"unknown":loadfile("$(LIBRARY)/attributes/bevel_normal.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/bumpmap.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/cloud.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/mask_texture.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/normal_map.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/occlusion.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/projection_texture.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/stripes.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/texture.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/tri_planar.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/tri_planar_bump.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/voronoi_cell.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/voronoi_distance.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/voxel.gnode")
_"unknown":loadfile("$(LIBRARY)/attributes/weaving.gnode")
_"unknown":loadfile("$(LIBRARY)/lenses/lens_3dedistortion.gnode")
_"unknown":loadfile("$(LIBRARY)/lenses/lens_default.gnode")
_"unknown":loadfile("$(LIBRARY)/lenses/lens_latlong.gnode")
_"unknown":loadfile("$(LIBRARY)/lenses/lens_spherize.gnode")
local mod=Document:modify()
mod.set(_"RenderGraph|head_mat|DiffuseColor.Shader","Texture")
mod.finish()
local mod=Document:modify()
mod.createplug("AttributeShaderPlug",_"RenderGraph|head_mat|DiffuseColor","File",4,types.texture,"")
mod.set(_"RenderGraph|head_mat|DiffuseColor.File","d:/test_char/char_head_dif.png")
mod.finish()


If somehow, I am able to get the data that I have extracted from Maya as .xls format and feed it in here,
I would have created the connections that existed in maya making my work easier.

Any help would be great in this regards.

Offline

 

#10 2015-11-17 12:56:53

Ben
Guerilla dev, the guy to hug

Re: Maya Shader Assignation > Guerilla

Hi,

You can find information in the Lua 5.1 Reference Manual.
More specifically, the Input and Output facilities

For instance:

Code:

-- open the xls file
local file = io.open ("c:/the/file.csv", "r")
-- check the file was properly opened
if file then
    -- iterate over all lines in the file
    for line in file:lines () do
        local fields = {}
        -- iterate over all comma separated fields (that is anything which is not a comma)
        for field in line:gmatch ("([^,]+)" do
            -- and insert the field into the fields list
            table.insert (fields, field)
        end
    end
    -- and close the file when done
    file:close ()
end

Benjamin 'Ben' Legros
Guerilla developer
http://www.guerillarender.com

Offline

 

#11 2015-11-17 16:03:52

hulud
Guerilla dev, the guy to hug

Re: Maya Shader Assignation > Guerilla

Note that you need a csv file, not a xls file.


Cyril 'Hulud' Corvazier
Guerilla developer
http://www.mercs-eng.com

Offline

 

#12 2015-11-18 06:32:19

ravikumar_vsp
Member

Re: Maya Shader Assignation > Guerilla

Thanks Ben!
Thanks Hulud
Will look into generating .csv file from Maya as well.
:-)

Last edited by ravikumar_vsp (2015-11-18 06:32:43)

Offline

 

#13 2015-11-19 09:17:46

hulud
Guerilla dev, the guy to hug

Re: Maya Shader Assignation > Guerilla

By the way you can also :

* generate lua text files to directly get your data in Guerilla with no need of a csv parser
* adding dynamic attributes (shader name, texture filename) on objects which will be exported by the Guerilla plug-in. You could control a custom shader inputs using those attributes.

Cyril


Cyril 'Hulud' Corvazier
Guerilla developer
http://www.mercs-eng.com

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2008 PunBB