Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/179-tweakpane-plugin-essentials
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Aug 25, 2023
2 parents 6797d6b + 5f60864 commit 76fc415
Show file tree
Hide file tree
Showing 16 changed files with 661 additions and 571 deletions.
9 changes: 5 additions & 4 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export default defineConfig({
{
text: 'Materials',
collapsed: true,
items: [{ text: 'WobbleMaterial', link: '/guide/materials/wobble-material' }],
items: [
{ text: 'WobbleMaterial', link: '/guide/materials/wobble-material' },
{ text: 'MeshGlassMaterial', link: '/guide/materials/glass-material' },
],
},
{
text: 'Shapes',
Expand All @@ -89,9 +92,7 @@ export default defineConfig({
{
text: 'Staging',
collapsed: true,
items: [
{ text: 'Backdrop', link: '/guide/staging/backdrop' },
]
items: [{ text: 'Backdrop', link: '/guide/staging/backdrop' }],
},
{
text: 'Misc',
Expand Down
57 changes: 57 additions & 0 deletions docs/guide/materials/glass-material.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# MeshGlassMaterial

![](/cientos/glass-material.gif)

The `cientos` package provides a new`<MeshGlassMaterial />` component that makes a geometry look like glass. This is achieved by re-defining the `MeshPhysicalMaterial` so all the default props can be passed normally.

## Usage

### You can use it like you normally do with TresJs

```html
<TresMesh>
<TresTorusGeometry />
<MeshGlassMaterial />
</TresMesh>
```

### You can also replace the material of an existing mesh like this:

```vue{3}
<script setup lang="ts">
import { ref, shallowRef, watch } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { MeshGlassMaterial, Box } from '@tresjs/cientos'
const glassMaterialRef = shallowRef()
const boxRef = shallowRef()
watch(glassMaterialRef, value => {
// For good practice we dispose the old material
boxRef.value.value.material.dispose()
// We assign the new MeshGlassMaterialClass
boxRef.value.value.material = value.MeshGlassMaterialClass
})
</script>
<template>
<TresMesh>
<TresTorusGeometry />
<MeshGlassMaterial ref="glassMaterialRef" />
</TresMesh>
<!-- Mesh to be replaced -->
<TresMesh ref="boxRef">
<TresBoxGeometry />
<MeshBasicMaterial />
</TresMesh>
</template
```
## Tips

For more fine tuning effects you can provide an environment map texture as an envMap and play with the intensity to achieve a more realistic effect

Also, another good option is to provide a normal texture as clearcoatNormalMap to add different results

You can find more information in the official [ThreeJs docs](https://threejs.org/docs/index.html?q=phys#api/en/materials/MeshPhysicalMaterial).
You can play with this [example](https://playground.tresjs.org/experiments/glass-material) and be inspired.
Also worth checking is this [blog](https://tympanus.net/codrops/2021/10/27/creating-the-effect-of-transparent-glass-and-plastic-in-three-js/)
Binary file added docs/public/cientos/glass-material.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
},
"peerDependencies": {
"three": ">=0.133",
"tweakpane": ">=4.0.0",
"tweakpane": ">=3.0.0",
"vue": ">=3.3"
},
"devDependencies": {
"@alvarosabu/prettier-config": "^1.3.0",
"@release-it/conventional-changelog": "^7.0.0",
"@tweakpane/core": "^2.0.0",
"@tweakpane/plugin-essentials": "^0.2.0",
"@types/node": "^20.5.3",
"@tweakpane/core": "^1.1.9",
"@tweakpane/plugin-essentials": "^0.1.8",
"@types/node": "^20.5.4",
"@types/three": "^0.155.1",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
Expand All @@ -73,16 +73,16 @@
"tweakpane": "^3.1.10",
"typescript": "^5.1.6",
"unocss": "^0.54.0",
"vite": "^4.4.7",
"vite": "^4.4.9",
"vite-plugin-banner": "^0.7.0",
"vite-plugin-dts": "3.3.1",
"vite-plugin-dts": "3.5.2",
"vite-svg-loader": "^4.0.0",
"vitepress": "1.0.0-beta.6"
"vitepress": "1.0.0-rc.4"
},
"dependencies": {
"@tresjs/core": "3.1.0",
"@vueuse/core": "^10.3.0",
"camera-controls": "^2.7.1",
"three-stdlib": "^2.23.13"
"three-stdlib": "^2.25.0"
}
}
3 changes: 2 additions & 1 deletion playground/.eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"watchEffect": true,
"watchPostEffect": true,
"watchSyncEffect": true,
"toValue": true
"toValue": true,
"WritableComputedRef": true
}
}
2 changes: 1 addition & 1 deletion playground/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ declare global {
// for type re-export
declare global {
// @ts-ignore
export type { Component, ComponentPublicInstance, ComputedRef, InjectionKey, PropType, Ref, VNode } from 'vue'
export type { Component, ComponentPublicInstance, ComputedRef, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
}
4 changes: 2 additions & 2 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"preview": "vite preview"
},
"dependencies": {
"@tresjs/core": "3.0.1",
"@tresjs/core": "3.1.0",
"vue-router": "^4.2.4"
},
"devDependencies": {
"@tresjs/leches": "^0.4.0",
"@tresjs/leches": "^0.7.0",
"unplugin-auto-import": "^0.16.6",
"unplugin-vue-components": "^0.25.1",
"vite-plugin-glsl": "^1.1.2",
Expand Down
46 changes: 46 additions & 0 deletions playground/src/components/GlassMaterialDemo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script setup lang="ts">
import { ref, shallowRef, watch } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { OrbitControls, MeshGlassMaterial, Box, Sphere } from '@tresjs/cientos'
import { BasicShadowMap, SRGBColorSpace, NoToneMapping } from 'three'
const gl = {
clearColor: '#82DBC5',
shadows: true,
alpha: false,
shadowMapType: BasicShadowMap,
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}
const context = ref()
const glassMaterialRef = shallowRef()
const boxRef = shallowRef()
watch(glassMaterialRef, value => {
boxRef.value.value.material.dispose()
boxRef.value.value.material = value.MeshGlassMaterialClass
})
</script>

<template>
<TresCanvas v-bind="gl" ref="context">
<TresPerspectiveCamera :position="[3, 3, 3]" />
<TresMesh :position-x="3">
<TresTorusKnotGeometry :args="[1, 0.4, 256, 20]" />
<MeshGlassMaterial ref="glassMaterialRef" />
</TresMesh>
<Sphere :scale="0.5">
<MeshGlassMaterial />
</Sphere>
<Box ref="boxRef" :position-x="-3" />
<TresMesh :position="[0, 0, -1]">
<TresPlaneGeometry :args="[3, 3]" />
<TresMeshBasicMaterial :color="0xff1111" />
</TresMesh>
<TresGridHelper :args="[10, 10]" />
<TresAmbientLight :intensity="1" />
<TresDirectionalLight :intensity="1" :position="[2, 2, 2]" />
<OrbitControls />
</TresCanvas>
</template>
6 changes: 3 additions & 3 deletions 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>
<UseVideoTextureDemo />
</Suspense>
<Suspense>
<GlassMaterialDemo />
</Suspense>
</template>
39 changes: 39 additions & 0 deletions playground/vite.config.ts.timestamp-1692851323714-59f8a1cdcae6.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// vite.config.ts
import { defineConfig } from "file:///Users/alvarosabu/Projects/tres/cientos/node_modules/.pnpm/vite@4.4.9_@types+node@20.5.4/node_modules/vite/dist/node/index.js";
import vue from "file:///Users/alvarosabu/Projects/tres/cientos/node_modules/.pnpm/@vitejs+plugin-vue@4.3.3_vite@4.4.9_vue@3.3.4/node_modules/@vitejs/plugin-vue/dist/index.mjs";
import AutoImport from "file:///Users/alvarosabu/Projects/tres/cientos/node_modules/.pnpm/unplugin-auto-import@0.16.6_@vueuse+core@10.3.0/node_modules/unplugin-auto-import/dist/vite.js";
import Components from "file:///Users/alvarosabu/Projects/tres/cientos/node_modules/.pnpm/unplugin-vue-components@0.25.1_vue@3.3.4/node_modules/unplugin-vue-components/dist/vite.mjs";
import { resolve } from "file:///Users/alvarosabu/Projects/tres/cientos/node_modules/.pnpm/pathe@1.1.1/node_modules/pathe/dist/index.mjs";
import glsl from "file:///Users/alvarosabu/Projects/tres/cientos/node_modules/.pnpm/vite-plugin-glsl@1.1.2_vite@4.4.9/node_modules/vite-plugin-glsl/src/index.js";
import UnoCSS from "file:///Users/alvarosabu/Projects/tres/cientos/node_modules/.pnpm/unocss@0.54.0_postcss@8.4.28_vite@4.4.9/node_modules/unocss/dist/vite.mjs";
import { templateCompilerOptions } from "file:///Users/alvarosabu/Projects/tres/cientos/node_modules/.pnpm/@tresjs+core@3.0.1_three@0.155.0_vue@3.3.4/node_modules/@tresjs/core/dist/tres.js";
var __vite_injected_original_dirname = "/Users/alvarosabu/Projects/tres/cientos/playground";
var vite_config_default = defineConfig({
plugins: [
glsl(),
vue(templateCompilerOptions),
AutoImport({
dts: true,
eslintrc: {
enabled: true
// <-- this
},
imports: ["vue"]
}),
Components({
/* options */
}),
UnoCSS({
/* options */
})
],
resolve: {
alias: {
"@tresjs/cientos": resolve(__vite_injected_original_dirname, "../src/")
}
}
});
export {
vite_config_default as default
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCIvVXNlcnMvYWx2YXJvc2FidS9Qcm9qZWN0cy90cmVzL2NpZW50b3MvcGxheWdyb3VuZFwiO2NvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9maWxlbmFtZSA9IFwiL1VzZXJzL2FsdmFyb3NhYnUvUHJvamVjdHMvdHJlcy9jaWVudG9zL3BsYXlncm91bmQvdml0ZS5jb25maWcudHNcIjtjb25zdCBfX3ZpdGVfaW5qZWN0ZWRfb3JpZ2luYWxfaW1wb3J0X21ldGFfdXJsID0gXCJmaWxlOi8vL1VzZXJzL2FsdmFyb3NhYnUvUHJvamVjdHMvdHJlcy9jaWVudG9zL3BsYXlncm91bmQvdml0ZS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