Skip to content

Conversation

snagy
Copy link

@snagy snagy commented Nov 26, 2021

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.

* include Basis and Draco loaders
* Animations don't do anything yet.
@vercel
Copy link

vercel bot commented Nov 26, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/svelte/svelte-cubed/FeiUotdviXKAr4ZyBybXMEqgkNng
✅ Preview: Failed

[Deployment for 008f4d0 failed]

@DefinitelyMaybe
Copy link

DefinitelyMaybe commented Nov 26, 2021

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 👍

@snagy
Copy link
Author

snagy commented Nov 26, 2021

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) {
Copy link

@aewing aewing Nov 29, 2021

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.

Copy link
Author

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?

Copy link

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...

Copy link

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} />

Copy link

@aewing aewing Nov 30, 2021

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()
Copy link

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?

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

Copy link

@aewing aewing Nov 30, 2021

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!

Copy link
Author

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.

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)
@snagy
Copy link
Author

snagy commented Dec 1, 2021

Can anyone see the Vercel deployment error? i'm still getting a 404 when I try to see the details. @Rich-Harris any ideas?

@Myrmod
Copy link

Myrmod commented Dec 10, 2021

For the time being I created a pull request with an example on how to load a gltf or glb file using SC.Primitive in #41.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants