Skip to content

Commit 07891d7

Browse files
committed
fix UnaryExpression w/ glsl
close #74
1 parent ce717a3 commit 07891d7

File tree

6 files changed

+1853
-1769
lines changed

6 files changed

+1853
-1769
lines changed

dist/shader-park-core.cjs.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Version: 0.1.26 - June 9, 2022 01:22:54 */
1+
/* Version: 0.1.27 - June 22, 2022 00:59:56 */
22
'use strict';
33

44
Object.defineProperty(exports, '__esModule', { value: true });
@@ -44009,6 +44009,33 @@ function replaceBinaryOp(syntaxTree) {
4400944009
replaceBinaryOp(syntaxTree[node]);
4401044010
}
4401144011
}
44012+
} // handles -variable
44013+
44014+
44015+
if (syntaxTree !== null && syntaxTree["type"] === "UnaryExpression") {
44016+
if (syntaxTree["operator"] == '-' && syntaxTree["argument"] && syntaxTree["argument"]["type"] == "Identifier") {
44017+
Object.assign(syntaxTree, {
44018+
"type": "CallExpression",
44019+
"callee": {
44020+
"type": "Identifier",
44021+
"name": "mult"
44022+
},
44023+
"arguments": [{
44024+
"type": "UnaryExpression",
44025+
"operator": "-",
44026+
"argument": {
44027+
"type": "Literal",
44028+
"value": 1,
44029+
"raw": "1"
44030+
},
44031+
"prefix": true
44032+
}, {
44033+
"type": "Identifier",
44034+
"name": syntaxTree["argument"]["name"]
44035+
}]
44036+
});
44037+
delete syntaxTree['prefix'];
44038+
}
4401244039
}
4401344040

4401444041
if (syntaxTree !== null && syntaxTree["type"] === "BinaryExpression") {
@@ -44467,8 +44494,6 @@ function sculptToGLSL(userProvidedSrc) {
4446744494
compileError("'mix' third argument must be float or match dim of first args");
4446844495
}
4446944496

44470-
ensureScalar("mix", arg_2);
44471-
4447244497
if (typeof arg_1 == "number" || arg_1.type == "float") {
4447344498
arg_0 = tryMakeNum(arg_0);
4447444499
arg_1 = tryMakeNum(arg_1);
@@ -96615,7 +96640,7 @@ function sculptToTouchDesignerShaderSource(source) {
9661596640
};
9661696641
}
9661796642

96618-
console.log('using shader-park-core version: 0.1.26'); /// Generate code for various targets
96643+
console.log('using shader-park-core version: 0.1.27'); /// Generate code for various targets
9661996644

9662096645
exports.baseUniforms = baseUniforms;
9662196646
exports.bindStaticData = bindStaticData;

dist/shader-park-core.esm.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Version: 0.1.26 - June 9, 2022 01:22:54 */
1+
/* Version: 0.1.27 - June 22, 2022 00:59:56 */
22
function createMetadataMethodsForProperty(metadataMap, kind, property) {
33
return {
44
getMetadata: function (key) {
@@ -44005,6 +44005,33 @@ function replaceBinaryOp(syntaxTree) {
4400544005
replaceBinaryOp(syntaxTree[node]);
4400644006
}
4400744007
}
44008+
} // handles -variable
44009+
44010+
44011+
if (syntaxTree !== null && syntaxTree["type"] === "UnaryExpression") {
44012+
if (syntaxTree["operator"] == '-' && syntaxTree["argument"] && syntaxTree["argument"]["type"] == "Identifier") {
44013+
Object.assign(syntaxTree, {
44014+
"type": "CallExpression",
44015+
"callee": {
44016+
"type": "Identifier",
44017+
"name": "mult"
44018+
},
44019+
"arguments": [{
44020+
"type": "UnaryExpression",
44021+
"operator": "-",
44022+
"argument": {
44023+
"type": "Literal",
44024+
"value": 1,
44025+
"raw": "1"
44026+
},
44027+
"prefix": true
44028+
}, {
44029+
"type": "Identifier",
44030+
"name": syntaxTree["argument"]["name"]
44031+
}]
44032+
});
44033+
delete syntaxTree['prefix'];
44034+
}
4400844035
}
4400944036

4401044037
if (syntaxTree !== null && syntaxTree["type"] === "BinaryExpression") {
@@ -44463,8 +44490,6 @@ function sculptToGLSL(userProvidedSrc) {
4446344490
compileError("'mix' third argument must be float or match dim of first args");
4446444491
}
4446544492

44466-
ensureScalar("mix", arg_2);
44467-
4446844493
if (typeof arg_1 == "number" || arg_1.type == "float") {
4446944494
arg_0 = tryMakeNum(arg_0);
4447044495
arg_1 = tryMakeNum(arg_1);
@@ -96611,6 +96636,6 @@ function sculptToTouchDesignerShaderSource(source) {
9661196636
};
9661296637
}
9661396638

96614-
console.log('using shader-park-core version: 0.1.26'); /// Generate code for various targets
96639+
console.log('using shader-park-core version: 0.1.27'); /// Generate code for various targets
9661596640

9661696641
export { baseUniforms, bindStaticData, createSculpture, createSculptureWithGeometry, defaultFragSourceGLSL, fragFooter, glslToMinimalHTMLRenderer, glslToMinimalRenderer, glslToOfflineRenderer, glslToThreeJSMaterial, glslToThreeJSMesh, glslToThreeJSShaderSource, glslToTouchDesignerShaderSource, minimalHeader, minimalVertexSource, sculptToGLSL, sculptToMinimalHTMLRenderer, sculptToMinimalRenderer, sculptToOfflineRenderer, sculptToRawSDF4Meshing, sculptToThreeJSMaterial, sculptToThreeJSMesh, sculptToThreeJSShaderSource, sculptToTouchDesignerShaderSource, sculptureStarterCode, uniformsToGLSL, useHemisphereLight, usePBRHeader };

dist/shader-park-core.umd.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Version: 0.1.26 - June 9, 2022 01:22:51 */
1+
/* Version: 0.1.27 - June 22, 2022 00:59:53 */
22
(function (global, factory) {
33
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
44
typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -44011,6 +44011,33 @@
4401144011
replaceBinaryOp(syntaxTree[node]);
4401244012
}
4401344013
}
44014+
} // handles -variable
44015+
44016+
44017+
if (syntaxTree !== null && syntaxTree["type"] === "UnaryExpression") {
44018+
if (syntaxTree["operator"] == '-' && syntaxTree["argument"] && syntaxTree["argument"]["type"] == "Identifier") {
44019+
Object.assign(syntaxTree, {
44020+
"type": "CallExpression",
44021+
"callee": {
44022+
"type": "Identifier",
44023+
"name": "mult"
44024+
},
44025+
"arguments": [{
44026+
"type": "UnaryExpression",
44027+
"operator": "-",
44028+
"argument": {
44029+
"type": "Literal",
44030+
"value": 1,
44031+
"raw": "1"
44032+
},
44033+
"prefix": true
44034+
}, {
44035+
"type": "Identifier",
44036+
"name": syntaxTree["argument"]["name"]
44037+
}]
44038+
});
44039+
delete syntaxTree['prefix'];
44040+
}
4401444041
}
4401544042

4401644043
if (syntaxTree !== null && syntaxTree["type"] === "BinaryExpression") {
@@ -44469,8 +44496,6 @@
4446944496
compileError("'mix' third argument must be float or match dim of first args");
4447044497
}
4447144498

44472-
ensureScalar("mix", arg_2);
44473-
4447444499
if (typeof arg_1 == "number" || arg_1.type == "float") {
4447544500
arg_0 = tryMakeNum(arg_0);
4447644501
arg_1 = tryMakeNum(arg_1);
@@ -96617,7 +96642,7 @@
9661796642
};
9661896643
}
9661996644

96620-
console.log('using shader-park-core version: 0.1.26'); /// Generate code for various targets
96645+
console.log('using shader-park-core version: 0.1.27'); /// Generate code for various targets
9662196646

9662296647
exports.baseUniforms = baseUniforms;
9662396648
exports.bindStaticData = bindStaticData;

generators/sculpt.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,39 @@ function replaceBinaryOp(syntaxTree) {
7676
}
7777
}
7878

79+
80+
// handles -variable
81+
if (syntaxTree !== null && syntaxTree["type"] === "UnaryExpression") {
82+
if (syntaxTree["operator"] == '-' && syntaxTree["argument"] &&
83+
syntaxTree["argument"]["type"] == "Identifier") {
84+
Object.assign(syntaxTree, {
85+
"type": "CallExpression",
86+
"callee": {
87+
"type": "Identifier",
88+
"name": "mult"
89+
},
90+
"arguments": [
91+
{
92+
"type": "UnaryExpression",
93+
"operator": "-",
94+
"argument": {
95+
"type": "Literal",
96+
"value": 1,
97+
"raw": "1"
98+
},
99+
"prefix": true
100+
},
101+
{
102+
"type": "Identifier",
103+
"name": syntaxTree["argument"]["name"]
104+
}
105+
]
106+
});
107+
delete syntaxTree['prefix']
108+
}
109+
}
110+
111+
79112
if (syntaxTree !== null && syntaxTree["type"] === "BinaryExpression") {
80113
let op = syntaxTree["operator"];
81114
if (op === "*" || op === "/" || op === "-" || op === "+") {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "shader-park-core",
3-
"version": "0.1.26",
3+
"version": "0.1.27",
44
"description": "core glsl and js framework for shader-park",
55
"main": "dist/shader-park-core.esm.js",
66
"csj": "dist/shader-park-core.cjs.js",

0 commit comments

Comments
 (0)