Maya's XGEN Geometries To Octane - Script

Forums: Maya's XGEN Geometries To Octane - Script
Post, discuss and share handy resources like textures, models and HDRI maps in this forum.
Forum rules
Please do not post any material that is copyrighted or restricted from public use in any way. OTOY NZ LTD and it's forum members are not liable for any copyright infringements on material in this forum. Please contact us if this is the case and we will remove the material in question.

Maya's XGEN Geometries To Octane - Script

Postby Renart » Sun Dec 04, 2016 6:50 pm

Renart Sun Dec 04, 2016 6:50 pm
Hi!

I was looking for a solution to export the csv format. How to use xgen to scatter objects across a surface and extract the data easily to have the same result in Octane. But I found nothing...
The closest thing I could extract from xgen was a .mel description file.

So with the help of a friend I made a script to extract the matrix information.
I'm not a scripter so there is probably a lot of solutions to improve this. Feel free to have a look.
But the idea is that you generate this description file. You run the script on it and you end up with a simple text file that you just have to copy and paste inside octane. It will automatically create the Read node pointing to the alembic of your objects (based on the xgen's archive) as well as the scatter nodes associated, for each objects.

It's very handy if you have for instance a Forest made with Xgen. Using a lot of different geometries. The script will give you all the read nodes + the scatter node for each type of object.

Hopefully Xgen will be one day supported by the Octane for Maya plugin as well..

Code: Select all
# XGENtoOctane

# This script translate the output mel description from xgen to the Octane's node format.

# HOW TO USE :
#    -Go to Output settings of your Xgen Description
#    -Change the Operation to Create MEL File, Create the file somewhere on your disk
#    -Change the inputFile path below as well as the outputFile path ( I usually use always the same outputFile )
#    -Run the script and open the new outputFile result
#    -copy and paste what's inside the file directly in Octane. It should automatically create the read nodes and scatter nodes, all connected, to match your xgen description.

# Notes :

# This is a very rough script. I'm not a scripter and a friend helped me. There is a lot of room for improvement so feel free to make it better !
# This hasn't been tested a lot, and works only for geometry scattering!

#-------------------CHANGE HERE ! -------------

# Path to .mel file to read :
inputFile = open("C:\Users\****\Desktop\Test_Description.mel", "r")
# Path to .txt file to write :
outputFile = open("C:\Users\****\Desktop\XgenToOctane_Result.txt", "w")


#-------------------------------------------------
lignes = []

reading = True
while reading :
    temp = inputFile.readline()
    if temp == "" :
        reading = False
    else :
        lignes.append(temp)

# Closing, everything is registe in Lignes
inputFile.close()


#Information sorting
# objets : list of [name, path, MatrixList, MatrixListNewFormat]
objets = []

for ligne_iterator in lignes :
    # looking for "AbcImport"
    if ligne_iterator.find("AbcImport") != -1 :
        debutChemin = len(ligne_iterator)-1
        finChemin = debutChemin
        while finChemin >= 0 and ligne_iterator[finChemin] != '"':
            finChemin = finChemin-1
        if finChemin <= 0:
            exit()
        debutChemin = finChemin -1
        while debutChemin >= 0 and ligne_iterator[debutChemin] != '"':
            debutChemin = debutChemin-1
        if debutChemin <= 0:
            exit()
        chemin = ligne_iterator[(debutChemin+1):(finChemin)]

        # add result to the list
        objets.append([chemin[(chemin.rfind('/')+1):len(chemin)-4],chemin,[],[]])
# end name's reading loop

# matrix's reading loop
compteur = -1
for iterator in range(0,len(lignes)) :
    # search for "xform"
    if lignes[iterator].find("xform") != -1:
        finNom = lignes[iterator-1].rfind(':')
        debutNom = lignes[iterator-1].rfind('"',0,finNom)+1
        nom = lignes[iterator-1][debutNom:finNom]
        #print("nom : "+nom+"\n")
        #print("debut : " + str(debutNom)+"\n")
        #print("fin : " + str(finNom)+"\n")
        #print("compteur : " + str(iterator-1)+"\n")
        #print("ligne : " + lignes[iterator-1]+"\n")
        running = True
        k = -1
        while running and k < (len(objets)-1) :
            k = k+1
            if(objets[k][0] == nom):
                running = False
        if(running):
            exit()
        matrice = []
        indice = lignes[iterator].find("-matrix")
        if indice == -1 :
            exit()
        indice = indice + len("-matrix ")
        for j in range(0,16) :
            fin = lignes[iterator].find(" ",indice)
            matrice.append(float(lignes[iterator][indice:(fin)]))
            indice = fin+1
        objets[k][2].append(matrice)
        nouveauFormat = str(matrice[0]) + " " + str(matrice[4]) + " " +str(matrice[8]) + " " + str(matrice[12]) + " " + str(matrice[1]) + " " + str(matrice[5]) + " " + str(matrice[9]) + " " + str(matrice[13]) + " " + str(matrice[2]) + " " + str(matrice[6]) + " " + str(matrice[10]) + " " + str(matrice[14]) + " "
        objets[k][3].append(nouveauFormat)



# Exit data
id_graph = 2
outputFile.write("<?xml version='1.0' encoding='utf-8'?><OCS2 version='3030004'><graph id='1' type='1' name='clipboard'>")
for obj in objets:
    id_mat = id_graph + 1
    id_geo = id_graph + 2
    id_scatter = id_graph + 4
    id_input = id_graph + 2
    outputFile.write("<graph id='%d' type='2' name='"%id_graph+obj[0]+"' inspectable='0' position='315 41'><attr name='filename' type='11'>"+obj[1]+"</attr><attr name='objectLayerImport' type='2'>1</attr><attr name='scaleUnitType' type='2'>4</attr><attr name='useSuppliedVertexNormals' type='1'>1</attr><attr name='maxSmoothAngle' type='6'>89</attr><attr name='defaultHairThickness' type='6'>0.0001</attr><attr name='subdLevel' type='2'>0</attr><attr name='subdSharpness' type='6'>0</attr><attr name='subdBoundInterp' type='2'>3</attr><attr name='subdFaceVaryingBoundInterp' type='2'>3</attr><attr name='subdFaceVaryingPropagateCorners' type='1'>0</attr><attr name='subdScheme' type='2'>1</attr><attr name='windingOrder' type='2'>2</attr><attr name='mergeMaterials' type='1'>1</attr><attr name='loadObjects' type='1'>0</attr><attr name='mergeObjects' type='1'>1</attr><attr name='importCameras' type='1'>1</attr><attr name='extraCameraInputs' type='1'>0</attr><attr name='importGeometry' type='1'>1</attr><attr name='detectInstances' type='1'>0</attr><attr name='subdivideAllMeshes' type='1'>0</attr><node id='%d' type='20007' name='Material' position='0 -150'></node><node id='%d' type='30012' name='Geometry' position='0 150'><pin name='input' connect='5'/></node></graph><node id='%d' type='5' name='Scatter' position='313 115'><attr name='filename' type='11'></attr><attr name='scaleUnitType' type='2'>4</attr><attr name='transforms' type='13' arrayId='7'>"%(id_mat, id_geo, id_scatter))
    for mat in obj[3]:
            for num in mat :
                outputFile.write(str(num) + "")
            outputFile.write("")
    id_graph += 5
    outputFile.write("</attr><attr name='inherit' type='1'>1</attr><pin name='geometry' connect='%d'/></node>" %id_input)

outputFile.write("</graph></OCS2>")
outputFile.close()



Cheers!
Renart
Licensed Customer
Licensed Customer
 
Posts: 33
Joined: Mon Jul 04, 2016 8:21 pm

Re: Maya's XGEN Geometries To Octane - Script

Postby calus » Sun Dec 04, 2016 6:55 pm

calus Sun Dec 04, 2016 6:55 pm
Very nice, thanks !!
Pascal ANDRE
--------------------
Maya 2018 SP1, Windows 7, 128 GB RAM
4x GTX 1070, driver 382.33
--------------------

--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/SEqj3F3Jfepe
--------------------
calus
Licensed Customer
Licensed Customer
 
Posts: 980
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Re: Maya's XGEN Geometries To Octane - Script

Postby calus » Sun Dec 04, 2016 6:59 pm

calus Sun Dec 04, 2016 6:59 pm
The script could be also posted in the help/tutorial/script section of the Maya subforum.
Pascal ANDRE
--------------------
Maya 2018 SP1, Windows 7, 128 GB RAM
4x GTX 1070, driver 382.33
--------------------

--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/SEqj3F3Jfepe
--------------------
calus
Licensed Customer
Licensed Customer
 
Posts: 980
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Re: Maya's XGEN Geometries To Octane - Script

Postby Renart » Mon Dec 05, 2016 1:57 pm

Renart Mon Dec 05, 2016 1:57 pm
Humm maybe, I though the subforum was for the Maya plugin. This script is only for the Standalone.
If a moderator see it feel free to move it to the right place :)
Renart
Licensed Customer
Licensed Customer
 
Posts: 33
Joined: Mon Jul 04, 2016 8:21 pm

Re: Maya's XGEN Geometries To Octane - Script

Postby calus » Mon Dec 05, 2016 2:02 pm

calus Mon Dec 05, 2016 2:02 pm
I didn't mean that you were not at the right place, sorry I wasn't clear.
I will add a link to this place in plugin help section, as when the plugin fail, standalone is the workaround.
Pascal ANDRE
--------------------
Maya 2018 SP1, Windows 7, 128 GB RAM
4x GTX 1070, driver 382.33
--------------------

--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/SEqj3F3Jfepe
--------------------
calus
Licensed Customer
Licensed Customer
 
Posts: 980
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Re: Maya's XGEN Geometries To Octane - Script

Postby Jolbertoquini » Mon Dec 05, 2016 5:21 pm

Jolbertoquini Mon Dec 05, 2016 5:21 pm
pretty good stuff right there! clever thanks Renart! :D

The big issue is the Octane plug is bug and make xgen crash when we create archives. You guys have the same errors?
Octane Render for Maya.
https://vimeo.com/jocg/videos
https://www.linkedin.com/in/jocgtd
http://www.hmxmedia.com/
--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/SEqj3F3Jfepe
User avatar
Jolbertoquini
Licensed Customer
Licensed Customer
 
Posts: 630
Joined: Sun Aug 31, 2014 7:08 am
Location: London

Re: Maya's XGEN Geometries To Octane - Script

Postby Renart » Tue Dec 13, 2016 12:16 pm

Renart Tue Dec 13, 2016 12:16 pm
Yeah, I've got the same issue. If I want to export archive I need to disable the Octane for Maya plugin..

I really hope XGEN will be supported one day. It's such a powerfull tool.
Renart
Licensed Customer
Licensed Customer
 
Posts: 33
Joined: Mon Jul 04, 2016 8:21 pm

Re: Maya's XGEN Geometries To Octane - Script

Postby Jolbertoquini » Tue Jan 10, 2017 10:26 am

Jolbertoquini Tue Jan 10, 2017 10:26 am
Renart wrote:Yeah, I've got the same issue. If I want to export archive I need to disable the Octane for Maya plugin..

I really hope XGEN will be supported one day. It's such a powerfull tool.


Yes same for me, I hope to is really good tool for hairs and others stuffs, let's see the next releases.

Best,
JO
Octane Render for Maya.
https://vimeo.com/jocg/videos
https://www.linkedin.com/in/jocgtd
http://www.hmxmedia.com/
--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/SEqj3F3Jfepe
User avatar
Jolbertoquini
Licensed Customer
Licensed Customer
 
Posts: 630
Joined: Sun Aug 31, 2014 7:08 am
Location: London

Return to Resources and Sharing


Who is online

Users browsing this forum: No registered users and 1 guest

Mon Dec 18, 2017 8:35 pm [ UTC ]