1- /* Version: 0.1.26 - May 31 , 2022 00:09:49 */
1+ /* Version: 0.1.26 - June 9 , 2022 01:22:54 */
22'use strict';
33
44Object.defineProperty(exports, '__esModule', { value: true });
@@ -96147,18 +96147,18 @@ if ( typeof window !== 'undefined' ) {
9614796147
9614896148/**
9614996149 * Three targets are provided for both GLSL and Sculpt/JS api.
96150- *
96150+ *
9615196151 * 1: source -> Threejs shader source components (easy customization)
9615296152 * 2: source -> Threejs material
9615396153 * 3: source -> Threejs mesh (easy to use)
96154- *
96154+ *
9615596155 * TODO: make these materials 'plug in' to threejs' lighting model, like unity's surface shaders
9615696156 */
9615796157
9615896158function glslToThreeJSShaderSource(source) {
9615996159 return {
9616096160 uniforms: baseUniforms(),
96161- frag: threeHeader + ' const float STEP_SIZE_CONSTANT = 0.9;\n' + ' const int MAX_ITERATIONS = 300;\n' + uniformsToGLSL(baseUniforms()) + sculptureStarterCode + source + fragFooter,
96161+ frag: threeHeader + " const float STEP_SIZE_CONSTANT = 0.9;\n" + " const int MAX_ITERATIONS = 300;\n" + uniformsToGLSL(baseUniforms()) + sculptureStarterCode + source + fragFooter,
9616296162 vert: threeJSVertexSource
9616396163 };
9616496164}
@@ -96176,7 +96176,7 @@ function sculptToThreeJSShaderSource(source) {
9617696176 console.log(src.error);
9617796177 }
9617896178
96179- var frg = threeHeader + usePBRHeader + useHemisphereLight + uniformsToGLSL(src.uniforms) + ' const float STEP_SIZE_CONSTANT = ' + src.stepSizeConstant + ' ;\n' + ' const int MAX_ITERATIONS = ' + src.maxIterations + ' ;\n' + sculptureStarterCode + src.geoGLSL + '\n' + src.colorGLSL + '\n' + fragFooter;
96179+ var frg = threeHeader + usePBRHeader + useHemisphereLight + uniformsToGLSL(src.uniforms) + " const float STEP_SIZE_CONSTANT = " + src.stepSizeConstant + " ;\n" + " const int MAX_ITERATIONS = " + src.maxIterations + " ;\n" + sculptureStarterCode + src.geoGLSL + "\n" + src.colorGLSL + "\n" + fragFooter;
9618096180 return {
9618196181 uniforms: src.uniforms,
9618296182 frag: frg,
@@ -96202,32 +96202,32 @@ function createSculptureWithGeometry(geometry, source) {
9620296202 };
9620396203 var params = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
9620496204 geometry.computeBoundingSphere();
96205- var radius = ' radius' in params ? params.radius : geometry.boundingSphere.radius;
96205+ var radius = " radius" in params ? params.radius : geometry.boundingSphere.radius;
9620696206 params.radius = radius;
9620796207 params.geometry = geometry;
9620896208 return createSculpture(source, uniformCallback, params);
96209- } // uniformCallback
96209+ } // uniformCallback
9621096210
9621196211function createSculpture(source) {
9621296212 var uniformCallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
9621396213 return {};
9621496214 };
9621596215 var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
9621696216 source = convertFunctionToString(source);
96217- var radius = ' radius' in params ? params.radius : 2;
96217+ var radius = " radius" in params ? params.radius : 2;
9621896218 var geometry;
9621996219
96220- if (' geometry' in params) {
96220+ if (" geometry" in params) {
9622196221 geometry = params.geometry;
9622296222 } else {
96223- var segments = ' segments' in params ? params.segments : 8;
96223+ var segments = " segments" in params ? params.segments : 8;
9622496224 geometry = new SphereGeometry(radius, segments, segments);
9622596225 }
9622696226
9622796227 var material = sculptToThreeJSMaterial(source);
96228- material.uniforms[' opacity' ].value = 1.0;
96229- material.uniforms[' mouse' ].value = new Vector3();
96230- material.uniforms[' _scale' ].value = radius;
96228+ material.uniforms[" opacity" ].value = 1.0;
96229+ material.uniforms[" mouse" ].value = new Vector3();
96230+ material.uniforms[" _scale" ].value = radius;
9623196231 var mesh = new Mesh(geometry, material);
9623296232
9623396233 mesh.onBeforeRender = function (renderer, scene, camera, geometry, material, group) {
@@ -96260,19 +96260,19 @@ function uniformDescriptionToThreeJSFormat(unifs, payload) {
9626096260 }
9626196261
9626296262 unifs.forEach(function (uniform) {
96263- if (uniform.type === ' float' ) {
96263+ if (uniform.type === " float" ) {
9626496264 finalUniforms[uniform.name] = {
9626596265 value: uniform.value
9626696266 };
96267- } else if (uniform.type === ' vec2' ) {
96267+ } else if (uniform.type === " vec2" ) {
9626896268 finalUniforms[uniform.name] = {
9626996269 value: new Vector2(uniform.value.x, uniform.value.y)
9627096270 };
96271- } else if (uniform.type === ' vec3' ) {
96271+ } else if (uniform.type === " vec3" ) {
9627296272 finalUniforms[uniform.name] = {
9627396273 value: new Vector3(uniform.value.x, uniform.value.y, uniform.value.z)
9627496274 };
96275- } else if (uniform.type === ' vec4' ) {
96275+ } else if (uniform.type === " vec4" ) {
9627696276 finalUniforms[uniform.name] = {
9627796277 value: new Vector4(uniform.value.x, uniform.value.y, uniform.value.z, uniform.value.w)
9627896278 };
@@ -96300,31 +96300,31 @@ function makeBasicMesh(material) {
9630096300}
9630196301
9630296302function uniformToCpp(uniforms) {
96303- var res = '' ;
96303+ var res = "" ;
9630496304
9630596305 for (var i = 0; i < uniforms.length; i++) {
9630696306 var unif = uniforms[i];
96307- res += unif.type + ' ' + unif.name + ' = ' ;
96307+ res += unif.type + " " + unif.name + " = " ;
9630896308
96309- if (typeof unif.value === ' number' ) {
96309+ if (typeof unif.value === " number" ) {
9631096310 // float
96311- res += unif.value + 0.0000001 + 'f' ;
96311+ res += unif.value + 0.0000001 + "f" ;
9631296312 } else {
9631396313 // vec
96314- res += ' vec' + unif.value.length + '(' ;
96314+ res += " vec" + unif.value.length + "(" ;
9631596315
9631696316 for (var j = 0; j < unif.value.length; j++) {
96317- res += unif.value[j] + 0.0000001 + 'f' ;
96317+ res += unif.value[j] + 0.0000001 + "f" ;
9631896318
9631996319 if (j + 1 < unif.value.length) {
96320- res += ', ' ;
96320+ res += ", " ;
9632196321 }
9632296322 }
9632396323
96324- res += ')' ;
96324+ res += ")" ;
9632596325 }
9632696326
96327- res += ' ;\n' ;
96327+ res += " ;\n" ;
9632896328 }
9632996329
9633096330 return res;
@@ -96335,21 +96335,21 @@ var cppHeader = uniformToCpp(baseUniforms());
9633596335
9633696336function glslToGLM(source) {
9633796337 // converts all numbers to floats
96338- var result = source.replace(/([^a-zA-Z][0-9]+([.][^a-zA-Z][0-9]*)|[.][0-9]+)()/g, ' $1f' ); // adds parentheses after swizzling for glm to pick up
96338+ var result = source.replace(/([^a-zA-Z][0-9]+([.][^a-zA-Z][0-9]*)|[.][0-9]+)()/g, " $1f" ); // adds parentheses after swizzling for glm to pick up
9633996339
96340- result = result.replace(/([a-zA-Z0-9][.][w-z]{2,})()/g, ' $1()' );
96340+ result = result.replace(/([a-zA-Z0-9][.][w-z]{2,})()/g, " $1()" );
9634196341 return result;
9634296342}
9634396343
9634496344function glslToOfflineRenderer(source) {}
9634596345function sculptToOfflineRenderer(source) {
9634696346 var src = sculptToGLSL(source); //console.log(filteredStarter);
9634796347
96348- return cppHeader + glslToGLM(' const float STEP_SIZE_CONSTANT = ' + src.stepSizeConstant + ' f;\n' + ' const int MAX_ITERATIONS = ' + src.maxIterations + ' ;\n' + sculptureStarterCode + src.geoGLSL + src.colorGLSL) + cppFooter;
96348+ return cppHeader + glslToGLM(" const float STEP_SIZE_CONSTANT = " + src.stepSizeConstant + " f;\n" + " const int MAX_ITERATIONS = " + src.maxIterations + " ;\n" + sculptureStarterCode + src.geoGLSL + src.colorGLSL) + cppFooter;
9634996349}
9635096350
9635196351function glslToMinimalRenderer(canvas, source, updateUniforms) {
96352- var fullFrag = minimalHeader + usePBRHeader + useHemisphereLight + uniformsToGLSL(baseUniforms()) + ' const float STEP_SIZE_CONSTANT = 0.9;\n' + ' const int MAX_ITERATIONS = 300;\n' + sculptureStarterCode + source + fragFooter;
96352+ var fullFrag = minimalHeader + usePBRHeader + useHemisphereLight + uniformsToGLSL(baseUniforms()) + " const float STEP_SIZE_CONSTANT = 0.9;\n" + " const int MAX_ITERATIONS = 300;\n" + sculptureStarterCode + source + fragFooter;
9635396353 return fragToMinimalRenderer(canvas, fullFrag, updateUniforms);
9635496354}
9635596355/**
@@ -96367,7 +96367,7 @@ function sculptToMinimalRenderer(canvas, source, updateUniforms) {
9636796367 }
9636896368
9636996369 var generatedGLSL = sculptToGLSL(source);
96370- var fullFrag = minimalHeader + usePBRHeader + useHemisphereLight + uniformsToGLSL(generatedGLSL.uniforms) + ' const float STEP_SIZE_CONSTANT = ' + generatedGLSL.stepSizeConstant + ' ;\n' + ' const int MAX_ITERATIONS = ' + generatedGLSL.maxIterations + ' ;\n' + sculptureStarterCode + generatedGLSL.geoGLSL + '\n' + generatedGLSL.colorGLSL + '\n' + fragFooter;
96370+ var fullFrag = minimalHeader + usePBRHeader + useHemisphereLight + uniformsToGLSL(generatedGLSL.uniforms) + " const float STEP_SIZE_CONSTANT = " + generatedGLSL.stepSizeConstant + " ;\n" + " const int MAX_ITERATIONS = " + generatedGLSL.maxIterations + " ;\n" + sculptureStarterCode + generatedGLSL.geoGLSL + "\n" + generatedGLSL.colorGLSL + "\n" + fragFooter;
9637196371 return fragToMinimalRenderer(canvas, fullFrag, updateUniforms);
9637296372}
9637396373
@@ -96392,10 +96392,15 @@ function fragToMinimalRenderer(canvas, fullFrag, updateUniforms) {
9639296392 }
9639396393
9639496394 resizeCanvas();
96395- window.addEventListener('resize', resizeCanvas);
96396- var gl = canvas.getContext('webgl2');
96397- var vertices = [-1.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0, 1.0, 1.0, 0.0];
96398- var indices = [3, 2, 1, 3, 1, 0];
96395+ window.addEventListener("resize", resizeCanvas);
96396+ var gl = canvas.getContext("webgl2"); // Learn more: https://github.com/mrdoob/three.js/pull/21358
96397+
96398+ var vertices = [-1.0, -1.0, 0.0, 3.0, -1.0, 0.0, -1.0, 3.0, 0.0];
96399+ var indices = [0, 1, 2]; // const vertices = [
96400+ // -1.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0, 1.0, 1.0, 0.0,
96401+ // ];
96402+ // const indices = [3, 2, 1, 3, 1, 0];
96403+
9639996404 var vertex_buffer = gl.createBuffer();
9640096405 gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer);
9640196406 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
@@ -96413,9 +96418,9 @@ function fragToMinimalRenderer(canvas, fullFrag, updateUniforms) {
9641396418
9641496419 var logShaderComp = function logShaderComp(shader) {
9641596420 var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
96416- console.log(' Shader compiled successfully: ' + compiled);
96421+ console.log(" Shader compiled successfully: " + compiled);
9641796422 var compilationLog = gl.getShaderInfoLog(shader);
96418- if (!compiled) console.error(' Shader compiler log: ' + compilationLog);
96423+ if (!compiled) console.error(" Shader compiler log: " + compilationLog);
9641996424 };
9642096425
9642196426 logShaderComp(vertShader);
@@ -96459,7 +96464,7 @@ function fragToMinimalRenderer(canvas, fullFrag, updateUniforms) {
9645996464 }, false);
9646096465
9646196466 function updateDraw() {
96462- if (typeof updateUniforms === ' function' ) {
96467+ if (typeof updateUniforms === " function" ) {
9646396468 callUniformFuncs(userUniformUpdateFuncs, updateUniforms());
9646496469 }
9646596470
@@ -96477,8 +96482,8 @@ function fragToMinimalRenderer(canvas, fullFrag, updateUniforms) {
9647796482 updateDraw(); // loops through a dictionary and calls the function sotred in the value
9647896483
9647996484 function callUniformFuncs(uniformFuncs, updatedUniforms) {
96480- if (_typeof(updatedUniforms) !== ' object' ) {
96481- console.error(' updateUniforms must return a dictionary of uniform names and values. Instead got: ' , updateUniforms);
96485+ if (_typeof(updatedUniforms) !== " object" ) {
96486+ console.error(" updateUniforms must return a dictionary of uniform names and values. Instead got: " , updateUniforms);
9648296487 return;
9648396488 }
9648496489
@@ -96494,23 +96499,23 @@ function fragToMinimalRenderer(canvas, fullFrag, updateUniforms) {
9649496499 }
9649596500
9649696501 function assignUniforms(updateUniforms) {
96497- if (typeof updateUniforms !== ' function' ) {
96498- console.error(' updateUniforms must be a function that returns a dictionary of uniform names and values' );
96502+ if (typeof updateUniforms !== " function" ) {
96503+ console.error(" updateUniforms must be a function that returns a dictionary of uniform names and values" );
9649996504 return {};
9650096505 }
9650196506
9650296507 var userUniformUpdateFuncs = {};
9650396508 var uniformsDict = updateUniforms();
9650496509
96505- if (uniformsDict !== undefined && _typeof(uniformsDict) === ' object' ) {
96510+ if (uniformsDict !== undefined && _typeof(uniformsDict) === " object" ) {
9650696511 Object.entries(uniformsDict).forEach(function (keys) {
9650796512 var _keys2 = _slicedToArray(keys, 2),
9650896513 key = _keys2[0],
9650996514 val = _keys2[1];
9651096515
9651196516 var unifLocation = gl.getUniformLocation(shaderProgram, key);
9651296517
96513- if (typeof val === ' number' ) {
96518+ if (typeof val === " number" ) {
9651496519 userUniformUpdateFuncs[key] = function (unif) {
9651596520 return gl.uniform1f(unifLocation, unif);
9651696521 };
@@ -96532,10 +96537,10 @@ function fragToMinimalRenderer(canvas, fullFrag, updateUniforms) {
9653296537 return gl.uniform4iv(unifLocation, unif);
9653396538 };
9653496539 } else {
96535- console.error(' Uniforms must be either a float or an array with length 1, 2, 3 or 4' );
96540+ console.error(" Uniforms must be either a float or an array with length 1, 2, 3 or 4" );
9653696541 }
9653796542 } else {
96538- console.error(' Uniforms must be either a float or an array with length 1, 2, 3 or 4' );
96543+ console.error(" Uniforms must be either a float or an array with length 1, 2, 3 or 4" );
9653996544 }
9654096545 });
9654196546 }
@@ -96550,10 +96555,10 @@ function fragToMinimalRenderer(canvas, fullFrag, updateUniforms) {
9655096555 * output - self-contained lightweight html which renders the sculpture
9655196556 **/
9655296557function sculptToMinimalHTMLRenderer(spCode, libPath) {
96553- return makeHTML(spCode, ' sculptToMinimalRenderer' , libPath);
96558+ return makeHTML(spCode, " sculptToMinimalRenderer" , libPath);
9655496559}
9655596560function glslToMinimalHTMLRenderer(spCode, libPath) {
96556- return makeHTML(spCode, ' glslToMinimalRenderer' , libPath);
96561+ return makeHTML(spCode, " glslToMinimalRenderer" , libPath);
9655796562}
9655896563
9655996564function makeHTML(spCode, minRenderFunc, libPath) {
@@ -96569,14 +96574,14 @@ function makeHTML(spCode, minRenderFunc, libPath) {
9656996574function sculptToRawSDF4Meshing(source) {
9657096575 var minimalHeader = "\nprecision highp float;\nuniform float w_width;\nuniform float w_height;\nuniform mat4 projectionMatrix;\n#define cameraPosition vec3(0.0,0.0,-1.0)\n#define vUv vec2(0.0)\n#define worldPos vec4(vec2((gl_FragCoord.x/w_width-0.5)*(w_width/w_height),gl_FragCoord.y/w_height-0.5)*1.75,0.0,0.0)\n#define STEP_SIZE_CONSTANT 0.9\n#define MAX_ITERATIONS 300\n#define stepSize 0.9\n#define mouse vec3(0.0)\n#define time 0.0\n";
9657196576 var generatedGLSL = sculptToGLSL(source);
96572- var fullFrag = minimalHeader + usePBRHeader + useHemisphereLight //+ uniformsToGLSL(generatedGLSL.uniforms)
96573- + sculptureStarterCode + generatedGLSL.geoGLSL;
96574- return fullFrag.replace(/surfaceDistance/g, ' mapDistance' );
96577+ var fullFrag = minimalHeader + usePBRHeader + useHemisphereLight + //+ uniformsToGLSL(generatedGLSL.uniforms)
96578+ sculptureStarterCode + generatedGLSL.geoGLSL;
96579+ return fullFrag.replace(/surfaceDistance/g, " mapDistance" );
9657596580}
9657696581
9657796582/**
9657896583 * TD target for GLSL and Sculpt/JS api.
96579- *
96584+ *
9658096585 * TODO: make these materials 'plug in' to Touch Designer's ' PBR lighting model.
9658196586 */
9658296587
@@ -96585,7 +96590,7 @@ var TDFooter = "\nvoid main()\n{\n\t// This allows things such as order independ
9658596590function glslToTouchDesignerShaderSource(source) {
9658696591 return {
9658796592 uniforms: baseUniforms(),
96588- frag: TDHeader + ' const float STEP_SIZE_CONSTANT = 0.9;\n' + ' const int MAX_ITERATIONS = 300;\n' + uniformsToGLSL(baseUniforms()) + sculptureStarterCode + source + TDFooter,
96593+ frag: TDHeader + " const float STEP_SIZE_CONSTANT = 0.9;\n" + " const int MAX_ITERATIONS = 300;\n" + uniformsToGLSL(baseUniforms()) + sculptureStarterCode + source + TDFooter,
9658996594 vert: minimalVertexSource
9659096595 };
9659196596}
@@ -96596,8 +96601,8 @@ function sculptToTouchDesignerShaderSource(source) {
9659696601 console.log(src.error);
9659796602 }
9659896603
96599- var frg = TDHeader + usePBRHeader + useHemisphereLight + uniformsToGLSL(src.uniforms) + ' const float STEP_SIZE_CONSTANT = ' + src.stepSizeConstant + ' ;\n' + ' const int MAX_ITERATIONS = ' + src.maxIterations + ' ;\n' + sculptureStarterCode + src.geoGLSL + '\n' + src.colorGLSL + '\n' + TDFooter;
96600- var sdf = ' const float STEP_SIZE_CONSTANT = ' + src.stepSizeConstant + ' ;\n' + ' const int MAX_ITERATIONS = ' + src.maxIterations + ' ;\n' + sculptureStarterCode + src.geoGLSL;
96604+ var frg = TDHeader + usePBRHeader + useHemisphereLight + uniformsToGLSL(src.uniforms) + " const float STEP_SIZE_CONSTANT = " + src.stepSizeConstant + " ;\n" + " const int MAX_ITERATIONS = " + src.maxIterations + " ;\n" + sculptureStarterCode + src.geoGLSL + "\n" + src.colorGLSL + "\n" + TDFooter;
96605+ var sdf = " const float STEP_SIZE_CONSTANT = " + src.stepSizeConstant + " ;\n" + " const int MAX_ITERATIONS = " + src.maxIterations + " ;\n" + sculptureStarterCode + src.geoGLSL;
9660196606 return {
9660296607 uniforms: src.uniforms,
9660396608 frag: frg,
0 commit comments