Skip to content

Commit

Permalink
fixed readpixels, fixed scale overload documentation, added getter an…
Browse files Browse the repository at this point in the history
…d setter documentation, documented the asc parser.
  • Loading branch information
Andor authored and Andor committed Feb 14, 2011
1 parent 179375a commit d703176
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 40 deletions.
24 changes: 12 additions & 12 deletions parsers/asc.js
Expand Up @@ -4,9 +4,9 @@
*/
/**
@class
Version: 0.1<br />
Author: Andor Salga<br />
asalga.wordpress.com<br />
@version: 0.1
@author: Andor Salga asalga.wordpress.com
Date: November 16, 2010<br />
<br />
This parser parses .ASC filetypes. These files are ASCII<br />
Expand Down Expand Up @@ -155,10 +155,10 @@ var ASCParser = (function() {
// -0.57831 -3.08477 -7.04268 64 32 16
return VERTS_COLS;
};

/**
Returns the version of this parser.
@name ASCParser#version
@returns {String} parser version.
*/
this.__defineGetter__("version", function(){
Expand All @@ -167,7 +167,7 @@ var ASCParser = (function() {

/**
Get the number of parsed points so far.
@name ASCParser#numParsedPoints
@returns {Number} number of points parsed.
*/
this.__defineGetter__("numParsedPoints", function(){
Expand All @@ -176,33 +176,33 @@ var ASCParser = (function() {

/**
Get the total number of points in the point cloud.
@returns {Number}
@name ASCParser#numTotalPoints
@returns {Number} number of points in the point cloud.
*/
this.__defineGetter__("numTotalPoints", function(){
return numTotalPoints;
});

/**
Returns the progress of downloading the point cloud between zero and one.
@returns {Number} value from zero to one or -1 if unknown.
@name ASCParser#progress
@returns {Number|-1} value from zero to one or -1 if unknown.
*/
this.__defineGetter__("progress", function(){
return progress;
});

/**
Returns the file size of the resource in bytes.
@name ASCParser#fileSize
@returns {Number} size of resource in bytes.
*/
this.__defineGetter__("fileSize", function(){
return fileSizeInBytes;
});

/**
@param path Path to the resource
@param {String} path Path to the resource
*/
this.load = function(path){
pathToFile = path;
Expand Down
107 changes: 79 additions & 28 deletions psapi.js
Expand Up @@ -1003,48 +1003,76 @@ var PointStream = (function() {
/*************************************/

/**
Set a function to run when a mouse button is pressed.
@name PointStream#onMousePressed
@param {Function}
*/
this.__defineSetter__("onMousePressed", function(func){
userMousePressed = func;
});

/**
Set a function to run when a mouse button is released.
@name PointStream#onMouseReleased
@param {Function}
*/
this.__defineSetter__("onMouseReleased", function(func){
userMouseReleased = func;
});

/**
Set a function to run when the mouse wheel is scrolled.
@name PointStream#onMouseScroll
@param {Function}
*/
this.__defineSetter__("onMouseScroll", function(func){
userMouseScroll = func;
});

/**
Set a function to run when a key is pressed.
@name PointStream#onKeyDown
@param {Function}
*/
this.__defineSetter__("onKeyDown", function(func){
userKeyDown = func;
});

/**
Set a function to run when a key is pressed and released.
@name PointStream#onKeyPressed
@param {Function}
*/
this.__defineSetter__("onKeyPressed", function(func){
userKeyPressed = func;
});

/**
Set a function to run when a key is released.
@name PointStream#onKeyUp
@param {Function} function
*/
this.__defineSetter__("onKeyUp", function(func){
userKeyUp = func;
});


/*************************************/
/********** Transformations **********/
/*************************************/

/**
Get the current mouse cursor's x coordinate
@name PointStream#mouseX
@returns {Number}
*/
this.__defineGetter__("mouseX", function(){
return mouseX;
});

/**
Get the current mouse cursor's y coordinate
@name PointStream#mouseY
@returns {Number}
*/
this.__defineGetter__("mouseY", function(){
return mouseY;
Expand All @@ -1057,27 +1085,36 @@ var PointStream = (function() {
});

/**
Get the width of the canvas.
@name PointStream#width
@returns {Number}
*/
this.__defineGetter__("width", function(){
return width;
});

/**
Get the height of the canvas.
@name PointStream#height
@returns {Number}
*/
this.__defineGetter__("height", function(){
return height;
});

/**
Get the version of the library.
@returns {String} library version
@name PointStream#version
@returns {String}
*/
this.__defineGetter__("version", function(){
return XBPS_VERSION;
});

/**
Get the current frame rate.
@name PointStream#frameRate
@returns {Number}
*/
this.__defineGetter__("frameRate", function(){
return frameRate;
Expand Down Expand Up @@ -1149,7 +1186,7 @@ var PointStream = (function() {

/**
Resize the viewport.
This can be called after setup
This can be called after setup.
@param {Number} pWidth
@param {Number} pHeight
Expand All @@ -1172,26 +1209,16 @@ var PointStream = (function() {
};

/**
Get a PNG of the current frame
@returns
Get a PNG of the current frame.
@example
var img = document.createElement('img');
img.src = pointStreamInstance.getPNG();
@returns HTMLCanvasElement.toDataURL()
*/
this.getPNG = function(){
// Minefield throws and exception
try{
var arr = ctx.readPixels(0, 0, width, height, ctx.RGBA, ctx.UNSIGNED_BYTE);

// Chrome posts an error
if(ctx.getError()){
throw "readPixels exception";
}
}
catch(e){
if(!arr){
arr = new TYPED_ARRAY_BYTE(width * height * 4);
ctx.readPixels(0, 0, width, height, ctx.RGBA, ctx.UNSIGNED_BYTE, arr);
}
}
var arr = this.readPixels();

var cvs = document.createElement('canvas');
cvs.width = width;
Expand Down Expand Up @@ -1219,20 +1246,44 @@ var PointStream = (function() {
@see getPNG
@returns
@returns {Uint8Array}
*/
this.readPixels = function(){
return ctx.readPixels(0, 0, xb.width, xb.height, ctx.RGBA, ctx.UNSIGNED_BYTE);
var arr;
// Minefield throws and exception
try{
var arr = ctx.readPixels(0, 0, width, height, ctx.RGBA, ctx.UNSIGNED_BYTE);

// Chrome posts an error
if(ctx.getError()){
throw "readPixels exception";
}
}
catch(e){
if(!arr){
arr = new TYPED_ARRAY_BYTE(width * height * 4);
ctx.readPixels(0, 0, width, height, ctx.RGBA, ctx.UNSIGNED_BYTE, arr);
}
}
return arr;
};

/*************************************/
/********** Transformations **********/
/*************************************/

/**
1 arg = uniform scaling
3 args = independant scaling
*/
/**
@name PointStream#scale
@function
@param {Number} s
*/
/**
@name PointStream#scale^2
@function
@param {Number} sx
@param {Number} sy
@param {Number} sz
*/
this.scale = function(sx, sy, sz){
var smat = (!sy && !sz) ? M4x4.scale1(sx, M4x4.I) :
M4x4.scale3(sx, sy, sz, M4x4.I);
Expand Down

0 comments on commit d703176

Please sign in to comment.