I'm having trouble getting the MeshNormalMaterial
to stay aligned with the object instead of the camera. I set
.normalMapType = THREE.ObjectSpaceNormalMap
, but it doesn't seem to be working as expected.
Is there something crucial that I might be overlooking, or is there an alternative method to achieve this?
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/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="52263a20373712627c6">[email protected]</a>@build/three.js"></script>
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f88c908a9d9db8c8">[email protected]</a>/examples/js/controls/OrbitControls.js"></script>