A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: PHP .obj file parser/importer

  1. #1
    Senior Member
    Join Date
    Sep 2001
    Location
    bleh
    Posts
    276

    PHP .obj file parser/importer

    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 Code:
     
    <?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($fp3000); 
          
    // 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:
    .
    PHP Code:
     
    model
    .addPoint(100,200,300); 
    // and for the faces 
    model.drawFace("faceName",pointListfillcolordepth); 
    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

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    Code:
    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

  3. #3
    Senior Member
    Join Date
    Sep 2001
    Location
    bleh
    Posts
    276
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center