troika-three-utils
Advanced tools
Comparing version 0.38.0 to 0.38.1
@@ -6,2 +6,15 @@ # Change Log | ||
## [0.38.1](https://github.com/protectwise/troika/compare/v0.38.0...v0.38.1) (2021-02-03) | ||
### Bug Fixes | ||
* hoist vertexTransform defs to top of the shader to prevent errors in chained derivations ([889ed38](https://github.com/protectwise/troika/commit/889ed38fcfb30edc630865b6e95f59c3f6322646)) | ||
* make derived material's customProgramCacheKey function writable ([10289dd](https://github.com/protectwise/troika/commit/10289dd1fc700facff9ab79fb6e1cc04109fc0ff)) | ||
* update to support up to Three r125 ([4edff04](https://github.com/protectwise/troika/commit/4edff042d13dec49377d18baf4f958de285a3f2a)) | ||
# [0.38.0](https://github.com/protectwise/troika/compare/v0.37.0...v0.38.0) (2021-01-24) | ||
@@ -8,0 +21,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { ShaderChunk, MathUtils, UniformsUtils, MeshDepthMaterial, RGBADepthPacking, MeshDistanceMaterial, ShaderLib, Vector3, Mesh, CylinderBufferGeometry, Vector2, MeshStandardMaterial, DoubleSide } from 'three'; | ||
import { ShaderChunk, MathUtils, UniformsUtils, MeshDepthMaterial, RGBADepthPacking, MeshDistanceMaterial, ShaderLib, Matrix4, Vector3, Mesh, CylinderBufferGeometry, Vector2, MeshStandardMaterial, DoubleSide } from 'three'; | ||
@@ -192,2 +192,4 @@ /** | ||
customProgramCacheKey: { | ||
writable: true, | ||
configurable: true, | ||
value: function () { | ||
@@ -360,6 +362,9 @@ return optionsKey | ||
if (vertexTransform) { | ||
vertexDefs = `${vertexDefs} | ||
vec3 troika_position_${key}; | ||
// Hoist these defs to the very top so they work in other function defs | ||
vertexShader = `vec3 troika_position_${key}; | ||
vec3 troika_normal_${key}; | ||
vec2 troika_uv_${key}; | ||
${vertexShader} | ||
`; | ||
vertexDefs = `${vertexDefs} | ||
void troikaVertexTransform${key}(inout vec3 position, inout vec3 normal, inout vec2 uv) { | ||
@@ -471,2 +476,17 @@ ${vertexTransform} | ||
/** | ||
* Helper for smoothing out the `m.getInverse(x)` --> `m.copy(x).invert()` conversion | ||
* that happened in ThreeJS r123. | ||
* @param {Matrix4} srcMatrix | ||
* @param {Matrix4} [tgtMatrix] | ||
*/ | ||
function invertMatrix4(srcMatrix, tgtMatrix = new Matrix4()) { | ||
if (typeof tgtMatrix.invert === 'function') { | ||
tgtMatrix.copy(srcMatrix).invert(); | ||
} else { | ||
tgtMatrix.getInverse(srcMatrix); | ||
} | ||
return tgtMatrix | ||
} | ||
/* | ||
@@ -681,2 +701,2 @@ Input geometry is a cylinder with r=1, height in y dimension from 0 to 1, | ||
export { BezierMesh, createDerivedMaterial, expandShaderIncludes, getShaderUniformTypes, getShadersForMaterial, voidMainRegExp }; | ||
export { BezierMesh, createDerivedMaterial, expandShaderIncludes, getShaderUniformTypes, getShadersForMaterial, invertMatrix4, voidMainRegExp }; |
@@ -198,2 +198,4 @@ (function (global, factory) { | ||
customProgramCacheKey: { | ||
writable: true, | ||
configurable: true, | ||
value: function () { | ||
@@ -369,3 +371,5 @@ return optionsKey | ||
if (vertexTransform) { | ||
vertexDefs = vertexDefs + "\nvec3 troika_position_" + key + ";\nvec3 troika_normal_" + key + ";\nvec2 troika_uv_" + key + ";\nvoid troikaVertexTransform" + key + "(inout vec3 position, inout vec3 normal, inout vec2 uv) {\n " + vertexTransform + "\n}\n"; | ||
// Hoist these defs to the very top so they work in other function defs | ||
vertexShader = "vec3 troika_position_" + key + ";\nvec3 troika_normal_" + key + ";\nvec2 troika_uv_" + key + ";\n" + vertexShader + "\n"; | ||
vertexDefs = vertexDefs + "\nvoid troikaVertexTransform" + key + "(inout vec3 position, inout vec3 normal, inout vec2 uv) {\n " + vertexTransform + "\n}\n"; | ||
vertexMainIntro = "\ntroika_position_" + key + " = vec3(position);\ntroika_normal_" + key + " = vec3(normal);\ntroika_uv_" + key + " = vec2(uv);\ntroikaVertexTransform" + key + "(troika_position_" + key + ", troika_normal_" + key + ", troika_uv_" + key + ");\n" + vertexMainIntro + "\n"; | ||
@@ -460,2 +464,19 @@ vertexShader = vertexShader.replace(/\b(position|normal|uv)\b/g, function (match, match1, index, fullStr) { | ||
/** | ||
* Helper for smoothing out the `m.getInverse(x)` --> `m.copy(x).invert()` conversion | ||
* that happened in ThreeJS r123. | ||
* @param {Matrix4} srcMatrix | ||
* @param {Matrix4} [tgtMatrix] | ||
*/ | ||
function invertMatrix4(srcMatrix, tgtMatrix) { | ||
if ( tgtMatrix === void 0 ) tgtMatrix = new three.Matrix4(); | ||
if (typeof tgtMatrix.invert === 'function') { | ||
tgtMatrix.copy(srcMatrix).invert(); | ||
} else { | ||
tgtMatrix.getInverse(srcMatrix); | ||
} | ||
return tgtMatrix | ||
} | ||
/* | ||
@@ -633,2 +654,3 @@ Input geometry is a cylinder with r=1, height in y dimension from 0 to 1, | ||
exports.getShadersForMaterial = getShadersForMaterial; | ||
exports.invertMatrix4 = invertMatrix4; | ||
exports.voidMainRegExp = voidMainRegExp; | ||
@@ -635,0 +657,0 @@ |
@@ -1,16 +0,16 @@ | ||
'use strict';(function(f,c){"object"===typeof exports&&"undefined"!==typeof module?c(exports,require("three")):"function"===typeof define&&define.amd?define(["exports","three"],c):(f=f||self,c(f.troika_three_utils={},f.THREE))})(this,function(f,c){function r(b){return b.replace(/^[ \t]*#include +<([\w\d./]+)>/gm,function(a,b){return(b=c.ShaderChunk[b])?r(b):a})}function l(b,a){var e=z(a),d=q.get(b);d||q.set(b,d=Object.create(null));if(d[e])return new d[e];var g="_onBeforeCompile"+e,C=function(h){b.onBeforeCompile.call(this, | ||
h);var d=e+"|||"+h.vertexShader+"|||"+h.fragmentShader,c=t[d];c||(c=A(h,a,e),c=t[d]=c);h.vertexShader=c.vertexShader;h.fragmentShader=c.fragmentShader;k(h.uniforms,this.uniforms);a.timeUniform&&(h.uniforms[a.timeUniform]={get value(){return Date.now()-B}});if(this[g])this[g](h)},f=function(){return p(a.chained?b:b.clone())},p=function(d){var h=Object.create(d,m);Object.defineProperty(h,"baseMaterial",{value:b});Object.defineProperty(h,"id",{value:E++});h.uuid=c.MathUtils.generateUUID();h.uniforms= | ||
k({},d.uniforms,a.uniforms);h.defines=k({},d.defines,a.defines);h.defines["TROIKA_DERIVED_MATERIAL_"+e]="";h.extensions=k({},d.extensions,a.extensions);h._listeners=void 0;return h},m={constructor:{value:f},isDerivedMaterial:{value:!0},customProgramCacheKey:{value:function(){return e}},onBeforeCompile:{get:function(){return C},set:function(b){this[g]=b}},copy:{writable:!0,configurable:!0,value:function(a){b.copy.call(this,a);b.isShaderMaterial||b.isDerivedMaterial||(k(this.extensions,a.extensions), | ||
k(this.defines,a.defines),k(this.uniforms,c.UniformsUtils.clone(a.uniforms)));return this}},clone:{writable:!0,configurable:!0,value:function(){var a=new b.constructor;return p(a).copy(this)}},getDepthMaterial:{writable:!0,configurable:!0,value:function(){var d=this._depthMaterial;d||(d=this._depthMaterial=l(b.isDerivedMaterial?b.getDepthMaterial():new c.MeshDepthMaterial({depthPacking:c.RGBADepthPacking}),a),d.defines.IS_DEPTH_MATERIAL="",d.uniforms=this.uniforms);return d}},getDistanceMaterial:{writable:!0, | ||
configurable:!0,value:function(){var d=this._distanceMaterial;d||(d=this._distanceMaterial=l(b.isDerivedMaterial?b.getDistanceMaterial():new c.MeshDistanceMaterial,a),d.defines.IS_DISTANCE_MATERIAL="",d.uniforms=this.uniforms);return d}},dispose:{writable:!0,configurable:!0,value:function(){var a=this._depthMaterial,d=this._distanceMaterial;a&&a.dispose();d&&d.dispose();b.dispose.call(this)}}};d[e]=f;return new f}function A(b,a,e){var d=b.vertexShader,g=b.fragmentShader;b=a.vertexDefs;var c=a.vertexMainIntro, | ||
f=a.vertexMainOutro,p=a.vertexTransform,m=a.fragmentDefs,h=a.fragmentMainIntro,k=a.fragmentMainOutro,n=a.fragmentColorTransform,l=a.customRewriter;a=a.timeUniform;b=b||"";c=c||"";f=f||"";m=m||"";h=h||"";k=k||"";if(p||l)d=r(d);if(n||l)g=g.replace(/^[ \t]*#include <((?:tonemapping|encodings|fog|premultiplied_alpha|dithering)_fragment)>/gm,"\n//!BEGIN_POST_CHUNK $1\n$&\n//!END_POST_CHUNK\n"),g=r(g);l&&(g=l({vertexShader:d,fragmentShader:g}),d=g.vertexShader,g=g.fragmentShader);if(n){var q=[];g=g.replace(/^\/\/!BEGIN_POST_CHUNK[^]+?^\/\/!END_POST_CHUNK/gm, | ||
function(a){q.push(a);return""});k=n+"\n"+q.join("\n")+"\n"+k}a&&(n="\nuniform float "+a+";\n",b=n+b,m=n+m);p&&(b=b+"\nvec3 troika_position_"+e+";\nvec3 troika_normal_"+e+";\nvec2 troika_uv_"+e+";\nvoid troikaVertexTransform"+e+"(inout vec3 position, inout vec3 normal, inout vec2 uv) {\n "+p+"\n}\n",c="\ntroika_position_"+e+" = vec3(position);\ntroika_normal_"+e+" = vec3(normal);\ntroika_uv_"+e+" = vec2(uv);\ntroikaVertexTransform"+e+"(troika_position_"+e+", troika_normal_"+e+", troika_uv_"+e+");\n"+ | ||
c+"\n",d=d.replace(/\b(position|normal|uv)\b/g,function(a,d,b,c){return/\battribute\s+vec[23]\s+$/.test(c.substr(0,b))?d:"troika_"+d+"_"+e}));d=u(d,e,b,c,f);g=u(g,e,m,h,k);return{vertexShader:d,fragmentShader:g}}function u(b,a,c,d,g){if(d||g||c)b=b.replace(v,"\n"+c+"\nvoid troikaOrigMain"+a+"() {"),b+="\nvoid main() {\n "+d+"\n troikaOrigMain"+a+"();\n "+g+"\n}";return b}function F(b,a){return"uniforms"===b?void 0:"function"===typeof a?a.toString():a}function z(b){b=JSON.stringify(b,F);var a=w.get(b); | ||
null==a&&w.set(b,a=++G);return a}var v=/\bvoid\s+main\s*\(\s*\)\s*{/g,k=Object.assign||function(){for(var b=arguments,a=arguments[0],c=1,d=arguments.length;c<d;c++){var g=b[c];if(g)for(var f in g)g.hasOwnProperty(f)&&(a[f]=g[f])}return a},B=Date.now(),q=new WeakMap,t=new Map,E=1E10,G=0,w=new Map,H={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical", | ||
MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"},x=null,y=new c.MeshStandardMaterial({color:16777215,side:c.DoubleSide}),I=function(b){function a(){b.call(this,a.getGeometry(),y);this.pointA=new c.Vector3;this.controlA=new c.Vector3;this.controlB=new c.Vector3;this.pointB=new c.Vector3;this.radius=.01;this.dashArray=new c.Vector2;this.dashOffset=0;this.frustumCulled= | ||
!1}b&&(a.__proto__=b);a.prototype=Object.create(b&&b.prototype);a.prototype.constructor=a;var e={material:{configurable:!0},customDepthMaterial:{configurable:!0},customDistanceMaterial:{configurable:!0}};a.getGeometry=function(){return x||(x=(new c.CylinderBufferGeometry(1,1,1,6,64)).translate(0,.5,0))};e.material.get=function(){var a=this._derivedMaterial,b=this._baseMaterial||this._defaultMaterial||(this._defaultMaterial=y.clone());a&&a.baseMaterial===b||(a=this._derivedMaterial=l(b,{chained:!0, | ||
uniforms:{pointA:{value:new c.Vector3},controlA:{value:new c.Vector3},controlB:{value:new c.Vector3},pointB:{value:new c.Vector3},radius:{value:.01},dashing:{value:new c.Vector3}},vertexDefs:"\nuniform vec3 pointA;\nuniform vec3 controlA;\nuniform vec3 controlB;\nuniform vec3 pointB;\nuniform float radius;\nvarying float bezierT;\n\nvec3 cubicBezier(vec3 p1, vec3 c1, vec3 c2, vec3 p2, float t) {\n float t2 = 1.0 - t;\n float b0 = t2 * t2 * t2;\n float b1 = 3.0 * t * t2 * t2;\n float b2 = 3.0 * t * t * t2;\n float b3 = t * t * t;\n return b0 * p1 + b1 * c1 + b2 * c2 + b3 * p2;\n}\n\nvec3 cubicBezierDerivative(vec3 p1, vec3 c1, vec3 c2, vec3 p2, float t) {\n float t2 = 1.0 - t;\n return -3.0 * p1 * t2 * t2 +\n c1 * (3.0 * t2 * t2 - 6.0 * t2 * t) +\n c2 * (6.0 * t2 * t - 3.0 * t * t) +\n 3.0 * p2 * t * t;\n}\n", | ||
'use strict';(function(f,c){"object"===typeof exports&&"undefined"!==typeof module?c(exports,require("three")):"function"===typeof define&&define.amd?define(["exports","three"],c):(f=f||self,c(f.troika_three_utils={},f.THREE))})(this,function(f,c){function t(b){return b.replace(/^[ \t]*#include +<([\w\d./]+)>/gm,function(a,b){return(b=c.ShaderChunk[b])?t(b):a})}function l(b,a){var e=A(a),d=q.get(b);d||q.set(b,d=Object.create(null));if(d[e])return new d[e];var g="_onBeforeCompile"+e,f=function(h){b.onBeforeCompile.call(this, | ||
h);var d=e+"|||"+h.vertexShader+"|||"+h.fragmentShader,c=u[d];c||(c=B(h,a,e),c=u[d]=c);h.vertexShader=c.vertexShader;h.fragmentShader=c.fragmentShader;k(h.uniforms,this.uniforms);a.timeUniform&&(h.uniforms[a.timeUniform]={get value(){return Date.now()-C}});if(this[g])this[g](h)},r=function(){return p(a.chained?b:b.clone())},p=function(d){var h=Object.create(d,m);Object.defineProperty(h,"baseMaterial",{value:b});Object.defineProperty(h,"id",{value:D++});h.uuid=c.MathUtils.generateUUID();h.uniforms= | ||
k({},d.uniforms,a.uniforms);h.defines=k({},d.defines,a.defines);h.defines["TROIKA_DERIVED_MATERIAL_"+e]="";h.extensions=k({},d.extensions,a.extensions);h._listeners=void 0;return h},m={constructor:{value:r},isDerivedMaterial:{value:!0},customProgramCacheKey:{writable:!0,configurable:!0,value:function(){return e}},onBeforeCompile:{get:function(){return f},set:function(a){this[g]=a}},copy:{writable:!0,configurable:!0,value:function(a){b.copy.call(this,a);b.isShaderMaterial||b.isDerivedMaterial||(k(this.extensions, | ||
a.extensions),k(this.defines,a.defines),k(this.uniforms,c.UniformsUtils.clone(a.uniforms)));return this}},clone:{writable:!0,configurable:!0,value:function(){var a=new b.constructor;return p(a).copy(this)}},getDepthMaterial:{writable:!0,configurable:!0,value:function(){var d=this._depthMaterial;d||(d=this._depthMaterial=l(b.isDerivedMaterial?b.getDepthMaterial():new c.MeshDepthMaterial({depthPacking:c.RGBADepthPacking}),a),d.defines.IS_DEPTH_MATERIAL="",d.uniforms=this.uniforms);return d}},getDistanceMaterial:{writable:!0, | ||
configurable:!0,value:function(){var d=this._distanceMaterial;d||(d=this._distanceMaterial=l(b.isDerivedMaterial?b.getDistanceMaterial():new c.MeshDistanceMaterial,a),d.defines.IS_DISTANCE_MATERIAL="",d.uniforms=this.uniforms);return d}},dispose:{writable:!0,configurable:!0,value:function(){var a=this._depthMaterial,d=this._distanceMaterial;a&&a.dispose();d&&d.dispose();b.dispose.call(this)}}};d[e]=r;return new r}function B(b,a,e){var d=b.vertexShader,g=b.fragmentShader;b=a.vertexDefs;var c=a.vertexMainIntro, | ||
f=a.vertexMainOutro,p=a.vertexTransform,m=a.fragmentDefs,h=a.fragmentMainIntro,k=a.fragmentMainOutro,n=a.fragmentColorTransform,l=a.customRewriter;a=a.timeUniform;b=b||"";c=c||"";f=f||"";m=m||"";h=h||"";k=k||"";if(p||l)d=t(d);if(n||l)g=g.replace(/^[ \t]*#include <((?:tonemapping|encodings|fog|premultiplied_alpha|dithering)_fragment)>/gm,"\n//!BEGIN_POST_CHUNK $1\n$&\n//!END_POST_CHUNK\n"),g=t(g);l&&(g=l({vertexShader:d,fragmentShader:g}),d=g.vertexShader,g=g.fragmentShader);if(n){var q=[];g=g.replace(/^\/\/!BEGIN_POST_CHUNK[^]+?^\/\/!END_POST_CHUNK/gm, | ||
function(a){q.push(a);return""});k=n+"\n"+q.join("\n")+"\n"+k}a&&(n="\nuniform float "+a+";\n",b=n+b,m=n+m);p&&(b=b+"\nvoid troikaVertexTransform"+e+"(inout vec3 position, inout vec3 normal, inout vec2 uv) {\n "+p+"\n}\n",c="\ntroika_position_"+e+" = vec3(position);\ntroika_normal_"+e+" = vec3(normal);\ntroika_uv_"+e+" = vec2(uv);\ntroikaVertexTransform"+e+"(troika_position_"+e+", troika_normal_"+e+", troika_uv_"+e+");\n"+c+"\n",d=("vec3 troika_position_"+e+";\nvec3 troika_normal_"+e+";\nvec2 troika_uv_"+ | ||
e+";\n"+d+"\n").replace(/\b(position|normal|uv)\b/g,function(a,d,b,c){return/\battribute\s+vec[23]\s+$/.test(c.substr(0,b))?d:"troika_"+d+"_"+e}));d=v(d,e,b,c,f);g=v(g,e,m,h,k);return{vertexShader:d,fragmentShader:g}}function v(b,a,c,d,g){if(d||g||c)b=b.replace(w,"\n"+c+"\nvoid troikaOrigMain"+a+"() {"),b+="\nvoid main() {\n "+d+"\n troikaOrigMain"+a+"();\n "+g+"\n}";return b}function E(b,a){return"uniforms"===b?void 0:"function"===typeof a?a.toString():a}function A(b){b=JSON.stringify(b,E);var a= | ||
x.get(b);null==a&&x.set(b,a=++F);return a}var w=/\bvoid\s+main\s*\(\s*\)\s*{/g,k=Object.assign||function(){for(var b=arguments,a=arguments[0],c=1,d=arguments.length;c<d;c++){var g=b[c];if(g)for(var f in g)g.hasOwnProperty(f)&&(a[f]=g[f])}return a},C=Date.now(),q=new WeakMap,u=new Map,D=1E10,F=0,x=new Map,G={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon", | ||
MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"},y=null,z=new c.MeshStandardMaterial({color:16777215,side:c.DoubleSide}),H=function(b){function a(){b.call(this,a.getGeometry(),z);this.pointA=new c.Vector3;this.controlA=new c.Vector3;this.controlB=new c.Vector3;this.pointB=new c.Vector3;this.radius=.01;this.dashArray=new c.Vector2; | ||
this.dashOffset=0;this.frustumCulled=!1}b&&(a.__proto__=b);a.prototype=Object.create(b&&b.prototype);a.prototype.constructor=a;var e={material:{configurable:!0},customDepthMaterial:{configurable:!0},customDistanceMaterial:{configurable:!0}};a.getGeometry=function(){return y||(y=(new c.CylinderBufferGeometry(1,1,1,6,64)).translate(0,.5,0))};e.material.get=function(){var a=this._derivedMaterial,b=this._baseMaterial||this._defaultMaterial||(this._defaultMaterial=z.clone());a&&a.baseMaterial===b||(a= | ||
this._derivedMaterial=l(b,{chained:!0,uniforms:{pointA:{value:new c.Vector3},controlA:{value:new c.Vector3},controlB:{value:new c.Vector3},pointB:{value:new c.Vector3},radius:{value:.01},dashing:{value:new c.Vector3}},vertexDefs:"\nuniform vec3 pointA;\nuniform vec3 controlA;\nuniform vec3 controlB;\nuniform vec3 pointB;\nuniform float radius;\nvarying float bezierT;\n\nvec3 cubicBezier(vec3 p1, vec3 c1, vec3 c2, vec3 p2, float t) {\n float t2 = 1.0 - t;\n float b0 = t2 * t2 * t2;\n float b1 = 3.0 * t * t2 * t2;\n float b2 = 3.0 * t * t * t2;\n float b3 = t * t * t;\n return b0 * p1 + b1 * c1 + b2 * c2 + b3 * p2;\n}\n\nvec3 cubicBezierDerivative(vec3 p1, vec3 c1, vec3 c2, vec3 p2, float t) {\n float t2 = 1.0 - t;\n return -3.0 * p1 * t2 * t2 +\n c1 * (3.0 * t2 * t2 - 6.0 * t2 * t) +\n c2 * (6.0 * t2 * t - 3.0 * t * t) +\n 3.0 * p2 * t * t;\n}\n", | ||
vertexTransform:'\nfloat t = position.y;\nbezierT = t;\nvec3 bezierCenterPos = cubicBezier(pointA, controlA, controlB, pointB, t);\nvec3 bezierDir = normalize(cubicBezierDerivative(pointA, controlA, controlB, pointB, t));\n\n// Make "sideways" always perpendicular to the camera ray; this ensures that any twists\n// in the cylinder occur where you won\'t see them: \nvec3 viewDirection = normalMatrix * vec3(0.0, 0.0, 1.0);\nif (bezierDir == viewDirection) {\n bezierDir = normalize(cubicBezierDerivative(pointA, controlA, controlB, pointB, t == 1.0 ? t - 0.0001 : t + 0.0001));\n}\nvec3 sideways = normalize(cross(bezierDir, viewDirection));\nvec3 upish = normalize(cross(sideways, bezierDir));\n\n// Build a matrix for transforming this disc in the cylinder:\nmat4 discTx;\ndiscTx[0].xyz = sideways * radius;\ndiscTx[1].xyz = bezierDir * radius;\ndiscTx[2].xyz = upish * radius;\ndiscTx[3].xyz = bezierCenterPos;\ndiscTx[3][3] = 1.0;\n\n// Apply transform, ignoring original y\nposition = (discTx * vec4(position.x, 0.0, position.z, 1.0)).xyz;\nnormal = normalize(mat3(discTx) * normal);\n', | ||
fragmentDefs:"\nuniform vec3 dashing;\nvarying float bezierT;\n",fragmentMainIntro:"\nif (dashing.x + dashing.y > 0.0) {\n float dashFrac = mod(bezierT - dashing.z, dashing.x + dashing.y);\n if (dashFrac > dashing.x) {\n discard;\n }\n}\n"}),b.addEventListener("dispose",function D(){b.removeEventListener("dispose",D);a.dispose()}));return a};e.material.set=function(a){this._baseMaterial=a};e.customDepthMaterial.get=function(){return this.material.getDepthMaterial()};e.customDistanceMaterial.get= | ||
function(){return this.material.getDistanceMaterial()};a.prototype.onBeforeRender=function(a){a=this.material.uniforms;var b=this.controlA,d=this.controlB,c=this.pointB,e=this.radius,f=this.dashArray,h=this.dashOffset;a.pointA.value.copy(this.pointA);a.controlA.value.copy(b);a.controlB.value.copy(d);a.pointB.value.copy(c);a.radius.value=e;a.dashing.value.set(f.x,f.y,h||0)};a.prototype.raycast=function(a,b){};Object.defineProperties(a.prototype,e);return a}(c.Mesh);f.BezierMesh=I;f.createDerivedMaterial= | ||
l;f.expandShaderIncludes=r;f.getShaderUniformTypes=function(b){for(var a=/\buniform\s+(int|float|vec[234])\s+([A-Za-z_][\w]*)/g,c=Object.create(null),d;null!==(d=a.exec(b));)c[d[2]]=d[1];return c};f.getShadersForMaterial=function(b){var a=H[b.type];return a?c.ShaderLib[a]:b};f.voidMainRegExp=v;Object.defineProperty(f,"__esModule",{value:!0})}) | ||
fragmentDefs:"\nuniform vec3 dashing;\nvarying float bezierT;\n",fragmentMainIntro:"\nif (dashing.x + dashing.y > 0.0) {\n float dashFrac = mod(bezierT - dashing.z, dashing.x + dashing.y);\n if (dashFrac > dashing.x) {\n discard;\n }\n}\n"}),b.addEventListener("dispose",function r(){b.removeEventListener("dispose",r);a.dispose()}));return a};e.material.set=function(a){this._baseMaterial=a};e.customDepthMaterial.get=function(){return this.material.getDepthMaterial()};e.customDistanceMaterial.get= | ||
function(){return this.material.getDistanceMaterial()};a.prototype.onBeforeRender=function(a){a=this.material.uniforms;var b=this.controlA,d=this.controlB,c=this.pointB,e=this.radius,f=this.dashArray,h=this.dashOffset;a.pointA.value.copy(this.pointA);a.controlA.value.copy(b);a.controlB.value.copy(d);a.pointB.value.copy(c);a.radius.value=e;a.dashing.value.set(f.x,f.y,h||0)};a.prototype.raycast=function(a,b){};Object.defineProperties(a.prototype,e);return a}(c.Mesh);f.BezierMesh=H;f.createDerivedMaterial= | ||
l;f.expandShaderIncludes=t;f.getShaderUniformTypes=function(b){for(var a=/\buniform\s+(int|float|vec[234])\s+([A-Za-z_][\w]*)/g,c=Object.create(null),d;null!==(d=a.exec(b));)c[d[2]]=d[1];return c};f.getShadersForMaterial=function(b){var a=G[b.type];return a?c.ShaderLib[a]:b};f.invertMatrix4=function(b,a){void 0===a&&(a=new c.Matrix4);"function"===typeof a.invert?a.copy(b).invert():a.getInverse(b);return a};f.voidMainRegExp=w;Object.defineProperty(f,"__esModule",{value:!0})}) |
{ | ||
"name": "troika-three-utils", | ||
"version": "0.38.0", | ||
"version": "0.38.1", | ||
"description": "Various utilities related to Three.js", | ||
@@ -17,5 +17,5 @@ "author": "Jason Johnston <jason.johnston@protectwise.com>", | ||
"peerDependencies": { | ||
"three": "0.103.x - 0.121.x" | ||
"three": "0.103.x - 0.125.x" | ||
}, | ||
"gitHead": "d48144bf99a2eaf2089c0cd2a8065506161dfdf4" | ||
"gitHead": "b54fd6f27b4d95190747ff94cf4e101239447fea" | ||
} |
@@ -172,2 +172,4 @@ import { voidMainRegExp } from './voidMainRegExp.js' | ||
customProgramCacheKey: { | ||
writable: true, | ||
configurable: true, | ||
value: function () { | ||
@@ -340,6 +342,9 @@ return optionsKey | ||
if (vertexTransform) { | ||
vertexDefs = `${vertexDefs} | ||
vec3 troika_position_${key}; | ||
// Hoist these defs to the very top so they work in other function defs | ||
vertexShader = `vec3 troika_position_${key}; | ||
vec3 troika_normal_${key}; | ||
vec2 troika_uv_${key}; | ||
${vertexShader} | ||
` | ||
vertexDefs = `${vertexDefs} | ||
void troikaVertexTransform${key}(inout vec3 position, inout vec3 normal, inout vec2 uv) { | ||
@@ -346,0 +351,0 @@ ${vertexTransform} |
@@ -7,3 +7,4 @@ // Troika Three.js Utilities exports | ||
export { expandShaderIncludes } from './expandShaderIncludes.js' | ||
export { invertMatrix4 } from './invertMatrix4.js' | ||
export { voidMainRegExp } from './voidMainRegExp.js' | ||
export { BezierMesh } from './BezierMesh.js' |
115145
18
2209