Skip to content

Commit

Permalink
fix: typing issues with useLoader and environment
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Feb 19, 2023
1 parent d6a422e commit d6aca6f
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 51 deletions.
4 changes: 2 additions & 2 deletions packages/cientos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
"rollup-plugin-visualizer": "^5.9.0",
"tweakpane": "^3.1.4",
"typescript": "^4.9.5",
"vite": "^4.1.1",
"vite": "^4.1.2",
"vite-plugin-banner": "^0.7.0",
"vite-plugin-dts": "^1.7.2"
"vite-plugin-dts": "2.0.0-beta.1"
},
"dependencies": {
"@tresjs/core": "workspace:^1.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cientos/src/core/OrbitControls.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import { Camera, Vector3 } from 'three'
import { OrbitControls } from 'three-stdlib'
import { ref, watch, watchEffect, unref, type Ref } from 'vue'
import { ref, watch, unref, type Ref } from 'vue'
import { useCientos } from './useCientos'
Expand Down
8 changes: 4 additions & 4 deletions packages/cientos/src/core/Text3D.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script async setup lang="ts">
<script setup lang="ts">
import { TextGeometry, FontLoader } from 'three-stdlib'
import { computed, useSlots } from 'vue'
Expand Down Expand Up @@ -34,7 +34,7 @@ const props = withDefaults(
bevelThickness?: number
bevelSize?: number
bevelOffset?: number
bevelSegments?: number,
bevelSegments?: number
center?: boolean
}>(),
{
Expand All @@ -46,9 +46,9 @@ const props = withDefaults(
bevelSize: 0.02,
bevelOffset: 0,
bevelSegments: 4,
center:false
center: false,
},
)
)
const { extend } = useCientos()
Expand Down
5 changes: 2 additions & 3 deletions packages/cientos/src/core/TransformControls.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script setup lang="ts">
import { useTres } from '@tresjs/core'
import { Camera, Object3D, Scene, WebGLRenderer, type Event } from 'three'
import { Object3D, type Event } from 'three'
import { TransformControls as TransformControlsImp } from 'three-stdlib'
import { inject, computed, type Ref, unref, watch, shallowRef, ShallowRef, onUnmounted } from 'vue'
import { computed, unref, watch, shallowRef, ShallowRef, onUnmounted } from 'vue'
import { pick, hasSetter } from '../utils'
import { useCientos } from './useCientos'
Expand Down
13 changes: 9 additions & 4 deletions packages/cientos/src/core/useEnvironment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ export async function useEnvironment({

const loader = isCubeMap ? CubeTextureLoader : RGBELoader

const result = await useLoader(loader, isCubeMap ? [files] : files, (loader: any) => {
if (path) loader.setPath(path)
if (encoding) loader.encoding = encoding
})
const result = await useLoader(
// @ts-expect-error There is a bug in the types for useLoader
loader,
isCubeMap ? [files] : files,
(loader: any) => {
if (path) loader.setPath(path)
if (encoding) loader.encoding = encoding
},
)

const texture: Texture | CubeTexture = isCubeMap ? result[0] : result

Expand Down
20 changes: 0 additions & 20 deletions packages/cientos/src/env.d.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/cientos/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference types="vite/client" />

declare module '*.glsl' {}
2 changes: 1 addition & 1 deletion packages/cientos/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"/@/*": ["src/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "histoire.setup.ts", "histoire.setup.ts"],
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"exclude": ["dist", "node_modules", "src/**/*.cy.ts", "src/**/*.test.ts"],
"references": [{ "path": "./tsconfig.node.json" }]
}
1 change: 1 addition & 0 deletions packages/tres/src/core/useLoader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface TresLoader<T> extends THREE.Loader {
onProgress?: (event: ProgressEvent) => void,
onError?: (event: ErrorEvent) => void,
): unknown
loadAsync(url: string, onProgress?: (event: ProgressEvent) => void): Promise<T>
}

export type LoaderProto<T> = new (...args: any) => TresLoader<T extends unknown ? any : T>
Expand Down
2 changes: 1 addition & 1 deletion packages/tres/src/core/useRenderer/component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ShadowMapType, TextureEncoding, ToneMapping } from 'three'
import { h, defineComponent, ref, provide, onBeforeUnmount, shallowRef, PropType } from 'vue'
import { h, defineComponent, ref, provide, onBeforeUnmount, PropType } from 'vue'
import { useRenderer } from '.'
import { useLogger } from '/@/composables'
import { TresVNodeType } from '/@/types'
Expand Down
4 changes: 2 additions & 2 deletions packages/tres/src/core/useTres/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Clock, EventDispatcher, Raycaster, Scene, Vector2, WebGLRenderer } from 'three'
import { ComputedRef, shallowReactive, ShallowRef, toRefs } from 'vue'
import { ComputedRef, shallowReactive, toRefs } from 'vue'
import { Camera } from '/@/core'

export interface TresState {
Expand All @@ -11,7 +11,7 @@ export interface TresState {
clock?: Clock
pointer?: Vector2
currentInstance?: any
controls?: EventDispatcher | null
controls?: (EventDispatcher & { enabled: boolean }) | null
[key: string]: any
}

Expand Down
99 changes: 86 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d6aca6f

Please sign in to comment.