@digo-org/digo-api 1.0.50 → 1.0.52

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@digo-org/digo-api",
3
3
  "private": false,
4
- "version": "1.0.50",
4
+ "version": "1.0.52",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
7
7
  "types": "src/index.ts",
package/src/index.ts CHANGED
@@ -15,3 +15,5 @@ export * from '@digo-org/digo-api/src/constants';
15
15
  export * from '@digo-org/digo-api/src/digo-asset';
16
16
 
17
17
  export * from '@digo-org/digo-api/src/templates/balls';
18
+
19
+ export * from '@digo-org/digo-api/src/three-utils';
@@ -305,7 +305,7 @@ class X {
305
305
  }
306
306
 
307
307
  dispose() {
308
- this.#onResizeCleanup();
308
+ this.onResizeCleanup();
309
309
  this.stopAnimation();
310
310
  this.clear();
311
311
  this._postprocessing?.dispose();
@@ -313,7 +313,7 @@ class X {
313
313
  this.isDisposed = true;
314
314
  }
315
315
 
316
- #onResizeCleanup() {
316
+ private onResizeCleanup() {
317
317
  window.removeEventListener('resize', this.onResize.bind(this));
318
318
  this.resizeObserver?.disconnect();
319
319
  this.intersectionObserver?.disconnect();
@@ -713,11 +713,11 @@ class Z extends InstancedMesh {
713
713
  super(geometry, material, config.count);
714
714
  this.config = config;
715
715
  this.physics = new W(config);
716
- this.#setupLights();
716
+ this.setupLights();
717
717
  this.setColors(config.colors);
718
718
  }
719
719
 
720
- #setupLights() {
720
+ private setupLights() {
721
721
  this.ambientLight = new AmbientLight(
722
722
  this.config.ambientColor,
723
723
  this.config.ambientIntensity,
@@ -0,0 +1,39 @@
1
+ import * as THREE from 'three';
2
+ import { useEffect, useState } from 'react';
3
+ import { useGLTF } from '@react-three/drei';
4
+
5
+ function normalizeModel(model: THREE.Group): THREE.Group {
6
+ const boundingBox = new THREE.Box3().setFromObject(model);
7
+ const size = new THREE.Vector3();
8
+ boundingBox.getSize(size);
9
+
10
+ const maxDimension = Math.max(size.x, size.y, size.z);
11
+ const scale = 1 / maxDimension;
12
+
13
+ model.scale.multiplyScalar(scale);
14
+
15
+ return model;
16
+ }
17
+
18
+ function prepareModel(scene: THREE.Group): THREE.Group {
19
+ const modelClone = scene.clone();
20
+ return normalizeModel(modelClone);
21
+ }
22
+
23
+ export function useModel(url: string | undefined): THREE.Group | undefined {
24
+ if (!url) return undefined;
25
+
26
+ const [model, setModel] = useState<THREE.Group | undefined>(undefined);
27
+
28
+ const gltf = url ? useGLTF(url) : undefined;
29
+
30
+ useEffect(() => {
31
+ if (!gltf) return;
32
+
33
+ const normalizedModel = prepareModel(gltf.scene);
34
+
35
+ setModel(normalizedModel);
36
+ }, [url]);
37
+
38
+ return model;
39
+ }
@@ -7,6 +7,7 @@ export enum ParameterType {
7
7
  TEXT = 'TEXT',
8
8
  GRADIENT = 'GRADIENT',
9
9
  RESOURCE = 'RESOURCE',
10
+ SELECT = 'SELECT',
10
11
  }
11
12
 
12
13
  export const PARAMETER_TYPES: ParameterType[] = Object.values(ParameterType);
@@ -18,7 +19,7 @@ export interface Parameter {
18
19
  arrayValues?: ParameterValueArray;
19
20
  }
20
21
 
21
- export type ParameterDefinition = ParameterNumber | ParameterBoolean | ParameterColor | ParameterText | ParameterGradient | ParameterResource;
22
+ export type ParameterDefinition = ParameterNumber | ParameterBoolean | ParameterColor | ParameterText | ParameterGradient | ParameterResource | ParameterSelect;
22
23
 
23
24
  export interface ParameterNumber {
24
25
  defaultValue: number;
@@ -54,6 +55,12 @@ export interface ParameterBoolean {
54
55
  defaultValue: boolean;
55
56
  };
56
57
 
58
+ export interface ParameterSelect {
59
+ defaultValue: string;
60
+ icon?: string;
61
+ options: Option[];
62
+ };
63
+
57
64
  export type ParameterValue = ParameterValueSingle | ParameterValueArray;
58
65
 
59
66
  export type ParameterValueSingle = number | boolean | string | GradientStop[];
package/src/types-misc.ts CHANGED
@@ -77,4 +77,11 @@ export enum ResourceType {
77
77
  CSV = 'CSV',
78
78
  DATA = 'DATA',
79
79
  IMAGE = 'IMAGE',
80
+ MODEL = 'MODEL',
81
+ }
82
+
83
+ export interface ResourceInfo {
84
+ name: string;
85
+ icon: string;
86
+ description: string;
80
87
  }