我试图让MeshNormalMaterial与物体对齐,而不是与相机对齐.据我所知,设置.normalMapType = THREE.ObjectSpaceNormalMap应该做到这一点.但事实并非如此.

为了让这一切顺利进行,我有没有遗漏什么或其他 Select ?

const scene = new THREE.Scene();

const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
camera.position.applyAxisAngle(new THREE.Vector3(1, 0, 0), 0.3);

const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

window.addEventListener('resize', () => {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();

  renderer.setSize(window.innerWidth, window.innerHeight);
}, false);

const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshNormalMaterial();
material.normalMapType = THREE.ObjectSpaceNormalMap;
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);

const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.update();

function animate() {
    requestAnimationFrame(animate);

    //cube.rotation.x += 0.01;
    cube.rotation.y += 0.01;

    controls.update();
    
    renderer.render(scene, camera);
};

animate();
body { margin: 0; overflow: hidden; background: black; }
<script src="https://unpkg.com/three@0.140.2/build/three.js"></script>
<script src="https://unpkg.com/three@0.140.2/examples/js/controls/OrbitControls.js"></script>

推荐答案

据我所知,这是一个背景.normalMapType=3.ObjectSpaceNormalMap应该能做到这一点.

normalMapType确定法线贴图的类型(切线与对象空间).您没有使用法线贴图,因此此属性与您的用例无关.

您试图达到的效果无法配置为MeshNormalMaterial.你必须自己实现一个自定义着色器.

Javascript相关问答推荐

如何使用侧边滚动按钮具体滚动每4个格?

如何在RTK上设置轮询,每24小时

调用removeEvents不起作用

WebRTC关闭navigator. getUserMedia正确

使用Java脚本根据按下的按钮更改S文本

Html文件和客户端存储的相关问题,有没有可能?

使用Google API无法进行Web抓取

从页面到应用程序(NextJS):REST.STATUS不是一个函数

在FAQ Accodion应用程序中使用React useState时出现问题

如何使用Astro优化大图像?

在Vercel中部署Next.js项目时获取`ReferenceError:未定义文档`

通过跳过某些元素的对象进行映射

JAVASCRIPT SWITCH CASE语句:当表达式为';ALL';

如何在FiRestore中的事务中使用getCountFromServer

在高位图中显示每个y轴系列的多个值

将字体样式应用于material -UI条形图图例

使用Java脚本替换字符串中的小文本格式hashtag

对象作为react 子对象无效(已找到:具有键的对象{type,props}).如果要呈现一个子级集合,请改用数组

在D3.js中创建具有旋转手柄的可拖动、可调整大小的框?

无限循环,因为变量不断被重新声明为其原始值