@judah-silva/rnacanvas 0.0.9 → 0.0.10

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/README.md CHANGED
@@ -129,7 +129,3 @@ const props: MotifProps = {
129
129
  locked: false,
130
130
  };
131
131
  ```
132
-
133
-
134
-
135
- test
package/dist/index.d.mts CHANGED
@@ -16,8 +16,9 @@ declare class Residue extends Group<MeshObject> {
16
16
  /**
17
17
  * Cretes a material with the given color and sets it to the mesh
18
18
  * @param color String in the format of #RRGGBB
19
+ * @param highlight Whether to apply a highlight effect to the residue
19
20
  */
20
- colorResidue(color: string): void;
21
+ colorResidue(color: string, highlight?: boolean): void;
21
22
  }
22
23
 
23
24
  /**
@@ -34,10 +35,15 @@ declare class MeshObject {
34
35
  applyHighlight(): void;
35
36
  resetHighlight(): void;
36
37
  /**
37
- * Cretes a material with the given color and sets it to the mesh
38
+ * Creates a material with the given color and sets it to the mesh
38
39
  * @param color String in the format of #RRGGBB
39
40
  */
40
41
  createAndSetMaterial(color: string): void;
42
+ /**
43
+ * Sets the material of the mesh object to the given color
44
+ * @param color String in the format of #RRGGBB
45
+ */
46
+ colorMaterial(color: string): void;
41
47
  setNewMesh(mesh: Mesh): MeshObject;
42
48
  get mesh(): Mesh;
43
49
  get uuid(): string;
@@ -300,6 +306,14 @@ declare class RenderScene {
300
306
  private _eventManager;
301
307
  private _isDisposed;
302
308
  isRunning: boolean;
309
+ /**
310
+ *
311
+ * @param canvas HTML Canvas Element
312
+ * @param hexColor Color in the format of #RRGGBB
313
+ * @param cameraPositionZ Z position of the camera
314
+ * @param renderWidth Width of the render window
315
+ * @param renderHeight Height of the render window
316
+ */
303
317
  constructor(canvas: HTMLCanvasElement, hexColor: string, cameraPositionZ: number, renderWidth: number, renderHeight: number);
304
318
  start(): void;
305
319
  stop(): void;
package/dist/index.d.ts CHANGED
@@ -16,8 +16,9 @@ declare class Residue extends Group<MeshObject> {
16
16
  /**
17
17
  * Cretes a material with the given color and sets it to the mesh
18
18
  * @param color String in the format of #RRGGBB
19
+ * @param highlight Whether to apply a highlight effect to the residue
19
20
  */
20
- colorResidue(color: string): void;
21
+ colorResidue(color: string, highlight?: boolean): void;
21
22
  }
22
23
 
23
24
  /**
@@ -34,10 +35,15 @@ declare class MeshObject {
34
35
  applyHighlight(): void;
35
36
  resetHighlight(): void;
36
37
  /**
37
- * Cretes a material with the given color and sets it to the mesh
38
+ * Creates a material with the given color and sets it to the mesh
38
39
  * @param color String in the format of #RRGGBB
39
40
  */
40
41
  createAndSetMaterial(color: string): void;
42
+ /**
43
+ * Sets the material of the mesh object to the given color
44
+ * @param color String in the format of #RRGGBB
45
+ */
46
+ colorMaterial(color: string): void;
41
47
  setNewMesh(mesh: Mesh): MeshObject;
42
48
  get mesh(): Mesh;
43
49
  get uuid(): string;
@@ -300,6 +306,14 @@ declare class RenderScene {
300
306
  private _eventManager;
301
307
  private _isDisposed;
302
308
  isRunning: boolean;
309
+ /**
310
+ *
311
+ * @param canvas HTML Canvas Element
312
+ * @param hexColor Color in the format of #RRGGBB
313
+ * @param cameraPositionZ Z position of the camera
314
+ * @param renderWidth Width of the render window
315
+ * @param renderHeight Height of the render window
316
+ */
303
317
  constructor(canvas: HTMLCanvasElement, hexColor: string, cameraPositionZ: number, renderWidth: number, renderHeight: number);
304
318
  start(): void;
305
319
  stop(): void;
package/dist/index.js CHANGED
@@ -328,10 +328,14 @@ var Residue = class extends Group {
328
328
  /**
329
329
  * Cretes a material with the given color and sets it to the mesh
330
330
  * @param color String in the format of #RRGGBB
331
+ * @param highlight Whether to apply a highlight effect to the residue
331
332
  */
332
- colorResidue(color) {
333
+ colorResidue(color, highlight = false) {
333
334
  this._children.forEach((child) => {
334
- child.createAndSetMaterial(color);
335
+ child.colorMaterial(color);
336
+ if (highlight) {
337
+ child.applyHighlight();
338
+ }
335
339
  });
336
340
  }
337
341
  };
@@ -363,24 +367,34 @@ var MeshObject = class {
363
367
  }
364
368
  applyHighlight() {
365
369
  const mat = this._mesh.material;
366
- mat.emissiveColor = mat.diffuseColor.scale(0.75);
370
+ mat.emissiveColor = mat.diffuseColor.scale(0.6);
367
371
  }
368
372
  resetHighlight() {
369
373
  const mat = this._mesh.material;
370
374
  mat.emissiveColor = import_core7.Color3.Black();
371
375
  }
372
376
  /**
373
- * Cretes a material with the given color and sets it to the mesh
377
+ * Creates a material with the given color and sets it to the mesh
374
378
  * @param color String in the format of #RRGGBB
375
379
  */
376
380
  createAndSetMaterial(color) {
377
381
  const mat = new import_core7.StandardMaterial("mat");
378
- const color3 = import_core7.Color3.FromHexString(`#${color.replace(/^0x/, "")}`);
382
+ const color3 = import_core7.Color3.FromHexString(`${color.replace(/^0x/i, "")}`);
379
383
  mat.diffuseColor = color3;
380
384
  mat.specularColor = color3;
381
385
  mat.backFaceCulling = false;
382
386
  this._mesh.material = mat;
383
387
  }
388
+ /**
389
+ * Sets the material of the mesh object to the given color
390
+ * @param color String in the format of #RRGGBB
391
+ */
392
+ colorMaterial(color) {
393
+ const mat = this._mesh.material;
394
+ const color3 = import_core7.Color3.FromHexString(`${color.replace(/^0x/i, "")}`);
395
+ mat.diffuseColor = color3;
396
+ mat.specularColor = color3;
397
+ }
384
398
  setNewMesh(mesh) {
385
399
  this._mesh = mesh;
386
400
  return this;
@@ -678,12 +692,20 @@ var RenderScene = class {
678
692
  // State variables
679
693
  _isDisposed = false;
680
694
  isRunning = false;
695
+ /**
696
+ *
697
+ * @param canvas HTML Canvas Element
698
+ * @param hexColor Color in the format of #RRGGBB
699
+ * @param cameraPositionZ Z position of the camera
700
+ * @param renderWidth Width of the render window
701
+ * @param renderHeight Height of the render window
702
+ */
681
703
  constructor(canvas, hexColor, cameraPositionZ, renderWidth, renderHeight) {
682
704
  this._canvas = canvas;
683
705
  this._engine = new import_core9.Engine(this._canvas, true);
684
706
  this._engine.setSize(renderWidth, renderHeight);
685
707
  this._scene = new import_core9.Scene(this._engine);
686
- this._scene.clearColor = import_core9.Color4.FromHexString(`${hexColor.replace(/^0x/, "")}`);
708
+ this._scene.clearColor = import_core9.Color4.FromHexString(`${hexColor.replace(/^0x/i, "")}`);
687
709
  this._camera = new import_core9.UniversalCamera("camera", new import_core9.Vector3(0, 0, cameraPositionZ));
688
710
  this._camera.setTarget(new import_core9.Vector3(0, 0, 0));
689
711
  this._camera.mode = import_core9.Camera.ORTHOGRAPHIC_CAMERA;
@@ -695,7 +717,6 @@ var RenderScene = class {
695
717
  const light = new import_core9.HemisphericLight("light", import_core9.Vector3.Up(), this._scene);
696
718
  light.intensity = 1.25;
697
719
  this._eventManager = new EventManager();
698
- window.addEventListener("resize", this._handleResize.bind(this));
699
720
  }
700
721
  // Start the render loop
701
722
  start() {
@@ -736,7 +757,6 @@ var RenderScene = class {
736
757
  // Stop and dispose of all resources
737
758
  dispose() {
738
759
  this.stop();
739
- window.removeEventListener("resize", this._handleResize);
740
760
  this._eventManager.dispose();
741
761
  this._scene.dispose();
742
762
  this._engine.dispose();
@@ -767,7 +787,7 @@ var RenderScene = class {
767
787
  this._children.clear();
768
788
  }
769
789
  setBackgroundColor(hexColor) {
770
- this._scene.clearColor = import_core9.Color4.FromHexString(`${hexColor.replace(/^0x/, "")}`);
790
+ this._scene.clearColor = import_core9.Color4.FromHexString(`${hexColor.replace(/^0x/i, "")}`);
771
791
  }
772
792
  _reattachToScene(node, currObj) {
773
793
  node._scene = this._scene;
@@ -880,7 +900,7 @@ function getPoints(nucleotideData, includeAtoms) {
880
900
  }
881
901
 
882
902
  // src/3D/utils/GetMotif.ts
883
- async function getMotif(motifName, motifMesh, motifColorHex = "0xcc2900", includeAtoms = true) {
903
+ async function getMotif(motifName, motifMesh, motifColorHex = "#cc2900", includeAtoms = true) {
884
904
  const motif = new Motif(`${motifName}_motif`);
885
905
  for (const [key] of Object.entries(motifMesh)) {
886
906
  const { vertices, indices } = getPoints(motifMesh[key], includeAtoms);
@@ -1221,6 +1241,21 @@ function Canvas({
1221
1241
  });
1222
1242
  });
1223
1243
  }
1244
+ function motifOutOfBounds(motif, deltaX, deltaY) {
1245
+ if (!canvasRef.current) {
1246
+ return false;
1247
+ }
1248
+ const canvasWidth = canvasRef.current.width;
1249
+ const canvasHeight = canvasRef.current.height;
1250
+ const left = -canvasWidth / 2;
1251
+ const right = canvasWidth / 2;
1252
+ const top = canvasHeight / 2;
1253
+ const bottom = -canvasHeight / 2;
1254
+ const newX = motif.position.x + deltaX;
1255
+ const newY = motif.position.y + deltaY;
1256
+ if (newX <= left || newX >= right || newY <= bottom || newY >= top) return true;
1257
+ return false;
1258
+ }
1224
1259
  function onSelectMotif(event) {
1225
1260
  if (event.type !== Events.EventType.OBJECT_SELECTED) {
1226
1261
  return;
@@ -1258,7 +1293,7 @@ function Canvas({
1258
1293
  const deltaX = rawDeltaX / renderWidth * canvasRef.current.width;
1259
1294
  const deltaY = rawDeltaY / renderHeight * canvasRef.current.height;
1260
1295
  selectedMotifMeshState.current.forEach((element) => {
1261
- if (!lockedMotifIdState.current.has(element.uuid) && !hardLockedMotifIds.includes(element.uuid)) {
1296
+ if (!lockedMotifIdState.current.has(element.uuid) && !hardLockedMotifIds.includes(element.uuid) && !motifOutOfBounds(element, -deltaX, -deltaY)) {
1262
1297
  element.translate(-deltaX, -deltaY, 0);
1263
1298
  }
1264
1299
  });
@@ -1328,7 +1363,7 @@ function Canvas({
1328
1363
  }
1329
1364
  event.translationDirection.multiplyScalar(4.5);
1330
1365
  selectedMotifMeshState.current.forEach((element) => {
1331
- if (!lockedMotifIdState.current.has(element.uuid) && !hardLockedMotifIds.includes(element.uuid)) {
1366
+ if (!lockedMotifIdState.current.has(element.uuid) && !hardLockedMotifIds.includes(element.uuid) && !motifOutOfBounds(element, event.translationDirection.x, event.translationDirection.y)) {
1332
1367
  element.translate(
1333
1368
  event.translationDirection.x,
1334
1369
  event.translationDirection.y,
package/dist/index.mjs CHANGED
@@ -271,10 +271,14 @@ var Residue = class extends Group {
271
271
  /**
272
272
  * Cretes a material with the given color and sets it to the mesh
273
273
  * @param color String in the format of #RRGGBB
274
+ * @param highlight Whether to apply a highlight effect to the residue
274
275
  */
275
- colorResidue(color) {
276
+ colorResidue(color, highlight = false) {
276
277
  this._children.forEach((child) => {
277
- child.createAndSetMaterial(color);
278
+ child.colorMaterial(color);
279
+ if (highlight) {
280
+ child.applyHighlight();
281
+ }
278
282
  });
279
283
  }
280
284
  };
@@ -306,24 +310,34 @@ var MeshObject = class {
306
310
  }
307
311
  applyHighlight() {
308
312
  const mat = this._mesh.material;
309
- mat.emissiveColor = mat.diffuseColor.scale(0.75);
313
+ mat.emissiveColor = mat.diffuseColor.scale(0.6);
310
314
  }
311
315
  resetHighlight() {
312
316
  const mat = this._mesh.material;
313
317
  mat.emissiveColor = Color3.Black();
314
318
  }
315
319
  /**
316
- * Cretes a material with the given color and sets it to the mesh
320
+ * Creates a material with the given color and sets it to the mesh
317
321
  * @param color String in the format of #RRGGBB
318
322
  */
319
323
  createAndSetMaterial(color) {
320
324
  const mat = new StandardMaterial("mat");
321
- const color3 = Color3.FromHexString(`#${color.replace(/^0x/, "")}`);
325
+ const color3 = Color3.FromHexString(`${color.replace(/^0x/i, "")}`);
322
326
  mat.diffuseColor = color3;
323
327
  mat.specularColor = color3;
324
328
  mat.backFaceCulling = false;
325
329
  this._mesh.material = mat;
326
330
  }
331
+ /**
332
+ * Sets the material of the mesh object to the given color
333
+ * @param color String in the format of #RRGGBB
334
+ */
335
+ colorMaterial(color) {
336
+ const mat = this._mesh.material;
337
+ const color3 = Color3.FromHexString(`${color.replace(/^0x/i, "")}`);
338
+ mat.diffuseColor = color3;
339
+ mat.specularColor = color3;
340
+ }
327
341
  setNewMesh(mesh) {
328
342
  this._mesh = mesh;
329
343
  return this;
@@ -621,12 +635,20 @@ var RenderScene = class {
621
635
  // State variables
622
636
  _isDisposed = false;
623
637
  isRunning = false;
638
+ /**
639
+ *
640
+ * @param canvas HTML Canvas Element
641
+ * @param hexColor Color in the format of #RRGGBB
642
+ * @param cameraPositionZ Z position of the camera
643
+ * @param renderWidth Width of the render window
644
+ * @param renderHeight Height of the render window
645
+ */
624
646
  constructor(canvas, hexColor, cameraPositionZ, renderWidth, renderHeight) {
625
647
  this._canvas = canvas;
626
648
  this._engine = new Engine(this._canvas, true);
627
649
  this._engine.setSize(renderWidth, renderHeight);
628
650
  this._scene = new Scene5(this._engine);
629
- this._scene.clearColor = Color4.FromHexString(`${hexColor.replace(/^0x/, "")}`);
651
+ this._scene.clearColor = Color4.FromHexString(`${hexColor.replace(/^0x/i, "")}`);
630
652
  this._camera = new UniversalCamera("camera", new Vector33(0, 0, cameraPositionZ));
631
653
  this._camera.setTarget(new Vector33(0, 0, 0));
632
654
  this._camera.mode = Camera.ORTHOGRAPHIC_CAMERA;
@@ -638,7 +660,6 @@ var RenderScene = class {
638
660
  const light = new HemisphericLight("light", Vector33.Up(), this._scene);
639
661
  light.intensity = 1.25;
640
662
  this._eventManager = new EventManager();
641
- window.addEventListener("resize", this._handleResize.bind(this));
642
663
  }
643
664
  // Start the render loop
644
665
  start() {
@@ -679,7 +700,6 @@ var RenderScene = class {
679
700
  // Stop and dispose of all resources
680
701
  dispose() {
681
702
  this.stop();
682
- window.removeEventListener("resize", this._handleResize);
683
703
  this._eventManager.dispose();
684
704
  this._scene.dispose();
685
705
  this._engine.dispose();
@@ -710,7 +730,7 @@ var RenderScene = class {
710
730
  this._children.clear();
711
731
  }
712
732
  setBackgroundColor(hexColor) {
713
- this._scene.clearColor = Color4.FromHexString(`${hexColor.replace(/^0x/, "")}`);
733
+ this._scene.clearColor = Color4.FromHexString(`${hexColor.replace(/^0x/i, "")}`);
714
734
  }
715
735
  _reattachToScene(node, currObj) {
716
736
  node._scene = this._scene;
@@ -823,7 +843,7 @@ function getPoints(nucleotideData, includeAtoms) {
823
843
  }
824
844
 
825
845
  // src/3D/utils/GetMotif.ts
826
- async function getMotif(motifName, motifMesh, motifColorHex = "0xcc2900", includeAtoms = true) {
846
+ async function getMotif(motifName, motifMesh, motifColorHex = "#cc2900", includeAtoms = true) {
827
847
  const motif = new Motif(`${motifName}_motif`);
828
848
  for (const [key] of Object.entries(motifMesh)) {
829
849
  const { vertices, indices } = getPoints(motifMesh[key], includeAtoms);
@@ -1164,6 +1184,21 @@ function Canvas({
1164
1184
  });
1165
1185
  });
1166
1186
  }
1187
+ function motifOutOfBounds(motif, deltaX, deltaY) {
1188
+ if (!canvasRef.current) {
1189
+ return false;
1190
+ }
1191
+ const canvasWidth = canvasRef.current.width;
1192
+ const canvasHeight = canvasRef.current.height;
1193
+ const left = -canvasWidth / 2;
1194
+ const right = canvasWidth / 2;
1195
+ const top = canvasHeight / 2;
1196
+ const bottom = -canvasHeight / 2;
1197
+ const newX = motif.position.x + deltaX;
1198
+ const newY = motif.position.y + deltaY;
1199
+ if (newX <= left || newX >= right || newY <= bottom || newY >= top) return true;
1200
+ return false;
1201
+ }
1167
1202
  function onSelectMotif(event) {
1168
1203
  if (event.type !== Events.EventType.OBJECT_SELECTED) {
1169
1204
  return;
@@ -1201,7 +1236,7 @@ function Canvas({
1201
1236
  const deltaX = rawDeltaX / renderWidth * canvasRef.current.width;
1202
1237
  const deltaY = rawDeltaY / renderHeight * canvasRef.current.height;
1203
1238
  selectedMotifMeshState.current.forEach((element) => {
1204
- if (!lockedMotifIdState.current.has(element.uuid) && !hardLockedMotifIds.includes(element.uuid)) {
1239
+ if (!lockedMotifIdState.current.has(element.uuid) && !hardLockedMotifIds.includes(element.uuid) && !motifOutOfBounds(element, -deltaX, -deltaY)) {
1205
1240
  element.translate(-deltaX, -deltaY, 0);
1206
1241
  }
1207
1242
  });
@@ -1271,7 +1306,7 @@ function Canvas({
1271
1306
  }
1272
1307
  event.translationDirection.multiplyScalar(4.5);
1273
1308
  selectedMotifMeshState.current.forEach((element) => {
1274
- if (!lockedMotifIdState.current.has(element.uuid) && !hardLockedMotifIds.includes(element.uuid)) {
1309
+ if (!lockedMotifIdState.current.has(element.uuid) && !hardLockedMotifIds.includes(element.uuid) && !motifOutOfBounds(element, event.translationDirection.x, event.translationDirection.y)) {
1275
1310
  element.translate(
1276
1311
  event.translationDirection.x,
1277
1312
  event.translationDirection.y,
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@judah-silva/rnacanvas",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "A 3D Canvas for displaying and interacting with custom RNA models. Powered by BabylonJS.",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/RNAStructureAnalysisLab/RNACanvas"
9
+ "url": "git+https://github.com/RNAStructureAnalysisLab/RNACanvas.git"
10
10
  },
11
11
  "module": "./dist/index.mjs",
12
12
  "scripts": {