Skip to content

Commit

Permalink
Merge pull request #134 from Tresjs/hotfix/default-aspect-ratio-break…
Browse files Browse the repository at this point in the history
…s-responsiveness

Hotfix/default aspect ratio breaks responsiveness
  • Loading branch information
alvarosabu authored Feb 28, 2023
2 parents 56124d6 + 17a8368 commit 7745c07
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/tres/src/core/useCamera/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTres } from '/@/core/'
import { PerspectiveCamera, OrthographicCamera } from 'three'

import { toRef, watch, Ref } from 'vue'
import { toRef, watch, Ref, inject } from 'vue'

export enum CameraType {
Perspective = 'Perspective',
Expand Down Expand Up @@ -105,7 +105,7 @@ let camera: Camera
*/
export function useCamera(): UseCameraReturn {
const { state, setState } = useTres()

const aspectRatio = inject('aspect-ratio')
/**
* Create camera and push to Tres `state.cameras` array
*
Expand Down Expand Up @@ -182,10 +182,10 @@ export function useCamera(): UseCameraReturn {
function clearCameras() {
state.cameras = []
}

if (state.aspectRatio) {
watch(state.aspectRatio, updateCamera)
if (aspectRatio) {
watch(aspectRatio, updateCamera)
}

return {
activeCamera: toRef(state, 'camera'),
createCamera,
Expand Down
6 changes: 3 additions & 3 deletions packages/tres/src/core/useInstanceCreator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ export function useInstanceCreator(prefix: string) {
return
} else {
const vNodeType = ((vnode.type as TresVNodeType).name as string).replace(prefix, '')
const { catalogue: fallback } = useCatalogue()
const catalogue = inject<Ref<TresCatalogue>>('catalogue') || fallback

const catalogue = inject<Ref<TresCatalogue>>('catalogue')

// check if args prop is defined on the vnode
let internalInstance
Expand Down Expand Up @@ -265,12 +265,12 @@ export function useInstanceCreator(prefix: string) {
const { onLoop } = useRenderLoop()
const scene = state.scene
const raycaster = state.raycaster
const { pushCamera } = useCamera()

let instance = createInstance(threeObj, attrs, slots)
processProps(attrs, instance)
// If the instance is a camera, push it to the camera stack
if (instance instanceof PerspectiveCamera || instance instanceof OrthographicCamera) {
const { pushCamera } = useCamera()
pushCamera(instance)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/tres/src/core/useRenderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export function useRenderer(canvas: MaybeElementRef, container: MaybeElementRef,
preset = undefined,
} = toRefs(options)

const { setState } = useTres()

const { width, height } = resolveUnref(windowSize) ? useWindowSize() : useElementSize(container)
const { logError } = useLogger()
const { pixelRatio } = useDevicePixelRatio()
Expand Down Expand Up @@ -212,7 +214,6 @@ export function useRenderer(canvas: MaybeElementRef, container: MaybeElementRef,
premultipliedAlpha: resolveUnref(premultipliedAlpha),
})

const { setState } = useTres()
setState('renderer', renderer.value)
setState('clock', new Clock())
setState('aspectRatio', aspectRatio)
Expand Down

0 comments on commit 7745c07

Please sign in to comment.