tsl-textures 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsl-textures",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "A collection of Three.js Shading Language (TSL) textures ",
5
5
  "main": "index.js",
6
6
  "repository": {
package/src/scaler.js ADDED
@@ -0,0 +1,72 @@
1
+ 
2
+ // TSL-Textures: Scaler
3
+
4
+
5
+
6
+ import { Vector2, Vector3 } from "three";
7
+ import { cross, Fn, mix, modelNormalMatrix, normalLocal, positionLocal, sub, tangentLocal, vec3, vec4 } from 'three';
8
+ import { matScale, matTrans, selectPlanar } from 'tsl-textures/tsl-utils.js';
9
+
10
+
11
+
12
+ var surfacePos = Fn( ([ pos, params ])=>{
13
+
14
+ var zone = selectPlanar( pos, params.selectorAngles, params.selectorCenter, params.selectorWidth );
15
+
16
+ var S = matScale( mix( vec3( 1, 1, 1 ), params.scales, zone ) ),
17
+ T = matTrans( params.center ),
18
+ TN = matTrans( params.center.negate() );
19
+
20
+ return T.mul( S ).mul( TN ).mul( vec4( pos, 1 ) ).xyz;
21
+
22
+ } );
23
+
24
+
25
+
26
+ var scaler = Fn( ( params )=>{
27
+
28
+ return surfacePos( positionLocal, params );
29
+
30
+ } );
31
+
32
+
33
+
34
+ scaler.normal = Fn( ( params ) => {
35
+
36
+ var eps = 0.01;
37
+
38
+ var position = positionLocal,
39
+ normal = normalLocal.normalize().toVar(),
40
+ tangent = tangentLocal.normalize().mul( eps ).toVar(),
41
+ bitangent = cross( normal, tangent ).normalize().mul( eps ).toVar();
42
+
43
+ var pos = surfacePos( position, params );
44
+ var posU = surfacePos( position.add( tangent ), params );
45
+ var posV = surfacePos( position.add( bitangent ), params );
46
+
47
+ var dU = sub( posU, pos ),
48
+ dV = sub( posV, pos );
49
+
50
+ return modelNormalMatrix.mul( cross( dU, dV ).normalize() );
51
+
52
+ } );
53
+
54
+
55
+
56
+ scaler.defaults = {
57
+ $name: 'Scaler',
58
+ $positionNode: true,
59
+ $selectorPlanar: true,
60
+
61
+ scales: new Vector3( 0.01, 0.9, 1.7 ),
62
+ center: new Vector3( 0, 0, 0 ),
63
+
64
+ selectorCenter: new Vector3( 0, 0, 0 ),
65
+ selectorAngles: new Vector2( 0, 0 ),
66
+ selectorWidth: 2,
67
+
68
+ };
69
+
70
+
71
+
72
+ export { scaler };
package/src/tsl-utils.js CHANGED
@@ -114,13 +114,13 @@ function dynamic( params ) {
114
114
 
115
115
  for ( var [ key, value ] of Object.entries( params ) ) {
116
116
 
117
- if ( key[ 0 ]!='$' ) {
117
+ if ( key[ 0 ]!='$' ) {
118
118
 
119
119
  if ( value instanceof Vector3 )
120
120
  result[ key ] = uniform( value, 'vec3' );
121
121
  else
122
122
  result[ key ] = uniform( value );
123
-
123
+
124
124
  }
125
125
 
126
126
  }
@@ -281,7 +281,20 @@ const matRotYXZ = Fn( ([ angles ])=>{
281
281
  RZ = matRotZ( angles.z );
282
282
 
283
283
  return RY.mul( RX ).mul( RZ );
284
-
284
+
285
+ } );
286
+
287
+
288
+
289
+ // generate scaling matrix
290
+ const matScale = Fn( ([ scales ])=>{
291
+
292
+ return mat4(
293
+ scales.x, 0, 0, 0,
294
+ 0, scales.y, 0, 0,
295
+ 0, 0, scales.z, 0,
296
+ 0, 0, 0, 1 );
297
+
285
298
  } );
286
299
 
287
300
 
@@ -387,6 +400,7 @@ export
387
400
  matRotZ,
388
401
  matRotYXZ,
389
402
  matTrans,
403
+ matScale,
390
404
  selectPlanar,
391
405
  overlayPlanar
392
406
  };