@judah-silva/rnacanvas 0.0.2 → 0.0.4

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/dist/index.d.mts CHANGED
@@ -60,10 +60,16 @@ declare class Quat {
60
60
  private _quaternion;
61
61
  constructor();
62
62
  rotateByQuaternion(quaternion: Quat): void;
63
- setToQuaternion(quaternion: Nullable<Quaternion>): void;
63
+ setToQuaternion(quaternion: Nullable<Quaternion>): this;
64
64
  setFromMatrix(matrix: Matrix4): this;
65
65
  setFromEuler(eulerAngle: Vec3): this;
66
+ setFromValues(w: number, x: number, y: number, z: number): this;
67
+ toArray(): number[];
66
68
  get quaternion(): Quaternion;
69
+ get w(): number;
70
+ get x(): number;
71
+ get y(): number;
72
+ get z(): number;
67
73
  }
68
74
 
69
75
  declare class Vec3 {
@@ -98,7 +104,6 @@ interface userData {
98
104
  */
99
105
  declare class Motif extends Group<Residue> {
100
106
  userData: userData;
101
- private _quat;
102
107
  constructor(name: string);
103
108
  addChild(child: Residue): void;
104
109
  setPosition(x: number, y: number, z: number): void;
@@ -107,9 +112,9 @@ declare class Motif extends Group<Residue> {
107
112
  rotateByQuaternion(quat: Quat): void;
108
113
  setQuaternion(quat: Quat): void;
109
114
  multiplyScalar(scalar: number): void;
110
- private _nanCheck;
111
115
  get uuid(): string;
112
116
  get quat(): Quat;
117
+ get scale(): number;
113
118
  get position(): Vec3;
114
119
  }
115
120
 
@@ -383,6 +388,7 @@ interface MotifProps {
383
388
  locked: boolean;
384
389
  position?: Vec3;
385
390
  rotation?: Quat;
391
+ scale?: number;
386
392
  }
387
393
  /**
388
394
  * ________________________________________________________________________________________________
package/dist/index.d.ts CHANGED
@@ -60,10 +60,16 @@ declare class Quat {
60
60
  private _quaternion;
61
61
  constructor();
62
62
  rotateByQuaternion(quaternion: Quat): void;
63
- setToQuaternion(quaternion: Nullable<Quaternion>): void;
63
+ setToQuaternion(quaternion: Nullable<Quaternion>): this;
64
64
  setFromMatrix(matrix: Matrix4): this;
65
65
  setFromEuler(eulerAngle: Vec3): this;
66
+ setFromValues(w: number, x: number, y: number, z: number): this;
67
+ toArray(): number[];
66
68
  get quaternion(): Quaternion;
69
+ get w(): number;
70
+ get x(): number;
71
+ get y(): number;
72
+ get z(): number;
67
73
  }
68
74
 
69
75
  declare class Vec3 {
@@ -98,7 +104,6 @@ interface userData {
98
104
  */
99
105
  declare class Motif extends Group<Residue> {
100
106
  userData: userData;
101
- private _quat;
102
107
  constructor(name: string);
103
108
  addChild(child: Residue): void;
104
109
  setPosition(x: number, y: number, z: number): void;
@@ -107,9 +112,9 @@ declare class Motif extends Group<Residue> {
107
112
  rotateByQuaternion(quat: Quat): void;
108
113
  setQuaternion(quat: Quat): void;
109
114
  multiplyScalar(scalar: number): void;
110
- private _nanCheck;
111
115
  get uuid(): string;
112
116
  get quat(): Quat;
117
+ get scale(): number;
113
118
  get position(): Vec3;
114
119
  }
115
120
 
@@ -383,6 +388,7 @@ interface MotifProps {
383
388
  locked: boolean;
384
389
  position?: Vec3;
385
390
  rotation?: Quat;
391
+ scale?: number;
386
392
  }
387
393
  /**
388
394
  * ________________________________________________________________________________________________
package/dist/index.js CHANGED
@@ -145,7 +145,8 @@ var Quat = class {
145
145
  if (quaternion === null) {
146
146
  throw new Error("Cannot set to null quaternion");
147
147
  }
148
- this._quaternion = quaternion;
148
+ this.setFromValues(quaternion.w, quaternion.x, quaternion.y, quaternion.z);
149
+ return this;
149
150
  }
150
151
  setFromMatrix(matrix) {
151
152
  this._quaternion = import_core3.Quaternion.FromRotationMatrix(matrix.matrix);
@@ -155,9 +156,30 @@ var Quat = class {
155
156
  this._quaternion = import_core3.Quaternion.FromEulerAngles(eulerAngle.x, eulerAngle.y, eulerAngle.z);
156
157
  return this;
157
158
  }
159
+ setFromValues(w, x, y, z) {
160
+ this._quaternion.set(x, y, z, w);
161
+ return this;
162
+ }
163
+ toArray() {
164
+ const quatArr = [];
165
+ this._quaternion.toArray(quatArr);
166
+ return quatArr;
167
+ }
158
168
  get quaternion() {
159
169
  return this._quaternion;
160
170
  }
171
+ get w() {
172
+ return this._quaternion.w;
173
+ }
174
+ get x() {
175
+ return this._quaternion.x;
176
+ }
177
+ get y() {
178
+ return this._quaternion.y;
179
+ }
180
+ get z() {
181
+ return this._quaternion.z;
182
+ }
161
183
  };
162
184
 
163
185
  // src/Math/Matrix4.ts
@@ -196,12 +218,10 @@ var Matrix4 = class {
196
218
  // src/3D/Motif.ts
197
219
  var Motif = class extends Group {
198
220
  userData;
199
- _quat;
200
221
  constructor(name) {
201
222
  const tempEngine = new import_core5.NullEngine();
202
223
  const tempScene = new import_core5.Scene(tempEngine);
203
224
  super(name, tempScene);
204
- this._quat = new Quat();
205
225
  this.userData = {
206
226
  atomInfo: [],
207
227
  fileName: ""
@@ -229,20 +249,18 @@ var Motif = class extends Group {
229
249
  axis.y,
230
250
  axis.z
231
251
  ), angle, import_core5.Space.WORLD);
232
- this._nanCheck();
233
252
  }
234
253
  rotateByQuaternion(quat) {
235
254
  if (this._node.rotationQuaternion === null) {
236
255
  this._node.rotationQuaternion = this._node.rotation.toQuaternion();
237
256
  }
238
257
  quat.quaternion.multiplyToRef(this._node.rotationQuaternion, this._node.rotationQuaternion);
239
- this._nanCheck();
240
258
  }
241
259
  setQuaternion(quat) {
242
260
  if (this._node.rotationQuaternion === null) {
243
261
  this._node.rotationQuaternion = this._node.rotation.toQuaternion();
244
262
  }
245
- this._quat.setToQuaternion(quat.quaternion);
263
+ this._node.rotationQuaternion.set(quat.x, quat.y, quat.z, quat.w);
246
264
  }
247
265
  multiplyScalar(scalar) {
248
266
  this._node.scaling = new import_core5.Vector3(
@@ -251,18 +269,17 @@ var Motif = class extends Group {
251
269
  this._node.scaling.z * scalar
252
270
  );
253
271
  }
254
- _nanCheck() {
255
- if (Number.isNaN(this._quat.quaternion.w) || Number.isNaN(this._quat.quaternion.x) || Number.isNaN(this._quat.quaternion.y) || Number.isNaN(this._quat.quaternion.z)) {
256
- this._quat.setToQuaternion(import_core5.Quaternion.Identity());
257
- throw new Error(`Quaternion is NaN for motif ${this._node.name}`);
258
- }
259
- }
260
272
  get uuid() {
261
273
  return this._node.uniqueId.toString();
262
274
  }
263
275
  get quat() {
264
- this._quat.setToQuaternion(this._node.rotationQuaternion);
265
- return this._quat;
276
+ if (this._node.rotationQuaternion === null) {
277
+ this._node.rotationQuaternion = this._node.rotation.toQuaternion();
278
+ }
279
+ return new Quat().setToQuaternion(this._node.rotationQuaternion);
280
+ }
281
+ get scale() {
282
+ return this._node.scaling.x;
266
283
  }
267
284
  get position() {
268
285
  return new Vec3(
@@ -1405,11 +1422,13 @@ function Canvas({
1405
1422
  });
1406
1423
  if (scene.current.children.size !== motifs.length) {
1407
1424
  motifs.forEach((motifMesh, index) => {
1408
- if (motifProps[index].position) positions[index] = motifProps[index].position;
1425
+ scene.current?.add(motifMesh);
1426
+ if (motifProps[index].position) positions[index] = motifProps[index].position.clone();
1409
1427
  motifMesh.setPosition(positions[index].x, positions[index].y, positions[index].z);
1410
1428
  if (motifProps[index].rotation) motifMesh.setQuaternion(motifProps[index].rotation);
1411
- motifMesh.multiplyScalar(canvasRef.current.width / 250);
1412
- scene.current?.add(motifMesh);
1429
+ let scale = canvasRef.current.width / 250;
1430
+ if (motifProps[index].scale) scale = motifProps[index].scale;
1431
+ motifMesh.multiplyScalar(scale);
1413
1432
  });
1414
1433
  const eventManager = scene.current?.eventManager;
1415
1434
  eventManager.on(Events.EventType.OBJECT_SELECTED, onSelectMotif);
package/dist/index.mjs CHANGED
@@ -27,7 +27,7 @@ var Group = class {
27
27
  };
28
28
 
29
29
  // src/3D/Motif.ts
30
- import { NullEngine, Quaternion as Quaternion3, Scene as Scene2, Space, Vector3 as Vector32 } from "@babylonjs/core";
30
+ import { NullEngine, Scene as Scene2, Space, Vector3 as Vector32 } from "@babylonjs/core";
31
31
 
32
32
  // src/Math/Vec3.ts
33
33
  import { Quaternion, Vector3 } from "@babylonjs/core";
@@ -88,7 +88,8 @@ var Quat = class {
88
88
  if (quaternion === null) {
89
89
  throw new Error("Cannot set to null quaternion");
90
90
  }
91
- this._quaternion = quaternion;
91
+ this.setFromValues(quaternion.w, quaternion.x, quaternion.y, quaternion.z);
92
+ return this;
92
93
  }
93
94
  setFromMatrix(matrix) {
94
95
  this._quaternion = Quaternion2.FromRotationMatrix(matrix.matrix);
@@ -98,9 +99,30 @@ var Quat = class {
98
99
  this._quaternion = Quaternion2.FromEulerAngles(eulerAngle.x, eulerAngle.y, eulerAngle.z);
99
100
  return this;
100
101
  }
102
+ setFromValues(w, x, y, z) {
103
+ this._quaternion.set(x, y, z, w);
104
+ return this;
105
+ }
106
+ toArray() {
107
+ const quatArr = [];
108
+ this._quaternion.toArray(quatArr);
109
+ return quatArr;
110
+ }
101
111
  get quaternion() {
102
112
  return this._quaternion;
103
113
  }
114
+ get w() {
115
+ return this._quaternion.w;
116
+ }
117
+ get x() {
118
+ return this._quaternion.x;
119
+ }
120
+ get y() {
121
+ return this._quaternion.y;
122
+ }
123
+ get z() {
124
+ return this._quaternion.z;
125
+ }
104
126
  };
105
127
 
106
128
  // src/Math/Matrix4.ts
@@ -139,12 +161,10 @@ var Matrix4 = class {
139
161
  // src/3D/Motif.ts
140
162
  var Motif = class extends Group {
141
163
  userData;
142
- _quat;
143
164
  constructor(name) {
144
165
  const tempEngine = new NullEngine();
145
166
  const tempScene = new Scene2(tempEngine);
146
167
  super(name, tempScene);
147
- this._quat = new Quat();
148
168
  this.userData = {
149
169
  atomInfo: [],
150
170
  fileName: ""
@@ -172,20 +192,18 @@ var Motif = class extends Group {
172
192
  axis.y,
173
193
  axis.z
174
194
  ), angle, Space.WORLD);
175
- this._nanCheck();
176
195
  }
177
196
  rotateByQuaternion(quat) {
178
197
  if (this._node.rotationQuaternion === null) {
179
198
  this._node.rotationQuaternion = this._node.rotation.toQuaternion();
180
199
  }
181
200
  quat.quaternion.multiplyToRef(this._node.rotationQuaternion, this._node.rotationQuaternion);
182
- this._nanCheck();
183
201
  }
184
202
  setQuaternion(quat) {
185
203
  if (this._node.rotationQuaternion === null) {
186
204
  this._node.rotationQuaternion = this._node.rotation.toQuaternion();
187
205
  }
188
- this._quat.setToQuaternion(quat.quaternion);
206
+ this._node.rotationQuaternion.set(quat.x, quat.y, quat.z, quat.w);
189
207
  }
190
208
  multiplyScalar(scalar) {
191
209
  this._node.scaling = new Vector32(
@@ -194,18 +212,17 @@ var Motif = class extends Group {
194
212
  this._node.scaling.z * scalar
195
213
  );
196
214
  }
197
- _nanCheck() {
198
- if (Number.isNaN(this._quat.quaternion.w) || Number.isNaN(this._quat.quaternion.x) || Number.isNaN(this._quat.quaternion.y) || Number.isNaN(this._quat.quaternion.z)) {
199
- this._quat.setToQuaternion(Quaternion3.Identity());
200
- throw new Error(`Quaternion is NaN for motif ${this._node.name}`);
201
- }
202
- }
203
215
  get uuid() {
204
216
  return this._node.uniqueId.toString();
205
217
  }
206
218
  get quat() {
207
- this._quat.setToQuaternion(this._node.rotationQuaternion);
208
- return this._quat;
219
+ if (this._node.rotationQuaternion === null) {
220
+ this._node.rotationQuaternion = this._node.rotation.toQuaternion();
221
+ }
222
+ return new Quat().setToQuaternion(this._node.rotationQuaternion);
223
+ }
224
+ get scale() {
225
+ return this._node.scaling.x;
209
226
  }
210
227
  get position() {
211
228
  return new Vec3(
@@ -1348,11 +1365,13 @@ function Canvas({
1348
1365
  });
1349
1366
  if (scene.current.children.size !== motifs.length) {
1350
1367
  motifs.forEach((motifMesh, index) => {
1351
- if (motifProps[index].position) positions[index] = motifProps[index].position;
1368
+ scene.current?.add(motifMesh);
1369
+ if (motifProps[index].position) positions[index] = motifProps[index].position.clone();
1352
1370
  motifMesh.setPosition(positions[index].x, positions[index].y, positions[index].z);
1353
1371
  if (motifProps[index].rotation) motifMesh.setQuaternion(motifProps[index].rotation);
1354
- motifMesh.multiplyScalar(canvasRef.current.width / 250);
1355
- scene.current?.add(motifMesh);
1372
+ let scale = canvasRef.current.width / 250;
1373
+ if (motifProps[index].scale) scale = motifProps[index].scale;
1374
+ motifMesh.multiplyScalar(scale);
1356
1375
  });
1357
1376
  const eventManager = scene.current?.eventManager;
1358
1377
  eventManager.on(Events.EventType.OBJECT_SELECTED, onSelectMotif);
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@judah-silva/rnacanvas",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "A 3D Canvas for displaying and interacting with custom RNA models. Powered by BabylonJS.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
Binary file