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!