微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Three.js - 仅在某些对象上使用模板

如何解决Three.js - 仅在某些对象上使用模板

我正在考虑使用 Three.js 制作一种门户效果

主要思想是能够通过多个窗口看到另一个场景。

就像在这个例子中一样: https://www.ronja-tutorials.com/post/022-stencil-buffers/(请参阅文章中的 gif,太大无法在此处上传

我找到了一个使用three.js尝试做的事情的确切示例。

这是链接https://sites.google.com/site/cgwith3js/home/masking-with-stencil

小提琴不起作用,但我对其进行了更改以使其起作用: http://jsfiddle.net/yzhreu6p/23/

  scene = new THREE.Scene();
  scenestencil = new THREE.Scene();
...
  scene.add(Box); // red one
...
  function animate() {

  requestAnimationFrame(animate);
  renderer.clear();
    
  // animate the Box
  Box.position.x = Math.cos(clock.getelapsedtime()) * 10;

  var gl = renderer.getContext();

  // enable stencil test
  gl.enable(gl.STENCIL_TEST);
  //renderer.state.setStencilTest( true );

  // config the stencil buffer to collect data for testing
  gl.stencilFunc(gl.ALWAYS,1,0xff);
  gl.stencilOp(gl.REPLACE,gl.REPLACE,gl.REPLACE);

    // render shape for stencil test
  renderer.render(scenestencil,camera);
  
  // set stencil buffer for testing
  gl.stencilFunc(gl.EQUAL,0xff);
  gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP);

  // render actual scene
  renderer.render(scene,camera);

  // disable stencil test
  gl.disable(gl.STENCIL_TEST);
  }

然后我在我的项目中重用了代码,在那里我有一个有建筑物的城镇,并且隐藏的场景有一个 nyan cat 纹理框。

我遇到的问题是当建筑物在后面时飞机会消失,更严重的问题是,当建筑物后面有 nyan cat 纹理时,我们会看到建筑物中的纹理。

为了更好地解释这里是一个 image

我正在寻找图像在建筑物内不可见的解决方案,我发现有人在谈论 stencilMask,但它对我来说是新的。

我是否需要创建另一个场景才能使其独立工作?

如果有人可以帮助我,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。