I'm using version 5.8.4
I am reading in .obj files which have coordinates for osg. The files look something like this:
v 1780.799897 -87.839999 279.996001
v 1804.990322 -87.839999 279.996001
v 1804.990121 -131.058317 279.996001
vn 1.000000 -0.000000 0.000000
vn 0.995644 -0.093240 0.000000
vn 0.965925 -0.258823 0.000000
f 2//3 30//3 3//4
f 32//4 3//4 30//3
f 3//4 32//4 12//5
The lines with v, are just vertices, no problem with those.
The lines that start with vn are normal vertices, again not the point here.
The lines that start with f are the faces. Here is the start of my problem.
As you can see the face lines have coords separated by "//". The number before the "//" is a reference to a vertice. The number after the "//" is a reference to a normal vertice.
So a face line has: v//vn v//vn v//vn
I am trying to run a script that will seperate this data, but no luck so far:
I would like to be able to output all the v's and then all the vn's of one line, ie:
f v1//vn1 v2//vn2 v3//vn3
The output would give me:
vertices: v1 v2 v3
normal vertices: vn1 vn2 vn3
I have used the approach of changing the Default Input Record Separator ($/) throughout a loop, but no luck with that
Here is a test file I used (match.obj):
f 1//2 2//4 3//5
f 5//4 9//6 9//10
f 85//100 22//299 330//400
Here's a basic script I started out with:
And it's giving me a "global symbol: requires explicit package" error.
I am new to Perl, so be patient. I'm sure there are much better/efficient ways to do this, which is why I came here for some direction.
When I take out the use strict/warnings, I get the following output:
2 2//3//5//
4 5
f 4 9//
10
f 85//2//330//
100 299 400
As you can see it went fubar. However the v3 and vn3 (last two lines) are giving the right values, so something is working. Except the v3 is including the "//" and "f" which I need to get rid of.
Any ideas?
Or a steer in a better direction....
I am reading in .obj files which have coordinates for osg. The files look something like this:
v 1780.799897 -87.839999 279.996001
v 1804.990322 -87.839999 279.996001
v 1804.990121 -131.058317 279.996001
vn 1.000000 -0.000000 0.000000
vn 0.995644 -0.093240 0.000000
vn 0.965925 -0.258823 0.000000
f 2//3 30//3 3//4
f 32//4 3//4 30//3
f 3//4 32//4 12//5
The lines with v, are just vertices, no problem with those.
The lines that start with vn are normal vertices, again not the point here.
The lines that start with f are the faces. Here is the start of my problem.
As you can see the face lines have coords separated by "//". The number before the "//" is a reference to a vertice. The number after the "//" is a reference to a normal vertice.
So a face line has: v//vn v//vn v//vn
I am trying to run a script that will seperate this data, but no luck so far:
I would like to be able to output all the v's and then all the vn's of one line, ie:
f v1//vn1 v2//vn2 v3//vn3
The output would give me:
vertices: v1 v2 v3
normal vertices: vn1 vn2 vn3
I have used the approach of changing the Default Input Record Separator ($/) throughout a loop, but no luck with that
Here is a test file I used (match.obj):
f 1//2 2//4 3//5
f 5//4 9//6 9//10
f 85//100 22//299 330//400
Here's a basic script I started out with:
Code:
use strict;
use warnings;
$STUFF="c:/scripts/match.obj";
open STUFF or die "Cannot open $STUFF for read :$!";
$/="//"; #change default input record seperator
while (<STUFF>) {
$/="//";
$v1=<STUFF>;
$/=" ";
$vn1=<STUFF>;
$/="//";
$v2=<STUFF>;
$/=" ";
$vn2=<STUFF>;
$/="//";
$v3=<STUFF>;
$vn3=<STUFF>;
print $v1, $v2, $v3;
print "\n";
print $vn1, $vn2, $vn3;
print "\n";
}
And it's giving me a "global symbol: requires explicit package" error.
I am new to Perl, so be patient. I'm sure there are much better/efficient ways to do this, which is why I came here for some direction.
When I take out the use strict/warnings, I get the following output:
2 2//3//5//
4 5
f 4 9//
10
f 85//2//330//
100 299 400
As you can see it went fubar. However the v3 and vn3 (last two lines) are giving the right values, so something is working. Except the v3 is including the "//" and "f" which I need to get rid of.
Any ideas?
Or a steer in a better direction....