solidjs-community / solid-three

port of @react-three/fiber for solid
https://solid-three.vercel.app
127 stars 13 forks source link

next `solid-three` #12

Open bigmistqke opened 1 year ago

bigmistqke commented 1 year ago

This branch continues the context-and-proxies-branch from @vorth in which he took the proxy-implementation from @nksaraf solid-three-chess branch of react-three-fiber.

This branch' intention is to remove all the dependencies and artefacts from react, remove the dependency on zustand as an internal state manager in favour of solid/store and streamline the code, while keeping as close as possible to r3f's v9 codebase.

what has been done

reflections

~Currently our codebase is somewhere between r3f's main branch and v9. For example, Instance is typed like the main branch, but we have Stages like v9. Probably these changes happened after nikhil made his implementation (found pr when they made the change). Idk if we should pull everything closer to v9 or not. I think yes, but my previous attempts have all failed.~

Instance has been ported to current v9 implementation. Our codebase is now up-to-date.

~As I said above; since we now have solid-store-related code throughout the codebase idk if it still makes sense to make the distinction between the two. I think mb it's best to just bring it back into 1 repo and try to mimic the structure as closely to r3f as possible, so we can at least manually compare the two when needed.~

I went ahead and merged those directories

I think it would probably be good to try out some more complex examples, to test out this version. Maybe port the examples of r3f.

bigmistqke commented 1 year ago

I refactored the type of Instance as described in this commit Now I think our codebase is pretty much aligned with the current v9-branch of r3f.

I also added r3f as a sub-module into the repo, so that it's easy to compare them.

I personally think syncing their repo automatically with ours will be difficult to do, as there are little changes throughout the codebase. Instead I tried to mimmic their codebase as much as possible with ours so we can diff manually (I have been using the vs-extension Diff Folders to do that, it's quite handy).

bigmistqke commented 1 year ago

[for documentation purposes]

The initial way how children were attached to parents, in this branch, was done with the use of context, from child to parent: each parent would wrap its children with a <Context.Provider value={() => Instance}>{props.children}</Context.Provider/> and each child would check this context with the use of the useParent-hook and attach itself to this parent. This however broke the expectation that only returned jsx would attach itself.

const Noop = () => {
  const mesh = new <T.Mesh/>
  return </></>
}

would actually connect the mesh to its parent.

To fix this I adjusted the code (see b6cbde4) to create the hierarchy from parent-to-child instead of from child-to-parent.

Instead of using context we read the props.children, from the parent, and attach the children to the parent accordingly. This way only returned jsx becomes a part of the tree.

connorgmeehan commented 1 year ago

I am looking to use this repo to create a solidjs renderer for pixi js and this maintenance and solid-js refactoring is massively appreciated. Looking forward to seeing where this PR goes :)

bigmistqke commented 1 year ago

[for documentation purposes]

Comments:

// this could have performance benefits if texture is defined
const material = new THREE.Material({map: texture})

// I am not sure this would, since it would need to compile the shader first anyway
// except if THREE would queueMicrotask the compilation of the shader 🤔
const material = new THREE.Material()
material.map = texture
bigmistqke commented 1 year ago

@connorgmeehan cool! I would be pretty interested if there is a way to generalize this renderer, so you could plug it in other libraries. If you wanna come and hang out with us at discord

bigmistqke commented 1 year ago

I removed all the timeline-management code and the suspension of three-element creation as they didn't compose nicely with ordinary jsx-elements and messed up some expectations, p.ex on when refs are resolved:

<T.Mesh ref={mesh}>
  <CustomComponent mesh={mesh}/>
</T.Mesh>

In the above example CustomComponent expects to receive mesh immediately, but with the initial inspection-run this resulted into undefined.

connorgmeehan commented 12 months ago

@connorgmeehan cool! I would be pretty interested if there is a way to generalize this renderer, so you could plug it in other libraries. If you wanna come and hang out with us at discord

Sorry for the late response. It's funny you say that. That's one of the first things that I did when adapting this code.

Here's an early version of the generalised proxy renderer. I haven't really bothered open sourcing it the up to date code because I'm working in a private monorepo with my app. https://github.com/sanspointes/constructables/ Basically it just lets you create a new root with a context and lets you wrap any classes into a component with automatic prop typing (which is honestly pretty buggy and slow for the typescript compiler). It also prefers defining implied props explicitly (such as position-x: number) rather than at runtime so you get proper typing. Also here's the pixi renderer implementation that uses the generalised renderer.

I am running into performance issues, especially surrounding the way props are tracked when components are created. I would love to combine efforts. :)

Also can you re-share the discord link? I can't open it.