Skip to content

Commit

Permalink
Add Node Material snippet by ID story #105
Browse files Browse the repository at this point in the history
  • Loading branch information
brianzinn committed Jan 10, 2021
1 parent 23c859f commit 4473f8a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions stories/babylonjs/Basic/snippetMaterial.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useState, useCallback, useEffect } from 'react'
import { Vector3, NodeMaterial } 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 scene = useScene();
const [material, setMaterial] = useState(null);
const parseMaterial = useCallback(async () => {
NodeMaterial.ParseFromSnippetAsync(snippetId, scene).then(
(nodeMaterial) => {
setMaterial(nodeMaterial);
}
);
}, [snippetId, scene]);

useEffect(() => {
parseMaterial();
}, [parseMaterial]);

return material === null ? null : (
<nodeMaterial name={name} fromInstance={material} />
);
};

export const SnippetMaterial = () => (
<div style={{ flex: 1, display: 'flex' }}>
<Engine antialias adaptToDeviceRatio canvasId='babylonJS'>
<Scene>
<arcRotateCamera name="arc" target={Vector3.Zero()} minZ={0.001}
alpha={-Math.PI / 4} beta={(Math.PI / 4)} radius={5} upperBetaLimit={(Math.PI / 2) * 0.99}
/>
<hemisphericLight name="light1" intensity={0.7} direction={Vector3.Up()} />
<sphere name="sphere1" diameter={2} segments={16} position={new Vector3(0, 1, 0)}>
<SnippetMaterialById name="sphereMat" snippetId="#81NNDY#20" />
</sphere>
<ground name="ground1" width={6} height={6} subdivisions={2} />
</Scene>
</Engine>
</div>
)

0 comments on commit 4473f8a

Please sign in to comment.