@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 +1 -1
- package/src/index.ts +2 -0
- package/src/templates/balls.tsx +4 -4
- package/src/three-utils.ts +39 -0
- package/src/types-common.ts +8 -1
- package/src/types-misc.ts +7 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/templates/balls.tsx
CHANGED
|
@@ -305,7 +305,7 @@ class X {
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
dispose() {
|
|
308
|
-
this
|
|
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
|
-
|
|
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
|
|
716
|
+
this.setupLights();
|
|
717
717
|
this.setColors(config.colors);
|
|
718
718
|
}
|
|
719
719
|
|
|
720
|
-
|
|
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
|
+
}
|
package/src/types-common.ts
CHANGED
|
@@ -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[];
|