Isotropix Forums

Layout from Maya to Clarisse

Clarisse Scripting related topics

Layout from Maya to Clarisse

Unread postby loneill » Tue Sep 26, 2017 4:06 pm

Hi,

I am tasked with reproducing a Maya scene in Clarisse.
Layout is done in Maya with proxy geo. A scene xml file is then generated which contains the path to the hi-res alembic files as well as the xform transformation matrix. I would like to decompose the xform values, get the relevant information (transformation, scale, rotation), import in the corresponding alembic files and set their attributes accordingly. This will automate the artist layout in Clarisse and will be a huge time saver.

My first question is, does Clarisse have any functions that will decompose the xform transformation matrix and return transformation, scale, rotation?
Second question is, do you recommend a different approach for laying out a scene in Clarisse that was done in Maya.

Thanks!
loneill
 
Posts: 5
Joined: Tue Sep 26, 2017 3:49 pm

Re: Layout from Maya to Clarisse

Unread postby bvaldes » Wed Sep 27, 2017 4:22 pm

Hi,

Could you please explain a bit more, or at least give us a sample of the XML file.

If you could provide us a sample of the XML file and explain how do you create it, it could help us a lot to understand your pipeline.

About the different approach, there is not a perfect one, it depends on your needs. Moreover, if I had to do this kind of script, I will make 2 scripts:
- Maya's script that creates the XML file by parsing all objects in my scene. All the objects are proxy and have a custom attribute that point on the Hi-res path. The script grabs the Hi-res path and the matrix of the proxy and stores the information inside of the XML file.
- Clarisse's script that parses the XML file, get the path of the model, import it and set the good transform.

As I said there is no perfect way and I think that we can do something without restart from scratch if you could provide us the right information.

Regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 153
Joined: Mon Sep 26, 2016 11:44 am

Re: Layout from Maya to Clarisse

Unread postby bvz2000 » Wed Sep 27, 2017 7:55 pm

You could also just export the Maya scene as an alembic. That way all of the xforms are embedded in your scene along with the native hierarchy that you create inside of Maya.

What I would explore is this: In Maya, I'd replace each lores geometry item with a locator. Then I would open this Alembic in Clarisse and save it out as a Clarisse project (layout_reference_v001.project).

Then in Clarisse I'd write a script that references this project, imports the hires geometry, makes this geo children of the locators in the referenced project (based on name), and zero's out the transformations. You should have a scene where the hires geometry lives in the correct location with the correct transformations.

Later, if the Maya layout changes, simply re-export the Maya scene as an alembic, read it into a separate Clarisse scene, save it out as your "layout_reference_v002.project", and then reload that reference and all of your Clarisse geo *should* move to the correct location. (Note: I have not tried this, it is just the first thing that pops into my head).

Ultimately your original plan is more robust, but will also take a lot of programming to handle edge cases and transform hierarchies etc. The advantage of using an Alembic as your transfer format vs. xml is that Clarisse (and Maya) natively read alembics, which means that all the transform manipulations are done for you.

That said, I haven't tried this so there may be roadblocks I am not thinking of.
bvz2000
 
Posts: 340
Joined: Thu Nov 13, 2014 7:05 pm

Re: Layout from Maya to Clarisse

Unread postby loneill » Wed Sep 27, 2017 9:37 pm

@bvaldes

Thanks for the quick response!
Below is an example of the xml file exported out of Maya. It contains the xform transformation matrix and the path to the hi res alembic file.
This is what we use in Katana to assemble our scene. From what I've been told, Katana has a node that parses this xml and is able to determine the location, scale, transform of the asset from the xform transformation matrix.I'm not too concerned with the parsing aspect of things more so the decomposition of the xform values into useable location, scale, rotation values in Clarisse.

xml code

<?xml version="1.0" encoding="UTF-8"?>
<scenegraphXML version="0.1.0">
<instanceList>
<instance groupType="assembly" name="item_a" type="group">
<bounds maxx="109.5480637" maxy="62.03710598" maxz="-60.38813261" minx="50.46317526" miny="41.62017811" minz="-120.757277" />
<xform value="1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0" />
<instanceList>
<instance groupType="lodGroup" name="item_geometry_hires" type="group">
<bounds maxx="109.5480637" maxy="62.03710598" maxz="-60.38813261" minx="50.46317526" miny="41.62017811" minz="-120.757277" />
<xform value="1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0" />
<instanceList>
<instance name="item_geometry_parent_hires" refFile="/fpath/cauldron_01_aa__geometry__hires.abc" refType="abc" type="reference">
<bounds maxx="109.5480637" maxy="62.03710598" maxz="-60.38813261" minx="50.46317526" miny="41.62017811" minz="-120.757277" />
<xform value="1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 80.2593559839 42.4934811039 -90.6733613351 1.0" />
</instance>
</instanceList>
</instance>
</instanceList>
</instance>
</instanceList>


Your suggestion would definitely work, but would require me to create some custom script for exporting out an xml with translation, rotation, scale explicitly stated. I would like to avoid this if possible.

I've implemented a combination of these two papers in an attempt to decompose the xform matrix without much success. Below you can find my implementation.

https://math.stackexchange.com/question ... ion-rotati
http://citeseerx.ist.psu.edu/viewdoc/do ... 1&type=pdf

python code

def translation(m):

return m[12], m[13], m[14]


def scale(m):

sx = math.sqrt(math.pow(m[0], 2) + math.pow(m[4], 2) + math.pow(m[8], 2))
sy = math.sqrt(math.pow(m[1], 2) + math.pow(m[5], 2) + math.pow(m[9], 2))
sz = math.sqrt(math.pow(m[2], 2) + math.pow(m[6], 2) + math.pow(m[10], 2))
return sx, sy, sz


def rotation(m):

sx, sy, sz = scale(m)

# rotation matrix
r = [ m[0]/sx, m[1]/sy, m[2]/sz,
m[4]/sx, m[5]/sy, m[6]/sz,
m[8]/sx, m[9]/sy, m[10]/sz,
]

# test rotation matrix values
# r = [0.5, -1.464, 0.8536, 0.5, 0.8536, -1.464, -0.7071, 0.5, 0.5]
# rx,ry,rz = (pi/4, pi/4, pi/4)

# Rotation around y
theta_1 = -math.asin(r[6])
theta_2 = math.pi - theta_1

# Rotation around x
gamma_1 = math.atan2(r[7]/math.cos(theta_1), r[8]/math.cos(theta_1))
gamma_2 = math.atan2(r[7]/math.cos(theta_2), r[8]/math.cos(theta_2))

# Rotation around z
phi_1 = math.atan2(r[3]/math.cos(theta_1), r[0]/math.cos(theta_1))
phi_2 = math.atan2(r[3]/math.cos(theta_2), r[0]/math.cos(theta_2))

return math.degrees(gamma_1), math.degrees(theta_1), math.degrees(phi_1)
# return math.degrees(theta_2), math.degrees(gamma_2), math.degrees(phi_2)


if __name__ == "__main__":

# xform transformation matrix obtained from maya
m = [4.9809734904587275, 0.0, -0.4357787137382908, 0.0,
0.0, 10.0, 0.0, 0.0,
1.3073361412148725, 0.0, 14.942920471376183, 0.0,
0.0, 0.0, 0.0, 1.0]

print translation(m)
print scale(m)
print rotation(m)
loneill
 
Posts: 5
Joined: Tue Sep 26, 2017 3:49 pm

Re: Layout from Maya to Clarisse

Unread postby loneill » Wed Sep 27, 2017 9:38 pm

@bvz2000

Thanks for your suggestion! This is what we are currently doing albeit, manually. We cannot layout our scene in maya with hires geo because it would be extremely slow, so we use proxy geo. We put a locator on the low res geo (there is some automation to this) and save the locators out as an alembic. We then use this alembic file in Clarisse and the artist manually references in the corresponding assets, zeroes out the transforms and parents under the locator. Since our scenes can get pretty massive, this is very time consuming for the artists. Your method for autoupdating the layout is something new though, I'll have to look into this!

My goal is to find the best way of bringing the layout scene from maya to clarisse. It would be ideal if I could use the xml file as it gets rid of the locator alembic middleman approach we've been using.
loneill
 
Posts: 5
Joined: Tue Sep 26, 2017 3:49 pm

Re: Layout from Maya to Clarisse

Unread postby bvaldes » Thu Sep 28, 2017 10:44 am

Hi,

Thanks for these information, I need just one more: a matrix and the transform displayed in Maya (translate, rotate, scale).
With that, I could find a function to extract the correct values from the matrix If you could provide me a matrix generated by your script and the result in Maya.

Regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 153
Joined: Mon Sep 26, 2016 11:44 am

Re: Layout from Maya to Clarisse

Unread postby loneill » Thu Sep 28, 2017 5:21 pm

@bvaldes

I created a poly cube at origin and manipulated in the following way.

tx,y,z = translation in x,y,z
rx,y,z = rotation in x,y,z
sx,y,z = scale in x,y,z

tx=5
ty=10
tz=20
t = [5,10,20]

rx=30
ry=40
rz=50
r = [30,40,50]

sx=3
sy=3
sz=3
s = [3,3,3]

resulting xform transformation matrix:

[1.4772116295183122, 1.7604722665003958, -1.9283628290596182, 0.0,
-1.3704779777570133, 2.4086170124384143, 1.1490666646784666, 0.0,
2.222529170584472, 0.315121383398856, 1.9902418445068155, 0.0,
5.0, 10.0, 20.0, 1.0]

Running the code I provided returns:
t = [5.0, 10.0, 20.0]
s = [3.0, 3.0000000000000004, 3.0]
r = [8.997136625188745, -47.803280676855046, -42.8535137670853]

I'm unable to decompose the rotation to the original values.
loneill
 
Posts: 5
Joined: Tue Sep 26, 2017 3:49 pm

Re: Layout from Maya to Clarisse

Unread postby bvaldes » Fri Sep 29, 2017 10:20 am

Hi,

After some investigation, I found several useful Clarisse's functions available in python to manipulate the matrices.

python code

xmlData = [1.4772116295183122, 1.7604722665003958, -1.9283628290596182, 0.0, -1.3704779777570133, 2.4086170124384143, 1.1490666646784666, 0.0, 2.222529170584472, 0.315121383398856, 1.9902418445068155, 0.0, 5.0, 10.0, 20.0, 1.0]
matrix = ix.api.GMathMatrix4x4d() # The Clarisse's matrix object

#We will fill the matrix with the given values
for i in range(16):
# As a matrix is a 4x4 array, we have to find X and Y values
x = i%4
y = int(i/4)
matrix.set_item(x, y, xmlData[i])

# The CLarisse's item that will recieve the extracted data from the matrix (the extract functions will fill them)
translate = ix.api.GMathVec3d()
rotate = ix.api.GMathVec3d()
scale = ix.api.GMathVec3d()

# Extract function to extract data from the matrix
matrix.extract_translation(translate)
matrix.compute_euler_angles(rotate, ix.api.GMATH_ROTATION_ORDER_XYZ) # The second parameter specify the rotation order (probably the thing that miss you in your script)
matrix.extract_scaling(scale)

# You won't be able to display the content of the translate, rotate and scale variables directly.
# But you can navigate into them like in LIST in Python
print "translate: ", translate[0], translate[1], translate[2] # translate: 5.0 10.0 20.0
print "rotate: ", rotate[0], rotate[1], rotate[2] # rotate: 30.0 39.999999461 50.0
print "scale: ", scale[0], scale[1], scale[2] # scale: 3.0 3.0 3.0

As you can see, there is just an aproximation issue with RotationY. This aproximation comes from the XML data but is ridiculusly small.
Feel free to ask if you need more explication, Regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 153
Joined: Mon Sep 26, 2016 11:44 am

Re: Layout from Maya to Clarisse

Unread postby loneill » Fri Sep 29, 2017 9:56 pm

Great, this is exactly what I was looking for!
Thanks for looking into this!
loneill
 
Posts: 5
Joined: Tue Sep 26, 2017 3:49 pm


Return to Scripting