Skip to content

Commit

Permalink
Merge branch 'main' into v4
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Feb 2, 2024
2 parents 08717ef + 91e047a commit 898a8b1
Show file tree
Hide file tree
Showing 31 changed files with 1,588 additions and 1,110 deletions.
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
## [3.7.0](https://github.com/Tresjs/tres/compare/3.6.1...3.7.0) (2024-01-29)


## [4.0.0-next.0](https://github.com/Tresjs/tres/compare/3.6.0...4.0.0-next.0) (2023-12-22)
### Features

* 474 vue chrome devtools plugin ([#526](https://github.com/Tresjs/tres/issues/526)) ([0185bfa](https://github.com/Tresjs/tres/commit/0185bfa6f04faff5eabbc526616713ef7747ebeb))
* 524 feat add directives to core ([#525](https://github.com/Tresjs/tres/issues/525)) ([5268e9f](https://github.com/Tresjs/tres/commit/5268e9f13bf65c61d5ddfe7153b71b335449b81d))


### Features
### Bug Fixes

* 474 vue chrome devtools plugin ([#479](https://github.com/Tresjs/tres/issues/479)) ([224ab06](https://github.com/Tresjs/tres/commit/224ab06a4404e2ae5a0cbd2f43041961862b09fd))

* **docs:** change image path to silence warning ([#519](https://github.com/Tresjs/tres/issues/519)) ([280d248](https://github.com/Tresjs/tres/commit/280d2482760bde1032e24c4a9e96af4beea954ed))

## [3.6.1](https://github.com/Tresjs/tres/compare/3.6.0...3.6.1) (2024-01-16)

Expand Down
38 changes: 29 additions & 9 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,48 @@ export default defineConfig({
},
],
},

{
text: 'Advanced',

items: [
{ text: 'Extending', link: '/advanced/extending' },
{ text: 'primitive', link: '/advanced/primitive' },
{ text: 'Performance', link: '/advanced/performance' },
{
text: 'Caveats',
link: '/advanced/caveats',
},
],
},
{
text: 'Debug',
items: [
{ text: 'Devtools', link: '/debug/devtools' },
],
},
{
text: 'Examples',
collapsed: true,
items: [
{ text: 'Orbit Controls', link: '/examples/orbit-controls' },
{ text: 'Basic Animations', link: '/examples/basic-animations' },
{ text: 'Groups', link: '/examples/groups' },
{ text: 'Load Textures', link: '/examples/load-textures' },
{ text: 'Load Models', link: '/examples/load-models' },
{ text: 'Load Text', link: '/examples/text-3d' },
{ text: 'Lights & Shadows', link: '/examples/lights-shadows' },
{ text: 'Shaders', link: '/examples/shaders' },
],
},
{
text: 'Advanced',

text: 'Directives',
collapsed: true,
items: [
{ text: 'Extending', link: '/advanced/extending' },
{ text: 'primitive', link: '/advanced/primitive' },
{ text: 'Performance', link: '/advanced/performance' },
{
text: 'Caveats',
link: '/advanced/caveats',
},
{ text: 'v-log', link: '/directives/v-log' },
{ text: 'v-light-helper', link: '/directives/v-light-helper' },
{ text: 'v-always-look-at', link: '/directives/v-always-look-at' },
{ text: 'v-distance-to', link: '/directives/v-distance-to' },
],
},
{
Expand Down
28 changes: 28 additions & 0 deletions docs/debug/devtools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Devtools



One of the most difficult things a developer faces when creating 3D experiences on the browser is debugging. The browser `canvas` is a black box, and it's hard to know what's going on inside. The imperative nature of [ThreeJS](https://threejs.org/) makes it incredibly difficult to debug, having to depend on `console.log` to see what's going on, or third party to fine-tune and inspect the scene.

Don't make me get started with checking the performance of your scene. 😱

![developer debugging 3D](/debug-3D.png)

One of our goals with TresJS is to offer **the best DX (Developer Experience)** when dealing with 3D scenes on the browser. Thanks to the declarative nature of the ecosystem plus the variety of solutions the Vue ecosystem offers such as the Vue Devtools, Nuxt and Vite, we can offer a better tooling for devs to debug their scenes.

## Introducing the Devtools

From <Badge text="^3.7.0" /> we are introducing the TresJS Devtools, a customized inspector tab for the [Official Vue Chrome Devtools](https://devtools.vuejs.org/guide/installation.html) that allows you to inspect your TresJS scenes and components.

![TresJS Devtools](/vue-chrome-devtools.png)

### Features

- **Scene Inspector**: Inspect the current scene and its components using a tree view similar to the Vue Devtools component inspector.
- **Memory Allocation**: See how much memory is being by the components.
- **Object Inspector**: Inspect the properties of the selected object in the scene, including its children.
- **Editable Properties**: And yes, you can edit the properties of the selected object and see the changes in real-time.

![](/devtools-scene-inspector.png)

Enjoy the new Devtools and let us know what you think! 🎉
61 changes: 61 additions & 0 deletions docs/directives/v-always-look-at.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# v-always-look-at 👀

With the new directive v-always-look-at provided by **TresJS**, you can add easily command an [Object3D](https://threejs.org/docs/index.html?q=object#api/en/core/Object3D) to always look at a specific position, this could be passed as a Vector3 or an Array.

## Usage

```vue{3,9}
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { Box, vAlwaysLookAt } from '@tresjs/cientos'
</script>
<template>
<TresCanvas >
<TresPerspectiveCamera :position="[0, 2, 5]" />
<Box
v-always-look-at="new Vector3(0, 0, 0)"
/>
</TresCanvas>
</template>
```
No matter where the Box move will always look-at the position [0,0,0]

### Why not use the in built method look-at?

You could ask, this is fine but I can use the `:look-at` method directly in the component, why should I need this?

The answers is that with the method `:look-at` you will indicated to look at that position just once, when the instance is mounted, then if the object changes this will not get updated

### You can look at other instance too!

Another advantage is that you can look at an instance in movement, for example with the camera, like so:

```vue{4,6,20,23}
<script setup lang="ts">
import { shallowRef } from 'vue'
import { TresCanvas, useRenderLoop } from '@tresjs/core'
import { Box, vAlwaysLookAt } from '@tresjs/cientos'
const sphereRef = shallowRef()
const { onLoop } = useRenderLoop()
// here we update the position of the sphere and the camera will always follow the object
onLoop(({ elapsed }) => {
if (sphereRef.value) {
sphereRef.value.value.position.y = Math.sin(elapsed) * 1.5
}
})
</script>
<template>
<TresCanvas >
<TresPerspectiveCamera :position="[0, 2, 5]"
v-always-look-at="sphereRef"
/>
<Sphere
ref="sphereRef"
:scale="0.5"
/>
</TresCanvas>
</template>
```
36 changes: 36 additions & 0 deletions docs/directives/v-distance-to.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# v-distance-to

Have you tried to calculate the distance between two Object3Ds?

With the new directive `v-distance-to` it's easier than ever, you should only indicate the target object to perform the measure and the result will appear in your console.

In addition, an arrow will be created to indicate which objects you're measuring.

```vue{2,8,13}
<script setup lang="ts">
import { OrbitControls, Sphere, vLog } from '@tresjs/cientos'
</script>
<template>
<TresCanvas v-bind="gl">
<TresPerspectiveCamera :position="[0, 2, 5]" />
<Sphere
ref="sphere1Ref"
:position="[-2, slider, 0]"
:scale="0.5"
/>
<Sphere
v-distance-to="sphere1Ref"
:position="[2, 0, 0]"
:scale="0.5"
/>
<TresGridHelper :args="[10, 10]" />
<OrbitControls />
</TresCanvas>
</template>
```

The use of `v-distance-to` is reactive, so it works perfectly with @tres/leches 🍰.

::: warning
`v-distance-to` will not measure an object in movement within the renderLoop.
:::
34 changes: 34 additions & 0 deletions docs/directives/v-light-helper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# v-light-helper 🔆

With the new directive v-light-helper provided by **TresJS**, you can add fast the respective helper to your lights with just one line of code 😍.

The following lights are supported:
- DirectionalLight
- PointLight
- SpotLight
- HemisphereLight

## Usage

```vue{2,8,11,14,17}
<script setup lang="ts">
import { OrbitControls, Sphere, vLightHelper } from '@tresjs/cientos'
</script>
<template>
<TresCanvas >
<TresPerspectiveCamera :position="[0, 2, 5]" />
<TresDirectionalLight
v-light-helper
/>
<TresPointLight
v-light-helper
/>
<TresSpotLight
v-light-helper
/>
<TresHemisphereLight
v-light-helper
/>
</TresCanvas>
</template>
```
53 changes: 53 additions & 0 deletions docs/directives/v-log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# v-log

### Problem

When you have to log your instance you have to use the template reference and then log them:

```vue
<script setup lang="ts">
import { shallowRef, watch } from 'vue'
const sphereRef = shallowRef()
watch(sphereRef, (value) => {
console.log(value) // Really for a log?!!! 😫
})
</script>
<template>
<TresCanvas>
<TresPerspectiveCamera :position="[0, 2, 5]" />
<Sphere
ref="sphereRef"
:scale="0.5"
/>
<OrbitControls />
</TresCanvas>
</template>
```

And is A LOT of code just for a simple log right?

## Usage

With the new directive v-log provided by **TresJS**, you can do this by just adding `v-log` to the instance.

```vue{2,10,12}
<script setup lang="ts">
import { OrbitControls, Sphere, vLog } from '@tresjs/cientos'
</script>
<template>
<TresCanvas >
<TresPerspectiveCamera :position="[0, 2, 5]" />
<Sphere
ref="sphereRef"
:scale="0.5"
v-log:material <!-- will print just the material 🎉 -->
/>
<OrbitControls v-log />
</TresCanvas>
</template>
```

Note that you can pass a modifier with the name of a property, for example `v-log:material`, and will log directly the `material` property 😍
Loading

0 comments on commit 898a8b1

Please sign in to comment.