@vib3code/sdk 2.0.3-canary.98b84da → 2.0.3-canary.ae15579

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": "@vib3code/sdk",
3
- "version": "2.0.3-canary.98b84da",
3
+ "version": "2.0.3-canary.ae15579",
4
4
  "description": "VIB3+ 4D Visualization SDK - Unified engine with 6D rotation, MCP agentic integration, and cross-platform support",
5
5
  "type": "module",
6
6
  "main": "src/core/VIB3Engine.js",
@@ -48,6 +48,19 @@ export class Mat4x4 {
48
48
  }
49
49
  }
50
50
 
51
+ /**
52
+ * Reset to identity matrix
53
+ * @returns {Mat4x4} this
54
+ */
55
+ identity() {
56
+ const d = this.data;
57
+ d[0] = 1; d[1] = 0; d[2] = 0; d[3] = 0;
58
+ d[4] = 0; d[5] = 1; d[6] = 0; d[7] = 0;
59
+ d[8] = 0; d[9] = 0; d[10] = 1; d[11] = 0;
60
+ d[12] = 0; d[13] = 0; d[14] = 0; d[15] = 1;
61
+ return this;
62
+ }
63
+
51
64
  /**
52
65
  * Create identity matrix
53
66
  * @returns {Mat4x4}
@@ -718,51 +731,78 @@ export class Mat4x4 {
718
731
  /**
719
732
  * Create XY plane rotation matrix (standard Z-axis rotation in 3D)
720
733
  * @param {number} angle - Rotation angle in radians
734
+ * @param {Mat4x4} [target=null] - Optional target matrix
721
735
  * @returns {Mat4x4}
722
736
  */
723
- static rotationXY(angle) {
737
+ static rotationXY(angle, target = null) {
724
738
  const c = Math.cos(angle);
725
739
  const s = Math.sin(angle);
726
- const out = new Mat4x4(Mat4x4.UNINITIALIZED);
740
+ const out = target || new Mat4x4(Mat4x4.UNINITIALIZED);
727
741
  const r = out.data;
728
- r[0] = c; r[1] = s;
729
- r[4] = -s; r[5] = c;
730
- r[10] = 1;
731
- r[15] = 1;
742
+
743
+ if (target) {
744
+ r[0] = c; r[1] = s; r[2] = 0; r[3] = 0;
745
+ r[4] = -s; r[5] = c; r[6] = 0; r[7] = 0;
746
+ r[8] = 0; r[9] = 0; r[10] = 1; r[11] = 0;
747
+ r[12] = 0; r[13] = 0; r[14] = 0; r[15] = 1;
748
+ } else {
749
+ r[0] = c; r[1] = s;
750
+ r[4] = -s; r[5] = c;
751
+ r[10] = 1;
752
+ r[15] = 1;
753
+ }
732
754
  return out;
733
755
  }
734
756
 
735
757
  /**
736
758
  * Create XZ plane rotation matrix (standard Y-axis rotation in 3D)
737
759
  * @param {number} angle - Rotation angle in radians
760
+ * @param {Mat4x4} [target=null] - Optional target matrix
738
761
  * @returns {Mat4x4}
739
762
  */
740
- static rotationXZ(angle) {
763
+ static rotationXZ(angle, target = null) {
741
764
  const c = Math.cos(angle);
742
765
  const s = Math.sin(angle);
743
- const out = new Mat4x4(Mat4x4.UNINITIALIZED);
766
+ const out = target || new Mat4x4(Mat4x4.UNINITIALIZED);
744
767
  const r = out.data;
745
- r[0] = c; r[2] = -s;
746
- r[5] = 1;
747
- r[8] = s; r[10] = c;
748
- r[15] = 1;
768
+
769
+ if (target) {
770
+ r[0] = c; r[1] = 0; r[2] = -s; r[3] = 0;
771
+ r[4] = 0; r[5] = 1; r[6] = 0; r[7] = 0;
772
+ r[8] = s; r[9] = 0; r[10] = c; r[11] = 0;
773
+ r[12] = 0; r[13] = 0; r[14] = 0; r[15] = 1;
774
+ } else {
775
+ r[0] = c; r[2] = -s;
776
+ r[5] = 1;
777
+ r[8] = s; r[10] = c;
778
+ r[15] = 1;
779
+ }
749
780
  return out;
750
781
  }
751
782
 
752
783
  /**
753
784
  * Create YZ plane rotation matrix (standard X-axis rotation in 3D)
754
785
  * @param {number} angle - Rotation angle in radians
786
+ * @param {Mat4x4} [target=null] - Optional target matrix
755
787
  * @returns {Mat4x4}
756
788
  */
757
- static rotationYZ(angle) {
789
+ static rotationYZ(angle, target = null) {
758
790
  const c = Math.cos(angle);
759
791
  const s = Math.sin(angle);
760
- const out = new Mat4x4(Mat4x4.UNINITIALIZED);
792
+ const out = target || new Mat4x4(Mat4x4.UNINITIALIZED);
761
793
  const r = out.data;
762
- r[0] = 1;
763
- r[5] = c; r[6] = s;
764
- r[9] = -s; r[10] = c;
765
- r[15] = 1;
794
+
795
+ if (target) {
796
+ r[0] = 1; r[1] = 0; r[2] = 0; r[3] = 0;
797
+ r[4] = 0; r[5] = c; r[6] = s; r[7] = 0;
798
+ r[8] = 0; r[9] = -s; r[10] = c; r[11] = 0;
799
+ r[12] = 0; r[13] = 0; r[14] = 0; r[15] = 1;
800
+ } else {
801
+ r[0] = 1;
802
+ r[5] = c; r[6] = s;
803
+ r[9] = -s; r[10] = c;
804
+ r[15] = 1;
805
+ }
766
806
  return out;
767
807
  }
768
808
 
@@ -770,51 +810,78 @@ export class Mat4x4 {
770
810
  * Create XW plane rotation matrix (4D hyperspace rotation)
771
811
  * Creates "inside-out" effect when w approaches viewer
772
812
  * @param {number} angle - Rotation angle in radians
813
+ * @param {Mat4x4} [target=null] - Optional target matrix
773
814
  * @returns {Mat4x4}
774
815
  */
775
- static rotationXW(angle) {
816
+ static rotationXW(angle, target = null) {
776
817
  const c = Math.cos(angle);
777
818
  const s = Math.sin(angle);
778
- const out = new Mat4x4(Mat4x4.UNINITIALIZED);
819
+ const out = target || new Mat4x4(Mat4x4.UNINITIALIZED);
779
820
  const r = out.data;
780
- r[0] = c; r[3] = s;
781
- r[5] = 1;
782
- r[10] = 1;
783
- r[12] = -s; r[15] = c;
821
+
822
+ if (target) {
823
+ r[0] = c; r[1] = 0; r[2] = 0; r[3] = s;
824
+ r[4] = 0; r[5] = 1; r[6] = 0; r[7] = 0;
825
+ r[8] = 0; r[9] = 0; r[10] = 1; r[11] = 0;
826
+ r[12] = -s; r[13] = 0; r[14] = 0; r[15] = c;
827
+ } else {
828
+ r[0] = c; r[3] = s;
829
+ r[5] = 1;
830
+ r[10] = 1;
831
+ r[12] = -s; r[15] = c;
832
+ }
784
833
  return out;
785
834
  }
786
835
 
787
836
  /**
788
837
  * Create YW plane rotation matrix (4D hyperspace rotation)
789
838
  * @param {number} angle - Rotation angle in radians
839
+ * @param {Mat4x4} [target=null] - Optional target matrix
790
840
  * @returns {Mat4x4}
791
841
  */
792
- static rotationYW(angle) {
842
+ static rotationYW(angle, target = null) {
793
843
  const c = Math.cos(angle);
794
844
  const s = Math.sin(angle);
795
- const out = new Mat4x4(Mat4x4.UNINITIALIZED);
845
+ const out = target || new Mat4x4(Mat4x4.UNINITIALIZED);
796
846
  const r = out.data;
797
- r[0] = 1;
798
- r[5] = c; r[7] = s;
799
- r[10] = 1;
800
- r[13] = -s; r[15] = c;
847
+
848
+ if (target) {
849
+ r[0] = 1; r[1] = 0; r[2] = 0; r[3] = 0;
850
+ r[4] = 0; r[5] = c; r[6] = 0; r[7] = s;
851
+ r[8] = 0; r[9] = 0; r[10] = 1; r[11] = 0;
852
+ r[12] = 0; r[13] = -s; r[14] = 0; r[15] = c;
853
+ } else {
854
+ r[0] = 1;
855
+ r[5] = c; r[7] = s;
856
+ r[10] = 1;
857
+ r[13] = -s; r[15] = c;
858
+ }
801
859
  return out;
802
860
  }
803
861
 
804
862
  /**
805
863
  * Create ZW plane rotation matrix (4D hyperspace rotation)
806
864
  * @param {number} angle - Rotation angle in radians
865
+ * @param {Mat4x4} [target=null] - Optional target matrix
807
866
  * @returns {Mat4x4}
808
867
  */
809
- static rotationZW(angle) {
868
+ static rotationZW(angle, target = null) {
810
869
  const c = Math.cos(angle);
811
870
  const s = Math.sin(angle);
812
- const out = new Mat4x4(Mat4x4.UNINITIALIZED);
871
+ const out = target || new Mat4x4(Mat4x4.UNINITIALIZED);
813
872
  const r = out.data;
814
- r[0] = 1;
815
- r[5] = 1;
816
- r[10] = c; r[11] = s;
817
- r[14] = -s; r[15] = c;
873
+
874
+ if (target) {
875
+ r[0] = 1; r[1] = 0; r[2] = 0; r[3] = 0;
876
+ r[4] = 0; r[5] = 1; r[6] = 0; r[7] = 0;
877
+ r[8] = 0; r[9] = 0; r[10] = c; r[11] = s;
878
+ r[12] = 0; r[13] = 0; r[14] = -s; r[15] = c;
879
+ } else {
880
+ r[0] = 1;
881
+ r[5] = 1;
882
+ r[10] = c; r[11] = s;
883
+ r[14] = -s; r[15] = c;
884
+ }
818
885
  return out;
819
886
  }
820
887
 
@@ -841,24 +908,58 @@ export class Mat4x4 {
841
908
  * Create combined rotation matrix from all 6 angles
842
909
  * Order: XY, XZ, YZ, XW, YW, ZW
843
910
  *
844
- * @param {object} angles - Rotation angles
845
- * @param {number} [angles.xy=0] - XY plane rotation
846
- * @param {number} [angles.xz=0] - XZ plane rotation
847
- * @param {number} [angles.yz=0] - YZ plane rotation
848
- * @param {number} [angles.xw=0] - XW plane rotation
849
- * @param {number} [angles.yw=0] - YW plane rotation
850
- * @param {number} [angles.zw=0] - ZW plane rotation
911
+ * Supports two signatures:
912
+ * 1. rotationFromAngles(angles, target?)
913
+ * 2. rotationFromAngles(xy, xz, yz, xw, yw, zw, target?)
914
+ *
915
+ * @param {object|number} anglesOrXY - Rotation angles object OR XY angle
916
+ * @param {number|Mat4x4} [xzOrTarget] - XZ angle OR target matrix
917
+ * @param {number} [yz=0] - YZ angle
918
+ * @param {number} [xw=0] - XW angle
919
+ * @param {number} [yw=0] - YW angle
920
+ * @param {number} [zw=0] - ZW angle
921
+ * @param {Mat4x4} [target=null] - Target matrix (if using 6-arg signature)
851
922
  * @returns {Mat4x4}
852
923
  */
853
- static rotationFromAngles(angles) {
854
- let result = Mat4x4.identity();
924
+ static rotationFromAngles(anglesOrXY, xzOrTarget, yz, xw, yw, zw, target) {
925
+ let xy = 0, xz = 0;
926
+ let _yz = 0, _xw = 0, _yw = 0, _zw = 0;
927
+ let out = null;
928
+
929
+ if (typeof anglesOrXY === 'number') {
930
+ // Signature: (xy, xz, yz, xw, yw, zw, target)
931
+ xy = anglesOrXY;
932
+ xz = typeof xzOrTarget === 'number' ? xzOrTarget : 0;
933
+ _yz = yz || 0;
934
+ _xw = xw || 0;
935
+ _yw = yw || 0;
936
+ _zw = zw || 0;
937
+ out = target || null;
938
+ } else {
939
+ // Signature: (angles, target)
940
+ const angles = anglesOrXY || {};
941
+ xy = angles.xy || 0;
942
+ xz = angles.xz || 0;
943
+ _yz = angles.yz || 0;
944
+ _xw = angles.xw || 0;
945
+ _yw = angles.yw || 0;
946
+ _zw = angles.zw || 0;
947
+ // The second argument is the target in this case
948
+ // Use duck typing or check constructor name to avoid circular dependency issues if any
949
+ if (xzOrTarget && typeof xzOrTarget === 'object' && xzOrTarget.data) {
950
+ out = xzOrTarget;
951
+ }
952
+ }
953
+
954
+ const result = out || new Mat4x4(); // Default constructor is identity
955
+ if (out) result.identity(); // Reset if reused
855
956
 
856
- if (angles.xy) result.rotateXY(angles.xy);
857
- if (angles.xz) result.rotateXZ(angles.xz);
858
- if (angles.yz) result.rotateYZ(angles.yz);
859
- if (angles.xw) result.rotateXW(angles.xw);
860
- if (angles.yw) result.rotateYW(angles.yw);
861
- if (angles.zw) result.rotateZW(angles.zw);
957
+ if (xy) result.rotateXY(xy);
958
+ if (xz) result.rotateXZ(xz);
959
+ if (_yz) result.rotateYZ(_yz);
960
+ if (_xw) result.rotateXW(_xw);
961
+ if (_yw) result.rotateYW(_yw);
962
+ if (_zw) result.rotateZW(_zw);
862
963
 
863
964
  return result;
864
965
  }
@@ -72,12 +72,23 @@ export class Projection {
72
72
  * The projection point is at (0, 0, 0, 1) - the "north pole"
73
73
  *
74
74
  * @param {Vec4} v - 4D point (ideally on unit hypersphere)
75
+ * @param {object|Vec4} [options] - Projection options or target vector
76
+ * @param {Vec4} [target] - Optional target vector to write result to
75
77
  * @returns {Vec4} Projected point (w=0)
76
78
  */
77
- static stereographic(v, options = {}) {
78
- const epsilon = options.epsilon ?? DEFAULT_EPSILON;
79
+ static stereographic(v, options = {}, target = null) {
80
+ if (options instanceof Vec4) {
81
+ target = options;
82
+ options = {};
83
+ }
84
+
85
+ const epsilon = (options && options.epsilon) ?? DEFAULT_EPSILON;
79
86
  const denom = clampDenominator(1 - v.w, epsilon);
80
87
  const scale = 1 / denom;
88
+
89
+ if (target) {
90
+ return target.set(v.x * scale, v.y * scale, v.z * scale, 0);
91
+ }
81
92
  return new Vec4(v.x * scale, v.y * scale, v.z * scale, 0);
82
93
  }
83
94
 
@@ -107,9 +118,13 @@ export class Projection {
107
118
  * Parallel projection - no perspective distortion.
108
119
  *
109
120
  * @param {Vec4} v - 4D point
121
+ * @param {Vec4} [target] - Optional target vector to write result to
110
122
  * @returns {Vec4} Projected point (w=0)
111
123
  */
112
- static orthographic(v) {
124
+ static orthographic(v, target = null) {
125
+ if (target) {
126
+ return target.set(v.x, v.y, v.z, 0);
127
+ }
113
128
  return new Vec4(v.x, v.y, v.z, 0);
114
129
  }
115
130