Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LocalClippingEnabled #684

Open
5 tasks done
hthaigler opened this issue May 16, 2024 · 1 comment
Open
5 tasks done

LocalClippingEnabled #684

hthaigler opened this issue May 16, 2024 · 1 comment

Comments

@hthaigler
Copy link

Describe the bug

I am trying to clip materials using local clipping planes, but no matter what I do, I am not able to access the localClippingEnabled attribute on the instance of the WebGLRenderer.

I think the most simple solution would be:

<TresCanvas ref="canvas" :shadows="true"  :local-clipping-enabled="true">
</TresCanvas>

... but this is not working.

I've tried using:

const { renderer } = useTresContext()
renderer.value.localClippingEnabled = true

but I get this error:

Uncaught TypeError: Cannot read properties of undefined (reading 'x')

Reproduction

https://stackblitz.com/edit/tresjs-basic-eaxcaf?file=src%2Fcomponents%2FTheExperience.vue

Steps to reproduce

No response

System Info

No response

Used Package Manager

npm

Code of Conduct

@JaimeTorrealba
Copy link
Member

JaimeTorrealba commented May 27, 2024

Hi I got this.

You can enable the localClippingEnabled by using the template ref (like in my example) or by using useTresContext

But I believe you got another problem related to the bound of clippingPlane null to the material.

<script setup lang="ts">
import { reactive, ref, shallowRef, watch } from 'vue';
import { BasicShadowMap, SRGBColorSpace, NoToneMapping } from 'three';
import { TresCanvas, vLog } from '@tresjs/core';
import { OrbitControls, ContactShadows } from '@tresjs/cientos';

const gl = {
  clearColor: '#82DBC5',
  shadows: true,
  alpha: false,
  shadowMapType: BasicShadowMap,
  outputColorSpace: SRGBColorSpace,
  toneMapping: NoToneMapping,
};

const clippingPlane = ref(null);

const ctxRef = shallowRef();

watch(ctxRef, (ctx) => {
  const { renderer } = ctx.context;
  renderer.value.localClippingEnabled = true;
  console.log(renderer.value.localClippingEnabled);
});
</script>

<template>
  <TresCanvas v-bind="gl" ref="ctxRef">
    <TresPerspectiveCamera :position="[9, 9, 9]" />
    <OrbitControls />
    <TresMesh>
      <TresBoxGeometry :args="[1, 1, 1]" />
      <TresMeshNormalMaterial /> // If I leave the null bound here throw error
    </TresMesh>
    <TresMesh :position="[0, 0.25, 0]" :rotation="[-Math.PI / 2, 0, 0]">
      <TresPlaneGeometry ref="clippingPlane" :args="[2, 2]" />
      <TresMeshBasicMaterial color="#555" :side="DoubleSide" />
    </TresMesh>
    <ContactShadows />
    <TresDirectionalLight :position="[0, 2, 4]" :intensity="1.2" cast-shadow />
  </TresCanvas>
</template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants