Tresjs / cientos

Collection of useful helpers and fully functional, ready-made abstractions for TresJS
https://cientos.tresjs.org/
MIT License
288 stars 40 forks source link

types of `useGLTF` missing in `3.9.0` #418

Closed NamesMT closed 2 months ago

NamesMT commented 6 months ago

Describe the bug

3.8.0: image

3.9.0: image

It's still exported in .js file and is usable, but the types missing makes IDE yelling error. image

Reproduction

https://www.npmjs.com/package/@tresjs/cientos?activeTab=code

Steps to reproduce

N/A

System Info

N/A

Used Package Manager

pnpm

Code of Conduct

wcheek commented 5 months ago

I'm using a temporary hack to get around this issue and still be able to build my project:

// tresjs-hack.d.ts

// HACK: THIS IS A HACK! REMOVE AFTER TRESJS FIXES TYPES
declare module "@tresjs/cientos" {
  export function useGLTF(any, any);
  export function CameraControls(any);
// Necessary to declare any other cientos packages you are importing here
}
NamesMT commented 5 months ago

Currently I just simply remove/opt-out of TS (remove lang="ts") on model components :D, Should be a quick fix but the team is preparing for 4.0 I guess.

BenoitBotton commented 5 months ago

I'm using a temporary hack to get around this issue and still be able to build my project:

// tresjs-hack.d.ts

// HACK: THIS IS A HACK! REMOVE AFTER TRESJS FIXES TYPES
declare module "@tresjs/cientos" {
  export function useGLTF(any, any);
  export function CameraControls(any);
// Necessary to declare any other cientos packages you are importing here
}

that worked brilliantly for me

but I am also getting a number of other type errors error TS2322: Type 'number[]' is not assignable to type 'Vector3 | Readonly<Vector3 | undefined>' error TS2322: Type 'string' is not assignable to type 'Color | Readonly<Color | undefined>' which are not resolved.

did anyone else get those?

NamesMT commented 5 months ago

@BenoitBotton I do get it if I enable ts for Tres-related component files, Tres types seems not fully aligned with real documented behavior.

wcheek commented 5 months ago

@BenoitBotton I have to use the classes from THREE in those places.

:position="new THREE.Vector3(0, 0, 0)"
:color="new THREE.Color('orange')"
BenoitBotton commented 5 months ago

thanks @NamesMT and @wcheek I went with using the THREE classes

BenoitBotton commented 5 months ago

actually that does not fully work. one of my components is called several times in a v-for loop. it's template is

<template>
    <TresGroup :rotation-z="cutter.theta * toRad" :key="cutter.spiral">
        <TresGroup :position-z="cutter.ztip">
            <TresGroup :position-x="cutter.radius">
                <TresGroup :rotation-y="cutter.yrot * toRad">
                    <TresGroup :rotation-z="-cutter.siderake * toRad">
                        <TresGroup :rotation-x="cutter.backrake * toRad">
                            <TresMesh :position="cutter.spiral < 500 ? [0, 0, -r] : [0, 0, 0]"
                                :rotation="[90 * toRad, 0, 0]">
                                <Suspense fallback={null}>
                                    <Comp :color="color" />
                                </Suspense>
                            </TresMesh>
                            <TresAxesHelper :visible="showTipHelper" :args="[10]" />
                        </TresGroup>
                    </TresGroup>
                </TresGroup>
            </TresGroup>
        </TresGroup>
    </TresGroup>
</template>

only :position="cutter.spiral < 500 ? [0, 0, -r] : [0, 0, 0]" is called out by the type error, not any of the other position or rotation props on the groups. issue is r is a reactive prop and, when I replace it with <TresMesh :position="cutter.spiral < 500 ? new THREE.Vector3(0, 0, -r) : new THREE.Vector3(0, 0, 0)" I end up with only one component showing (or maybe all of them on top of each other? tresjs scene is blank in the dev tools! )

and if I revert back but remove lang=ts from the component, I get nothing at all!

I guess I will revert to cientos 3.8 for now

alvarosabu commented 2 months ago

Should be fixed by 4.0 https://github.com/Tresjs/cientos/releases/tag/4.0.0 . If not feel free to reopen