Exporting Mesh / loading with mesh creator

monobrau's picture

I've been trying to build something that could export a mesh.

It seems that saving a vertice/normals/colors/indices structures with structure to file and loading the data with the structure from file works fine when rendering it with the GL point structure.

Now I'm wondering why the mesh creator wouldn't create a resembling mesh from the vertice/normals/color/indices I input. Any of you have a clue?

PreviewAttachmentSize
test_writer.zip393.24 KB

monobrau's picture
Re: Exporting Mesh / loading with mesh creator

screenshot of what's happening. From left to right original mesh, saved vertices/normals as GL points structure, vertices/normals/colours/indices with mesh creator/render

PreviewAttachmentSize
screenshot.jpg
screenshot.jpg39.74 KB

dust's picture
Re: Exporting Mesh / loading with mesh creator

here is a plugin that will write your mesh down to a file, as well as read from the same file path.

PreviewAttachmentSize
mesh_writer.zip27.4 KB

cybero's picture
Re: Exporting Mesh / loading with mesh creator

What's :amorim_xmlPlugIn ? -> Eclipse LUA plugin dependency depriving one of functionality, composition example does not render / load correctly.

sorry to report as above :-(

monobrau's picture
Re: Exporting Mesh / loading with mesh creator

setting QC to 64-bit helped for me

dust's picture
Re: Exporting Mesh / loading with mesh creator

you have to save the structure before it will load. amorim is bernardos last name i was helping him make a xml exporter plugin one day. i changed the plugs name to mesh_writer but maybe it should be renamed amorim_xml.plugin ?

i just downloaded the zip double clicked the plugin and let kcore install it and then launched the example on a clean machine hit save and the model showes up.

so not sure why the bundle name would cause a problem for you cybero. unless you had installed the xml exporter before in which case it would have the same class names and maybe cause a conflict. so i would say delete amorim_xml and mesh_writer then try again.

here is the og plug

PreviewAttachmentSize
amorim_xml.plugin.zip4.53 KB

gtoledo3's picture
Re: Exporting Mesh / loading with mesh creator

Reusing class names=much suffering

What did you decide to do if a user doesn't supply all the needed data for a collada file. Does this write a dae or an xml file? (Sorry, I'm on an install I don't want to install anything on at the moment).

There's a filed/confirmed bug on mesh creator in this kind of context, that makes it so that you sort of need to have a legitimate collada file, so that you can then use "set mesh" methods to construct the mesh.

If anyone wanted to slog through the thread where usefuldesign was coming up with a javscript smooth for collada structure, you'll see how that wound up being discovered. (Which reminds me that I need to see whatever happened with that bug... I think they told me it was a duplicate, so who knows.)

dust's picture
Re: Exporting Mesh / loading with mesh creator

this isn't a mesh exporter literally it saves components down not the mesh dae data type. its for cl sculpting. kind of like how your cl sculpt patch does gt. the idea is instead of sample and holding the mesh to save and load the vertex's at the same time. property lists are great for structures. i contemplated on saving down NSData but xml is more versatile i suppose. pretty fast if you pulse a save at patch start the structure loads instantly. defiantly a good idea you brought up a dae mesh exporter. this just saves a float4 array down to file and reads it back as a structure.

maybe i shouldn't say reader that sort of implies theres actually scanning and stuff done i suppose. i'm doing just this.

self.output = [NSArray arrayWithContentsOfFile:self.inputPath]

vade's picture
Re: Exporting Mesh / loading with mesh creator

You really ought to do something like have a private instance variable in your class that something like:

@interface MyPlugin: QCPlugin
{
   NSarray* the arrayFromFile;
}
 
// declare property ports
@end

In your init, make sure to init the array as nil;

In your execution, you really want to check if the valueForInputKey@"inputPath" changed, so you only load the file once, and only when the path changes, like:

if([self didValueForInputKeyChange:@"inputPath"])
{
   // this array is autoreleased, unless you explicitly retain it.
       arrayFromFile = [[NSArray arrayWithContentsOfFile:self.inputPath] retain]
}
 
self.output = arrayFromFile;

It looks like (from that snippet), you are, every frame (or every time executionAtTime is called, which depends on your time mode etc), you are reading from disk and parsing the xml. Thats bad™.

Caveats for code typed into a web form apply. All rights reserved, vade™ ©. vade™ © is not responsible for code correctness or syntax errors. 9 out of 10 doctors suggest using vade™ ©. Do not take vade™ © if you are pregnant, smoking, have liver or heart problems. Taking vade™ © may cause severe episodes of diarrhea and cause tooth decay. Consult your doctor before using vade™ ©.

monobrau's picture
Re: Exporting Mesh / loading with mesh creator

Thanks for sharing!

I've been playing around with it, in combination with the sculpting composition.

What seems to happen is that it's adding up meshes. When I'm saving a mesh, and writing a mesh after that in a different or the same file it takes the previous mesh data and add's it to the new one (file size of the .plist files increase as well).

I'm not a biggie in actual cocoa stuff so forgive my terminology, but to me it seems the cache isn't cleared in between different write actions, or when writing a file it isn't overwritten but added to.

I've attached a sample screen capture and QC comp so you can see what's happening.

PreviewAttachmentSize
test writer copy4.qtz24.29 KB
test1.mov1.39 MB

dust's picture
Re: Exporting Mesh / loading with mesh creator

im using one global ivar i'm sure i forgot to release something somewhere.

@interface amorim_xmlPlugIn : QCPlugIn
{
 
   NSMutableArray * index;
 
}
 
 
@property(assign) NSMutableArray * index;
@property BOOL inputWrite;
@property BOOL inputRead;
@property(assign) NSString* inputPath;
@property(assign) NSDictionary* inputStructure;
@property(assign) NSArray* outputStructure;

my init...

- (id) init
{
   if(self = [super init]) {
 
      index = [[NSMutableArray alloc]init];   
      }
 
   return self;
}

dealloc

- (void) dealloc
{
   [index release];
   [super dealloc];
}

and the executable.

- (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary*)arguments
{
 
    BOOL writer = self.inputWrite;
    if(writer) 
    {
            NSString * error;
 
            NSEnumerator *enumerator = [self.inputStructure keyEnumerator];
            id key;
 
 
 
            int i = 0;
 
            while ((key = [enumerator nextObject])) {
 
               NSNumber *dex = [NSNumber numberWithInt:i];
               [index addObject:[self.inputStructure    objectForKey:dex]];   
 
 
                  i++;
 
            }
 
 
            id plist = [NSPropertyListSerialization dataFromPropertyList:(id)index
                                                     format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
 
 
            if(plist) {
               NSLog(@"No error creating XML data.");
               [plist writeToFile:self.inputPath atomically:YES];
            }
            else {
               NSLog(error);
               [error release];
            }
 
 
 
         }
 
   BOOL reader = self.inputRead;
 
     if(reader)
     {
 
        self.outputStructure = [NSArray  arrayWithContentsOfFile:self.inputPath];
 
     }
 
 
         return YES;
      }      

dust's picture
Re: Exporting Mesh / loading with mesh creator

ok yeah i see that if using the same name file it gets added to original file. i will see if i can sort that with some logic and another working array. you can however for now save your events. like on the mouse up.... the save is triggered and the filename is incremented.

if you can use something like this i can do some of the optimizations vade is talking about and maybe test for various class ids so it will work with any structure's data types. as it is now the kineme structure to file works for most my needs. it doesn't seem to work with larges float4's.

i just got to think about it for a second. i want to try to minimize the structure comparisons and file writes. any suggestions ?

cwright's picture
Re: Exporting Mesh / loading with mesh creator

dust wrote:
im using one global ivar i'm sure i forgot to release something somewhere.

I'm going to ask you to use correct terminology.

An ivar (Instance VARiable) cannot be global in scope. A global is outside of all scope. i.e.,:

#include <stdio.h>
 
int thisIsARealLiveGlobalVariable;

An instance variable cannot be global because it belongs to an instance of an object, and no one else can touch it without the object's permission (black magic hackery notwithstanding).

The difference is quite important. Globals must be locked or otherwise synchronized when accessed (to prevent multiple threads from colliding). ivars typicaly don't need it (unless the object is shared across threads simultaneously, which is less common).

Overall, the code you pasted looks clean. QC editor will leak it for you (due to some bugs in the editor), but that's not your fault.

Note that stuff like self.inputStructure is a function call. you should cache that outside of loops. Also, NSNumber will create an autoreleased object each time around the loop (except for special numbers like 0 and 1) -- that will cause periodic jumps in allocations to keep all those temporaries around until the autorelease pool is drained (which QC will do for you, after the graph finishes evaluating for that frame). for large structures this can become measurable.

monobrau's picture
Re: Exporting Mesh / loading with mesh creator

It happens as well when I'm switching between different file paths. For instance this will happen in this workflow:

deforming standard mesh, saving mesh1. return to standard mesh. deforming standard mesh, saving mesh2

mesh 2 = mesh1+mesh2

It seems that the first mesh I saved is staying in the 'cache', and when I'm saving to a different file it creates a combined mesh with the previous stored ones.

cwright's picture
Re: Exporting Mesh / loading with mesh creator

expected: he's never removing items from index, only adding objects.

dust's picture
Re: Exporting Mesh / loading with mesh creator

cool yeah "ivar" instance variable drrrr. thought global referred to anything outside the scope of a method or function. maybe thats just c, all these languages hard to keep them all strait. declaring the right property is sometimes confusing. normally i like to instantiate objects in interface builder rather than alloc all the time.

dust's picture
Re: Exporting Mesh / loading with mesh creator

did a removeAllObjects and seems to work now the way expected. let me know if this works. i just tested a mesh filter and the change was reflected on each save with the same filename.

PreviewAttachmentSize
amorim_xml.plugin 2.zip4.53 KB

dust's picture
Re: Exporting Mesh / loading with mesh creator

ok calling self.inputStrucutre is just like calling [self myMethod] which is costly. and you should stay away from doing this. are you talking the qc execution loop or just any loop.

i got rid of the enumeration loop all together. the program gets boiled down to these three lines of code now...

id plist = [NSPropertyListSerialization dataFromPropertyList:[NSArray arrayWithArray:self.inputStructure]
                                                     format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
      [plist writeToFile:self.inputPath atomically:YES];
 
self.outputStructure = [NSArray  arrayWithContentsOfFile:self.inputPath];

now with this i'm not using any temps just a local string error that is released and the local plist. the only other variables are the input outputs for the plugin. seems like this may be better no need add objects loop and remove them but i could be horribly wrong.

i do like the constructive critiques, very productive even if i continue to make a complete tit of myself trying to explain things ;)

here is without a loop. it should be able to handle a larger file.

PreviewAttachmentSize
no_loop_amorim_xml.plugin.zip4.35 KB

monobrau's picture
Re: Exporting Mesh...sculpttool

Cool, works!

I've attached a modified 3d sculpt from George, with his morph CL and Dust' mesh writer. I'll post a more elaborate version soon!

Enjoy!

P.S. A nice addition would be 32-bit mode, and relative path names.

PreviewAttachmentSize
sculpt_withsave.qtz63.05 KB

jrs's picture
Re: Exporting Mesh / loading with mesh creator

Cheers dust this is most useful - does this version include the fix's from amorim_xmlplugin2.zip below?

dust's picture
Re: Exporting Mesh...sculpttool

hey monobrau here is a 32bit version. i had "build active machine architecture" turned on so that might be messing you up in 32bit mode. here are 2 versions with relative paths. 32/64 universal and 32 universal.

Scratchpole's picture
Re: Exporting Mesh / loading with mesh creator

Thankyou all for this you lovely people :) Here's something I made with it today. http://www.facebook.com/photo.php?v=10151189235025522

dust's picture
Re: Exporting Mesh / loading with mesh creator

check out http://kineme.net/composition/dust/savexmlplugin for the most recent mesh export example

dust's picture
Re: Exporting Mesh / loading with mesh creator

check out http://kineme.net/composition/dust/savexmlplugin for the most recent mesh export example