1
嗨我創建了一個環境貼圖,它可以縫合6張圖像來創建房間,我在房間裏有一個物體會投下陰影,以使其看起來貼在地板上,但我仍然獲得對象在3D空間中浮動的效果。有沒有一種方法可以解決這個問題,將物體粘貼到地面上。記住env地圖在攝像機位置周圍呈現。將物體貼到環境地圖上
- example1.js
function envMap(scene) {
var testMaterials = [
'image1.png',
'image2.png',
'image3.png',
'image4.png',
'image5.png',
'image6.png'
];
reflectionCube = new THREE.CubeTextureLoader().load(cubeMaterials);
reflectionCube.format = THREE.RGBFormat;
scene.background = reflectionCube;
}
- example1.html的
<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no,
minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
margin: 0px;
background-color: #000000;
overflow: hidden;
}
</style>
</head>
<body>
<script src="three.js"></script>
<script>
var camera, scene, renderer;
var mesh;
init();
animate();
function init() {
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
.shadowMap.type = THREE.PCFShadowMap;
scene = new THREE.Scene();
envMap(scene);
document.body.appendChild(renderer.domElement);
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
</script>
</body>
</html>
對不起。我的代碼確實有用,我把它作爲一個例子寫下來,忘記了這些事情。我有點希望人們明白我在試圖解決問題的方法。測試代碼。至少我的理解是爲了讓人們瞭解我想要做的事情。我不認爲它需要100%可用 – electronduck