Forum: Poser Technical


Subject: Pocket Protector required on this one...

_dodger opened this issue on Dec 19, 2002 ยท 18 posts


_dodger posted Thu, 19 December 2002 at 2:49 PM

Okay, I have become very sick of manually cleaning up my files, props, etc. Especially because I have a lot of them before I learned cleaner ways to do things. So I came up with this thing that seems to work pretty well. Really, there is no forum right for this. It's closest to going in Poser Python Scripting. But it's not Python. It's Perl. If you have Perl (or if you go get Perl from www.cpan.org), this little perlscript will do two cool things: 1) it will extract prop objects and seperate them out. 2) it will clean up your texture pathing. A note on 1: it will extract out your prop object, but it will put it right there in the same directory you're in. However, the script as-is will reference the object from :Runtime:Geometries:autoConvert so you will have to drop the OBJ in the right place yourself. Feel free to modify it, of course. Hell, it's a Perlscript. In the spirit of Perl, feel free to modify it beyond all belief and hack it up to make it set your automatic coffeemaker, if you please. What it does: from the command line, this script will take a filename as an argument and extract any prop object customGeom from it and create a file for each prop found with customGeom named .obj. This is the internal name, not the human-friendly Name name. It will strip out the customGeom data and replace it with a reference to the object file under :Runtime:Geometries:autoConvert but you will have to move the prop there yourself. It will also fix any "C:Program FilesMetaCreationsRuntimeTexturesyaddayaddapropsyaddayadda.jpg" type texture path references and trim them down to the bare necessities, i.e. the above would become :yaddayaddaprops:yaddayadda.jpg - it adds quotes only for paths with spaces but you can change this easily enough. The resulting px2 file will be spit out to the screen unless you redirect it into a file. For instance, I set this up for me to use on Linux (though it should work the same in a DOS window). Simply do something like this: dodger@gc% ./fileCleaner.pl poserSillyProp.pp2 > poserCleanProp.pp2 I am not too familiar with MacPerl but if you are using MacPerl already, you know how to translate this to the MacPerl shell, I'm sure. The shebang line (the first line that starts with hash-bang (#!) should be changed to point to your Perl executable if what I have there isn't it, i.e. #!/usr/local/bin/perl5 or #!C:perlbinperl.exe or whatever. However, unless you are running cygwin on a PC, this won't really matter because on a PC you probably have to say something like: C:> perl fileCleaner.pl poserSillyProp.pp2 > poserCleanProp.pp2 I think. I never use Perl on the PC, though, even though I have it installed in three places L commence script


#!/usr/bin/perl
use strict;
my $debug = 0;
my $geomMode = 0;
my $readMode = 0;
my $propName;
my $indent;
my $obj;
my $px2;
while (<>) {
    if ($debug) {
        my $next = <STDIN>;
        exit if $next =~ /qn/i;
    }
    chomp;
    s/^(s+)//; # strip leading whitespace
    $indent = $1;
    if (/^prop (S+)/) {
        $propName = $1; # prop name definition
        $propName =~ s/:d+//; # trim figureID
        $px2 .= "$indent$_n";
    }
    elsif (/^geomCustom/) {
        $geomMode = 1; # start customGeom block
        $obj = "# generated by Dodger's autoConvert poserfile cleanern";
    }
    elsif ($geomMode) { # in customGeom block
        if ($_ eq '{') { # start reading customGeom data
            $readMode = 1;
        }
        elsif ($_ eq '}') { # end geomCustom block
            $readMode = 0;
            $geomMode = 0;
            $px2 .= <<"EOF"; # add external OBJ reference
${indent}storageOffset 0 0.3487 0
${indent}objFileGeom 0 0 :Runtime:Geometries:autoConvert:$propName.obj
${indent}}
EOF
            # write the OBJect file
            open OBJ, ">$propName.obj";
            print OBJ $obj;
            close OBJ;
        }
        if ($readMode) {
            if (/^(v )|(vt )|(usemtl )|(g )|(f )|(vn )|(mtllib )/) {
                # proper Wavefront OBJ info
                $obj .= "$_n";
            }
            else {
                # not proper OBJ info -- keep but comment it out
                $obj .= "# $_n";
            }
        }
    }
    elsif (/^(texture|bump|reflection|transparency)Map (.*)$/) {
        # this is a map identifier
        my $mapType = $1;
        my $mapLoc = $2;
        if ($mapLoc =~ /Runtime/) { # don't affect if map not in Runtime
            $mapLoc =~ s/"//g; # strip quotes
            $mapLoc =~ s/C:.*Runtime/:Runtime/i; # remove absolute path
            $mapLoc =~ s//:/g; # replace  with :
            $mapLoc =~ s/:Runtime:Textures//i; # strip :Runtime:Textures
            $mapLoc = qq|"$mapLoc"| if $mapLoc =~ /s/; # quote if spaces
        }
        $px2 .= "$indent${mapType}Map $mapLocn";
    }
    else {
        # leave as-is unless blank
        $px2 .= "$indent$_n" if $_;
        # add whitespace if an end of block
        $px2 .= "n" if $_ eq '}';
    }
}

print $px2;