1.5.12 • Published 2 years ago

effectnode v1.5.12

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

effectnode

generic effectnode runtime, demo in react

NPM JavaScript Style Guide

Install

npm install --save effectnode

Usage

import React, { useEffect, useRef, useState } from 'react'
import { ENRuntime, getEffectNodeData } from 'effectnode'
import { Canvas, useFrame } from '@react-three/fiber'
export function FirebaseDemo() {
  return (
    <div style={{ width: '100%', height: '100%' }}>
      <Canvas style={{ width: '100%', height: '100%' }}>
        <EffectNodeInFiber></EffectNodeInFiber>
      </Canvas>
    </div>
  )
}

export function EffectNodeInFiber() {
  let mounter = useRef()
  let graph = useRef()
  let [myInst, setCompos] = useState(() => {
    return <group></group>
  })

  useEffect(() => {
    getEffectNodeData({ firebaseConfig, graphID: `-MdBQtfGPXXPkl-NuEoW` }).then(
      (json) => {
        graph.current = new ENRuntime({
          json: json,
          codes: getCodes()
        })

        graph.current.mini.get('DefaultComponent').then((v) => {
          setCompos(v)
        })
      }
    )

    return () => {
      if (graph.current) {
        graph.current.mini.clean()
        graph.current.clean()
      }
    }
  }, [])

  useFrame(({ get }) => {
    let three = get()
    if (graph.current) {
      for (let kn in three) {
        graph.current.mini.set(kn, three[kn])
      }
      if (mounter.current) {
        graph.current.mini.set('mounter', mounter.current)
      }
      graph.current.mini.work()
    }
  })

  return (
    <>
      <group ref={mounter}>{myInst}</group>
    </>
  )
}

export const getCodes = () => {
  let path = require('path')
  let r = require.context('./vfx-codes', true, /\.js$/, 'lazy')

  function importAll(r) {
    let arr = []
    r.keys().forEach((key) => {
      let filename = path.basename(key)

      arr.push({
        title: filename,
        loader: () => r(key)
      })
    })

    return arr
  }
  let codes = importAll(r)

  return codes
}

export const firebaseConfig = {
  databaseURL: 'https://en-you.firebaseio.com/'
}

License

MIT © wonglok

1.5.5

2 years ago

1.5.4

2 years ago

1.5.12

2 years ago

1.5.7

2 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.0.9

3 years ago

1.0.7

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago