mirror of
https://github.com/SamEyeBam/animate.git
synced 2025-12-16 10:41:05 +00:00
larry babby and threejs for glsl
This commit is contained in:
21
webGl/my-threejs-test/node_modules/glsl-token-inject-block/LICENSE.md
generated
vendored
Normal file
21
webGl/my-threejs-test/node_modules/glsl-token-inject-block/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2015 Jam3
|
||||
|
||||
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.
|
||||
|
||||
63
webGl/my-threejs-test/node_modules/glsl-token-inject-block/README.md
generated
vendored
Normal file
63
webGl/my-threejs-test/node_modules/glsl-token-inject-block/README.md
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
# glsl-token-inject-block
|
||||
|
||||
[](http://github.com/badges/stability-badges)
|
||||
|
||||
Injects a "block" of GLSL tokens into a shader, after any `#version`, `#extension` and `precision` statements. This will pad the new tokens with the necessary amount of newlines (but no more).
|
||||
|
||||
This module ignores token `line`, `column` and `position`.
|
||||
|
||||
## Example
|
||||
|
||||
Your source:
|
||||
|
||||
```js
|
||||
var tokenizer = require('glsl-tokenizer')
|
||||
var inject = require('glsl-token-inject-block')
|
||||
var stringify = require('glsl-token-string')
|
||||
|
||||
var tokens = tokenizer(shaderInput)
|
||||
var newToken = {
|
||||
type: 'preprocessor',
|
||||
data: '#define FOOBAR'
|
||||
}
|
||||
|
||||
var source = stringify(inject(tokens, newToken))
|
||||
console.log(source)
|
||||
```
|
||||
|
||||
The following shader input:
|
||||
|
||||
```glsl
|
||||
// some comment
|
||||
#version 300 es
|
||||
#extension SOME_EXTENSION : enable
|
||||
|
||||
void main() {}
|
||||
```
|
||||
|
||||
Results in the following injected define:
|
||||
|
||||
```glsl
|
||||
// some comment
|
||||
#version 300 es
|
||||
#extension SOME_EXTENSION : enable
|
||||
#define FOOBAR
|
||||
|
||||
void main() {}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
[](https://www.npmjs.com/package/glsl-token-inject-block)
|
||||
|
||||
#### `tokens = inject(tokens, newTokens)`
|
||||
|
||||
For the given shader source (`tokens`), injects `newTokens` into them, assuming the new tokens are a "block" of code that should be placed on its own line.
|
||||
|
||||
`newTokens` can be a single token object, or an array of token objects.
|
||||
|
||||
Modifies `tokens` in place and returns it.
|
||||
|
||||
## License
|
||||
|
||||
MIT, see [LICENSE.md](http://github.com/Jam3/glsl-token-inject-block/blob/master/LICENSE.md) for details.
|
||||
50
webGl/my-threejs-test/node_modules/glsl-token-inject-block/index.js
generated
vendored
Normal file
50
webGl/my-threejs-test/node_modules/glsl-token-inject-block/index.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
module.exports = glslTokenInject
|
||||
|
||||
var newline = { data: '\n', type: 'whitespace' }
|
||||
var regex = /[^\r\n]$/
|
||||
|
||||
function glslTokenInject (tokens, newTokens) {
|
||||
if (!Array.isArray(newTokens))
|
||||
newTokens = [ newTokens ]
|
||||
var start = getStartIndex(tokens)
|
||||
var last = start > 0 ? tokens[start-1] : null
|
||||
if (last && regex.test(last.data)) {
|
||||
tokens.splice(start++, 0, newline)
|
||||
}
|
||||
tokens.splice.apply(tokens, [ start, 0 ].concat(newTokens))
|
||||
|
||||
var end = start + newTokens.length
|
||||
if (tokens[end] && /[^\r\n]$/.test(tokens[end].data)) {
|
||||
tokens.splice(end, 0, newline)
|
||||
}
|
||||
return tokens
|
||||
}
|
||||
|
||||
function getStartIndex (tokens) {
|
||||
// determine starting index for attributes
|
||||
var start = -1
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
var token = tokens[i]
|
||||
if (token.type === 'preprocessor') {
|
||||
if (/^#(extension|version)/.test(token.data)) {
|
||||
start = Math.max(start, i)
|
||||
}
|
||||
} else if (token.type === 'keyword' && token.data === 'precision') {
|
||||
var semi = findNextSemicolon(tokens, i)
|
||||
if (semi === -1) {
|
||||
throw new Error('precision statement not followed by any semicolons!')
|
||||
}
|
||||
start = Math.max(start, semi)
|
||||
}
|
||||
}
|
||||
return start + 1
|
||||
}
|
||||
|
||||
function findNextSemicolon (tokens, start) {
|
||||
for (var i = start; i < tokens.length; i++) {
|
||||
if (tokens[i].type === 'operator' && tokens[i].data === ';') {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
42
webGl/my-threejs-test/node_modules/glsl-token-inject-block/package.json
generated
vendored
Normal file
42
webGl/my-threejs-test/node_modules/glsl-token-inject-block/package.json
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "glsl-token-inject-block",
|
||||
"version": "1.1.0",
|
||||
"description": "safely inject a block of tokens into a shader",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Matt DesLauriers",
|
||||
"email": "dave.des@gmail.com",
|
||||
"url": "https://github.com/mattdesl"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"faucet": "0.0.1",
|
||||
"glsl-token-string": "^1.0.1",
|
||||
"glsl-tokenizer": "^2.0.2",
|
||||
"tape": "^4.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test.js | faucet"
|
||||
},
|
||||
"keywords": [
|
||||
"glsl",
|
||||
"glslify",
|
||||
"stackgl",
|
||||
"token",
|
||||
"tokenize",
|
||||
"tokenizer",
|
||||
"start",
|
||||
"varying",
|
||||
"define",
|
||||
"inject"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/Jam3/glsl-token-inject-block.git"
|
||||
},
|
||||
"homepage": "https://github.com/Jam3/glsl-token-inject-block",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Jam3/glsl-token-inject-block/issues"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user