Problems with mesh export (python API)

Discussion related to the 'LuxMaya' exporter plugin for Autodesk Maya.

Moderators: Ratow, coordinators

Re: Problems with mesh export (python API)

Postby Radiance » Wed May 07, 2008 1:12 am

hey,

nice one :)
Send a PM to user 'dco', he's also a maya user, he could help you out with testing etc...

greetz,
radiance
User avatar
Radiance
 
Posts: 3968
Joined: Wed Sep 19, 2007 2:13 am

Re: Problems with mesh export (python API)

Postby Radiance » Wed May 07, 2008 1:31 am

Hi,

The pbrt book does'nt mention Nurbs apparently, i think they were added afterwards.
Anyways judging from the code they are refined during scene building into trianglemeshes,
by rendering/dicing them to a trianglemesh.

I don't know how other renderers do this as i have absoluteley no experience with nurbs,
and don't know if there are readily available approaches to intersect them directly during rendering,
this might be the reason why this is so, or otherwise, don't know.

Anyways i think it would be more flexible for the user to do the conversion from nurbs primivites in a 3D app
during export to trianglemeshes as you'd have more control over dicing resolution etc...

greetz,
radiance
User avatar
Radiance
 
Posts: 3968
Joined: Wed Sep 19, 2007 2:13 am

Re: Problems with mesh export (python API)

Postby dougal2 » Wed May 07, 2008 10:20 am

OK cool. I proved it to work at least. If an expert wants to refine the code then it's there ready and waiting.
I'm much like you though, don't know too much about it, and I'm not going to do any more on the nurbs module.
User avatar
dougal2
Developer
 
Posts: 3074
Joined: Mon Jan 14, 2008 7:21 am

Re: Problems with mesh export (python API)

Postby dougal2 » Thu May 08, 2008 11:32 pm

SUCCESS !!

After R'ing TFM I've discovered the MScriptUtil class which is designed to specifically solve the problem of passing references to basic types to methods.
Then examining some of the sample code in the Maya devkit, I have constructed some code that looks something like this:
Code: Select all
    # Setup 'proxy' and pointer
    numTrianglesPx = OpenMaya.MScriptUtil()
    numTrianglesPx.createFromInt(0)
    numTrianglesPtr = numTrianglesPx.asIntPtr()

    # pass pointer
    itMeshPolygon.numTriangles(numTrianglesPtr)
       
    # get real int value back from pointer
    numTriangles = OpenMaya.MScriptUtil(numTrianglesPtr).asInt()


I can now proceed to export properly triangulated meshes and UV coordinates.

The next big problem I face is sorting out normal smoothing. I'm gonna just outright ask anyone for help on this one. HELP!?
User avatar
dougal2
Developer
 
Posts: 3074
Joined: Mon Jan 14, 2008 7:21 am

Re: Problems with mesh export (python API)

Postby dougal2 » Fri May 09, 2008 12:19 am

Here's a render with the proper triangulation code:

I twisted the cylinder to see the effect on those quads... not really very pretty
Attachments
newmeshcode.jpg
User avatar
dougal2
Developer
 
Posts: 3074
Joined: Mon Jan 14, 2008 7:21 am

Re: Problems with mesh export (python API)

Postby Radiance » Fri May 09, 2008 1:39 am

Hey,

It's very simple really:

no smoothing: only export faces and vertices
smoothing: export faces, vertices and normals. (per vertex normals) (see options for 'trianglemesh' in scenefile docos)

maya should be able to supply you with vertex normals easily, it's a standard thing.

for tricky things like when you need normals but you don't want smoothing (like glass materials which need the right facing normals),
do this:

Write out your faces with unique vertices for each, and write the face normal for all 3 triangle vertices you exported for it (they will be same values)
So you end up with unique vertices for your faces (eg mutliple faces connected to eachother will not share them anymore)

I suggest you get the first stuff going, then worry about the tricky bit above.

greetz,
radiance
User avatar
Radiance
 
Posts: 3968
Joined: Wed Sep 19, 2007 2:13 am

Re: Problems with mesh export (python API)

Postby dougal2 » Fri May 09, 2008 9:57 am

Trouble is I'm already exporting the normals - these meshes are supposed to be smooth!
User avatar
dougal2
Developer
 
Posts: 3074
Joined: Mon Jan 14, 2008 7:21 am

Re: Problems with mesh export (python API)

Postby Radiance » Fri May 09, 2008 10:04 am

Hey,

there are 2 kinds of normals:

- face normals (for unsmooth objects)
- vertex normals (for smooth objects)

i mean the vertex normals, not the face normals :)

you might be ending up exporting face normals as vertex normals (lxs) which will end up being non-smooth.

greetz,
radiance
User avatar
Radiance
 
Posts: 3968
Joined: Wed Sep 19, 2007 2:13 am

Re: Problems with mesh export (python API)

Postby Radiance » Fri May 09, 2008 10:08 am

look at the box attached,
the normals in the middle of the faces are face normals,
the ones sticking out of the vertices are vertex normals.

if you supply the vertex normals, the box will be rendered smooth.

choosing an object to be smoothed or not in your 3d app will use vertex normals instead of face normals,
with lux you export what you need in question.

greetz,
radiance
Attachments
vnormals.jpg
User avatar
Radiance
 
Posts: 3968
Joined: Wed Sep 19, 2007 2:13 am

Re: Problems with mesh export (python API)

Postby Radiance » Fri May 09, 2008 10:18 am

in this pic we're rendering a non smoothed box,
but we're passing face normals to lux (masquerading as vertex normals)

in this scenario we're actually having 3 vertices at each point with they're own vertex normals.
so in total 24 vertices (4 per face) are exported. (and during export each quad is cut into 2 triangles! :) )
this is'nt very optimal, so in case of non smooth objects, just drop them, lux can calculate these for you. (and only export the 8 original vertices)
(if it's really necessary like with portals or transmitters, you can use this scenario)

so i'll sum it up:

non-smooth: export faces, vertices
smooth: export faces, vertices and vertexnormals
non-smooth but need to control direction of faces?: export faces, vertices and facenormals as vertexnormals, but triple your vertices and each vertex normal belonging to a face is the same face normal.

check the luxblend export mesh function, it's python too and very readable and it explains it all :)

greetz,
radiance
Attachments
fnormals.jpg
User avatar
Radiance
 
Posts: 3968
Joined: Wed Sep 19, 2007 2:13 am

PreviousNext

Return to LuxMaya (Autodesk Maya Exporter)

Who is online

Users browsing this forum: Bing [Bot] and 1 guest