How to get Pixel Precision in PV3D

Surfing the web I found an interesting post in Everyday Flash , it explains how to get Pixel Precision in PV3D ( Getting a textured object show his texture with a 1:1 aspect relation )

To position the object we use this formula:

1
3dobj.z = (camera.zoom * camera.focus) - Math.abs(camera.z)

And to get x,y 2D coordinates of the 3D object this one:

1
2
screenPosX = 3dobj.screen.x + viewport.viewportWidth / 2;
screenPosY = 3dobj.screen.y + viewport.viewportHeight / 2;

PBJ2ShaderFilter AIR tool to generate a ShaderFilter class from Pixel Bender Files

This is a little app I made that lets us generate a ShaderFilter class from a Pixelbender file.

The app loads a “.pbj” file and generates a class that contains the Pixel Bender bytecode, and all the getters/setters for all of the Kernel parameters.

Download PBJ2ShaderFilter AIR tool. ( source code included )

PureASTemplate an AS3 port of PureJSTemplate engine.

In the last post I used javascript to dinamically parse a template and post back the results to AS3. Now I have ported the PureJSTemplate to AS3 with the help of D.eval API.

This means no Javascript/Browser need. Now you can integrate it directly to your AS3/Flex projects.

Download PureASTemplate.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package es.xperiments.utils
{
    import r1.deval.D;

    /**
     * @author xperiments
     */

    public class PureASTemplate
    {
        private static var tplMap : Array = new Array();
        private static var left : String = "<#";
        private static var right : String = "#>";
        //Delimiters can have regex special characters in them; the following two variables will hold escaped versions of them
        private static var escapedLeft : String = "<#";
        private static var escapedRight : String = "#>";
        private static var escapeRegex : RegExp = new RegExp( '(\' + [ ', '^', '?', '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\' ].join( '|\' ) + ')', 'g' );
        private static var replaceLeft : RegExp = new RegExp( "<#", "g" );
        private static var regexLeftRight : RegExp = new RegExp( "<#" + "|" + "#>", "g" );
        private static var replaceSingleQuote : RegExp = new RegExp( "'
", "g" );
        private static var replaceLineBreak : RegExp = new RegExp( "
\\r|\\n", "g" );

        public static function parseTemplate( id : String, tpl : String, data : Object ):String
        {
            var unreplaceLineBreak : RegExp = new RegExp( "
{lineBreak}", "g" );
            var tplID : String = id;
            var tplObj : Object = tplMap[tplID];
            if (!tplObj)
            {
                var leftjs : String = String.fromCharCode( 21 );
                var leftjsout : String = leftjs + "
=";
                tpl = tpl.replace( replaceLeft, left + leftjs );
                var tplSplit : Array = tpl.split( regexLeftRight );
                var js:String = "
function "+id+"( data ) { ";
                    js += "
var output=''; var ld='" + left + "'; var rd='" + right + "'; ";
                for (var i : uint = 0; i < tplSplit.length ; i++)
                {
                    var line : String = tplSplit[i];
                    if (PureASTemplate.stringStartsWith( line, leftjsout ))
                    {
                        js += "
output+=" + line.substring( leftjsout.length ) + "; ";
                    }
                    else if (PureASTemplate.stringStartsWith( line, leftjs ))
                    {
                        js += "
" + line.substring( leftjs.length ) + " ";
                    }
                    else
                    {
                        js += "
output+='" + line.replace( replaceSingleQuote, "\'" ).replace( replaceLineBreak, '{lineBreak}' ) + "'; ";
                    }
                }
                js += "
return output; }";
                tplObj = D.parseFunctions( js );
                tplMap[tplID] = tplObj;
            }
            return D.evalToString( id+'( data )', { data:data }, tplObj ).replace( unreplaceLineBreak, '\n' );
        }

        public static function setDelimiters(l : String, r : String) : void
        {
            if (l != r)
            {
                left = l;
                escapedLeft = left.replace( escapeRegex, '\\$1' );
                replaceLeft = new RegExp( escapedLeft, "
g" );

                right = r;
                escapedRight = right.replace( escapeRegex, '\\$1' );

                regexLeftRight = new RegExp( escapedLeft + "
|" + escapedRight, "g" );
            }
        }

        private static function stringStartsWith(str : String, startsWith : String):Boolean
        {
            return str.substring( 0, startsWith.length ) == startsWith;
        }
    }
}