Custom Exporter plugin for maya
by Celu Ramasamy
I implemented an exporter plugin for maya to enable my renderer to import maya scenes. The plugin exports the scene in a custom format(.celu). I designed the .celu format in such a way that before you actually parse any given data item, you will know the count of the number of items that are going to follow. This is something that I found to be missing with the .obj format. Getting the count of the number of items that are going to follow helps in two ways:
i) it makes error checking and identifying corrupt data a lot easier.
ii) In languages like C, that do not provide support for STL vector and list (as C++ does), you must implement a linked list in order to parse an .obj file as you don't know the number of items present in that file before hand. with .celu format since you have to access to the item count before hand, you can directly read in the data items without the need for any linked list.
Currently this format,
i) supports exporting of polygonal data, including vertex colors, vertex normals and multiple UV sets.
ii) recognizes object instances
iii) exports lights (currently only point and spot lights are exported).
iv) exports cameras.
I keep adding new features to the .celu format as and when I need them for my Renderer.
File Format Details
i) The position and direction values are exported in world space.
ii) Lights, Camera and Geometry information are all in separate files so that one can be replaced independent of the other in a scene.
iii) when a scene is exported using the .celu exporter plug-in, the following files are generated.
-> FileName_header.celu
-> FileName_data.celu
the above two files contain the actual geometric information for the scene. The '_header.celu' file contains a kind of an overview of what and how many objects are present in the '_data.celu' file. The '_data.celu' file contains the actual geometry data. You could recreate the entire scene only by parsing the '_data.celu' file. But, you won't be able to perform proper error checking.
-> FileName_light.celu - contains the light data for the scene.
-> FileName_camera.celu - contains the camera data for the scene
Structure and Content Of The Individual Files
Note: The keywords present in the files are identified using italics.
'_header.celu' : contains the count of the total number of meshes in the scene and also the instance count of each mesh. These values can be used for verification and memory allocation when parsing the '_data.celu' file.
File Structure:
mesh, Number Of Meshes, Instance Count for Mesh 1, Instance Count for Mesh 2, Instance Count for Mesh 3,......., Instance Count for Mesh N,
Example:
Header file for a scene containing 3 meshes each with one instance.
mesh,3,1,1,1,
'_data.celu' : contains the actual geometry data for the scene.
File Structure:
m, Name of Mesh1, instance, Instance Count, vertices, Number Of Vertices, v,Vertex1 X Component,Vertex1 Y Component,Vertex1 Z Component, v, Vertex2 X Component,Vertex2 Y Component,Vertex2 Z Component,...., normals, Number Of Normals, n, Normal1 X Component, Normal1 Y Component, Normal1 Z Component,....., uvsetcount, Number of UV sets, Name of UV Set1, Number of Pairs of Values for UV set1,U1,V1,U2,V2,..., Name of UV Set2, Number of Pairs of Values for UV set2,U1,V1,U2,V2,....., facecount, Number Of Polygonal Faces, f, Number Of Vertices for Face1, vi, Index into vertices array for face vertex1, Index into vertices array for face vertex2,..., ni, Index into normals array for face vertex1, Index into normals array for face vertex2,..., uvi, UV Set ID 1, Index into UV set 1 array for face Vertex1, Index into UV set 1 array for face Vertex2,...., UV Set ID 2, Index into UV set 2 array for face Vertex1, Index into UV set 2 array for face Vertex2,...., vc, Red Component of Vertex Color for face vertex1, Green Component of Vertex Color for face vertex1, Blue Component of Vertex Color for face vertex1, Alpha Component of Vertex Color for face vertex1, Red Component of Vertex Color for face vertex2, Green Component of Vertex Color for face vertex2, Blue Component of Vertex Color for face vertex2, Alpha Component of Vertex Color for face vertex2,...., f, Number Of Vertices for Face2, vi, Index into vertices array for face vertex1, Index into vertices array for face vertex2,..., ni, Index into normals array for face vertex1,......,m, Name of Mesh2, instance, Instance Count, vertices, v, Vertex1 X Component, Vertex1 Y Component, Vertex1 Z Component,........
Example:
Data file for a scene containing a cube.
m,pCubeShape1,instance,1,vertices,8,v,-5.872517e+000,1.075831e+001,3.629219e+000,v,9.072774e-001,1.061832e+001,9.059445e+000,v,-2.070499e+000,1.647406e+001,-9.703567e-001,v,4.709295e+000,1.633407e+001,4.459869e+000,v,2.294899e+000,9.029851e+000,-6.612596e+000,v,9.074693e+000,8.889859e+000,-1.182370e+000,v,-1.507118e+000,3.314102e+000,-2.013019e+000,v,5.272676e+000,3.174110e+000,3.417207e+000,normals,24,n,-4.233907e-001,7.219979e-001,5.472288e-001,n,-4.233907e-001,7.219979e-001,5.472288e-001,n,-4.233907e-001,7.219979e-001,5.472288e-001,n,-4.233907e-001,7.219979e-001,5.472288e-001,n,4.601119e-001,6.917076e-001,-5.566307e-001,n,4.601119e-001,6.917076e-001,-5.566307e-001,n,4.601119e-001,6.917076e-001,-5.566307e-001,n,4.601119e-001,6.917076e-001,-5.566307e-001,n,4.233907e-001,-7.219979e-001,-5.472288e-001,n,4.233907e-001,-7.219979e-001,-5.472288e-001,n,4.233907e-001,-7.219979e-001,-5.472288e-001,n,4.233907e-001,-7.219979e-001,-5.472288e-001,n,-4.601119e-001,-6.917076e-001,5.566307e-001,n,-4.601119e-001,-6.917076e-001,5.566307e-001,n,-4.601119e-001,-6.917076e-001,5.566307e-001,n,-4.601119e-001,-6.917076e-001,5.566307e-001,n,7.804086e-001,-1.611420e-002,6.250624e-001,n,7.804086e-001,-1.611420e-002,6.250624e-001,n,7.804086e-001,-1.611420e-002,6.250624e-001,n,7.804086e-001,-1.611420e-002,6.250624e-001,n,-7.804086e-001,1.611420e-002,-6.250624e-001,n,-7.804086e-001,1.611420e-002,-6.250624e-001,n,-7.804086e-001,1.611420e-002,-6.250624e-001,n,-7.804086e-001,1.611420e-002,-6.250624e-001,uvsetcount,1,map1,14,3.750000e-001,0.000000e+000,6.250000e-001,0.000000e+000,3.750000e-001,2.500000e-001,6.250000e-001,2.500000e-001,3.750000e-001,5.000000e-001,6.250000e-001,5.000000e-001,3.750000e-001,7.500000e-001,6.250000e-001,7.500000e-001,3.750000e-001,1.000000e+000,6.250000e-001,1.000000e+000,8.750000e-001,0.000000e+000,8.750000e-001,2.500000e-001,1.250000e-001,0.000000e+000,1.250000e-001,2.500000e-001,facecount,6,f,4,vi,0,1,3,2,ni,0,1,2,3,uvi,1,0,1,3,2,vc,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,f,4,vi,2,3,5,4,ni,4,5,6,7,uvi,1,2,3,5,4,vc,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,
f,4,vi,4,5,7,6,ni,8,9,10,11,uvi,1,4,5,7,6,vc,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,f,4,vi,6,7,1,0,ni,12,13,14,15,uvi,1,6,7,9,8,vc,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,
f,4,vi,1,7,5,3,ni,16,17,18,19,uvi,1,1,10,11,3,vc,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,f,4,vi,6,0,2,4,ni,20,21,22,23,uvi,1,12,0,2,13,vc,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,
'_light.celu' : contains the light data for the scene
File Structure:
Total Number of Lights in the Scene, light, Light ID 1,Position,Position of the Light (X,Y,Z), color, Color of the Light (R,G,B), intensity, Intensity Of the Light, decayrate, Decay Rate for the Current Light, direction, Direction in which the light is pointing, coneangle, Cone Angle of the Current Light, penumbraangle, Penumbra Angle of the current Light, light, Light ID 2,Position,Position of the Light (X,Y,Z),......
Example:
Light file for a scene containing a single light.
1,light,1,position,5.370834e+001,5.077496e+001,0.000000e+000,color,1.000000e+000,1.000000e+000,1.000000e+000,intensity,1.000000e+000,decayrate,0,direction,-7.240072e-001,-6.854781e-001,-7.702859e-002,coneangle,6.981317e-001,penumbraangle,0.000000e+000,
'_camera.celu' : contains the camera information for the scene
File Structure:
Total Number Of Cameras in the scene, camera, Name of the Camera1, eyepoint, Eye Point of the Camera1(X,Y,Z), lookatpoint, Look At point of Camera1(X,Y,Z), viewvector, View Direction of the Camera(X,Y,Z), upvector, Up Vector of the Camera (X,Y,Z), rightvector, Right Vector of the Camera(X,Y,Z), aspectratio, Pixel Aspect Ratio for the camera, verticalfov, Vertical Field of View of the camera, nearplane, Near Projection Plane Distance of the camera, farplane, Near Projection Plane Distance of the camera, camera, Name of the Camera2, eyepoint, Eye Point of the Camera1(X,Y,Z),......
Example:
1,camera,perspShape,eyepoint,1.640495e+002,9.943687e+001,5.128070e+001,lookatpoint,3.877711e+001,1.831747e+001,9.121887e+000,viewvector,-8.077737e-001,-5.230692e-001,-2.718459e-001,upvector,-4.957485e-001,8.522902e-001,-1.668378e-001,rightvector,3.189593e-001,0.000000e+000,-9.477684e-001,aspectratio,1.500000e+000,verticalfov,6.605947e-001,nearplane,1.000000e-001,farplane,1.000000e+003,
Downloads:
Plugin:
CeluExporter.mll - Celu Exporter plugin for maya 8.5 (Windows Version)
Parser:
C version of the parser - Basic parser implemented in C.
C++ version of the parser - Robust parser in C++, identifies corrupt data as being mesh critical or polygon critical and based on that skips only the affected mesh or polygon and continues to read in the rest of the scene that contains valid data (Recommended Parser).
© 2007 Celambarasan Ramasamy. All rights reserved.