gpt4 book ai didi

javascript - Three.js 阴影不起作用

转载 作者:行者123 更新时间:2023-11-29 23:28:43 25 4
gpt4 key购买 nike

我正在测试 r82 版本的 Three.js 阴影效果,但不起作用。

看来我已经设置了所有必要的东西。

我找不到原因。

谁能告诉我是否忽略了什么。

示例如下:https://jsfiddle.net/JesseLuo/z1m6uffu/

var scene = new THREE.Scene()
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth /
window.innerHeight, 0.1, 1000 )
var renderer = new THREE.WebGLRenderer()

camera.position.set(2,2,2)
camera.lookAt(scene.position)

renderer.setSize(window.innerWidth, window.innerHeight)
renderer.shadowMap.enabled = true
renderer.shadowMap.type = THREE.PCFSoftShadowMap
document.body.appendChild(renderer.domElement)

var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.6 );
directionalLight.position.set( 3, 10, 5 );
directionalLight.castShadow = true
directionalLight.shadowCameraVisible = true;
scene.add( directionalLight );

directionalLight.shadow.mapSize.width = 512; // default
directionalLight.shadow.mapSize.height = 512; // default
directionalLight.shadow.camera.near = 0.1; // default
directionalLight.shadow.camera.far = 500;

var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshPhongMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh( geometry, material );
cube.castShadow = true
scene.add( cube );

var planeGeometry = new THREE.PlaneGeometry(10,10,10)
var plane = new THREE.Mesh(planeGeometry, material)
plane.rotateX(-0.5*Math.PI)
plane.position.y = -0.5
plane.receiveShadow = true
scene.add(plane)

var animate = function () {
requestAnimationFrame( animate );

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

renderer.render(scene, camera);
};

animate()

最佳答案

planecube 使用相同的材​​料似乎会导致问题。我不知道为什么会这样。

给飞机添加一个新 Material ,应该没问题。

var material2 = new THREE.MeshPhongMaterial({ color: 0x00ffaa });
var plane = new THREE.Mesh(planeGeometry, material2)

顺便说一下,有一个警告:THREE.Light: .shadowCameraVisible has been removed.

关于javascript - Three.js 阴影不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48091718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com