diff --git a/stories/babylonjs/Basic/snippetMaterial.stories.js b/stories/babylonjs/Basic/snippetMaterial.stories.js index 72c4580d..a878769c 100644 --- a/stories/babylonjs/Basic/snippetMaterial.stories.js +++ b/stories/babylonjs/Basic/snippetMaterial.stories.js @@ -1,12 +1,12 @@ import React, { useState, useCallback, useEffect } from 'react' -import { Vector3, NodeMaterial } from '@babylonjs/core'; +import { Vector3, NodeMaterial, Color3 } from '@babylonjs/core'; import '@babylonjs/core/Rendering/edgesRenderer' // You this need for side-effects import { Engine, Scene, useScene } from '../../../dist/react-babylonjs' import '../../style.css'; export default { title: 'Babylon Basic' }; -const SnippetMaterialById = ({snippetId, name}) => { +const SnippetMaterialById = ({snippetId, name, surfaceColor}) => { const scene = useScene(); const [material, setMaterial] = useState(null); const parseMaterial = useCallback(async () => { @@ -17,6 +17,13 @@ const SnippetMaterialById = ({snippetId, name}) => { ); }, [snippetId, scene]); + useEffect(() => { + if (material) { + let block = material.getInputBlockByPredicate((b) => b.name === 'Surface Color'); + block.value = Color3[surfaceColor](); + } + }, [surfaceColor]); + useEffect(() => { parseMaterial(); }, [parseMaterial]); @@ -26,19 +33,34 @@ const SnippetMaterialById = ({snippetId, name}) => { ); }; -export const SnippetMaterial = () => ( -
- - - - - - - - - - -
-) +const colors = ["Red", "Green", "Yellow"] + +export const SnippetMaterial = () => { + const [selectedColor, setSelectedColor] = useState("Green"); + const onChange = (e) => { + setSelectedColor(e.target.value); + } + return ( + <> +
+ +
+
+ + + + + + + + + + +
+ + ) +}