;

PDA

Click to See Complete Forum and Search --> : PHP .obj file parser/importer


ferdymania
01-15-2004, 08:11 AM
hi there
I am trying to make an importer for .obj 3D model files.
It is for a 3D engine..
I have written something in PHP but i know very little about php.
here is the code i have used:


<?php
$fp = fopen("model.obj", "r" );

if(!$fp)
{
echo "Couldn't open the data file. Try again later.";
exit;
}
$counter = 0;
while(!feof($fp))
{
// get a line
$line = fgets($fp, 3000);
// Split the input string into words as an array
$arrWords = explode( ' ', $line );
// Count the words in the string
$numWords = count( $arrWords );
// if first word is v - vertices
if($arrWords[0] == "v"){
// write flash code to add a vertex
echo "model.addPoint($arrWords[1] ,
$arrWords[2] , $arrWords[3] ); ";
}
// if first word is f - face
if($arrWords[0] == "f"){
$counter++;
// write flash code to render face
echo "model.drawFace(\"face$counter\" ,
[ $arrWords[1] , $arrWords[2],
$arrWords[3] ] ,0xff0000 , $counter);" ;
}

}
fclose($fp);

?>


What it does is take the vertices and parse them into
my method like so:
.


model.addPoint(100,200,300);
// and for the faces
model.drawFace("faceName",pointList, fillcolor, depth);


My question is - How can i have it so that any number of vertices
can be added to a face ?. at the moment it is hard coded at 3.

I have more details here.
http://www.video-animation.com/flash3d_002.shtml

tahnks
steve

Musicman
01-15-2004, 09:53 AM
Hi,


if($arrWords[0] == "f"){
$counter++;
array_shift($arrWords);
// write flash code to render face
echo "model.drawFace(\"face$counter\" ,[" . implode(", ", $arrWords) . "] ,0xff0000 , $counter);\n" ;
}


Is there an example of your 3D thingy to look at?

Musicman

ferdymania
01-15-2004, 05:05 PM
hi musicman,
man that is a sweet solution...
thank you very much..
so simple yet so divine...:-)

Here is a 77 poly model

http://www.video-animation.com/games/games_012.htm

and here is a ridiculous 600 poly model... slugsville

http://www.video-animation.com/games/games_011.htm

We will be releasing the 3D engine soon

just a few things needed to work out..

Do you think my way of doing the model importer is the
easiest way.. it seems to me easy.. ?
is there a better way...
once again thanks very much
steve