-
Notifications
You must be signed in to change notification settings - Fork 73
Create GLTF component #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
* include Basis and Draco loaders * Animations don't do anything yet.
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/svelte/svelte-cubed/FeiUotdviXKAr4ZyBybXMEqgkNng [Deployment for 008f4d0 failed] |
Would like to have a further look into this but haven't been able to check in on the inspection from the bot. let us know if there's anything you'd like some help on edit: Also a GLTF component sounds good to me 👍 |
I get a 404 page when I try to check the Vercel error. I'll look into it more later tonight. |
const { root, parent, self } = setup(new THREE.Object3D()); | ||
|
||
$: { | ||
if(gltfScene) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: Maybe worth dispatching an event on load/change as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example of what that might look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
At the top of the file before/after the props are exported, we could create an event dispatcher:
import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher();
And then on line 77 where we have successfully loaded (or failed to load) the model, we could dispatch("load", gltf);
or dispatch("error", err);
, etc...
My thinking was that this could provide a convenient entry point for manipulating the materials in the scene, etc...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a consumer of the component, that would look something like
<SC.GLTF {...} on:load={swapMyTexture} on:error={swapFallbackScene} />
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that dispatching on change would provide any value to me, but the implementation would be similar, just within the reactive statement.
|
||
onMount(() => { | ||
|
||
const loader = new GLTFLoader() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a benefit to creating the loader for each component instance rather than reusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hear what your saying but also just doing a thing and getting it off the ground/running is step # 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And reviewing it and iterating on it is step # 2!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely! I submitted this PR early to get feedback, so I'm excited to get feedback. I looked into the loader and figured out how to share it; i'll push a version with this in a bit. This also shares the KTX and Draco loaders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah! all good then. looking forward to previewing the deploy when that comes together
Fix path so it can be left blank. Added cesium man animated glb (not animated in component yet)
Can anyone see the Vercel deployment error? i'm still getting a 404 when I try to see the details. @Rich-Harris any ideas? |
For the time being I created a pull request with an example on how to load a gltf or glb file using |
I'm guessing (from the glb in the repo) this is already in progress, but here's a first cut at a glTF component. It supports gltf or GLB files.
It supports draco and KTX2 (basis) compression, but those have to be referenced at runtime and the loaders are in the static folder. There is probably a better way to do this.
Animations are not supported yet.