The cientos package provides a new<MeshGlassMaterial /> component that makes a geometry look like glass. This is achieved by re-defining the MeshPhysicalMaterial.
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { MeshGlassMaterial } from '@tresjs/cientos'
</script>
<template>
<TresCanvas>
<TresPerspectiveCamera :position="[3, 3, 3]" :look-at="[0, 0, 0]" />
<TresMesh>
<TresTorusGeometry />
<MeshGlassMaterial />
</TresMesh>
<TresAmbientLight />
<TresDirectionalLight :position="[0, 2, 4]" />
</TresCanvas>
</template>
No props are required. The component extends THREE.MeshPhysicalMaterial and accepts all the same props plus additional reflection-specific properties.
<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.instance.material.dispose()
// We assign the new MeshGlassMaterialClass
boxRef.value.instance.material = value.MeshGlassMaterialClass
})
</script>
<template>
<TresMesh>
<TresTorusGeometry />
<MeshGlassMaterial ref="glassMaterialRef" />
</TresMesh>
<!-- Mesh to be replaced -->
<TresMesh ref="boxRef">
<TresBoxGeometry />
<MeshBasicMaterial />
</TresMesh>
</template>