game.models.obj: some cleanup.

db4
John Benediktsson 2015-06-01 19:46:15 -07:00
parent 6480a46c1e
commit 343e8d7b87
1 changed files with 12 additions and 17 deletions

View File

@ -46,10 +46,8 @@ TUPLE: material
" \t\n" split harvest ; " \t\n" split harvest ;
: line>mtl ( line -- ) : line>mtl ( line -- )
" \t\n" split harvest " \t\n" split harvest [
[ unclip {
[ rest ] [ first ] bi
{
{ "newmtl" [ first { "newmtl" [ first
[ material new swap >>name current-material set ] [ material new swap >>name current-material set ]
[ cm swap md set-at ] bi [ cm swap md set-at ] bi
@ -90,8 +88,7 @@ VERTEX-FORMAT: obj-vertex-format
{ "NORMAL" float-components 3 f } ; { "NORMAL" float-components 3 f } ;
: triangle>aos ( x -- y ) : triangle>aos ( x -- y )
dup length dup length {
{
{ 3 [ { 3 [
first3 first3
[ 1 - vp get nth ] [ 1 - vp get nth ]
@ -107,15 +104,15 @@ VERTEX-FORMAT: obj-vertex-format
: quad>aos ( x -- y z ) : quad>aos ( x -- y z )
[ 3 head [ triangle>aos 1array ] map ] [ 3 head [ triangle>aos 1array ] map ]
[ [ 2 swap nth ] [
[ 2 swap nth ]
[ 3 swap nth ] [ 3 swap nth ]
[ 0 swap nth ] tri 3array [ 0 swap nth ] tri 3array
[ triangle>aos 1array ] map ] [ triangle>aos 1array ] map
bi ; ] bi ;
: face>aos ( x -- y ) : face>aos ( x -- y )
dup length dup length {
{
{ 3 [ [ triangle>aos 1array ] map 1array ] } { 3 [ [ triangle>aos 1array ] map 1array ] }
{ 4 [ quad>aos 2array ] } { 4 [ quad>aos 2array ] }
} case ; } case ;
@ -132,10 +129,8 @@ VERTEX-FORMAT: obj-vertex-format
] unless-empty ; ] unless-empty ;
: line>obj ( line -- ) : line>obj ( line -- )
split-string split-string [
[ unclip {
[ rest ] [ first ] bi
{
{ "mtllib" [ first read-mtl material-dictionary set ] } { "mtllib" [ first read-mtl material-dictionary set ] }
{ "v" [ strings>numbers 3 head vp [ push* ] change ] } { "v" [ strings>numbers 3 head vp [ push* ] change ] }
{ "vt" [ strings>numbers 2 head vt [ push* ] change ] } { "vt" [ strings>numbers 2 head vt [ push* ] change ] }