AndrewPrifer / react-three-editable

⚠️ Moved! See @theatre/r3f and the theatre-js/theatre repo for the new version with animation tools! Link below 👇 Edit your react-three-fiber scene with a visual editor without giving up control over your code.
https://docs.theatrejs.com/extensions/r3f/
MIT License
363 stars 36 forks source link

GLTSFX integration #49

Closed hector-crean closed 3 years ago

hector-crean commented 3 years ago

Love react-three editable. As noted in the documentation, it solves some of the same problems that GLTSFX was trying to solve, but with a different approach. I'm finding it difficult to integrate the use of react-three-edtiable with GLTSFX. As far as I'm aware, you're able to make custom components editable, by wrapping them in editable, but I'm running into problems with this. Any best practice way to do this?

`/* ////Model.tsx

Auto-generated by: https://github.com/pmndrs/gltfjsx */

import * as THREE from 'three' import React, { useRef } from 'react' import { useGLTF } from '@react-three/drei/useGLTF'

import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader'

type GLTFResult = GLTF & { nodes: {

['A-1.001_2']: THREE.Mesh

} materials: {

['Wood-3 Ver.001']: THREE.MeshStandardMaterial

} }

export default function Model(props: JSX.IntrinsicElements['group']) { const group = useRef() const { nodes, materials } = useGLTF('/A1.glb') as GLTFResult return ( <group ref={group} {...props} dispose={null}>

  </group>
</group>

) }

useGLTF.preload('/A1.glb')`

` //App.tsx import { editable as e } from 'react-three-editable';

import Model from './path/to/Model.tsx'

const EModel = e(Model, 'group'); <EModel uniqueName={'Emodel'} />

`

AndrewPrifer commented 3 years ago

Hi @hector-crean, sorry for getting back to you so late!

The reason the above code doesn't work is that editable needs a ref to the wrapped object, and the component generated by GLTFJSX doesn't forward it to the group. I opened an issue in GLTFJSX, however in the meantime, you can forward the ref yourself: https://reactjs.org/docs/forwarding-refs.html.

Update

Since the requirement to use forwardRef will be removed in React 18, GLTFJSX doesn't plan to use forwardRef, so you'll need to do it by hand in the meantime. Feel free to @ me if you need help with it.

hector-crean commented 3 years ago

Many thanks! X