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).  ================================================ 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 ================================================