Difference between revisions of "XB PointStream/custom parsers"

From CDOT Wiki
Jump to: navigation, search
(Parser Skeleton)
Line 11: Line 11:
 
==Parser Skeleton==
 
==Parser Skeleton==
  
The following bit of code is a skeleton which you can use as an aid to help you write your own parser.
+
The following bit of code is a skeleton which you can use as an aid to help you write your own parser for XB PointStream.
  
 
<pre>
 
<pre>
 
var Your_Parser_Name = (function() {
 
var Your_Parser_Name = (function() {
   /**
+
   /*
   XBPS will create an instance of your parser and pass in an object with three
+
   XBPS will create an instance of your parser and pass in an object with three named properties:
  named properties:
 
 
    
 
    
   start - must occur exactly once. Has one argument, the parser itself
+
   start - must occur exactly once. When you call this function, pass in a reference to your parser
   end  - must occur exactly once. Has one argument, the parser itself
+
   end  - must occur exactly once. When you call this function, pass in a reference to your parser
 +
  parse - may occur one or many times. When you call this function, pass in a reference to your parser
 +
  as the first argument and an object as the second argument.
  
   Everytime your parser calls the parse function, it must send in an object with
+
   This second object must have variables referencing typed single-dimensional arrays which contain
   named arrays. In the following example, vertexArray is a Float32Array which contain
+
   the parsed values. For example, if vertsArray and colsArray were Float32Array arrays, you would call
   the vertices which have already been read and parsed.
+
   the parse function like this:
  
 
   var attributes = {};
 
   var attributes = {};
   attributes["ps_Vertex"] = vertexArray;
+
   attributes["ps_Vertex"] = vertsArray;
   attributes["ps_Color"] = colorsArray;
+
   attributes["ps_Color"] = colsArray;
 +
  parse(thisParser, attributes);
 +
 
 +
  PointStream will create buffers using these values and start rendering them using the built-in
 +
  shaders. Notice the variable names have been qualified with "ps_". If you are using the XB PointStream
 +
  built-in shaders, you will need to use these exact variable names.
 
   
 
   
   parse - may occur one or many times. Has two arguments, the parser itself and a
+
   These are the only two variables the built-in shaders read. If your parser reads in vertex normal data,
    
+
   you will need to write your own shaders to handle lighting.
  Your parser is responsible for calling these functions at the appropriate times.
 
 
   */
 
   */
 
   function Your_Parser_Name(config) {
 
   function Your_Parser_Name(config) {
 
    
 
    
 
     /*Returns the version of this parser.*/
 
     /*Returns the version of this parser.*/
     this.__defineGetter__("version", function(){
+
     this.__defineGetter__("version", function(){return /*!!*/;});
      return /*!!*/;
 
    });
 
 
    
 
    
 
     /*Get the number of parsed points so far.*/
 
     /*Get the number of parsed points so far.*/
     this.__defineGetter__("numParsedPoints", function(){
+
     this.__defineGetter__("numParsedPoints", function(){return /*!!*/;});
      return /*!!*/;
 
    });
 
 
    
 
    
 
     /*Get the total number of points in the point cloud.*/
 
     /*Get the total number of points in the point cloud.*/
     this.__defineGetter__("numTotalPoints", function(){
+
     this.__defineGetter__("numTotalPoints", function(){return /*!!*/;});
      return /*!!*/;
 
    });
 
 
    
 
    
 
     /*Returns the progress of downloading the point cloud between zero and one.*/
 
     /*Returns the progress of downloading the point cloud between zero and one.*/
     this.__defineGetter__("progress", function(){
+
     this.__defineGetter__("progress", function(){return /*!!*/;});
      return /*!!*/;
 
    });
 
 
    
 
    
 
     /*Returns the file size of the resource in bytes.*/
 
     /*Returns the file size of the resource in bytes.*/
     this.__defineGetter__("fileSize", function(){
+
     this.__defineGetter__("fileSize", function(){return /*!!*/;});
      return /*!!*/;
 
    });
 
 
    
 
    
     /**
+
     /*Path = path to the resource */
      @param path Path to the resource
+
     this.load = function(path){/*!!*/};
    */
 
     this.load = function(path){
 
      /*!!*/
 
    };
 
 
   }
 
   }
 
   return Your_Parser_Name;
 
   return Your_Parser_Name;

Revision as of 13:40, 16 February 2011

Parser Interface

Intro

Currently XBPS only supports reading .ASC file types. If you require the library to render other files, you will need to write a custom parser and register it with the library. This should not be difficult, there are only a few things your parser must implement.


Example

Here is an example which you can use to help understand the process: [link here]


Parser Skeleton

The following bit of code is a skeleton which you can use as an aid to help you write your own parser for XB PointStream.

var Your_Parser_Name = (function() {
  /*
  XBPS will create an instance of your parser and pass in an object with three named properties:
  
  start - must occur exactly once. When you call this function, pass in a reference to your parser
  end   - must occur exactly once. When you call this function, pass in a reference to your parser
  parse - may occur one or many times. When you call this function, pass in a reference to your parser
  as the first argument and an object as the second argument.

  This second object must have variables referencing typed single-dimensional arrays which contain
  the parsed values. For example, if vertsArray and colsArray were Float32Array arrays, you would call
  the parse function like this:

  var attributes = {};
  attributes["ps_Vertex"] = vertsArray;
  attributes["ps_Color"] = colsArray;
  parse(thisParser, attributes);

  PointStream will create buffers using these values and start rendering them using the built-in
  shaders. Notice the variable names have been qualified with "ps_". If you are using the XB PointStream
  built-in shaders, you will need to use these exact variable names.
 
  These are the only two variables the built-in shaders read. If your parser reads in vertex normal data,
  you will need to write your own shaders to handle lighting.
  */
  function Your_Parser_Name(config) {
   
    /*Returns the version of this parser.*/
    this.__defineGetter__("version", function(){return /*!!*/;});
   
    /*Get the number of parsed points so far.*/
    this.__defineGetter__("numParsedPoints", function(){return /*!!*/;});
   
    /*Get the total number of points in the point cloud.*/
    this.__defineGetter__("numTotalPoints", function(){return /*!!*/;});
   
    /*Returns the progress of downloading the point cloud between zero and one.*/
    this.__defineGetter__("progress", function(){return /*!!*/;});
   
    /*Returns the file size of the resource in bytes.*/
    this.__defineGetter__("fileSize", function(){return /*!!*/;});
   
    /*Path = path to the resource */
    this.load = function(path){/*!!*/};
  }
  return Your_Parser_Name;
}());


/*
  The following example demonstrates how XBPS might use
  a particular parser.
*/

var parser;

function startCallback(parser){
  // started
}

function parseCallback(parser, attributes){
  parser.version;
  parser.numParsedPoints;
  parser.numTotalPoints;
  parser.progress;
  parser.fileSize;
}

function finishCallback(parser){
  // finished
}

// create a hypothetical parser and set the callbacks
parser = new Your_Parser_Name({ start: startCallback,
                                parse: parseCallback,
                                end: finishCallback});
// load some resource
parser.load("pointcloud.xyz");