|
@@ -80,18 +80,6 @@ export const TresScene = defineComponent<TresSceneProps>({
|
|
|
setState('container', container)
|
|
|
setState('pointerEventHandler', pointerEventHandler)
|
|
|
|
|
|
- const isCameraAvailable = ref()
|
|
|
-
|
|
|
- const internal = slots && slots.default && slots.default()
|
|
|
-
|
|
|
- if (internal && internal?.length > 0) {
|
|
|
- isCameraAvailable.value =
|
|
|
- internal.some((node: VNode) => isString(node.type) && node.type.includes('Camera')) || props.camera
|
|
|
- if (!isCameraAvailable.value) {
|
|
|
- logWarning('No camera found in the scene, please add one!')
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
const { onLoop, resume } = useRenderLoop()
|
|
|
|
|
|
onMounted(() => {
|
|
@@ -104,6 +92,22 @@ export const TresScene = defineComponent<TresSceneProps>({
|
|
|
|
|
|
const { activeCamera, pushCamera, clearCameras } = useCamera()
|
|
|
|
|
|
+ function setCamera() {
|
|
|
+ const camera = scene.children.find((child: any) => child.isCamera)
|
|
|
+
|
|
|
+ if (!camera) {
|
|
|
+ // eslint-disable-next-line max-len
|
|
|
+ logWarning('No camera found, creating a default perspective one, to have full control over a camera, please add one to the scene.')
|
|
|
+ const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000)
|
|
|
+ camera.position.set(3,3,3)
|
|
|
+ camera.lookAt(0,0,0)
|
|
|
+ pushCamera(camera)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ pushCamera(camera as TresCamera)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function initRenderer() {
|
|
|
const { renderer } = useRenderer(props)
|
|
|
|
|
@@ -125,6 +129,7 @@ export const TresScene = defineComponent<TresSceneProps>({
|
|
|
app.provide(TRES_CONTEXT_KEY, tres)
|
|
|
app.provide('extend', extend)
|
|
|
app.mount(scene as unknown)
|
|
|
+ setCamera()
|
|
|
}
|
|
|
mountApp()
|
|
|
|
|
@@ -138,8 +143,7 @@ export const TresScene = defineComponent<TresSceneProps>({
|
|
|
app = createTres(slots)
|
|
|
app.provide('extend', extend)
|
|
|
app.mount(scene as unknown)
|
|
|
- const camera = scene.children.find((child: any) => child.isCamera)
|
|
|
- pushCamera(camera as TresCamera)
|
|
|
+ setCamera()
|
|
|
resume()
|
|
|
}
|
|
|
|