@ntalmagor/3drize-viewer 0.1.2
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/components/AnimatedObject.d.ts +22 -0
- package/dist/components/AnimatedObject.d.ts.map +1 -0
- package/dist/components/AnimatedObject.js +121 -0
- package/dist/components/CameraController.d.ts +16 -0
- package/dist/components/CameraController.d.ts.map +1 -0
- package/dist/components/CameraController.js +132 -0
- package/dist/components/Clouds.d.ts +14 -0
- package/dist/components/Clouds.d.ts.map +1 -0
- package/dist/components/Clouds.js +97 -0
- package/dist/components/CreatedObject.d.ts +12 -0
- package/dist/components/CreatedObject.d.ts.map +1 -0
- package/dist/components/CreatedObject.js +139 -0
- package/dist/components/CustomPrimitive.d.ts +12 -0
- package/dist/components/CustomPrimitive.d.ts.map +1 -0
- package/dist/components/CustomPrimitive.js +80 -0
- package/dist/components/EffectsGenerator.d.ts +10 -0
- package/dist/components/EffectsGenerator.d.ts.map +1 -0
- package/dist/components/EffectsGenerator.js +59 -0
- package/dist/components/EffectsGroup.d.ts +8 -0
- package/dist/components/EffectsGroup.d.ts.map +1 -0
- package/dist/components/EffectsGroup.js +8 -0
- package/dist/components/EnvironmentManager.d.ts +9 -0
- package/dist/components/EnvironmentManager.d.ts.map +1 -0
- package/dist/components/EnvironmentManager.js +47 -0
- package/dist/components/Frame.d.ts +26 -0
- package/dist/components/Frame.d.ts.map +1 -0
- package/dist/components/Frame.js +50 -0
- package/dist/components/FrameGeometry.d.ts +10 -0
- package/dist/components/FrameGeometry.d.ts.map +1 -0
- package/dist/components/FrameGeometry.js +17 -0
- package/dist/components/FrameImage.d.ts +14 -0
- package/dist/components/FrameImage.d.ts.map +1 -0
- package/dist/components/FrameImage.js +15 -0
- package/dist/components/Galaxy.d.ts +8 -0
- package/dist/components/Galaxy.d.ts.map +1 -0
- package/dist/components/Galaxy.js +9 -0
- package/dist/components/GalleryLayout.d.ts +10 -0
- package/dist/components/GalleryLayout.d.ts.map +1 -0
- package/dist/components/GalleryLayout.js +18 -0
- package/dist/components/GridHelper.d.ts +23 -0
- package/dist/components/GridHelper.d.ts.map +1 -0
- package/dist/components/GridHelper.js +38 -0
- package/dist/components/ImageGeometry.d.ts +14 -0
- package/dist/components/ImageGeometry.d.ts.map +1 -0
- package/dist/components/ImageGeometry.js +62 -0
- package/dist/components/Lensflare.d.ts +12 -0
- package/dist/components/Lensflare.d.ts.map +1 -0
- package/dist/components/Lensflare.js +66 -0
- package/dist/components/Letter.d.ts +20 -0
- package/dist/components/Letter.d.ts.map +1 -0
- package/dist/components/Letter.js +83 -0
- package/dist/components/Letters.d.ts +16 -0
- package/dist/components/Letters.d.ts.map +1 -0
- package/dist/components/Letters.js +18 -0
- package/dist/components/LightsManager.d.ts +9 -0
- package/dist/components/LightsManager.d.ts.map +1 -0
- package/dist/components/LightsManager.js +121 -0
- package/dist/components/Lines.d.ts +9 -0
- package/dist/components/Lines.d.ts.map +1 -0
- package/dist/components/Lines.js +19 -0
- package/dist/components/LoadingIndicator.d.ts +10 -0
- package/dist/components/LoadingIndicator.d.ts.map +1 -0
- package/dist/components/LoadingIndicator.js +143 -0
- package/dist/components/MaterialLibrary.d.ts +9 -0
- package/dist/components/MaterialLibrary.d.ts.map +1 -0
- package/dist/components/MaterialLibrary.js +57 -0
- package/dist/components/Moon.d.ts +13 -0
- package/dist/components/Moon.d.ts.map +1 -0
- package/dist/components/Moon.js +52 -0
- package/dist/components/ObjectNode.d.ts +11 -0
- package/dist/components/ObjectNode.d.ts.map +1 -0
- package/dist/components/ObjectNode.js +61 -0
- package/dist/components/ObjectsRenderer.d.ts +11 -0
- package/dist/components/ObjectsRenderer.d.ts.map +1 -0
- package/dist/components/ObjectsRenderer.js +19 -0
- package/dist/components/Ocean.d.ts +8 -0
- package/dist/components/Ocean.d.ts.map +1 -0
- package/dist/components/Ocean.js +111 -0
- package/dist/components/ParticlesR3f.d.ts +16 -0
- package/dist/components/ParticlesR3f.d.ts.map +1 -0
- package/dist/components/ParticlesR3f.js +66 -0
- package/dist/components/Path.d.ts +13 -0
- package/dist/components/Path.d.ts.map +1 -0
- package/dist/components/Path.js +41 -0
- package/dist/components/PathGeometry.d.ts +11 -0
- package/dist/components/PathGeometry.d.ts.map +1 -0
- package/dist/components/PathGeometry.js +109 -0
- package/dist/components/PathRenderer.d.ts +14 -0
- package/dist/components/PathRenderer.d.ts.map +1 -0
- package/dist/components/PathRenderer.js +33 -0
- package/dist/components/ProductionScene.d.ts +29 -0
- package/dist/components/ProductionScene.d.ts.map +1 -0
- package/dist/components/ProductionScene.js +18 -0
- package/dist/components/ProjectLoader.d.ts +14 -0
- package/dist/components/ProjectLoader.d.ts.map +1 -0
- package/dist/components/ProjectLoader.js +76 -0
- package/dist/components/Rain.d.ts +8 -0
- package/dist/components/Rain.d.ts.map +1 -0
- package/dist/components/Rain.js +133 -0
- package/dist/components/SceneBuilder.d.ts +5 -0
- package/dist/components/SceneBuilder.d.ts.map +1 -0
- package/dist/components/SceneBuilder.js +104 -0
- package/dist/components/SceneFog.d.ts +8 -0
- package/dist/components/SceneFog.d.ts.map +1 -0
- package/dist/components/SceneFog.js +19 -0
- package/dist/components/ShootingStar.d.ts +16 -0
- package/dist/components/ShootingStar.d.ts.map +1 -0
- package/dist/components/ShootingStar.js +92 -0
- package/dist/components/ShootingStars.d.ts +8 -0
- package/dist/components/ShootingStars.d.ts.map +1 -0
- package/dist/components/ShootingStars.js +40 -0
- package/dist/components/SkyController.d.ts +10 -0
- package/dist/components/SkyController.d.ts.map +1 -0
- package/dist/components/SkyController.js +159 -0
- package/dist/components/SkyMesh.d.ts +11 -0
- package/dist/components/SkyMesh.d.ts.map +1 -0
- package/dist/components/SkyMesh.js +36 -0
- package/dist/components/SkySystem.d.ts +34 -0
- package/dist/components/SkySystem.d.ts.map +1 -0
- package/dist/components/SkySystem.js +47 -0
- package/dist/components/Skybox.d.ts +12 -0
- package/dist/components/Skybox.d.ts.map +1 -0
- package/dist/components/Skybox.js +79 -0
- package/dist/components/Stars.d.ts +14 -0
- package/dist/components/Stars.d.ts.map +1 -0
- package/dist/components/Stars.js +165 -0
- package/dist/components/SunLight.d.ts +15 -0
- package/dist/components/SunLight.d.ts.map +1 -0
- package/dist/components/SunLight.js +57 -0
- package/dist/components/Text2D.d.ts +9 -0
- package/dist/components/Text2D.d.ts.map +1 -0
- package/dist/components/Text2D.js +56 -0
- package/dist/components/Text3D.d.ts +10 -0
- package/dist/components/Text3D.d.ts.map +1 -0
- package/dist/components/Text3D.js +8 -0
- package/dist/components/effects/AuraEffect.d.ts +10 -0
- package/dist/components/effects/AuraEffect.d.ts.map +1 -0
- package/dist/components/effects/AuraEffect.js +127 -0
- package/dist/components/effects/AuroraEffect.d.ts +10 -0
- package/dist/components/effects/AuroraEffect.d.ts.map +1 -0
- package/dist/components/effects/AuroraEffect.js +112 -0
- package/dist/components/effects/BlackHoleEffect.d.ts +10 -0
- package/dist/components/effects/BlackHoleEffect.d.ts.map +1 -0
- package/dist/components/effects/BlackHoleEffect.js +193 -0
- package/dist/components/effects/ConstellationEffect.d.ts +10 -0
- package/dist/components/effects/ConstellationEffect.d.ts.map +1 -0
- package/dist/components/effects/ConstellationEffect.js +189 -0
- package/dist/components/effects/DataStreamEffect.d.ts +10 -0
- package/dist/components/effects/DataStreamEffect.d.ts.map +1 -0
- package/dist/components/effects/DataStreamEffect.js +138 -0
- package/dist/components/effects/DnaHelixEffect.d.ts +10 -0
- package/dist/components/effects/DnaHelixEffect.d.ts.map +1 -0
- package/dist/components/effects/DnaHelixEffect.js +311 -0
- package/dist/components/effects/FireEffect.d.ts +10 -0
- package/dist/components/effects/FireEffect.d.ts.map +1 -0
- package/dist/components/effects/FireEffect.js +194 -0
- package/dist/components/effects/ForcefieldEffect.d.ts +10 -0
- package/dist/components/effects/ForcefieldEffect.d.ts.map +1 -0
- package/dist/components/effects/ForcefieldEffect.js +132 -0
- package/dist/components/effects/HologramEffect.d.ts +10 -0
- package/dist/components/effects/HologramEffect.d.ts.map +1 -0
- package/dist/components/effects/HologramEffect.js +143 -0
- package/dist/components/effects/IceCrystalsEffect.d.ts +10 -0
- package/dist/components/effects/IceCrystalsEffect.d.ts.map +1 -0
- package/dist/components/effects/IceCrystalsEffect.js +190 -0
- package/dist/components/effects/LightningEffect.d.ts +10 -0
- package/dist/components/effects/LightningEffect.d.ts.map +1 -0
- package/dist/components/effects/LightningEffect.js +240 -0
- package/dist/components/effects/MoleculesEffect.d.ts +10 -0
- package/dist/components/effects/MoleculesEffect.d.ts.map +1 -0
- package/dist/components/effects/MoleculesEffect.js +179 -0
- package/dist/components/effects/NeuralNetworkEffect.d.ts +10 -0
- package/dist/components/effects/NeuralNetworkEffect.d.ts.map +1 -0
- package/dist/components/effects/NeuralNetworkEffect.js +188 -0
- package/dist/components/effects/OrbEffect.d.ts +10 -0
- package/dist/components/effects/OrbEffect.d.ts.map +1 -0
- package/dist/components/effects/OrbEffect.js +291 -0
- package/dist/components/effects/PortalEffect.d.ts +10 -0
- package/dist/components/effects/PortalEffect.d.ts.map +1 -0
- package/dist/components/effects/PortalEffect.js +191 -0
- package/dist/components/effects/ShockwaveEffect.d.ts +10 -0
- package/dist/components/effects/ShockwaveEffect.d.ts.map +1 -0
- package/dist/components/effects/ShockwaveEffect.js +159 -0
- package/dist/components/effects/SmokePlumeEffect.d.ts +10 -0
- package/dist/components/effects/SmokePlumeEffect.d.ts.map +1 -0
- package/dist/components/effects/SmokePlumeEffect.js +141 -0
- package/dist/components/effects/SmokeRingEffect.d.ts +10 -0
- package/dist/components/effects/SmokeRingEffect.d.ts.map +1 -0
- package/dist/components/effects/SmokeRingEffect.js +158 -0
- package/dist/components/effects/VolumetricFogEffect.d.ts +10 -0
- package/dist/components/effects/VolumetricFogEffect.d.ts.map +1 -0
- package/dist/components/effects/VolumetricFogEffect.js +111 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useAnimationEvents.d.ts +10 -0
- package/dist/hooks/useAnimationEvents.d.ts.map +1 -0
- package/dist/hooks/useAnimationEvents.js +28 -0
- package/dist/hooks/useCameraAnimation.d.ts +35 -0
- package/dist/hooks/useCameraAnimation.d.ts.map +1 -0
- package/dist/hooks/useCameraAnimation.js +268 -0
- package/dist/hooks/useContinuousEffects.d.ts +15 -0
- package/dist/hooks/useContinuousEffects.d.ts.map +1 -0
- package/dist/hooks/useContinuousEffects.js +173 -0
- package/dist/hooks/useCubeCamera.d.ts +19 -0
- package/dist/hooks/useCubeCamera.d.ts.map +1 -0
- package/dist/hooks/useCubeCamera.js +73 -0
- package/dist/hooks/useEnvironmentEffects.d.ts +12 -0
- package/dist/hooks/useEnvironmentEffects.d.ts.map +1 -0
- package/dist/hooks/useEnvironmentEffects.js +22 -0
- package/dist/hooks/useFrameEffects.d.ts +6 -0
- package/dist/hooks/useFrameEffects.d.ts.map +1 -0
- package/dist/hooks/useFrameEffects.js +19 -0
- package/dist/hooks/useInteractionEffects.d.ts +11 -0
- package/dist/hooks/useInteractionEffects.d.ts.map +1 -0
- package/dist/hooks/useInteractionEffects.js +35 -0
- package/dist/hooks/useKey.d.ts +26 -0
- package/dist/hooks/useKey.d.ts.map +1 -0
- package/dist/hooks/useKey.js +73 -0
- package/dist/hooks/useLightHandlers.d.ts +14 -0
- package/dist/hooks/useLightHandlers.d.ts.map +1 -0
- package/dist/hooks/useLightHandlers.js +116 -0
- package/dist/hooks/useMaterialApplication.d.ts +9 -0
- package/dist/hooks/useMaterialApplication.d.ts.map +1 -0
- package/dist/hooks/useMaterialApplication.js +113 -0
- package/dist/hooks/useMaterialOptions.d.ts +13 -0
- package/dist/hooks/useMaterialOptions.d.ts.map +1 -0
- package/dist/hooks/useMaterialOptions.js +110 -0
- package/dist/hooks/useMaterialUniforms.d.ts +18 -0
- package/dist/hooks/useMaterialUniforms.d.ts.map +1 -0
- package/dist/hooks/useMaterialUniforms.js +96 -0
- package/dist/hooks/useMeshController.d.ts +3 -0
- package/dist/hooks/useMeshController.d.ts.map +1 -0
- package/dist/hooks/useMeshController.js +152 -0
- package/dist/hooks/useMouseHandlers.d.ts +8 -0
- package/dist/hooks/useMouseHandlers.d.ts.map +1 -0
- package/dist/hooks/useMouseHandlers.js +47 -0
- package/dist/hooks/useObjectAnimation.d.ts +13 -0
- package/dist/hooks/useObjectAnimation.d.ts.map +1 -0
- package/dist/hooks/useObjectAnimation.js +11 -0
- package/dist/hooks/useObjectEdges.d.ts +4 -0
- package/dist/hooks/useObjectEdges.d.ts.map +1 -0
- package/dist/hooks/useObjectEdges.js +199 -0
- package/dist/hooks/useOrbitControls.d.ts +7 -0
- package/dist/hooks/useOrbitControls.d.ts.map +1 -0
- package/dist/hooks/useOrbitControls.js +9 -0
- package/dist/hooks/useParticlePositions.d.ts +19 -0
- package/dist/hooks/useParticlePositions.d.ts.map +1 -0
- package/dist/hooks/useParticlePositions.js +56 -0
- package/dist/hooks/useParticlesColors.d.ts +14 -0
- package/dist/hooks/useParticlesColors.d.ts.map +1 -0
- package/dist/hooks/useParticlesColors.js +27 -0
- package/dist/hooks/useParticlesTextures.d.ts +10 -0
- package/dist/hooks/useParticlesTextures.d.ts.map +1 -0
- package/dist/hooks/useParticlesTextures.js +23 -0
- package/dist/hooks/usePathAnimation.d.ts +26 -0
- package/dist/hooks/usePathAnimation.d.ts.map +1 -0
- package/dist/hooks/usePathAnimation.js +120 -0
- package/dist/hooks/useSkyAnimation.d.ts +14 -0
- package/dist/hooks/useSkyAnimation.d.ts.map +1 -0
- package/dist/hooks/useSkyAnimation.js +46 -0
- package/dist/hooks/useSkySystem.d.ts +26 -0
- package/dist/hooks/useSkySystem.d.ts.map +1 -0
- package/dist/hooks/useSkySystem.js +57 -0
- package/dist/hooks/useSkyUniforms.d.ts +18 -0
- package/dist/hooks/useSkyUniforms.d.ts.map +1 -0
- package/dist/hooks/useSkyUniforms.js +59 -0
- package/dist/hooks/useTransformControls.d.ts +6 -0
- package/dist/hooks/useTransformControls.d.ts.map +1 -0
- package/dist/hooks/useTransformControls.js +111 -0
- package/dist/hooks/useWaterEnvironment.d.ts +5 -0
- package/dist/hooks/useWaterEnvironment.d.ts.map +1 -0
- package/dist/hooks/useWaterEnvironment.js +27 -0
- package/dist/hooks/useWaterReflections.d.ts +17 -0
- package/dist/hooks/useWaterReflections.d.ts.map +1 -0
- package/dist/hooks/useWaterReflections.js +77 -0
- package/dist/index.d.ts +140 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +109 -0
- package/dist/services/AnimationsManager.d.ts +33 -0
- package/dist/services/AnimationsManager.d.ts.map +1 -0
- package/dist/services/AnimationsManager.js +58 -0
- package/dist/services/FontManager.d.ts +32 -0
- package/dist/services/FontManager.d.ts.map +1 -0
- package/dist/services/FontManager.js +76 -0
- package/dist/services/TexturesManager.d.ts +17 -0
- package/dist/services/TexturesManager.d.ts.map +1 -0
- package/dist/services/TexturesManager.js +48 -0
- package/dist/shaders/RainMaterial.d.ts +34 -0
- package/dist/shaders/RainMaterial.d.ts.map +1 -0
- package/dist/shaders/RainMaterial.js +56 -0
- package/dist/shaders/ShaderEffectsMaterial.d.ts +279 -0
- package/dist/shaders/ShaderEffectsMaterial.d.ts.map +1 -0
- package/dist/shaders/ShaderEffectsMaterial.js +257 -0
- package/dist/shaders/ShootingStarMaterial.d.ts +14 -0
- package/dist/shaders/ShootingStarMaterial.d.ts.map +1 -0
- package/dist/shaders/ShootingStarMaterial.js +33 -0
- package/dist/shaders/SkyboxMaterial.d.ts +38 -0
- package/dist/shaders/SkyboxMaterial.d.ts.map +1 -0
- package/dist/shaders/SkyboxMaterial.js +57 -0
- package/dist/shaders/effects/EffectsVertexFunctions.glsl.d.ts +2 -0
- package/dist/shaders/effects/EffectsVertexFunctions.glsl.d.ts.map +1 -0
- package/dist/shaders/effects/EffectsVertexFunctions.glsl.js +167 -0
- package/dist/utils/CameraSingleton.d.ts +35 -0
- package/dist/utils/CameraSingleton.d.ts.map +1 -0
- package/dist/utils/CameraSingleton.js +178 -0
- package/dist/utils/anchorUtils.d.ts +10 -0
- package/dist/utils/anchorUtils.d.ts.map +1 -0
- package/dist/utils/anchorUtils.js +13 -0
- package/dist/utils/frameAnimations.d.ts +49 -0
- package/dist/utils/frameAnimations.d.ts.map +1 -0
- package/dist/utils/frameAnimations.js +213 -0
- package/dist/utils/handleGenerativeEffectsAnimations.d.ts +5 -0
- package/dist/utils/handleGenerativeEffectsAnimations.d.ts.map +1 -0
- package/dist/utils/handleGenerativeEffectsAnimations.js +268 -0
- package/dist/utils/hasHoverAnimation.d.ts +3 -0
- package/dist/utils/hasHoverAnimation.d.ts.map +1 -0
- package/dist/utils/hasHoverAnimation.js +15 -0
- package/dist/utils/particleAnimations.d.ts +3 -0
- package/dist/utils/particleAnimations.d.ts.map +1 -0
- package/dist/utils/particleAnimations.js +17 -0
- package/dist/utils/sceneQuery.d.ts +9 -0
- package/dist/utils/sceneQuery.d.ts.map +1 -0
- package/dist/utils/sceneQuery.js +22 -0
- package/dist/utils/shaderUtils.d.ts +6 -0
- package/dist/utils/shaderUtils.d.ts.map +1 -0
- package/dist/utils/shaderUtils.js +145 -0
- package/dist/utils/textEffects.d.ts +31 -0
- package/dist/utils/textEffects.d.ts.map +1 -0
- package/dist/utils/textEffects.js +61 -0
- package/dist/utils/utils3d.d.ts +7 -0
- package/dist/utils/utils3d.d.ts.map +1 -0
- package/dist/utils/utils3d.js +34 -0
- package/package.json +43 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
import { MaterialInstance, MaterialSettings } from '@ntalmagor/3drize-core';
|
|
3
|
+
export declare const useMaterialApplication: (obj: Object3D | null | undefined, materialSettings: MaterialSettings, shouldApply3driseMaterial?: boolean, onApplied?: () => void) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Standalone utility: Apply material to a single object (for use outside the hook).
|
|
6
|
+
* Uses shared utilities for texture resolution and material creation.
|
|
7
|
+
*/
|
|
8
|
+
export declare const applyMaterialToObject: (object: any, materialSettings: MaterialSettings) => Promise<MaterialInstance | undefined>;
|
|
9
|
+
//# sourceMappingURL=useMaterialApplication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMaterialApplication.d.ts","sourceRoot":"","sources":["../../src/hooks/useMaterialApplication.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAiD,gBAAgB,EAAuB,gBAAgB,EAAwE,MAAM,wBAAwB,CAAC;AAEtN,eAAO,MAAM,sBAAsB,GACjC,KAAK,QAAQ,GAAG,IAAI,GAAG,SAAS,EAChC,kBAAkB,gBAAgB,EAClC,4BAA4B,OAAO,EACnC,YAAY,MAAM,IAAI,SAsGvB,CAAC;AAGF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAU,QAAQ,GAAG,EAAE,kBAAkB,gBAAgB,0CAgB1F,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// useMaterialApplication — React Hook for Material Application
|
|
3
|
+
// =============================================================================
|
|
4
|
+
//
|
|
5
|
+
// Watches materialSettings changes and imperatively applies materials to a
|
|
6
|
+
// Three.js object. Uses shared utilities from materialApplicationUtils.
|
|
7
|
+
//
|
|
8
|
+
import { useEffect, useRef } from 'react';
|
|
9
|
+
import { createAndApplyMaterial, MATERIAL_INSTANCE_KEY, MaterialRegistryAPI, ObjectManager, resolveTextures, traverseSkippingEdges } from '@ntalmagor/3drize-core';
|
|
10
|
+
export const useMaterialApplication = (obj, materialSettings, shouldApply3driseMaterial, onApplied) => {
|
|
11
|
+
const prevSettingsRef = useRef(null);
|
|
12
|
+
// Track all material instances we've created so we can release them on change/unmount
|
|
13
|
+
const activeInstancesRef = useRef([]);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!obj || !materialSettings || materialSettings.materialType === 'advanced' || (shouldApply3driseMaterial === false))
|
|
16
|
+
return;
|
|
17
|
+
const currentSettings = JSON.stringify(materialSettings);
|
|
18
|
+
prevSettingsRef.current = currentSettings;
|
|
19
|
+
handleSettingsChange(obj, materialSettings);
|
|
20
|
+
// Cleanup: release materials when settings change or component unmounts
|
|
21
|
+
return () => {
|
|
22
|
+
releaseActiveInstances();
|
|
23
|
+
};
|
|
24
|
+
}, [materialSettings, obj]);
|
|
25
|
+
/**
|
|
26
|
+
* Release all material instances we've created.
|
|
27
|
+
*/
|
|
28
|
+
const releaseActiveInstances = () => {
|
|
29
|
+
for (const instance of activeInstancesRef.current) {
|
|
30
|
+
try {
|
|
31
|
+
MaterialRegistryAPI.releaseMaterial(instance);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
// Silently ignore release errors during cleanup
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
activeInstancesRef.current = [];
|
|
38
|
+
};
|
|
39
|
+
const handleSettingsChange = async (obj, materialSettings) => {
|
|
40
|
+
if (!obj || !materialSettings || materialSettings.materialType === 'advanced' || !materialSettings.materialVariant)
|
|
41
|
+
return;
|
|
42
|
+
const applyMaterial = materialSettings.apply !== undefined ? materialSettings.apply : true;
|
|
43
|
+
// console.log({
|
|
44
|
+
// obj,
|
|
45
|
+
// applyMaterial
|
|
46
|
+
// })
|
|
47
|
+
// If apply is false, restore original materials
|
|
48
|
+
if (!applyMaterial) {
|
|
49
|
+
const objectId = obj.userData?.id;
|
|
50
|
+
if (objectId) {
|
|
51
|
+
releaseActiveInstances();
|
|
52
|
+
ObjectManager.restoreOriginalMaterials(objectId);
|
|
53
|
+
}
|
|
54
|
+
onApplied?.();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const variant = materialSettings.materialVariant || 'Standard';
|
|
58
|
+
// 1. Resolve textures using shared utility (registry-driven TextureResolver)
|
|
59
|
+
const resolvedSettings = await resolveTextures(variant, materialSettings);
|
|
60
|
+
// console.log('Resolved material settings with textures:', resolvedSettings);
|
|
61
|
+
// 2. Release previous material instances before creating new ones
|
|
62
|
+
releaseActiveInstances();
|
|
63
|
+
// 3. Traverse the object tree and apply material to any child with .material.
|
|
64
|
+
// Skips edges subtrees (EDGES_GROUP_KEY) so they keep their own material,
|
|
65
|
+
// unless obj itself is the edges group (then we apply normally).
|
|
66
|
+
traverseSkippingEdges(obj, true, (child) => {
|
|
67
|
+
if (child.material) {
|
|
68
|
+
// Only skip children with ORIGINAL baked textures (e.g., from loaded GLTF models).
|
|
69
|
+
// If we previously applied a 3drise material to this child, always allow re-application.
|
|
70
|
+
// console.log(child)
|
|
71
|
+
const hasBakedTexture = child.material.map && !child.userData[MATERIAL_INSTANCE_KEY];
|
|
72
|
+
// if (hasBakedTexture && !resolvedSettings.map) return;
|
|
73
|
+
applyMaterialToChild(child, variant, resolvedSettings);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
onApplied?.();
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Create a fresh material instance and apply resolved settings to a single child object.
|
|
80
|
+
* Uses shared createAndApplyMaterial utility.
|
|
81
|
+
*/
|
|
82
|
+
const applyMaterialToChild = (object, variant, resolvedSettings) => {
|
|
83
|
+
try {
|
|
84
|
+
const materialInstance = createAndApplyMaterial(variant, resolvedSettings);
|
|
85
|
+
// Assign to the object
|
|
86
|
+
object.material = materialInstance.material;
|
|
87
|
+
// Track the instance for cleanup
|
|
88
|
+
activeInstancesRef.current.push(materialInstance);
|
|
89
|
+
// Also store on userData for external access if needed
|
|
90
|
+
object.userData[MATERIAL_INSTANCE_KEY] = materialInstance;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error(`Failed to apply material "${variant}" to object:`, error);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Standalone utility: Apply material to a single object (for use outside the hook).
|
|
99
|
+
* Uses shared utilities for texture resolution and material creation.
|
|
100
|
+
*/
|
|
101
|
+
export const applyMaterialToObject = async (object, materialSettings) => {
|
|
102
|
+
if (!object || !materialSettings)
|
|
103
|
+
return;
|
|
104
|
+
const variant = materialSettings.materialVariant || 'Standard';
|
|
105
|
+
// Resolve textures via shared utility
|
|
106
|
+
const resolvedSettings = await resolveTextures(variant, materialSettings);
|
|
107
|
+
// Create and apply via shared utility
|
|
108
|
+
const materialInstance = createAndApplyMaterial(variant, resolvedSettings);
|
|
109
|
+
object.material = materialInstance.material;
|
|
110
|
+
// Store instance on userData for potential cleanup
|
|
111
|
+
object.userData[MATERIAL_INSTANCE_KEY] = materialInstance;
|
|
112
|
+
return materialInstance;
|
|
113
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MaterialRegistryAPI, MaterialSettings, SelectOptions } from '@ntalmagor/3drize-core';
|
|
2
|
+
type RegistryMaterialType = Exclude<Parameters<typeof MaterialRegistryAPI.getVariants>[0], undefined>;
|
|
3
|
+
export interface UseMaterialOptionsReturn {
|
|
4
|
+
selectedType: RegistryMaterialType;
|
|
5
|
+
selectedVariant: string;
|
|
6
|
+
materialTypeOptions: SelectOptions;
|
|
7
|
+
variantOptions: SelectOptions;
|
|
8
|
+
handleTypeChange: (type: RegistryMaterialType) => void;
|
|
9
|
+
handleVariantChange: (variant: string) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const useMaterialOptions: (initialSettings: MaterialSettings, onSettingsChange?: (newSettings: MaterialSettings) => void) => UseMaterialOptionsReturn;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=useMaterialOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMaterialOptions.d.ts","sourceRoot":"","sources":["../../src/hooks/useMaterialOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE9F,KAAK,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;AAGtG,MAAM,WAAW,wBAAwB;IACvC,YAAY,EAAE,oBAAoB,CAAC;IACnC,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,aAAa,CAAC;IACnC,cAAc,EAAE,aAAa,CAAC;IAC9B,gBAAgB,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACvD,mBAAmB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,eAAO,MAAM,kBAAkB,GAC7B,iBAAiB,gBAAgB,EACjC,mBAAmB,CAAC,WAAW,EAAE,gBAAgB,KAAK,IAAI,KACzD,wBA8HF,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { MaterialRegistryAPI } from '@ntalmagor/3drize-core';
|
|
3
|
+
export const useMaterialOptions = (initialSettings, onSettingsChange) => {
|
|
4
|
+
// Ensure we always have a valid material type
|
|
5
|
+
const validType = (initialSettings.materialType || 'basic');
|
|
6
|
+
const [selectedType, setSelectedType] = useState(validType);
|
|
7
|
+
const availableVariantsForInit = MaterialRegistryAPI.getVariants(validType);
|
|
8
|
+
const initialVariant = initialSettings.materialVariant || availableVariantsForInit[0] || '';
|
|
9
|
+
const [selectedVariant, setSelectedVariant] = useState(initialVariant);
|
|
10
|
+
// Sync internal state when the external settings change (e.g. Redux-driven
|
|
11
|
+
// updates or edge-type resets). Without this, the dropdowns stay stale after
|
|
12
|
+
// any external materialType / materialVariant change.
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
// console.log('useMaterialOptions - syncing with new initialSettings:', initialSettings);
|
|
15
|
+
const newType = initialSettings.materialType || 'basic';
|
|
16
|
+
setSelectedType(newType);
|
|
17
|
+
const variants = MaterialRegistryAPI.getVariants(newType);
|
|
18
|
+
setSelectedVariant(initialSettings.materialVariant || variants[0] || '');
|
|
19
|
+
}, [initialSettings.materialType, initialSettings.materialVariant]);
|
|
20
|
+
const allmaterialTypes = MaterialRegistryAPI.getTypes();
|
|
21
|
+
const is3dRiseShaderMaterial = initialSettings.materialType === 'particles' || initialSettings.materialType === 'custom';
|
|
22
|
+
const isLineMaterial = initialSettings.materialType === 'line';
|
|
23
|
+
const meshMaterialTypes = allmaterialTypes.filter(type => type !== 'particles' && type !== 'custom' && type !== 'line');
|
|
24
|
+
const lineMaterialTypes = allmaterialTypes.filter(type => type === 'line');
|
|
25
|
+
const dRiseShaderMaterialTypes = allmaterialTypes.filter(type => type === 'particles' || type === 'custom');
|
|
26
|
+
const materialTypeOptions = () => {
|
|
27
|
+
if (is3dRiseShaderMaterial) {
|
|
28
|
+
return dRiseShaderMaterialTypes.map((type) => ({
|
|
29
|
+
value: type,
|
|
30
|
+
label: type.charAt(0).toUpperCase() + type.slice(1)
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
if (isLineMaterial) {
|
|
34
|
+
return lineMaterialTypes.map((type) => ({
|
|
35
|
+
value: type,
|
|
36
|
+
label: type.charAt(0).toUpperCase() + type.slice(1)
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
return meshMaterialTypes.map((type) => ({
|
|
40
|
+
value: type,
|
|
41
|
+
label: type.charAt(0).toUpperCase() + type.slice(1)
|
|
42
|
+
}));
|
|
43
|
+
};
|
|
44
|
+
// is3dRiseShaderMaterial ?
|
|
45
|
+
// dRiseShaderMaterialTypes.map((type: string) => ({
|
|
46
|
+
// value: type,
|
|
47
|
+
// label: type.charAt(0).toUpperCase() + type.slice(1)
|
|
48
|
+
// })) :
|
|
49
|
+
// meshMaterialTypes.map((type: string) => ({
|
|
50
|
+
// value: type,
|
|
51
|
+
// label: type.charAt(0).toUpperCase() + type.slice(1)
|
|
52
|
+
// }));
|
|
53
|
+
// Variant options for current type - with safety check
|
|
54
|
+
const availableVariants = selectedType ? MaterialRegistryAPI.getVariants(selectedType) : [];
|
|
55
|
+
const variantOptions = availableVariants.map(variant => ({
|
|
56
|
+
value: variant,
|
|
57
|
+
label: variant
|
|
58
|
+
}));
|
|
59
|
+
const handleTypeChange = (type) => {
|
|
60
|
+
// console.log('Material type changed to:', type);
|
|
61
|
+
setSelectedType(type);
|
|
62
|
+
const availableVariants = MaterialRegistryAPI.getVariants(type);
|
|
63
|
+
const defaultVariant = availableVariants[0];
|
|
64
|
+
// console.log({defaultVariant})
|
|
65
|
+
setSelectedVariant(defaultVariant);
|
|
66
|
+
// Auto-select first variant when type changes
|
|
67
|
+
if (defaultVariant) {
|
|
68
|
+
handleMaterialUpdate(type, defaultVariant);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const handleVariantChange = (variant) => {
|
|
72
|
+
console.log('Material variant changed to:', variant);
|
|
73
|
+
setSelectedVariant(variant);
|
|
74
|
+
handleMaterialUpdate(selectedType, variant);
|
|
75
|
+
};
|
|
76
|
+
const handleMaterialUpdate = (type, variant) => {
|
|
77
|
+
if (!onSettingsChange)
|
|
78
|
+
return;
|
|
79
|
+
try {
|
|
80
|
+
const variantDefinition = MaterialRegistryAPI.getVariantDefinition(variant);
|
|
81
|
+
if (!variantDefinition) {
|
|
82
|
+
console.warn(`Variant definition for "${variant}" not found.`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Start fresh from the new variant's defaults — this ensures
|
|
86
|
+
// texture properties from the previous variant are cleared (reset to null).
|
|
87
|
+
const variantDefaults = variantDefinition.defaultSettings || {};
|
|
88
|
+
const newSettings = {
|
|
89
|
+
apply: true,
|
|
90
|
+
materialType: type,
|
|
91
|
+
materialVariant: variant,
|
|
92
|
+
// Preserve handlers from previous settings if they exist
|
|
93
|
+
// ...(initialSettings.handlers ? { handlers: initialSettings.handlers } : {}),
|
|
94
|
+
...variantDefaults,
|
|
95
|
+
};
|
|
96
|
+
onSettingsChange(newSettings);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.error('Error updating material:', error);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
selectedType,
|
|
104
|
+
selectedVariant,
|
|
105
|
+
materialTypeOptions: materialTypeOptions(),
|
|
106
|
+
variantOptions,
|
|
107
|
+
handleTypeChange,
|
|
108
|
+
handleVariantChange
|
|
109
|
+
};
|
|
110
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Material, Object3D } from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for direct material manipulation on a scene object ref.
|
|
4
|
+
*
|
|
5
|
+
* Usage pattern (like SkyControllerUi):
|
|
6
|
+
* - On slider drag → updateProperty(key, value) — instant visual feedback, no Redux
|
|
7
|
+
* - On slider end → updateProperty(key, value) + dispatch to Redux
|
|
8
|
+
* - On color change → updateColor(key, hex) + dispatch to Redux
|
|
9
|
+
* - On variant change → changeMaterial(variant, settings) + dispatch to Redux
|
|
10
|
+
*/
|
|
11
|
+
export declare function useMaterialUniforms(object: Object3D | null | undefined): {
|
|
12
|
+
getMaterial: () => Material | null;
|
|
13
|
+
updateProperty: (key: string, value: any) => void;
|
|
14
|
+
updateColor: (key: string, hexValue: string) => void;
|
|
15
|
+
applyAllSettings: (settings: Record<string, any>) => void;
|
|
16
|
+
changeMaterial: (variant: string, settings: Record<string, any>) => void;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=useMaterialUniforms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMaterialUniforms.d.ts","sourceRoot":"","sources":["../../src/hooks/useMaterialUniforms.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAWhD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS;uBAKjC,QAAQ,GAAG,IAAI;0BAkBV,MAAM,SAAS,GAAG;uBAYrB,MAAM,YAAY,MAAM;iCAad,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;8BAatB,MAAM,YAAY,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;EAsBnF"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { applySingleProperty, applyColorProperty, createAndApplyMaterial, MATERIAL_INSTANCE_KEY, traverseSkippingEdges, MaterialRegistryAPI } from '@ntalmagor/3drize-core';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for direct material manipulation on a scene object ref.
|
|
5
|
+
*
|
|
6
|
+
* Usage pattern (like SkyControllerUi):
|
|
7
|
+
* - On slider drag → updateProperty(key, value) — instant visual feedback, no Redux
|
|
8
|
+
* - On slider end → updateProperty(key, value) + dispatch to Redux
|
|
9
|
+
* - On color change → updateColor(key, hex) + dispatch to Redux
|
|
10
|
+
* - On variant change → changeMaterial(variant, settings) + dispatch to Redux
|
|
11
|
+
*/
|
|
12
|
+
export function useMaterialUniforms(object) {
|
|
13
|
+
/**
|
|
14
|
+
* Get the material from the first non-edges child mesh that has one.
|
|
15
|
+
*/
|
|
16
|
+
const getMaterial = useCallback(() => {
|
|
17
|
+
if (!object)
|
|
18
|
+
return null;
|
|
19
|
+
if (object.material)
|
|
20
|
+
return object.material;
|
|
21
|
+
let found = null;
|
|
22
|
+
traverseSkippingEdges(object, true, (child) => {
|
|
23
|
+
if (!found && child.material) {
|
|
24
|
+
found = child.material;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return found;
|
|
28
|
+
}, [object]);
|
|
29
|
+
/**
|
|
30
|
+
* Update a single numeric property on the material (instant feedback).
|
|
31
|
+
* Does NOT persist to Redux — caller should do that on slider end.
|
|
32
|
+
*/
|
|
33
|
+
const updateProperty = useCallback((key, value) => {
|
|
34
|
+
if (!object)
|
|
35
|
+
return;
|
|
36
|
+
traverseSkippingEdges(object, true, (child) => {
|
|
37
|
+
if (child.material) {
|
|
38
|
+
applySingleProperty(child.material, key, value);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}, [object]);
|
|
42
|
+
/**
|
|
43
|
+
* Update a color property on the material (instant feedback).
|
|
44
|
+
*/
|
|
45
|
+
const updateColor = useCallback((key, hexValue) => {
|
|
46
|
+
if (!object)
|
|
47
|
+
return;
|
|
48
|
+
traverseSkippingEdges(object, true, (child) => {
|
|
49
|
+
if (child.material) {
|
|
50
|
+
applyColorProperty(child.material, key, hexValue);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}, [object]);
|
|
54
|
+
/**
|
|
55
|
+
* Apply a full set of settings to the current material.
|
|
56
|
+
* Used for randomize or batch updates.
|
|
57
|
+
*/
|
|
58
|
+
const applyAllSettings = useCallback((settings) => {
|
|
59
|
+
if (!object)
|
|
60
|
+
return;
|
|
61
|
+
traverseSkippingEdges(object, true, (child) => {
|
|
62
|
+
if (child.material) {
|
|
63
|
+
MaterialRegistryAPI.applySettings(child.material, settings);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}, [object]);
|
|
67
|
+
/**
|
|
68
|
+
* Change the material variant entirely.
|
|
69
|
+
* Creates a new material instance and assigns it to all non-edges children.
|
|
70
|
+
*/
|
|
71
|
+
const changeMaterial = useCallback((variant, settings) => {
|
|
72
|
+
if (!object)
|
|
73
|
+
return;
|
|
74
|
+
traverseSkippingEdges(object, true, (child) => {
|
|
75
|
+
if (child.material) {
|
|
76
|
+
const oldInstance = child.userData[MATERIAL_INSTANCE_KEY];
|
|
77
|
+
if (oldInstance) {
|
|
78
|
+
try {
|
|
79
|
+
MaterialRegistryAPI.releaseMaterial(oldInstance);
|
|
80
|
+
}
|
|
81
|
+
catch (_) { }
|
|
82
|
+
}
|
|
83
|
+
const instance = createAndApplyMaterial(variant, settings);
|
|
84
|
+
child.material = instance.material;
|
|
85
|
+
child.userData[MATERIAL_INSTANCE_KEY] = instance;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}, [object]);
|
|
89
|
+
return {
|
|
90
|
+
getMaterial,
|
|
91
|
+
updateProperty,
|
|
92
|
+
updateColor,
|
|
93
|
+
applyAllSettings,
|
|
94
|
+
changeMaterial,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMeshController.d.ts","sourceRoot":"","sources":["../../src/hooks/useMeshController.ts"],"names":[],"mappings":"AAkBA,wBAAgB,iBAAiB,IAAI,GAAG,CA0KvC;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { createMeshByType, createTempId, MaterialRegistryAPI, ObjectManager, uniformConverter, } from '@ntalmagor/3drize-core';
|
|
2
|
+
export function useMeshController() {
|
|
3
|
+
let defaultSettings = {
|
|
4
|
+
color: { value: '#ffffff' },
|
|
5
|
+
opacity: { value: 1 },
|
|
6
|
+
wireframe: { value: false },
|
|
7
|
+
};
|
|
8
|
+
const createMeshes = (meshes) => {
|
|
9
|
+
const createdObjectsSettings = [];
|
|
10
|
+
// console.log("createMeshes...", meshes);
|
|
11
|
+
if (!Array.isArray(meshes))
|
|
12
|
+
return [];
|
|
13
|
+
meshes.forEach(mesh => {
|
|
14
|
+
try {
|
|
15
|
+
const id = mesh.id || createTempId();
|
|
16
|
+
const meshType = mesh.type || 'box';
|
|
17
|
+
const meshData = {
|
|
18
|
+
...mesh,
|
|
19
|
+
id,
|
|
20
|
+
type: meshType
|
|
21
|
+
};
|
|
22
|
+
// console.log({ meshData });
|
|
23
|
+
// let createdObject: CreatedRef | null = ;
|
|
24
|
+
const createdObject = {
|
|
25
|
+
id,
|
|
26
|
+
name: mesh.name || `mesh-${id}`,
|
|
27
|
+
object: createMeshByType(meshData)
|
|
28
|
+
};
|
|
29
|
+
createdObject && ObjectManager.addObject(createdObject);
|
|
30
|
+
if (!createdObject)
|
|
31
|
+
return;
|
|
32
|
+
// const materialType: MaterialType = meshData.materialType || 'basic';
|
|
33
|
+
const materialSettings = createMaterialSettings(meshData);
|
|
34
|
+
const meshSettings = ObjectManager.getMeshSettingsFromMesh(createdObject.object);
|
|
35
|
+
// const effects: Use3driseShaderEffects = {
|
|
36
|
+
// general: {
|
|
37
|
+
// wave: { enabled: false, intensity: 0.3, frequency: 3.0, speed: 1.0, direction: 'horizontal' },
|
|
38
|
+
// vortex: { enabled: false, intensity: 0.5, speed: 0.5, centerX: 0, centerY: 0 },
|
|
39
|
+
// ripple: { enabled: false, intensity: 0.3, speed: 2.0, centerX: 0, centerY: 0, frequency: 5.0 },
|
|
40
|
+
// grayscale: {
|
|
41
|
+
// enabled: false,
|
|
42
|
+
// mode: 'static',
|
|
43
|
+
// intensity: 1.0,
|
|
44
|
+
// contrast: 1.0,
|
|
45
|
+
// brightness: 0.0,
|
|
46
|
+
// waveFrequency: 3.0,
|
|
47
|
+
// waveSpeed: 1.0,
|
|
48
|
+
// waveDirection: 'horizontal',
|
|
49
|
+
// pulseSpeed: 2.0,
|
|
50
|
+
// rippleSpeed: 2.0,
|
|
51
|
+
// rippleCenterX: 0,
|
|
52
|
+
// rippleCenterY: 0,
|
|
53
|
+
// },
|
|
54
|
+
// },
|
|
55
|
+
// pointer: {
|
|
56
|
+
// global: { radius: 2.5 },
|
|
57
|
+
// vertex: {
|
|
58
|
+
// ripple: { enabled: false, intensity: 0.5, speed: 2.0, frequency: 5.0 },
|
|
59
|
+
// displacement: { enabled: false, intensity: 0.5 },
|
|
60
|
+
// scale: { enabled: false, intensity: 0.5, minScale: 0.5, maxScale: 2.0 },
|
|
61
|
+
// vortex: { enabled: false, intensity: 0.5, speed: 1.0 },
|
|
62
|
+
// wave: { enabled: false, intensity: 0.5, frequency: 5.0, speed: 1.0, direction: 'horizontal' },
|
|
63
|
+
// },
|
|
64
|
+
// fragment: {
|
|
65
|
+
// glow: { enabled: false, intensity: 0.5, color: '#ffffff' },
|
|
66
|
+
// colorShift: { enabled: false, intensity: 0.5, targetColor: '#ff6600' },
|
|
67
|
+
// brightness: { enabled: false, intensity: 0.5 },
|
|
68
|
+
// pulse: { enabled: false, intensity: 0.5, speed: 2.0 },
|
|
69
|
+
// grayscale: { enabled: false, intensity: 1.0, contrast: 1.0, brightness: 0.0 },
|
|
70
|
+
// },
|
|
71
|
+
// },
|
|
72
|
+
// }
|
|
73
|
+
let createdObjectSettings = {
|
|
74
|
+
id: meshData.id,
|
|
75
|
+
name: meshData.name || createdObject.name || `mesh-${createdObject.id}`,
|
|
76
|
+
type: 'mesh',
|
|
77
|
+
meshSettings: {
|
|
78
|
+
...meshSettings,
|
|
79
|
+
anchor: meshData.anchor ?? null,
|
|
80
|
+
},
|
|
81
|
+
materialSettings: materialSettings,
|
|
82
|
+
// animations: [],
|
|
83
|
+
// effects: effects,
|
|
84
|
+
userData: meshData
|
|
85
|
+
};
|
|
86
|
+
if (meshData.animations && meshData.animations.length > 0) {
|
|
87
|
+
createdObjectSettings.animations = meshData.animations.map((animation) => ({
|
|
88
|
+
...animation,
|
|
89
|
+
active: true
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
// console.log("Created object settings:", createdObjectSettings);
|
|
93
|
+
createdObjectsSettings.push(createdObjectSettings);
|
|
94
|
+
console.log("Created mesh:", createdObject.name);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.error(`Error creating mesh of type ${mesh.type}:`, error);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return createdObjectsSettings;
|
|
101
|
+
};
|
|
102
|
+
const createMaterialSettings = (meshData) => {
|
|
103
|
+
// let materialVariant = 'Standard';
|
|
104
|
+
// if (!meshData.material) {
|
|
105
|
+
// console.warn("Mesh data is missing material property:", meshData);
|
|
106
|
+
// // return;
|
|
107
|
+
// }
|
|
108
|
+
// if (!meshData.material.variant) {
|
|
109
|
+
// console.warn("Mesh data is missing material variant:", meshData);
|
|
110
|
+
// // return;
|
|
111
|
+
// }
|
|
112
|
+
const materialVariant = meshData.material &&
|
|
113
|
+
meshData.material.variant &&
|
|
114
|
+
MaterialRegistryAPI.getTypeFromVariantName(meshData.material.variant) ?
|
|
115
|
+
meshData.material.variant :
|
|
116
|
+
'Standard';
|
|
117
|
+
const materialType = MaterialRegistryAPI.getTypeFromVariantName(materialVariant) || 'basic';
|
|
118
|
+
if (materialType === 'advanced') {
|
|
119
|
+
const variant = MaterialRegistryAPI.getVariantDefinition(materialVariant);
|
|
120
|
+
if (variant && variant.defaultSettings) {
|
|
121
|
+
defaultSettings = variant.defaultSettings;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const materialInstance = MaterialRegistryAPI.createMaterial(materialVariant);
|
|
126
|
+
// Extract current uniform values as default settings
|
|
127
|
+
defaultSettings = {
|
|
128
|
+
...uniformConverter.convertToSettings(materialInstance.uniforms),
|
|
129
|
+
...materialInstance.settings
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// console.log("Default settings for material ", materialVariant, ":", defaultSettings);
|
|
133
|
+
Object.keys(meshData.material || {}).forEach(key => {
|
|
134
|
+
if (defaultSettings[key]) {
|
|
135
|
+
defaultSettings[key] = meshData.material[key];
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
const materialSettings = {
|
|
139
|
+
materialType,
|
|
140
|
+
materialVariant,
|
|
141
|
+
materialName: materialVariant,
|
|
142
|
+
...defaultSettings,
|
|
143
|
+
// ...options
|
|
144
|
+
};
|
|
145
|
+
return materialSettings;
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
createMeshes,
|
|
149
|
+
createMaterialSettings,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export default useMeshController;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const useMouseHandlers: () => {
|
|
2
|
+
getInterpolatedValue: (baseValue: any, minValue: any, maxValue: any, multiplier: number, sensitivity?: number) => any;
|
|
3
|
+
interpolateProperty: (baseValue: any, minValue: any, maxValue: any, pointer: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
}, axis?: "x" | "y" | "both", sensitivity?: number, inverted?: boolean) => any;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=useMouseHandlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMouseHandlers.d.ts","sourceRoot":"","sources":["../../src/hooks/useMouseHandlers.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB;sCAEV,GAAG,YACJ,GAAG,YACH,GAAG,cACD,MAAM,gBACL,MAAM,KACpB,GAAG;qCAuCS,GAAG,YACJ,GAAG,YACH,GAAG,WACJ;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,SAC3B,GAAG,GAAG,GAAG,GAAG,MAAM,gBACX,MAAM,aACT,OAAO;CAgBxB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Color, MathUtils } from "three";
|
|
2
|
+
export const useMouseHandlers = () => {
|
|
3
|
+
const getInterpolatedValue = (baseValue, minValue, maxValue, multiplier, sensitivity = 1) => {
|
|
4
|
+
// Normalize multiplier from [-1, 1] to [0, 1] for lerp
|
|
5
|
+
const normalizedMultiplier = (multiplier + 1) / 2;
|
|
6
|
+
const finalMultiplier = Math.max(0, Math.min(1, normalizedMultiplier * sensitivity));
|
|
7
|
+
// Handle Color objects or hex strings
|
|
8
|
+
if ((typeof minValue === 'string' && minValue.startsWith('#')) ||
|
|
9
|
+
(typeof maxValue === 'string' && maxValue.startsWith('#'))) {
|
|
10
|
+
const minColor = new Color(minValue);
|
|
11
|
+
const maxColor = new Color(maxValue);
|
|
12
|
+
const minArr = minColor.toArray();
|
|
13
|
+
const maxArr = maxColor.toArray();
|
|
14
|
+
const interpolated = minArr.map((min, index) => MathUtils.lerp(min, maxArr[index], finalMultiplier));
|
|
15
|
+
return new Color().fromArray(interpolated);
|
|
16
|
+
}
|
|
17
|
+
// Handle Vector3/Array [x, y, z]
|
|
18
|
+
if (Array.isArray(minValue) && Array.isArray(maxValue) && minValue.length === 3) {
|
|
19
|
+
return [
|
|
20
|
+
MathUtils.lerp(minValue[0], maxValue[0], finalMultiplier),
|
|
21
|
+
MathUtils.lerp(minValue[1], maxValue[1], finalMultiplier),
|
|
22
|
+
MathUtils.lerp(minValue[2], maxValue[2], finalMultiplier)
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
// Handle numbers
|
|
26
|
+
if (typeof minValue === 'number' && typeof maxValue === 'number') {
|
|
27
|
+
return MathUtils.lerp(minValue, maxValue, finalMultiplier);
|
|
28
|
+
}
|
|
29
|
+
return baseValue;
|
|
30
|
+
};
|
|
31
|
+
const interpolateProperty = (baseValue, minValue, maxValue, pointer, axis = 'both', sensitivity = 1, inverted = false) => {
|
|
32
|
+
let multiplier = 0;
|
|
33
|
+
if (axis === 'x')
|
|
34
|
+
multiplier = pointer.x;
|
|
35
|
+
if (axis === 'y')
|
|
36
|
+
multiplier = pointer.y;
|
|
37
|
+
if (axis === 'both')
|
|
38
|
+
multiplier = (pointer.x + pointer.y) / 2;
|
|
39
|
+
if (inverted)
|
|
40
|
+
multiplier *= -1;
|
|
41
|
+
return getInterpolatedValue(baseValue, minValue, maxValue, multiplier, sensitivity);
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
getInterpolatedValue,
|
|
45
|
+
interpolateProperty
|
|
46
|
+
};
|
|
47
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Object3D } from "three";
|
|
2
|
+
import { type CreatedObjectSettings } from '@ntalmagor/3drize-core';
|
|
3
|
+
import { type UseContinuousEffectsResult } from "./useContinuousEffects";
|
|
4
|
+
import { type UseInteractionEffectsResult } from "./useInteractionEffects";
|
|
5
|
+
interface UseObjectAnimationOptions {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
hovered?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface UseObjectAnimationResult extends UseContinuousEffectsResult, UseInteractionEffectsResult {
|
|
10
|
+
}
|
|
11
|
+
export declare const useObjectAnimation: (objectSettings: CreatedObjectSettings | null, animateMaterial: boolean, options?: UseObjectAnimationOptions, ref?: Object3D) => UseObjectAnimationResult | null;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=useObjectAnimation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useObjectAnimation.d.ts","sourceRoot":"","sources":["../../src/hooks/useObjectAnimation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,KAAK,qBAAqB,EAAY,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAwB,KAAK,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EAAyB,KAAK,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAGlG,UAAU,yBAAyB;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,wBAAyB,SAAQ,0BAA0B,EAAE,2BAA2B;CAAG;AAErG,eAAO,MAAM,kBAAkB,GAC7B,gBAAgB,qBAAqB,GAAG,IAAI,EAC5C,iBAAiB,OAAO,EACxB,UAAS,yBAA8B,EACvC,MAAM,QAAQ,KACb,wBAAwB,GAAG,IAQ7B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { findById } from '@ntalmagor/3drize-core';
|
|
2
|
+
import { useContinuousEffects } from "./useContinuousEffects";
|
|
3
|
+
import { useInteractionEffects } from "./useInteractionEffects";
|
|
4
|
+
export const useObjectAnimation = (objectSettings, animateMaterial, options = {}, ref) => {
|
|
5
|
+
const { enabled = true, hovered = false } = options;
|
|
6
|
+
const objectRef = ref || findById(objectSettings?.id);
|
|
7
|
+
// console.log(objectRef)
|
|
8
|
+
const continuousResult = useContinuousEffects(objectSettings, { enabled, animateMaterial, hovered }, objectRef);
|
|
9
|
+
const interactionResult = useInteractionEffects(objectSettings, { enabled, animateMaterial }, objectRef);
|
|
10
|
+
return { ...continuousResult, ...interactionResult };
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useObjectEdges.d.ts","sourceRoot":"","sources":["../../src/hooks/useObjectEdges.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAqM1D,wBAAgB,cAAc,CAC1B,MAAM,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,EACnC,aAAa,EAAE,WAAW,QAyC7B"}
|