Skip to content
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

fix: draco loader is now config correctly #48

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cientos/src/core/useGLTF/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ export const GLTFModel = defineComponent({
props: {
path: String,
draco: Boolean,
decoderPath: String,
},

async setup(props) {
const scene = inject<Ref<Scene>>('local-scene')

const { scene: model } = await useGLTF(props.path as string, { draco: props.draco })
const { scene: model } = await useGLTF(props.path as string, { draco: props.draco, decoderPath: props.decoderPath })
if (scene?.value) {
scene.value.add(model)
}
Expand Down
10 changes: 7 additions & 3 deletions packages/cientos/src/core/useGLTF/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GLTFLoader, DRACOLoader } from 'three-stdlib'
/* import { useLoader } from '../../../../tres/src/core' */
import { useLoader } from '@tresjs/core'
import { Object3D } from 'three'

Expand All @@ -24,10 +25,13 @@ function setExtensions(options: GLTFLoaderOptions, extendLoader?: (loader: GLTFL
if (extendLoader) {
extendLoader(loader as GLTFLoader)
}
if (!dracoLoader) {
dracoLoader = new DRACOLoader()
if (options.draco) {
if (!dracoLoader) {
dracoLoader = new DRACOLoader()
}
dracoLoader.setDecoderPath(options.decoderPath || 'https://www.gstatic.com/draco/versioned/decoders/1.4.3/')
loader.setDRACOLoader(dracoLoader)
}
dracoLoader.setDecoderPath(options.decoderPath || 'https://www.gstatic.com/draco/versioned/decoders/1.4.3/')
}
}
export async function useGLTF(
Expand Down
11 changes: 4 additions & 7 deletions packages/tres/src/components/TheExperience.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { OrbitControls } from '@tresjs/cientos'
import { OrbitControls, GLTFModel } from '../../../cientos/src/'
/* import { OrbitControls, GLTFModel } from '@tresjs/cientos' */
</script>
<template>
<TresCanvas
Expand All @@ -14,12 +15,8 @@ import { OrbitControls } from '@tresjs/cientos'
<TresScene>
<OrbitControls />
<TresAmbientLight :intensity="0.5" />
<!-- <TresOrbitControls v-if="state.renderer" :args="[state.camera, state.renderer?.domElement]" /> -->
<TresMesh :position="[0, 0, 0]">
<TresBoxGeometry />
<TresMeshNormalMaterial />
</TresMesh>
<TresAxesHelper :args="[1]" :visible="false" />
<TresFog :color="'#444'" />
<GLTFModel draco path="https://raw.githubusercontent.com/Tresjs/assets/main/models/gltf/portal/portal.gltf" />
<TresDirectionalLight :position="[0, 2, 4]" :intensity="2" cast-shadow />
</TresScene>
</TresCanvas>
Expand Down
2 changes: 1 addition & 1 deletion packages/tres/src/core/useLoader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function useLoader<T extends LoaderProto<T>, U extends string | str
}

if (extensions) {
extensions(Loader)
extensions(proto)
}

const paths = (Array.isArray(url) ? url : [url]) as string[]
Expand Down