Riptide - Wavefront .Obj Import/Export Plugin


#1

My new plugin is nearing completion and I thought I’d show a little preview of it here…

Below are some excerpts from the included Readme file [Long/Wordy post warning!]:

------------------- S N I P ----------------------

Introduction:

I got frustrated by the inflexible way that C4D handles .obj files and decided that I could do a better job of it - this plugin package is the result…

Included in this package is a “Wavefront .obj File Format Import/Export Filter Plugin”. The current plugin consists of 2 new tags - a “Group Tag” and a “Region Tag” used to (optionally) specify ‘Groups’ and ‘UVMapper Regions’, along with the Import and Export filters with extensive output/formatting options. The plugin was written for/using the v7.303 and v8.5 C++ SDKs (PC ONLY - sorry) and has been tested in C4D v7.303, v8.207 and v8.503.

Background:

I guess I should start by describing some of the reasoning/issues behind writing this plugin… I primarily use C4D to produce clothing/props/models to be used in Poser. Poser supports several 3D formats, but I’m very familiar with the Wavefront .obj format, it’s very flexible, it’s ASCII (easily accessible) and it’s become the somewhat de facto standard among Poser artists. However, C4D’s implementation of the format leaves some things to be desired…

C4D .obj Export Issues:

  • all ‘materials’ from a particular mesh are condensed and combined into the first material listed on the mesh. This is probably the biggest problem I continually ran into. I might have a dozen or more material selections defined on a single mesh (skinhead, lips, nostrils, eyesockets, innermouth, gums, skinbody, fingernails, toenails, nipples, etc), but when I export the model, I was LOSING all of those material selections and had to recreate them using some external application (UVMapper, for example). It’s very easy to define these selections within C4D and can be quite a pain to do in other applications… so losing them all on export sucks.

  • no real ‘group’ support and/or inflexible group support, where it exists. Basically, C4D creates ONE group record for each ‘mesh’ (a separate group of polygons) contained in the document and the group name is basically made up from all of the grouping hierarchy used within the C4D tree, so you might end up with something like:

Hyper_NURBS:Symmetry:Eye_Base:Left_Eye

…as a group name in the .obj file (note that the ':'s are added by C4D on import - they are spaces in the .obj file). This is perfectly valid and probably a reasonable approach (C4D is a general-purpose 3D editor and not designed around the .obj file format), but the file format allows for MULTIPLE groups per mesh, which can all share the same set of vertices (see the import section below for additional issues related to this).

Anyway, a typical Poser humanoid character might have dozens of groups within the same ‘mesh’ (head, neck, chest, abdomen, hip, left collar, right collar, left shoulder, right shoulder, left forearm, right forearm, lots-o-finger-segments, you get the idea…). Short of creating separate ‘meshes’ for each of these ‘groups’, there’s no way of defining them within
C4D currently.

  • normals are ‘reversed’. This one is no big deal really… they had to pick a direction, but the one they picked doesn’t happen to coincide with Poser’s idea of which way they should face (or even C4D’s, for that matter, so I guess they get a ‘bonk’ for this one as well ;). Anyway, the normals can be flipped around on import to Poser, export from UVMapper or prior to export in C4D, but the new plugin makes it easy to get it right to start with.

  • no support for UVMapper ‘regions’. As far as I know, ‘regions’ are something Steve Cox (author of UVMapper) came up with and implemented as an extension to the .obj format (using comment fields), so this issue is clearly not an omission with the C4D code, but I thought it would be handy to be able to define these while modelling, to help with UV Mapping and layout later on (these ‘regions’ are just another way of grouping polygons together, but they are separate from and can ‘span’ across group boundaries, which makes them very useful).

C4D .obj Import Issues:

  • Material import… while C4D drops the ball on exporting materials, it actually does retain/recreate the proper polygon selections on import. I guess my only real issues/complaints here is the choice of naming of those selections (“Selection 1” … “Selection 2” … “Selection 3”, etc.). Why not just use the material name(s)? And the fact that it makes no attempt to actually read the .mtl file and reproduce any of the desired material settings.

  • Groups. This is a tough one and I can’t really cast to much blame for this one. Programmatically, it’s very difficult (very time-comsuming, at the least) to determine the ‘intent’ of how a .obj file should be broken up upon import into separate meshes. There are a couple of obvious choices…

a) create one big mesh, and create polygon selection tags for each ‘group’ record.
b) create a separate mesh for each group record.

…C4D chose option ‘b’. Unfortunately, neither of those options is optimal in all situations, though option ‘a’ would have been less ‘destructive’. By that, I’m referring to the fact that implementing option ‘b’ means creating new vertices at the seams between what used to be group selections of the same mesh. This can screw up vertex ordering, for things like morph files.

  • Loss of UVMapper regions. Again, I’m not casting blame on this one, but an import filter could preserve (recreate) these as polygon selections.

  • Lack of additional import options. There are no options to flip normals or textures or… well, any options, aside from the scaling factor.

Implementation:

Ok, so now you know some of the issues I was trying to address and while I was at it, I came up with some additional features to add flexibility. The plugin itself is made up of two new Tags, as well as an Import and Export plugins. Below I will describe the role and function of each.

Group Tag

This is a new tag that can be attached to your polygonal mesh objects (Editable Meshes). To add one, right-click on the mesh name in the Objects Tab, then select “New Tag->Plugin Tags->Group Tag” (or just “New Tag->Group Tag” in v8.x) from the menu. A dialog will open, displaying all available/current (and named, btw) ‘Polygon Selection Tags’. You can move these from the ‘Available’ to the ‘Selected’ list (and back) by highlighting them with the mouse and clicking on the appropriate arrow gadgets.

By moving a selection to the ‘Selected’ list, you are basically defining that polygon selection as a ‘Group’. The export filter will scan this list of selections and create the appropriate group records within the .obj file. The tag itself will be saved/loaded with your .c4d file.

Region Tag

This new tag functions identically to the Group Tag outlined above. To add one, right-click on the mesh name in the Objects Tab, then select “New Tag->Plugin Tags->UVM Region Tag” (or just “New Tag->UVM Region Tag” in v8.x) from the menu.

By moving a selection to the ‘Selected’ list, you are basically defining that polygon selection as a ‘UVMapper Region’. The export filter will scan this list of selections and create the appropriate region records within the .obj file.

.obj Export Plugin

Once the plugin is installed, a new option shows up in the Plugins menu, named “Riptide”. One of it’s sub-menus is named “.Obj Exporter”. After selecting a filename, an export options dialog will appear. Below is a description of each option…

o Scale Factor:
This is used for scaling the output mesh and should be set to the same value as the C4D .obj import/export value.

o Export Faces
You can choose to export the polygon faces or not (morph files don’t need faces, just vertices, for example). Also enables the additional Face Sorting options…

o C4D Ordering
Writes out the facet (polygon) records in the order encountered in the C4D in-memory image.

o Sort By Material
Sorts facets (within each mesh) based on the material groups.

o Sort By Group
Sorts facets (within each mesh) based on the Group Tag selections.

o Sort By Region
Sorts facets (within each mesh) based on the Region Tag selections.

…just as background, it doesn’t adversely affect anything to change the ‘order’ facets are listed in the .obj file (unlike vertex ordering, which can redefine things to the extent that may break things like morph files). There are a couple of reasons that you might want to sort them differently, and most of them have to do with aesthetics (.obj files are human-readable ASCII text files) or file-size, but may also be relevant for application implementers who prefer a particular ordering.

o Reverse Faces
This reverses the winding order of the polygons (in effect, changing the direction that the ‘Normals’ point), which changes the direction that the polygons face. Since C4D itself uses the opposite face direction for determining backface culling, you should pretty much always leave this option selected.

o Export UV Coords
UV (sometimes called UVW) Coordinates are basically the texture coordinates… you can choose to export these or not.

o Flip UV Horizontally/Vertically
If your textures show up upside-down or flipped left->right in whatever external application you use, you can use these options to flip them around.

o Export Materials
Enable/Disable saving material groups. Note that these groups are saved based on the materials/selections you have set up in C4D. To get the expected results, you really should use the ‘Restrict to Selection’ feature of the material dialog. As implemented, a “default” material record will be written to hold any polygons that don’t belong to any other material group.

o Export Groups
This option determines whether any group records are written to the exported file and also enables the additional group options on the dialog…
o Mesh Names
determines whether the mesh names are written to the file (default C4D behavior is to write out the mesh names as groups).

o As groups
mimic C4D .obj export functionality

o As UVMapper Regions
write the mesh names out as UVMapper Regions instead of Groups (without using any Region tags, you can still create ‘region wrappers’ around the separate meshes being saved).

o Group Tag Names
determines whether the list of selections in the Group Tag(s) are saved as group records. As implemented, a “default” group record will be written to hold any polygons that don’t belong to any other group.

o Preserve Hierarchy
using the example given earlier, would produce “Hyper_NURBS:Symmetry:Eye_Base:Left_Eye” when enabled or just “Left_Eye” as a group name if disabled.

o Export Regions
determines whether the list of selections in the Region Tag(s) are saved in the output file. As implemented, a “default” region record will be written to hold any polygons that don’t belong to any other region.

.obj Import Plugin

The other sub-menu of the new “Plugins->Riptide” menu is “.Obj Importer”. This feature will allow you to import either a Wavefront format “.obj” mesh file or a Wavefront format “.mtl” material file (importing a .obj file can also import the specified .mtl file… see below for details).

If a .mtl file is selected, that file is read any existing materials in the active document that are named the same are updated with the new information. New materials are created for any uniquely named materials found in the file. If a .obj file is selected, an Import Options dialog will open, with the following options…

o Scale Factor:
This is used for scaling the input mesh and should normally be set to the same value as the C4D .obj import/export value.

o Import Groups

  • Selection tags are created for any Groups within the mesh and a ‘Group Tag’ is created and set up to track them.
  • If disabled, no Group Selections or Group Tags will be created (note that even if this option is disabled, you can still “Split by Group” and get separate meshes, who’s names are the group names).

o Import Regions

  • Selection tags are created for any UVMapper regions found and a ‘Region Tag’ is created and set up to track them.
  • If disabled, no UVMapper Region Selections or Region Tags will be created (note that even if this option is disabled, you can still “Split by Region” and get separate meshes, who’s names are the region names).

o Import Materials

  • If the .obj file lists a mtllib and it can be found and read, Materials are created (or updated) using that information, otherwise they are created using some default settings (see information below about some re-mapping that takes place).
  • Selection tags are created for any Material groupings and the selections use the material names (no more “Selection 1”, “Selection 2” … “Selection 34”, etc. (yay!)).
  • Texture Tags are created for every material grouping.
  • If disabled, no Material Selections, Texture Tags or Materials will be created (note that even if this option is disabled, you can still “Split by Material” and get separate meshes, who’s names are the material names).

o Import UV Coords

  • If the mesh has UV (texture) coordinates, a UVW Coordinates tag(s) is created and added.
  • If disabled, no UV Coordinate Tags will be created.

o Flip UV Horizontally/Vertically
These can be used to flip textures left->right or top->bottom.

o Reverse Faces
This option can be used to reverse the facets of the imported mesh.

o Don’t Split
The mesh is set up as one big Polygon Object (editable mesh).

o Split by Group
The mesh being loaded is split up into one Polygon Object per group record found in the file (ala C4D’s importer).

o Split by Region
The mesh being loaded is split up into one Polygon Object per UVMapper Region record found in the file.

o Split by Material
The mesh being loaded is split up into one Polygon Object per Material selection found in the file.

o Create New Document
When selected, the mesh being loaded is loaded into a fresh/new document.

o Merge Into Current Document
When selected, the mesh being loaded is merged into the current/active document.

------------------- S N I P ----------------------

Pricing and Availabilty:

At this time, pricing has not been established, though my intent is to keep it affordable (sub-$30.00 range). As for ‘when’, the best answer is “RSN” (Real Soon Now), or my other favorite “Two Weeks”. I’ll post here again once it’s available.

Thanks for your time… I’m happy to answer any qestions.

  • Keith
    Red-i Productions

#2

The attached screen-shot shows my current mdelling project that was imported and rendered. No other preperation (aside from camera positioning) was done. All materials were read from the Wavefront .mtl file and set up by the plugin.


#3

My main gripe with obj import is the loss of materials as the mtl file isnt accessable in c4d. If you could fix this that would be great. By the way have you seen this:

http://www.greenbriarstudio.com/3D/C4cr2load.htm

http://www.greenbriarstudio.com/3D


#4

JoelD,

My plugin imports and exports wavefront .mtl files (see my second post, above). Of course there is a problem in that Poser doesn’t fill in all the needed information in the .mtl files (it doesn’t list filenames for the transmaps, for example), so you will still need to adjust some settings.

I am/was aware of the Greenbriar Studios plugins, which look nice (!) My plugin differs in that it knows nothing about Poser files (.cr2, .hr2, etc), it only knows about .obj and .mtl files. I intially wrote it for myself as a means of using C4D to develope meshes for use in Poser, but having more to do with the structure and flexibilities of the output .obj file than anything necesarily Poser-specific.

As a result, it’s really a .obj file toolset and can enhance your workflow and capabilities with any other external application that reads/writes .obj files (Bryce, Vue, etc).

  • Keith

#5

i think its a good idea to focus on the obj/mtl file side of things rather than limit yourself to poser stuff…i think paul everetts 10comm toolset allows you to do something with normals like create them and invert them or something can’t remember exactly what though.

other than that sounds very interesting stuff…i just wonder whether there are any issues importing/exporting stuff from apps like Zbrush2 which might be able to be addressed in a plugin like this if its currently in development?

anyways good luck with it and keep us informed about its release.:thumbsup:


#6

This is very good news! I have silently cursed through my teeth at these obj-related issues on many occasions. I might consider shelling out for something like this in about “two weeks”. :thumbsup:


#7

The handling of materials info. would definitely be welcome. Do the plugins also i/o normals information (like the built-in .obj i/o)?


#8

…i just wonder whether there are any issues importing/exporting stuff from apps like Zbrush2 which might be able to be addressed in a plugin like this if its currently in development?

It kinda’ depends on what those issues might be… (do you know of any?). One thing of note that may be relevant… The Wavefront .obj format is actually fairly flexible and supports things like splines and matrices and other things, however, my plugin does not support the full set of possible record types. Mostly, it covers the records needed to export a polygonized version of a C4D document, along with optional grouping, UV Mapper region information and Material groupings/information. The technical/specific answer is that my plugin deals with the following record-types:

‘mtllib’ - material library name
‘v’ - vertex
‘vt’ - uv texture coordinate
‘vn’ - vertex normal (currently ignored)
‘g’ - group record
‘usemtl’ - material selection record
‘f’ - face/facet record, handles older/obsolete ‘fo’ records as well… handles the 5 different known formats of this record, handles direct and relative referenced vertex indices, triangulates n-gons, etc.
‘# r’ - UVMapper region record (would otherwise be a comment record)

…those few record types (in conjunction with the multitude of import/export options) provide a lot of flexibility.

  • Keith

#9

i don’t know of any to be honest and don’t even own zb2 yet…but quite a few c4d users do and as obj is the likely export/import process it would be good to know of any if they exist…hence my comment really to prompt people into informing you if there are any then the possibility exists of resolving them at least…


#10

I currently only own C4D v7.303, which doesn’t support ‘normal’ loading. So, when I started writing the plugin, I stripped out all of my ‘normal’ handling code. When I ported it to the v8.5 SDK, I saw that normals are now loaded, but I have not tried to wedge that code back in yet… I think that will have to wait for a second release of the plugin.

(just as a matter of possible interest, my previous program that I canabalized code for this plugin from was specifically written to generate specialized normals that smoothed out seams between groups of unconnected, separate meshes :wink: ).

  • Keith

#11

Hi Keith,
This looks a useful plug.

I know I’m not alone in bringing FormZ models into Cinema, and while there are various export / import combos to do that, none are really ideal. Perhaps your plug would be useful on that front too.

Mike A.


#12

Okay, thanks for the info. I mainly use .obj for importing Rhino meshes which benefit quite a bit from the normals data.


#13

I’m not familiar with FormZ models, but if you want to mail me a .obj file to play with, I can check into it.

  • Keith

#14

rhino was the other thing i was thinking about adam. maybe its worth emailling keith with this also unless he intends to wait until v2 to look into it…dunno just a thought…if its more open to obj data from different sources or at least main ones then its sure to be successful. anyways think its a great idea for a plugin personally. looking forward to a real soon now release…heh heh. i mentioned zb2 purely cos its on my list to get just holding off to see if any news from siggraph.


#15

And of course the most important feature (to me) ; Macintosh compatiblity. :love:

No longer having to deal with “selection 1” , etc., on imported selection-set names will be a Godsend. :applause:


#16

Sorry acme, it’s PC only.


#17

What would it take to get it compiled for Mac? You have at least 2 buyers. :slight_smile:


#18

Let’s see…

  1. A Mac ($1,500.00 -> $3,500.00 ?)
  2. CodeWarrior compiler ($no_idea)
  3. Cinema 4d, v7.3/v8.5 Mac version ($whatever_the_going_rate_is_for_these)

…would be the minimum requirements. If anyone wants to donate these to me, I’d be happy to do the port ;).


#19

I’m sure there’s someone out there that has all those things and can help you. Maybe someone could compile it for you? You could post a request at plugin cafe?


#20

<sounds of me caving in>

I had some free time and decided to implement Normal import/export for the initial release :wink: (at least in the v8.5 version). I have the import side of things working now and will add the export code after I get some sleep…

Cheers,

  • Keith