Full Code of pex-gl/pex for AI

master 593c10eaaca2 cached
12 files
11.7 KB
3.4k tokens
11 symbols
1 requests
Download .txt
Repository: pex-gl/pex
Branch: master
Commit: 593c10eaaca2
Files: 12
Total size: 11.7 KB

Directory structure:
gitextract_p74wbejl/

├── .gitignore
├── .npmignore
├── LICENSE.md
├── README.md
├── index.js
├── lib/
│   ├── init/
│   │   ├── init.js
│   │   └── templates/
│   │       ├── assets/
│   │       │   ├── ShowNormals.frag
│   │       │   └── ShowNormals.vert
│   │       ├── index.html
│   │       └── main.js
│   └── pkg/
│       └── pex-packages-core.json
└── package.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
.DS_Store
*~
stuff
experiments
node_modules


================================================
FILE: .npmignore
================================================
/assets
stuff
experiments

================================================
FILE: LICENSE.md
================================================
The MIT License (MIT)

Copyright (c) 2014 Marcin Ignac

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

================================================
FILE: README.md
================================================
# Pex

PEX is a collection of JavaScript modules the combination of which becomes a powerful 3D graphics library for the desktop and the web. This repository is currently **DEPRECATED**. 

Please use [pex-context](https://github.com/pex-gl/pex-context) (stable) or [pex-renderer](https://github.com/pex-gl/pex-renderer) (beta).

![Pex](assets/pex.jpg)




================================================
FILE: index.js
================================================
#!/usr/bin/env node

var program = require('commander');
var pkg = require(__dirname + '/package.json');
var version = pkg.version;
var init = require('./lib/init/init.js');

var args = process.argv.slice(2);

program
  .usage('[command] [options]')
  .version(version)
  .option('-f, --force', 'force on non-empty directory')

program
  .command('init [projectName]')
  .description('generate example project')
  .action(function(name) {
    init.generate(name);
  });

program.on('--help', function(){
  console.log('  Examples:');
  console.log('');
  console.log('    $ pex init projectName');
  console.log('');
});

program.parse(process.argv);

if (process.argv.length == 2) {
  program.help();
}

var destPath = program.args.shift() || '.';


================================================
FILE: lib/init/init.js
================================================
var aasciArt = (
        '            _               _        _      _       \n'
        +'           /\\ \\            /\\ \\    /_/\\    /\\ \\    \n'
        +'          /  \\ \\          /  \\ \\   \\ \\ \\   \\ \\_\\   \n'
        +'         / /\\ \\ \\        / /\\ \\ \\   \\ \\ \\__/ / /   \n'
        +'        / / /\\ \\_\\      / / /\\ \\_\\   \\ \\__ \\/_/    \n'
        +'       / / /_/ / /     / /_/_ \\/_/    \\/_/\\__/\\    \n'
        +'      / / /__\\/ /     / /____/\\        _/\\/__\\ \\   \n'
        +'     / / /_____/     / /\\____\\/       / _/_/\\ \\ \\  \n'
        +'    / / /           / / /______      / / /   \\ \\ \\  \n'
        +'   / / /           / / /_______\\    / / /    /_/ /  \n'
        +'   \\/_/            \\/__________/    \\/_/     \\_\\/  \n'
);

var mkdirp = require('mkdirp');
var os = require('os');
var fs = require('fs');
var path = require('path');
var inquirer = require('inquirer');
var async = require('async');
var exec = require('child_process').exec;

var appName = 'pexample';
var eol = os.EOL;

function loadTemplate(name) {
  return fs.readFileSync(path.join(__dirname, '.', 'templates', name), 'utf-8');
}

var mainfile    = loadTemplate('main.js');
var indexHTML   = loadTemplate('index.html');
var showNormalsVert     = loadTemplate('assets/ShowNormals.vert');
var showNormalsFrag     = loadTemplate('assets/ShowNormals.frag');


module.exports.generate = function(destPath, options) {
    options = options || {};
    options.force = options.force || false;

    appName = path.basename(path.resolve(destPath));
    emptyDirectory(destPath, function(empty){
        if (empty || options.force) {
            createApplicationAt(destPath, options);
        } else {
            inquirer.prompt([
                {
                    type: 'confirm',
                    name: 'deleteDestPath',
                    message: 'destination path is not empty. continue?',
                    default: false
            }],

            function(response){
                if (response.deleteDestPath) {
                    createApplicationAt(destPath, options);
                } else {
                    abort('aborting');
                }
            });
        }
    });
};

function isOnline(callback) {
    require('dns').resolve('www.google.com', function(err) {
        if (err) { callback(err, false); }
        else callback(null, true);
    });
}

function getPackageVersion(pkg, callback) {
    var version = execSync('npm show ' + pkg.name + ' version');
    version = version.trim();
    return version;
}

var pexPackages = require('../pkg/pex-packages-core');

function getPackageVersion(packageInfo, callback) {
    exec('npm show ' + packageInfo.name + ' version', function(err, stdout, stderr) {
        var version = stdout.trim();
        console.log('   \x1b[36mmodule\x1b[0m : ' +packageInfo.name + ' @ ' + version);
        callback(null, version);
    })
}

function generatePackageInfo(callback) {
    isOnline(function(err, online) {
        var pkg = {
            name: appName,
            version: '0.0.1',
            private: true,
            dependencies: {
                'beefy':            '^2.1.5',
                'browserify':       '^12.0.1',
                'glslify-promise':  '^1.0.1',
                'is-browser':       '^2.0.1',
                'primitive-cube':   '^1.0.2'
            }
        }
        function dummy(packageName, callback) {
            callback(null, '*');
        }
        async.map(pexPackages, online ? getPackageVersion : dummy, function(err, results) {
            pexPackages.forEach(function(packageInfo, packageIndex) {
                pkg.dependencies[packageInfo.name] = '^' + results[packageIndex];
            })
            callback(null, pkg);
        })
    })
}

function createApplicationAt(path, options) {
    var buildCommand = '';
    console.log();
    process.on('exit', function(){
        console.log();
        console.log(aasciArt);
        console.log();
        console.log(' don\'t forget to install dependencies:');
        console.log();
        console.log('     $ cd %s', path);
        console.log('     $ npm install');
        console.log('     $ ' + buildCommand);
        console.log();
    });

    mkdir(path, function() {
        generatePackageInfo(function(err, pkg) {
            pkg.scripts = {};
            pkg.scripts.start = 'beefy main.js:main.web.js --open -- -i plask -g glslify-promise/transform';
            pkg.scripts.build = 'browserify main.js -i plask -g glslify-promise/transform -o main.web.js';
            buildCommand = 'npm start';
            write(path + '/package.json', JSON.stringify(pkg, null, 2));
            write(path + '/main.js', mainfile);
            write(path + '/index.html', indexHTML);
            mkdir(path + '/assets', function() {
                write(path + '/assets/ShowNormals.vert', showNormalsVert);
                write(path + '/assets/ShowNormals.frag', showNormalsFrag);
            });
        })
    });
}

function copyTemplate(from, to) {
  from = path.join(__dirname, '..', 'templates', from);
  write(to, fs.readFileSync(from, 'utf-8'));
}

function emptyDirectory(path, fn) {
    fs.readdir(path, function(err, files){
        if (err && 'ENOENT' != err.code) throw err;
        fn(!files || !files.length);
    });
}


function write(path, str, mode) {
    fs.writeFile(path, str, { mode: mode || 0666 });
    console.log('   \x1b[36mcreate\x1b[0m : ' + path);
}


function mkdir(path, fn) {
    mkdirp(path, 0755, function(err){
        if (err) throw err;
        console.log('   \033[36mcreate\033[0m : ' + path);
        fn && fn();
    });
}

function abort(str) {
    console.error(str);
    process.exit(1);
}


================================================
FILE: lib/init/templates/assets/ShowNormals.frag
================================================
#ifdef GL_ES
precision highp float;
#endif

varying vec3 ecNormal;

void main() {
    gl_FragColor = vec4(normalize(ecNormal) * 0.5 + 0.5, 1.0);
}


================================================
FILE: lib/init/templates/assets/ShowNormals.vert
================================================
attribute vec4 aPosition;
attribute vec3 aNormal;

uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;
uniform mat4 uModelMatrix;
uniform mat3 uNormalMatrix;

varying vec3 ecNormal;

void main() {
    gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * aPosition;
    ecNormal = uNormalMatrix * aNormal;
}


================================================
FILE: lib/init/templates/index.html
================================================
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <meta charset="UTF-8">
        <title>PEX</title>
        <script src="main.web.js"></script>
        <style type="text/css">
        body { padding: 0; margin: 0; overflow: hidden; }
        </style>
    </head>
    <body>
    </body>
</html>


================================================
FILE: lib/init/templates/main.js
================================================
var Window          = require('pex-sys/Window');
var PerspCamera     = require('pex-cam/PerspCamera');
var Arcball         = require('pex-cam/Arcball');
var createCube      = require('primitive-cube');
var glslify         = require('glslify-promise');
var isBrowser       = require('is-browser');

Window.create({
    settings: {
        width:  1280,
        height: 720,
        fullScreen: isBrowser ? true : true
    },
    resources: {
        showNormalsVert: { glsl: glslify(__dirname + '/assets/ShowNormals.vert') },
        showNormalsFrag: { glsl: glslify(__dirname + '/assets/ShowNormals.frag') },
    },
    init: function() {
        var ctx = this.getContext();
        var res = this.getResources();

        this.camera  = new PerspCamera(45,this.getAspectRatio(),0.001,20.0);
        this.camera.lookAt([0, 1, 3], [0, 0, 0]);
        ctx.setProjectionMatrix(this.camera.getProjectionMatrix());

        this.arcball = new Arcball(this.camera, this.getWidth(), this.getHeight());
        this.arcball.setDistance(3.0);
        this.addEventListener(this.arcball);

        this.showNormalsProgram = ctx.createProgram(res.showNormalsVert, res.showNormalsFrag);
        ctx.bindProgram(this.showNormalsProgram);

        var cube = createCube();
        var cubeAttributes = [
            { data: cube.positions, location: ctx.ATTRIB_POSITION },
            { data: cube.normals, location: ctx.ATTRIB_NORMAL }
        ];
        var cubeIndices = { data: cube.cells };
        this.cubeMesh = ctx.createMesh(cubeAttributes, cubeIndices, ctx.TRIANGLES);
    },
    draw: function() {
        var ctx = this.getContext();

        this.arcball.apply();
        ctx.setViewMatrix(this.camera.getViewMatrix());

        ctx.setClearColor(1, 0.2, 0.2, 1);
        ctx.clear(ctx.COLOR_BIT | ctx.DEPTH_BIT);
        ctx.setDepthTest(true);

        ctx.bindProgram(this.showNormalsProgram);
        ctx.bindMesh(this.cubeMesh);
        ctx.drawMesh();
    }
})


================================================
FILE: lib/pkg/pex-packages-core.json
================================================
[
  { "name" : "pex-cam" },
  { "name" : "pex-color" },
  { "name" : "pex-context" },
  { "name" : "pex-draw" },
  { "name" : "pex-geom" },
  { "name" : "pex-io" },
  { "name" : "pex-math" },
  { "name" : "pex-sys" }
]


================================================
FILE: package.json
================================================
{
  "name": "pex",
  "version": "1.0.2",
  "description": "Pex is a javascript 3d library / engine allowing for seamless development between Plask and WebGL in the browser.",
  "keywords": [
    "pex",
    "plask",
    "cli"
  ],
  "main": "index.js",
  "preferGlobal": "true",
  "bin": {
    "pex": "./index.js"
  },
  "author": {
    "name": "Marcin Ignac",
    "email": "marcin.ignac@gmail.com",
    "url": "http://marcinignac.com"
  },
  "contributors": [
    {
      "name": "Nick Nikolov"
    },
    {
      "name": "Marcin Ignac"
    }
  ],
  "dependencies": {
    "async": "^0.9.0",
    "commander": "^2.3.0",
    "inquirer": "^0.5.1",
    "mkdirp": "^0.5.0"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/pex-gl/pex.git"
  },
  "homepage": "https://github.com/pex-gl/pex",
  "bugs": "https://github.com/pex-gl/pex/issues",
  "license": "MIT"
}
Download .txt
gitextract_p74wbejl/

├── .gitignore
├── .npmignore
├── LICENSE.md
├── README.md
├── index.js
├── lib/
│   ├── init/
│   │   ├── init.js
│   │   └── templates/
│   │       ├── assets/
│   │       │   ├── ShowNormals.frag
│   │       │   └── ShowNormals.vert
│   │       ├── index.html
│   │       └── main.js
│   └── pkg/
│       └── pex-packages-core.json
└── package.json
Download .txt
SYMBOL INDEX (11 symbols across 1 files)

FILE: lib/init/init.js
  function loadTemplate (line 26) | function loadTemplate(name) {
  function isOnline (line 64) | function isOnline(callback) {
  function getPackageVersion (line 71) | function getPackageVersion(pkg, callback) {
  function getPackageVersion (line 79) | function getPackageVersion(packageInfo, callback) {
  function generatePackageInfo (line 87) | function generatePackageInfo(callback) {
  function createApplicationAt (line 113) | function createApplicationAt(path, options) {
  function copyTemplate (line 145) | function copyTemplate(from, to) {
  function emptyDirectory (line 150) | function emptyDirectory(path, fn) {
  function write (line 158) | function write(path, str, mode) {
  function mkdir (line 164) | function mkdir(path, fn) {
  function abort (line 172) | function abort(str) {
Condensed preview — 12 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (13K chars).
[
  {
    "path": ".gitignore",
    "chars": 44,
    "preview": ".DS_Store\n*~\nstuff\nexperiments\nnode_modules\n"
  },
  {
    "path": ".npmignore",
    "chars": 25,
    "preview": "/assets\nstuff\nexperiments"
  },
  {
    "path": "LICENSE.md",
    "chars": 1078,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2014 Marcin Ignac\n\nPermission is hereby granted, free of charge, to any person obta"
  },
  {
    "path": "README.md",
    "chars": 354,
    "preview": "# Pex\n\nPEX is a collection of JavaScript modules the combination of which becomes a powerful 3D graphics library for the"
  },
  {
    "path": "index.js",
    "chars": 749,
    "preview": "#!/usr/bin/env node\n\nvar program = require('commander');\nvar pkg = require(__dirname + '/package.json');\nvar version = p"
  },
  {
    "path": "lib/init/init.js",
    "chars": 5764,
    "preview": "var aasciArt = (\n        '            _               _        _      _       \\n'\n        +'           /\\\\ \\\\           "
  },
  {
    "path": "lib/init/templates/assets/ShowNormals.frag",
    "chars": 147,
    "preview": "#ifdef GL_ES\nprecision highp float;\n#endif\n\nvarying vec3 ecNormal;\n\nvoid main() {\n    gl_FragColor = vec4(normalize(ecNo"
  },
  {
    "path": "lib/init/templates/assets/ShowNormals.vert",
    "chars": 323,
    "preview": "attribute vec4 aPosition;\nattribute vec3 aNormal;\n\nuniform mat4 uProjectionMatrix;\nuniform mat4 uViewMatrix;\nuniform mat"
  },
  {
    "path": "lib/init/templates/index.html",
    "chars": 412,
    "preview": "<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0"
  },
  {
    "path": "lib/init/templates/main.js",
    "chars": 1968,
    "preview": "var Window          = require('pex-sys/Window');\nvar PerspCamera     = require('pex-cam/PerspCamera');\nvar Arcball      "
  },
  {
    "path": "lib/pkg/pex-packages-core.json",
    "chars": 219,
    "preview": "[\n  { \"name\" : \"pex-cam\" },\n  { \"name\" : \"pex-color\" },\n  { \"name\" : \"pex-context\" },\n  { \"name\" : \"pex-draw\" },\n  { \"na"
  },
  {
    "path": "package.json",
    "chars": 879,
    "preview": "{\n  \"name\": \"pex\",\n  \"version\": \"1.0.2\",\n  \"description\": \"Pex is a javascript 3d library / engine allowing for seamless"
  }
]

About this extraction

This page contains the full source code of the pex-gl/pex GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 12 files (11.7 KB), approximately 3.4k tokens, and a symbol index with 11 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!