larry babby and threejs for glsl

This commit is contained in:
Sam
2024-06-24 21:24:00 +12:00
parent 87d5dc634d
commit 907ebae4c0
6474 changed files with 1279596 additions and 8 deletions

View File

@@ -0,0 +1,9 @@
node_modules
*.log
.DS_Store
bundle.js
test
test.js
demo
example
!.gitignore

View File

@@ -0,0 +1,12 @@
The MIT License (MIT)
=====================
Copyright (c) 2014 [stackgl](http://github.com/stackgl/) contributors
*stackgl contributors listed at <https://github.com/stackgl/contributing/blob/master/CONTRIBUTING.md#contributors>*
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.

View File

@@ -0,0 +1,41 @@
# glsl-token-assignments
[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)
Take an array of GLSL tokens and determine which tokens are either assignments
or variable declarations.
## Usage
[![NPM](https://nodei.co/npm/glsl-token-assignments.png)](https://nodei.co/npm/glsl-token-assignments/)
### `assignments(tokens)`
Takes an array of GLSL tokens from
[`glsl-tokenizer`](http://github.com/stackgl/glsl-tokenizer) and sets the
following boolean values for each `ident` token, i.e. any variable names:
#### `token.assignment`
If the value of the variable is being changed here.
#### `token.declaration`
If a new variable is being defined here for this scope.
#### `token.structMember`
If this token is specifying a new struct member, e.g.:
``` glsl
struct X {
float member1;
float member2;
};
```
The `tokens` array will be modified in-place.
## License
MIT. See [LICENSE.md](http://github.com/stackgl/glsl-token-assignments/blob/master/LICENSE.md) for details.

View File

@@ -0,0 +1,15 @@
module.exports = {
'<<=': true
, '>>=': true
, '++': true
, '--': true
, '+=': true
, '-=': true
, '*=': true
, '/=': true
, '%=': true
, '&=': true
, '^=': true
, '|=': true
, '=': true
}

View File

@@ -0,0 +1,23 @@
module.exports = {
'precision': true
, 'highp': true
, 'mediump': true
, 'lowp': true
, 'attribute': true
, 'const': true
, 'uniform': true
, 'varying': true
, 'break': true
, 'continue': true
, 'do': true
, 'for': true
, 'while': true
, 'if': true
, 'else': true
, 'in': true
, 'out': true
, 'inout': true
, 'true': true
, 'false': true
, 'return': true
}

View File

@@ -0,0 +1,170 @@
var assignments = require('./assignments')
var ignoredKeywords = require('./ignored')
module.exports = assigns
// Here be dragons. Apologies in advance for the hairy code!
function assigns(tokens) {
var idx = 0
// Determine if a value has been assigned, e.g.
// x = 1.0;
// float x = 1.0;
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i]
var type = token.type
token.assignment = false
token.declaration = false
if (type !== 'ident' && type !== 'builtin') continue
idx = i + 1
skipWhitespace(+1)
if (tokens[idx].type !== 'operator') continue
if (!assignments[tokens[idx].data]) continue
token.assignment = true
}
// Determine if a value is being defined, e.g.
// float x;
// float x, y, z;
// float x, y = vec3(sin(1.0 + 3.0)), z;
// float[3][2] x, y = vec3(sin(1.0 + 3.0)), z;
// float[][2] x, y = vec3(sin(1.0 + 3.0)), z;
// float x[2], y = vec3(sin(1.0 + 3.0)), z[4];
// float x(float y, float z) {};
// float x(float y[2], Thing[3] z) {};
// Thing x[2], y = Another(sin(1.0 + 3.0)), z[4];
for (var i = 0; i < tokens.length; i++) {
var datatype = tokens[i]
var type = datatype.type
var data = datatype.data
datatype.declaration = false
if (type === 'keyword') {
if (ignoredKeywords[data]) continue
} else
if (type !== 'ident') continue
idx = i + 1
skipArrayDimensions()
if (tokens[idx].type !== 'ident') continue
tokens[idx++].declaration = true
skipArrayDimensions()
// Function arguments/parameters
if (tokens[idx].data === '(') {
idx++
skipWhitespace(+1)
while (tokens[idx] && tokens[idx].data !== ')') {
if (tokens[idx].type !== 'keyword' && tokens[idx].type !== 'ident') break
idx++
skipWhitespace(+1)
if (tokens[idx].type !== 'ident') continue
tokens[idx++].declaration = true
skipWhitespace(+1)
skipArrayDimensions()
skipWhitespace(+1)
if (tokens[idx].data !== ',') continue
idx++
skipWhitespace(+1)
}
i = idx
continue
}
// Declaration Lists
while (tokens[idx] && tokens[idx].data !== ';') {
if (tokens[idx].data === ',') {
idx++
skipWhitespace(+1)
if (tokens[idx].declaration = tokens[idx].type === 'ident') idx++
} else {
skipWhitespace(+1)
skipParens()
skipWhitespace(+1)
idx++
}
}
i = idx
}
// Handle struct declarations:
// struct declaration {
// float x, y, z;
// Other w;
// } declaration;
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i]
if (token.type !== 'keyword') continue
if (token.data !== 'struct') continue
idx = i + 1
skipWhitespace(+1)
if (tokens[idx].type !== 'ident') continue
idx++
skipWhitespace(+1)
if (tokens[idx++].data !== '{') continue
skipWhitespace(+1)
while (tokens[idx].type === 'ident' || tokens[idx].type === 'keyword') {
do {
idx++
skipWhitespace(+1)
tokens[idx].structMember = true
tokens[idx].declaration = false
idx++
skipArrayDimensions()
} while (tokens[idx].data === ',')
if (tokens[idx].data === ';') idx++
skipWhitespace()
}
idx++
skipWhitespace(+1)
if (tokens[idx].type !== 'ident') continue
tokens[idx].declaration = true
skipWhitespace(+1)
while (tokens[++idx].data === ',') {
skipWhitespace(+1)
idx++
skipWhitespace(+1)
if (tokens[idx].type === 'ident') tokens[idx].declaration = true
skipWhitespace(+1)
}
}
return tokens
function skipWhitespace(n) {
while (tokens[idx] && tokens[idx].type === 'whitespace') idx++
}
function skipArrayDimensions() {
while (tokens[idx] && (
tokens[idx].type === 'integer'
|| tokens[idx].data === '['
|| tokens[idx].data === ']'
|| tokens[idx].type === 'whitespace'
)) idx++
}
function skipParens() {
if (!tokens[idx]) return
if (tokens[idx].data !== '(') return
var depth = 0
var a = idx
do {
if (tokens[idx].data === ';') break
if (tokens[idx].data === '(') depth++
if (tokens[idx].data === ')') depth--
} while(depth && tokens[++idx])
}
}

View File

@@ -0,0 +1,48 @@
{
"name": "glsl-token-assignments",
"version": "2.0.2",
"description": "Take an array of GLSL tokens and determine which tokens are either assignments or variable declarations.",
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "npm run test:node && npm run test:browser",
"test:node": "node test | tap-spec",
"test:eyeball": "PRETTY=1 node test > /dev/null",
"test:browser": "browserify -t 6to5ify test | tap-closer | smokestack | tap-spec",
"test:browser:view": "browserify -t 6to5ify test | smokestack | tap-spec"
},
"author": {
"name": "Hugh Kennedy",
"email": "hughskennedy@gmail.com",
"url": "http://hughsk.io/"
},
"dependencies": {},
"devDependencies": {
"6to5": "^2.4.8",
"6to5ify": "^3.1.0",
"browserify": "^8.0.3",
"chalk": "^0.5.1",
"glsl-tokenizer": "^2.0.0",
"smokestack": "^3.0.0",
"tap-closer": "^1.0.0",
"tap-spec": "^2.1.2",
"tape": "^3.0.3"
},
"repository": {
"type": "git",
"url": "git://github.com/stackgl/glsl-token-assignments.git"
},
"keywords": [
"ecosystem:stackgl",
"pseudoparser",
"syntax",
"glsl",
"tokens",
"assignments",
"declarations"
],
"homepage": "https://github.com/stackgl/glsl-token-assignments",
"bugs": {
"url": "https://github.com/stackgl/glsl-token-assignments/issues"
}
}