Skip to content

Commit

Permalink
fix: added default position and direction to camera if props are not …
Browse files Browse the repository at this point in the history
…passed
  • Loading branch information
alvarosabu committed Apr 6, 2023
1 parent 8d030fb commit 63a340f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
8 changes: 5 additions & 3 deletions docs/guide/your-first-scene.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ Then you can add a [**PerspectiveCamera**](https://threejs.org/docs/index.html?q

```vue
<template>
<TresCanvas window-size> <TresPerspectiveCamera :position="[3, 3, 3]" :look-at="[0, 0, 0]" /> </TresCanvas>
<TresCanvas window-size>
<TresPerspectiveCamera />
</TresCanvas>
</template>
```

Expand All @@ -118,7 +120,7 @@ Now let's see how we can easily achieve the same with **TresJS**. To do that we
```vue
<template>
<TresCanvas window-size>
<TresPerspectiveCamera :position="[3, 3, 3]" :look-at="[0,0,0]"" />
<TresPerspectiveCamera />
<TresMesh>
<TresTorusGeometry :args="[1, 0.5, 16, 32]" />
<TresMeshBasicMaterial color="orange" />
Expand All @@ -142,7 +144,7 @@ import { TresCanvas } from '@tresjs/core'
<template>
<TresCanvas clear-color="#82DBC5" window-size>
<TresPerspectiveCamera :position="[3, 3, 3]" :look-at="[0,0,0]"" />
<TresPerspectiveCamera :position="[3, 3, 3]" :look-at="[0, 0, 0]" />
<TresMesh>
<TresTorusGeometry :args="[1, 0.5, 16, 32]" />
<TresMeshBasicMaterial color="orange" />
Expand Down
1 change: 1 addition & 0 deletions playground/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare module '@vue/runtime-core' {
TheExperience: typeof import('./src/components/TheExperience.vue')['default']
TheExperiment: typeof import('./src/components/gltf/TheExperiment.vue')['default']
TheFireFlies: typeof import('./src/components/portal-journey/TheFireFlies.vue')['default']
TheFirstScene: typeof import('./src/components/TheFirstScene.vue')['default']
TheGizmos: typeof import('./src/components/TheGizmos.vue')['default']
TheGroups: typeof import('./src/components/TheGroups.vue')['default']
TheParticles: typeof import('./src/components/TheParticles.vue')['default']
Expand Down
20 changes: 20 additions & 0 deletions playground/src/components/TheFirstScene.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script setup lang="ts">
import { TresCanvas } from '/@/'
const context = ref()
watchEffect(() => {
console.log(context)
})
</script>

<template>
<TresCanvas ref="context" clear-color="#82DBC5" window-size="true">
<TresPerspectiveCamera />
<TresMesh>
<TresTorusGeometry :args="[1, 0.5, 16, 32]" />
<TresMeshBasicMaterial color="orange" />
</TresMesh>
<TresAmbientLight :intensity="1" />
</TresCanvas>
</template>
2 changes: 1 addition & 1 deletion playground/src/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts"></script>
<template>
<Suspense>
<TheEvents />
<TheFirstScene />
</Suspense>
</template>
3 changes: 2 additions & 1 deletion playground/src/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
html,
/* html,
body {
margin: 0;
padding: 0;
Expand All @@ -9,3 +9,4 @@ body {
height: 100%;
width: 100%;
}
*/
13 changes: 5 additions & 8 deletions src/core/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { isFunction } from '@vueuse/core'
import { TresObject } from '../types'
import { isHTMLTag, kebabToCamel } from '../utils'

const { logWarning } = useLogger()

const onRE = /^on[^a-z]/
export const isOn = (key: string) => onRE.test(key)

Expand All @@ -32,12 +30,11 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
}

if (instance.isCamera) {
// Let users know that camera is in the center of the scene
if (!props?.position || props?.position.every((v: number) => v == 0)) {
logWarning(
// eslint-disable-next-line max-len
'Camera is positioned at the center of the scene [0,0,0], if this is not intentional try setting a position if your scene seems empty 🤗',
)
if (!props?.position) {
instance.position.set(3, 3, 3)
}
if (!props?.lookAt) {
instance.lookAt(0, 0, 0)
}
const { pushCamera } = useCamera()
pushCamera(instance)
Expand Down

0 comments on commit 63a340f

Please sign in to comment.