Forráskód Böngészése

Merge branch 'main' into docs/announcing-cientos-3-2-0

Jaime A Torrealba C 1 éve
szülő
commit
4211267f3c

+ 1 - 1
.github/workflows/lint.yml

@@ -8,7 +8,7 @@ env:
 jobs:
   lint:
     name: Lint
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-22.04
     strategy:
       matrix:
         node-version: [16]

+ 1 - 1
.github/workflows/test.yml

@@ -8,7 +8,7 @@ env:
 jobs:
   test:
     name: Unit Test
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-22.04
     strategy:
       matrix:
         node-version: [16]

+ 15 - 0
CHANGELOG.md

@@ -1,5 +1,20 @@
 
 
+## [3.1.0](https://github.com/Tresjs/tres/compare/3.0.1...3.1.0) (2023-08-23)
+
+
+### Features
+
+* use render instead of createApp ([#375](https://github.com/Tresjs/tres/issues/375)) ([9461a78](https://github.com/Tresjs/tres/commit/9461a78b1cb8082311765b5ef309e436da770012))
+
+
+### Bug Fixes
+
+* added logic on pathProps to re-instance nodes once `args` change ([#367](https://github.com/Tresjs/tres/issues/367)) ([453b031](https://github.com/Tresjs/tres/commit/453b031b258ab840af7d6b372ac3785b5f006851))
+* added revision version to apply useLegacyLights only if neccesary ([#373](https://github.com/Tresjs/tres/issues/373)) ([dee4b97](https://github.com/Tresjs/tres/commit/dee4b97faf906b8796dffa9f32369230f5bc417d))
+* args should be empty when args was falsy ([#369](https://github.com/Tresjs/tres/issues/369)) ([81b7914](https://github.com/Tresjs/tres/commit/81b7914fc685aa7314541480a96801c0cc7fd542))
+* instances re-instancing when not needed ([#374](https://github.com/Tresjs/tres/issues/374)) ([f2ae46b](https://github.com/Tresjs/tres/commit/f2ae46bebd7aa9a99961259dbc1db5ae6cf876dd))
+
 ### [3.0.1](https://github.com/Tresjs/tres/compare/3.0.0...3.0.1) (2023-07-29)
 
 

+ 101 - 0
docs/blog/announcing-v-3-1-0.md

@@ -0,0 +1,101 @@
+---
+sidebar: false
+---
+
+# Vue Devtools are back on v3.1.0 🎉
+
+We are excited to announce the release of **TresJS v3.1.0**. This release brings back the support for Vue Devtools, which was broken since v2 🤯 thanks to [@enpitsuLin](https://github.com/enpitsuLin)
+
+<video controls>
+    <source src="https://res.cloudinary.com/alvarosaburido/video/upload/v1692768893/Tres/devtools-are-back_cuynao.mp4" type="video/mp4">
+</video>
+
+This is huge for DX since you can now inspect the internal state of the library and the components that are using it. Although, we are still working on improving the experience, so expect more improvements in the future.
+
+## What's hot 🔥?
+
+### Guess who is back? Back again? Vue Devtools are back 🎶
+
+![Vue Devtools](https://media.tenor.com/idcVQVMSDvMAAAAC/again-guess-whos-back-again.gif)
+
+So since v2, the Vue Devtools were broken whenever `<TresCanvas />` was mounted. This is because we were using the custom Renderer API `createApp` to mount a second App inside the `<TresCanvas />` component. This was causing the Vue Devtools to break since it only works with DOM based vue apps (See [issue](https://github.com/vuejs/devtools/issues/2078)).
+
+Now, we are using the `render` function from the custom Renderer API to render the `<TresCanvas />` component, which means that the Vue Devtools are working again 🎉
+
+```ts
+const { render } = createRenderer(nodeOps)
+
+const createInternalComponent = (context: TresContext) => {
+    return defineComponent({
+        setup() {
+            provide('useTres', context)
+            provide('extend', extend)
+            return () => h(Fragment, null, slots?.default ? slots.default() : [])
+        }
+    })
+}
+
+const mountCustomRenderer = (context: TresContext) => {
+    const InternalComponent = createInternalComponent(context)
+    render(h(InternalComponent), scene.value as unknown as TresObject)
+}
+
+mountCustomRenderer(context)
+```
+
+Thanks again to [@enpitsuLin](https://github.com/enpitsuLin) for solving this issue 🙏🥹.
+
+## Re-instancing of THREE Objects
+
+Another important caveheat of Tres was that it was not possible to reactively change the constructor params of a THREE Object via the props `args`. 
+
+### Before 😠
+
+```html
+<script lang="ts" setup>
+const color = ref('#ffffff')
+const intensity = ref(1)
+
+const lightRef = ref<THREE.DirectionalLight>()
+
+watch([color, intensity], ([color, intensity]) => {
+    // this will not work
+    lightRef.value = new THREE.DirectionalLight(color, intensity)
+})
+</script>
+
+<template>
+    <TresDirectionalLight ref="lightRef" :args=[color, intensity] />
+</template>
+```
+
+As you can see, we are trying to re-instance the `THREE.DirectionalLight` object whenever the `color` or `intensity` refs change. So we needed to do it manually by using the `watch` function and re-assigning the template ref `lightRef` value.
+
+### After 😎
+
+```html
+<script lang="ts" setup>
+const color = ref('#ffffff')
+const intensity = ref(1)
+</script>
+
+<template>
+    <TresDirectionalLight :args=[color, intensity] />
+</template>
+```
+
+Now, we can just pass the `color` and `intensity` refs to the `args` prop and Tres will take care of re-instancing the `THREE.DirectionalLight` object whenever the refs change 🤭😉.
+
+## No more `useLegacyLights` warning
+
+Since [threejs v155](https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733) update there was pretty annoying warning on the console.
+
+![annoying useLegacyLights warning](/blog/annoying-warning.png)
+
+And it's GONEEEEEEE! 🎉🎉🎉
+
+## Share your work 🎨
+
+We want to see what you are creating with TresJS, so please share your work with us in our [Discord server](https://discord.gg/UCr96AQmWn) where we have a `#Showcase` area or in our [Twitter](https://twitter.com/tresjs_dev) 😊.
+
+Happy coding! 🚀

+ 4 - 4
docs/examples/orbit-controls.md

@@ -42,10 +42,10 @@ Now you can use the `TresOrbitControls` component in your scene.
 
 Since [OrbitControls](https://threejs.org/docs/index.html?q=orbit#examples/en/controls/OrbitControls) needs a reference to the camera and the renderer, you need to pass them as arguments.
 
-You can use the [useThree](/api/composables#usethree) composable to get the camera and the renderer.
+You can use the [useTres](/api/composables#usetres) composable to get the camera and the renderer.
 
 ```ts
-import { useThree } from '@tresjs/core'
+import { useTres } from '@tresjs/core'
 
 const { state } = useTres()
 ```
@@ -54,12 +54,12 @@ So the final code would be something like this:
 
 ```vue
 <script setup lang="ts">
-import { extend } from '@tresjs/core'
+import { extend, useTres } from '@tresjs/core'
 import { OrbitControls } from 'three/addons/controls/OrbitControls'
 
 extend({ OrbitControls })
 
-const { state } = useThree()
+const { state } = useTres()
 </script>
 <template>
   <TresCanvas shadows alpha>

BIN
docs/public/blog/annoying-warning.png


+ 2 - 11
docs/vite.config.ts

@@ -2,12 +2,7 @@ import { defineConfig } from 'vite'
 import Unocss from 'unocss/vite'
 import svgLoader from 'vite-svg-loader'
 import Components from 'unplugin-vue-components/vite'
-
-const whitelist = [
-  'TresCanvas',
-  'TresLeches',
-  'TresScene',
-]
+import { templateCompilerOptions } from '@tresjs/core'
 
 export default defineConfig({
   plugins: [
@@ -23,10 +18,6 @@ export default defineConfig({
     }),
   ],
   vue: {
-    template: {
-      compilerOptions: {
-        isCustomElement: (tag: string) => tag.startsWith('Tres') && !whitelist.includes(tag) || tag === 'primitive',
-      },
-    },
+    ...templateCompilerOptions
   }
 })

+ 17 - 17
package.json

@@ -1,7 +1,7 @@
 {
   "name": "@tresjs/core",
   "description": "Declarative ThreeJS using Vue Components",
-  "version": "3.0.1",
+  "version": "3.1.0",
   "type": "module",
   "packageManager": "pnpm@8.3.1",
   "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
@@ -71,25 +71,25 @@
     "@huntersofbook/plausible-vue": "^1.0.0",
     "@release-it/conventional-changelog": "^7.0.0",
     "@stackblitz/sdk": "^1.9.0",
-    "@tresjs/cientos": "3.0.1",
-    "@types/three": "^0.154.0",
-    "@typescript-eslint/eslint-plugin": "^6.2.0",
-    "@typescript-eslint/parser": "^6.2.0",
-    "@vitejs/plugin-vue": "^4.2.3",
+    "@tresjs/cientos": "3.1.0",
+    "@types/three": "^0.155.1",
+    "@typescript-eslint/eslint-plugin": "^6.4.1",
+    "@typescript-eslint/parser": "^6.4.1",
+    "@vitejs/plugin-vue": "^4.3.3",
     "@vitest/coverage-c8": "^0.33.0",
-    "@vitest/ui": "^0.33.0",
+    "@vitest/ui": "^0.34.2",
     "@vue/test-utils": "^2.4.1",
-    "eslint": "^8.46.0",
-    "eslint-config-prettier": "^8.9.0",
-    "eslint-plugin-vue": "^9.16.1",
+    "eslint": "^8.47.0",
+    "eslint-config-prettier": "^9.0.0",
+    "eslint-plugin-vue": "^9.17.0",
     "esno": "^0.17.0",
     "gsap": "^3.12.2",
     "jsdom": "^22.1.0",
     "kolorist": "^1.8.0",
     "ohmyfetch": "^0.4.21",
     "pathe": "^1.1.1",
-    "prettier": "^3.0.0",
-    "release-it": "^16.1.3",
+    "prettier": "^3.0.2",
+    "release-it": "^16.1.5",
     "rollup-plugin-analyzer": "^4.0.0",
     "rollup-plugin-copy": "^3.4.0",
     "rollup-plugin-visualizer": "^5.9.2",
@@ -97,14 +97,14 @@
     "unocss": "^0.54.0",
     "unplugin": "^1.4.0",
     "unplugin-vue-components": "^0.25.1",
-    "vite": "^4.4.7",
+    "vite": "^4.4.9",
     "vite-plugin-banner": "^0.7.0",
-    "vite-plugin-dts": "3.4.0",
-    "vite-plugin-inspect": "^0.7.33",
+    "vite-plugin-dts": "3.5.2",
+    "vite-plugin-inspect": "^0.7.38",
     "vite-plugin-require-transform": "^1.0.21",
     "vite-svg-loader": "^4.0.0",
-    "vitepress": "1.0.0-beta.7",
-    "vitest": "^0.33.0",
+    "vitepress": "1.0.0-rc.4",
+    "vitest": "^0.34.2",
     "vue": "^3.3.4",
     "vue-demi": "^0.14.5"
   }

+ 3 - 2
playground/package.json

@@ -9,12 +9,13 @@
     "preview": "vite preview"
   },
   "dependencies": {
-    "@tresjs/cientos": "3.0.1",
+    "@tresjs/cientos": "3.1.0",
     "@tresjs/core": "workspace:3.0.1",
     "vue-router": "^4.2.4"
   },
   "devDependencies": {
-    "@tresjs/leches": "^0.5.0",
+    "@tresjs/leches": "^0.7.0",
+    "@tweakpane/plugin-essentials": "^0.2.0",
     "unplugin-auto-import": "^0.16.6",
     "vite-plugin-glsl": "^1.1.2",
     "vue-tsc": "^1.8.8"

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 216 - 242
pnpm-lock.yaml


+ 23 - 21
src/components/TresCanvas.vue

@@ -1,26 +1,26 @@
 <script setup lang="ts">
-import { extend } from '../core/catalogue'
-import { onMounted } from 'vue'
-import { createTres } from '../core/renderer'
-import { useTresContextProvider, type TresContext } from '../composables'
-import { App, Ref, computed, ref, shallowRef, watch, watchEffect } from 'vue'
 import {
-    Scene,
     PerspectiveCamera,
+    Scene,
     WebGLRendererParameters,
     type ColorSpace,
     type ShadowMapType,
     type ToneMapping,
 } from 'three'
+import { Ref, computed, onMounted, provide, ref, shallowRef, watch, watchEffect } from 'vue'
+import { useTresContextProvider, type TresContext } from '../composables'
+import { extend } from '../core/catalogue'
+import { render } from '../core/renderer'
 
 import {
     useLogger,
-    useRenderLoop,
     usePointerEventHandler,
+    useRenderLoop,
 } from '../composables'
 
-import type { TresCamera } from '../types/'
+import { Fragment, defineComponent, h } from 'vue'
 import type { RendererPresetsType } from '../composables/useRenderer/const'
+import type { TresCamera, TresObject } from '../types/'
 
 
 export interface TresCanvasProps extends Omit<WebGLRendererParameters, 'canvas'> {
@@ -65,22 +65,24 @@ const slots = defineSlots<{
     default(): any
 }>()
 
-
-let app: App
+const createInternalComponent = (context: TresContext) => {
+    return defineComponent({
+        setup() {
+            provide('useTres', context)
+            provide('extend', extend)
+            return () => h(Fragment, null, slots?.default ? slots.default() : [])
+        }
+    })
+}
 
 const mountCustomRenderer = (context: TresContext) => {
-    app = createTres(slots)
-    app.provide('useTres', context) // TODO obsolete?
-    app.provide('extend', extend)
-    app.mount(scene.value)
+    const InternalComponent = createInternalComponent(context)
+    render(h(InternalComponent), scene.value as unknown as TresObject)
 }
 
-const dispose = () => {
+const dispose = (context: TresContext) => {
     scene.value.children = []
-    app.unmount()
-    app = createTres(slots)
-    app.provide('extend', extend)
-    app.mount(scene.value)
+    mountCustomRenderer(context)
     resume()
 }
 
@@ -140,7 +142,7 @@ onMounted(() => {
     }
 
     if (import.meta.hot)
-        import.meta.hot.on('vite:afterUpdate', dispose)
+        import.meta.hot.on('vite:afterUpdate', () => dispose(context))
 })
 </script>
 <template>
@@ -156,4 +158,4 @@ onMounted(() => {
         zIndex: 1,
     }">
     </canvas>
-</template>
+</template>

+ 3 - 11
src/core/renderer.ts

@@ -1,20 +1,12 @@
 import * as THREE from 'three'
 
-import { createRenderer, Slots } from 'vue'
+import { createRenderer } from 'vue'
 import { extend } from './catalogue'
 import { nodeOps } from './nodeOps'
 
-export const { createApp } = createRenderer(nodeOps)
-
-export const createTres = (slots: Slots) => {
-  const app = createApp(internalFnComponent)
-  function internalFnComponent() {
-    return slots && slots.default ? slots.default() : []
-  }
-  return app
-}
+export const { render } = createRenderer(nodeOps)
 
 // Creates the catalogue of components based on THREE namespace
 extend(THREE)
 
-export default { createTres, extend }
+export default { extend }

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott